2
0

Makefile 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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. wchar/wcswidth \
  119. wctype/towlower \
  120. wctype/towupper
  121. # TODO: Fix these
  122. # mkfifo
  123. # netdb/netdb \
  124. DYNAMIC_ONLY_NAMES=\
  125. dlfcn
  126. # Binaries that may generate varied output
  127. NAMES=\
  128. $(EXPECT_NAMES) \
  129. dirent/main \
  130. pwd \
  131. stdio/tempnam \
  132. stdio/tmpnam \
  133. stdlib/bsearch \
  134. stdlib/mktemp \
  135. stdlib/realpath \
  136. sys_epoll/epoll \
  137. sys_utsname/uname \
  138. time/gettimeofday \
  139. unistd/chdir \
  140. unistd/getcwd \
  141. unistd/gethostname \
  142. unistd/getid \
  143. unistd/getpagesize \
  144. unistd/isatty \
  145. unistd/link \
  146. unistd/pathconf \
  147. unistd/setid \
  148. unistd/stat \
  149. unistd/sysconf
  150. # resource/getrusage
  151. # time/times
  152. #TODO: dynamic tests currently broken
  153. BINS=$(patsubst %,bins_static/%,$(NAMES))
  154. #BINS+=$(patsubst %,bins_dynamic/%,$(NAMES))
  155. #BINS+=$(patsubst %,bins_dynamic/%,$(DYNAMIC_ONLY_NAMES))
  156. EXPECT_BINS=$(patsubst %,bins_static/%,$(EXPECT_NAMES))
  157. #EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(EXPECT_NAMES))
  158. #EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(DYNAMIC_ONLY_NAMES))
  159. CARGO_TEST?=cargo
  160. TEST_RUNNER?=
  161. .PHONY: all clean run expected verify
  162. all: $(BINS)
  163. clean:
  164. rm -rf bins_* gen *.out
  165. run: | $(BINS)
  166. for bin in $(BINS); \
  167. do \
  168. echo "# $${bin} #"; \
  169. "$${bin}" test args || exit $$?; \
  170. done
  171. expected: | $(EXPECT_BINS)
  172. rm -rf expected
  173. mkdir -p expected
  174. for bin in $(EXPECT_BINS); \
  175. do \
  176. echo "# $${bin} #"; \
  177. mkdir -p expected/`dirname $${bin}`; \
  178. "$${bin}" test args > "expected/$${bin}.stdout" 2> "expected/$${bin}.stderr" || exit $$?; \
  179. done
  180. bins_verify/relibc-tests: src/main.rs
  181. $(CARGO_TEST) build --release --bin relibc-tests --out-dir bins_verify -Z unstable-options
  182. verify: bins_verify/relibc-tests | $(EXPECT_BINS)
  183. $(TEST_RUNNER) $< $(EXPECT_BINS)
  184. FLAGS=\
  185. -std=c11 \
  186. -fno-builtin \
  187. -fno-stack-protector \
  188. -Wall \
  189. -pedantic \
  190. -g \
  191. -I .
  192. STATIC_FLAGS=\
  193. -static
  194. DYNAMIC_FLAGS=\
  195. -Wl,--enable-new-dtags \
  196. -Wl,-export-dynamic
  197. ../sysroot:
  198. $(MAKE) -C .. sysroot
  199. NATIVE_RELIBC?=0
  200. ifeq ($(NATIVE_RELIBC),0)
  201. FLAGS+=\
  202. -nostdinc \
  203. -nostdlib \
  204. -isystem ../sysroot/include \
  205. ../sysroot/lib/crt0.o \
  206. ../sysroot/lib/crti.o \
  207. ../sysroot/lib/crtn.o
  208. SYSROOT_LIB=$(shell realpath ../sysroot/lib/)
  209. STATIC_FLAGS+=\
  210. $(SYSROOT_LIB)/libc.a
  211. DYNAMIC_FLAGS+=\
  212. -Wl,-dynamic-linker=$(SYSROOT_LIB)/ld64.so.1 \
  213. -Wl,-rpath=$(SYSROOT_LIB):\$$ORIGIN \
  214. -L $(SYSROOT_LIB) \
  215. -lc
  216. DEPS=../sysroot
  217. else
  218. DYNAMIC_FLAGS+=\
  219. -Wl,-rpath=\$$ORIGIN
  220. endif
  221. bins_static/%: %.c $(DEPS)
  222. mkdir -p "$$(dirname "$@")"
  223. $(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS)
  224. bins_dynamic/%.so: %.c $(DEPS)
  225. mkdir -p "$$(dirname "$@")"
  226. $(CC) "$<" -o "$@" -shared -fpic $(FLAGS) $(DYNAMIC_FLAGS)
  227. bins_dynamic/dlfcn: dlfcn.c bins_dynamic/sharedlib.so $(DEPS)
  228. mkdir -p "$$(dirname "$@")"
  229. $(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)
  230. bins_dynamic/%: %.c $(DEPS)
  231. mkdir -p "$$(dirname "$@")"
  232. $(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)