Makefile 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. # Binaries that should generate the same output every time
  2. EXPECT_NAMES=\
  3. alloca \
  4. args \
  5. arpainet \
  6. assert \
  7. constructor \
  8. ctype \
  9. destructor \
  10. dirent/scandir \
  11. errno \
  12. error \
  13. fcntl/create \
  14. fcntl/fcntl \
  15. fnmatch \
  16. futimens \
  17. libgen \
  18. locale \
  19. math \
  20. netdb/getaddrinfo \
  21. ptrace \
  22. regex \
  23. select \
  24. setjmp \
  25. sigaction \
  26. signal \
  27. stdio/all \
  28. stdio/buffer \
  29. stdio/fgets \
  30. stdio/fputs \
  31. stdio/fread \
  32. stdio/freopen \
  33. stdio/fseek \
  34. stdio/fwrite \
  35. stdio/getc_unget \
  36. stdio/mutex \
  37. stdio/popen \
  38. stdio/printf \
  39. stdio/rename \
  40. stdio/scanf \
  41. stdio/setvbuf \
  42. stdio/sprintf \
  43. stdio/printf_space_pad \
  44. stdio/ungetc_ftell \
  45. stdio/ungetc_multiple \
  46. stdio/fscanf_offby1 \
  47. stdio/fscanf \
  48. stdio/printf_neg_pad \
  49. stdlib/a64l \
  50. stdlib/alloc \
  51. stdlib/atof \
  52. stdlib/atoi \
  53. stdlib/div \
  54. stdlib/env \
  55. stdlib/mkostemps \
  56. stdlib/rand \
  57. stdlib/rand48 \
  58. stdlib/random \
  59. stdlib/strtod \
  60. stdlib/strtol \
  61. stdlib/strtoul \
  62. stdlib/system \
  63. string/mem \
  64. string/strcat \
  65. string/strchr \
  66. string/strcpy \
  67. string/strcspn \
  68. string/strlen \
  69. string/strncmp \
  70. string/strpbrk \
  71. string/strrchr \
  72. string/strspn \
  73. string/strstr \
  74. string/strtok \
  75. string/strtok_r \
  76. string/strsignal \
  77. strings \
  78. sys_mman \
  79. time/asctime \
  80. time/constants \
  81. time/gmtime \
  82. time/localtime \
  83. time/macros \
  84. time/mktime \
  85. time/strftime \
  86. time/time \
  87. tls \
  88. unistd/access \
  89. unistd/brk \
  90. unistd/dup \
  91. unistd/exec \
  92. unistd/fchdir \
  93. unistd/fork \
  94. unistd/fsync \
  95. unistd/ftruncate \
  96. unistd/getopt \
  97. unistd/getopt_long \
  98. unistd/pipe \
  99. unistd/rmdir \
  100. unistd/sleep \
  101. unistd/swab \
  102. unistd/write \
  103. waitpid \
  104. wchar/fwide \
  105. wchar/mbrtowc \
  106. wchar/mbsrtowcs \
  107. wchar/printf-on-wchars \
  108. wchar/putwchar \
  109. wchar/wcrtomb \
  110. wchar/wcscspn \
  111. wchar/wcsrchr \
  112. wchar/wcsstr \
  113. wchar/wcstod \
  114. wchar/wcstok \
  115. wchar/wcstol \
  116. wchar/wcscasecmp \
  117. wchar/wcsncasecmp \
  118. wctype/towlower \
  119. wctype/towupper
  120. # TODO: Fix these
  121. # mkfifo
  122. # netdb/netdb \
  123. DYNAMIC_ONLY_NAMES=\
  124. dlfcn
  125. # Binaries that may generate varied output
  126. NAMES=\
  127. $(EXPECT_NAMES) \
  128. dirent/main \
  129. pwd \
  130. stdio/tempnam \
  131. stdio/tmpnam \
  132. stdlib/bsearch \
  133. stdlib/mktemp \
  134. stdlib/realpath \
  135. sys_epoll/epoll \
  136. sys_utsname/uname \
  137. time/gettimeofday \
  138. unistd/chdir \
  139. unistd/getcwd \
  140. unistd/gethostname \
  141. unistd/getid \
  142. unistd/getpagesize \
  143. unistd/isatty \
  144. unistd/link \
  145. unistd/pathconf \
  146. unistd/setid \
  147. unistd/stat \
  148. unistd/sysconf
  149. # resource/getrusage
  150. # time/times
  151. #TODO: dynamic tests currently broken
  152. BINS=$(patsubst %,bins_static/%,$(NAMES))
  153. #BINS+=$(patsubst %,bins_dynamic/%,$(NAMES))
  154. #BINS+=$(patsubst %,bins_dynamic/%,$(DYNAMIC_ONLY_NAMES))
  155. EXPECT_BINS=$(patsubst %,bins_static/%,$(EXPECT_NAMES))
  156. #EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(EXPECT_NAMES))
  157. #EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(DYNAMIC_ONLY_NAMES))
  158. CARGO_TEST?=cargo
  159. TEST_RUNNER?=
  160. .PHONY: all clean run expected verify
  161. all: $(BINS)
  162. clean:
  163. rm -rf bins_* gen *.out
  164. run: | $(BINS)
  165. for bin in $(BINS); \
  166. do \
  167. echo "# $${bin} #"; \
  168. "$${bin}" test args || exit $$?; \
  169. done
  170. expected: | $(EXPECT_BINS)
  171. rm -rf expected
  172. mkdir -p expected
  173. for bin in $(EXPECT_BINS); \
  174. do \
  175. echo "# $${bin} #"; \
  176. mkdir -p expected/`dirname $${bin}`; \
  177. "$${bin}" test args > "expected/$${bin}.stdout" 2> "expected/$${bin}.stderr" || exit $$?; \
  178. done
  179. bins_verify/relibc-tests: src/main.rs
  180. $(CARGO_TEST) build --release --bin relibc-tests --out-dir bins_verify -Z unstable-options
  181. verify: bins_verify/relibc-tests | $(EXPECT_BINS)
  182. $(TEST_RUNNER) $< $(EXPECT_BINS)
  183. FLAGS=\
  184. -std=c11 \
  185. -fno-builtin \
  186. -fno-stack-protector \
  187. -Wall \
  188. -pedantic \
  189. -g \
  190. -I .
  191. STATIC_FLAGS=\
  192. -static
  193. DYNAMIC_FLAGS=\
  194. -Wl,--enable-new-dtags \
  195. -Wl,-export-dynamic
  196. ../sysroot:
  197. $(MAKE) -C .. sysroot
  198. NATIVE_RELIBC?=0
  199. ifeq ($(NATIVE_RELIBC),0)
  200. FLAGS+=\
  201. -nostdinc \
  202. -nostdlib \
  203. -isystem ../sysroot/include \
  204. ../sysroot/lib/crt0.o \
  205. ../sysroot/lib/crti.o \
  206. ../sysroot/lib/crtn.o
  207. SYSROOT_LIB=$(shell realpath ../sysroot/lib/)
  208. STATIC_FLAGS+=\
  209. $(SYSROOT_LIB)/libc.a
  210. DYNAMIC_FLAGS+=\
  211. -Wl,-dynamic-linker=$(SYSROOT_LIB)/ld64.so.1 \
  212. -Wl,-rpath=$(SYSROOT_LIB):\$$ORIGIN \
  213. -L $(SYSROOT_LIB) \
  214. -lc
  215. DEPS=../sysroot
  216. else
  217. DYNAMIC_FLAGS+=\
  218. -Wl,-rpath=\$$ORIGIN
  219. endif
  220. bins_static/%: %.c $(DEPS)
  221. mkdir -p "$$(dirname "$@")"
  222. $(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS)
  223. bins_dynamic/%.so: %.c $(DEPS)
  224. mkdir -p "$$(dirname "$@")"
  225. $(CC) "$<" -o "$@" -shared -fpic $(FLAGS) $(DYNAMIC_FLAGS)
  226. bins_dynamic/dlfcn: dlfcn.c bins_dynamic/sharedlib.so $(DEPS)
  227. mkdir -p "$$(dirname "$@")"
  228. $(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)
  229. bins_dynamic/%: %.c $(DEPS)
  230. mkdir -p "$$(dirname "$@")"
  231. $(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)