From afdc80629fc62f4cd0668f53e61a1a2c39951aa7 Mon Sep 17 00:00:00 2001
From: Jeremy Soller <jackpot51@gmail.com>
Date: Tue, 27 Mar 2018 20:14:22 -0600
Subject: [PATCH] Fix Makefile spurious rebuilds Add mem* functions to stdio
 Add constant int functions

---
 Makefile                 |  5 +++++
 include/bits/string.h    |  9 +++++++++
 include/stdint.h         | 26 ++++++++++++++++++--------
 src/mman/cbindgen.toml   |  2 +-
 src/string/cbindgen.toml |  1 +
 5 files changed, 34 insertions(+), 9 deletions(-)
 create mode 100644 include/bits/string.h

diff --git a/Makefile b/Makefile
index 39a070185..48323ac90 100644
--- a/Makefile
+++ b/Makefile
@@ -49,21 +49,26 @@ test: all
 
 $(BUILD)/debug/libc.a: $(SRC)
 	cargo build $(CARGOFLAGS)
+	touch $@
 
 $(BUILD)/debug/crt0.o: $(SRC)
 	cargo rustc --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@
+	touch $@
 
 $(BUILD)/release/libc.a: $(SRC)
 	cargo build --release $(CARGOFLAGS)
+	touch $@
 
 $(BUILD)/release/crt0.o: $(SRC)
 	cargo rustc --release --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@
+	touch $@
 
 $(BUILD)/openlibm: openlibm
 	rm -rf $@ $@.partial
 	mkdir -p $(BUILD)
 	cp -r $< $@.partial
 	mv $@.partial $@
+	touch $@
 
 $(BUILD)/openlibm/libopenlibm.a: $(BUILD)/openlibm
 	make CC=$(CC) CFLAGS=-fno-stack-protector -C $< libopenlibm.a
diff --git a/include/bits/string.h b/include/bits/string.h
new file mode 100644
index 000000000..f3a5b1684
--- /dev/null
+++ b/include/bits/string.h
@@ -0,0 +1,9 @@
+#ifndef _BITS_STDIO_H
+#define _BITS_STDIO_H
+
+int memcmp(const void *s1, const void *s2, size_t n);
+void *memcpy(void *dest, const void *src, size_t n);
+void *memmove(void *dest, const void *src, size_t n);
+void *memset(void *s, int c, size_t n);
+
+#endif /* _BITS_STDIO_H */
diff --git a/include/stdint.h b/include/stdint.h
index faf369343..69d7e5529 100644
--- a/include/stdint.h
+++ b/include/stdint.h
@@ -1,54 +1,64 @@
 #ifndef _STDINT_H
 #define _STDINT_H
 
+#define INT8_C(value) ((int8_t) value)
 #define INT8_MIN -0x80
 #define INT8_MAX 0x7F
 typedef signed char int8_t;
 
+#define UINT8_C(value) ((uint8_t) __CONCAT(value, U))
 #define UINT8_MIN 0x00
 #define UINT8_MAX 0xFF
 typedef unsigned char uint8_t;
 
+#define INT16_C(value) value
 #define INT16_MIN -0x8000
 #define INT16_MAX 0x7FFF
 typedef signed short int16_t;
 
+#define UINT16_C(value) __CONCAT(value, U)
 #define UINT16_MIN 0x0000
 #define UINT16_MAX 0xFFFF
 typedef unsigned short uint16_t;
 
+#define INT32_C(value) __CONCAT(value, L)
 #define INT32_MIN -0x80000000
 #define INT32_MAX 0x7FFFFFFF
 typedef signed long int32_t;
 
+#define UINT32_C(value) __CONCAT(value, UL)
 #define UINT32_MIN 0x00000000
 #define UINT32_MAX 0xFFFFFFFF
 typedef unsigned long uint32_t;
 
+#define INT64_C(value) __CONCAT(value, LL)
 #define INT64_MIN -0x8000000000000000
 #define INT64_MAX 0x7FFFFFFFFFFFFFFF
 typedef signed long long int64_t;
 
+#define UINT64_C(value) __CONCAT(value, ULL)
 #define UINT64_MIN 0x0000000000000000
 #define UINT64_MAX 0xFFFFFFFFFFFFFFFF
 typedef unsigned long long uint64_t;
 
-#define INTPTR_MIN INT64_MIN
-#define INTPTR_MAX INT64_MAX
-typedef int64_t intptr_t;
-
-#define UINTPTR_MIN UINT64_MIN
-#define UINTPTR_MAX UINT64_MAX
-typedef uint64_t uintptr_t;
-
+#define INTMAX_C(value) __CONCAT(value, LL)
 #define INTMAX_MIN INT64_MIN
 #define INTMAX_MAX INT64_MAX
 typedef int64_t intmax_t;
 
+#define UINTMAX_C(value) __CONCAT(value, ULL)
 #define UINTMAX_MIN UINT64_MIN
 #define UINTMAX_MAX UINT64_MAX
 typedef uint64_t uintmax_t;
 
+#define INTPTR_MIN INT64_MIN
+#define INTPTR_MAX INT64_MAX
+typedef int64_t intptr_t;
+
+#define UINTPTR_MIN UINT64_MIN
+#define UINTPTR_MAX UINT64_MAX
+typedef uint64_t uintptr_t;
+
 #define SIZE_MAX UINT64_MAX
 
 #endif /* _STDINT_H */
diff --git a/src/mman/cbindgen.toml b/src/mman/cbindgen.toml
index 783348bac..9858a56ae 100644
--- a/src/mman/cbindgen.toml
+++ b/src/mman/cbindgen.toml
@@ -1,4 +1,4 @@
-sys_includes = ["sys/types.h"]
+sys_includes = ["stdint.h", "sys/types.h"]
 include_guard = "_SYS_MMAN_H"
 language = "C"
 
diff --git a/src/string/cbindgen.toml b/src/string/cbindgen.toml
index 33100dc27..dd39d24e2 100644
--- a/src/string/cbindgen.toml
+++ b/src/string/cbindgen.toml
@@ -1,5 +1,6 @@
 sys_includes = ["stddef.h", "stdint.h"]
 include_guard = "_STRING_H"
+trailer = "#include <bits/string.h>"
 language = "C"
 
 [enum]
-- 
GitLab