Makefile 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. dirent/scandir \
  10. errno \
  11. error \
  12. fcntl/create \
  13. fcntl/fcntl \
  14. fnmatch \
  15. futimens \
  16. libgen \
  17. locale \
  18. math \
  19. netdb/getaddrinfo \
  20. ptrace \
  21. regex \
  22. select \
  23. setjmp \
  24. sigaction \
  25. signal \
  26. stdio/all \
  27. stdio/buffer \
  28. stdio/fgets \
  29. stdio/fputs \
  30. stdio/fread \
  31. stdio/freopen \
  32. stdio/fseek \
  33. stdio/fwrite \
  34. stdio/getc_unget \
  35. stdio/mutex \
  36. stdio/popen \
  37. stdio/printf \
  38. stdio/rename \
  39. stdio/scanf \
  40. stdio/setvbuf \
  41. stdio/sprintf \
  42. stdio/printf_space_pad \
  43. stdio/ungetc_ftell \
  44. stdio/ungetc_multiple \
  45. stdio/fscanf_offby1 \
  46. stdio/fscanf \
  47. stdio/printf_neg_pad \
  48. stdlib/a64l \
  49. stdlib/alloc \
  50. stdlib/atof \
  51. stdlib/atoi \
  52. stdlib/div \
  53. stdlib/env \
  54. stdlib/mkostemps \
  55. stdlib/rand \
  56. stdlib/rand48 \
  57. stdlib/random \
  58. stdlib/strtod \
  59. stdlib/strtol \
  60. stdlib/strtoul \
  61. stdlib/system \
  62. string/mem \
  63. string/strcat \
  64. string/strchr \
  65. string/strcpy \
  66. string/strcspn \
  67. string/strlen \
  68. string/strncmp \
  69. string/strpbrk \
  70. string/strrchr \
  71. string/strspn \
  72. string/strstr \
  73. string/strtok \
  74. string/strtok_r \
  75. string/strsignal \
  76. strings \
  77. sys_mman \
  78. time/asctime \
  79. time/gmtime \
  80. time/localtime \
  81. time/macros \
  82. time/mktime \
  83. time/strftime \
  84. time/time \
  85. tls \
  86. unistd/access \
  87. unistd/brk \
  88. unistd/dup \
  89. unistd/exec \
  90. unistd/fchdir \
  91. unistd/fork \
  92. unistd/fsync \
  93. unistd/ftruncate \
  94. unistd/getopt \
  95. unistd/getopt_long \
  96. unistd/pipe \
  97. unistd/rmdir \
  98. unistd/sleep \
  99. unistd/swab \
  100. unistd/write \
  101. waitpid \
  102. wchar/fwide \
  103. wchar/mbrtowc \
  104. wchar/mbsrtowcs \
  105. wchar/printf-on-wchars \
  106. wchar/putwchar \
  107. wchar/wcrtomb \
  108. wchar/wcscspn \
  109. wchar/wcsrchr \
  110. wchar/wcsstr \
  111. wchar/wcstod \
  112. wchar/wcstok \
  113. wchar/wcstol \
  114. wchar/wcscasecmp \
  115. wchar/wcsncasecmp \
  116. wctype/towlower \
  117. wctype/towupper
  118. # TODO: Fix these
  119. # mkfifo
  120. # netdb/netdb \
  121. # need to call fini in ld_so's _start
  122. STATIC_ONLY_NAMES=\
  123. destructor
  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. BINS=$(patsubst %,bins_static/%,$(NAMES))
  153. BINS+=$(patsubst %,bins_static/%,$(STATIC_ONLY_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_static/%,$(STATIC_ONLY_NAMES))
  158. EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(EXPECT_NAMES))
  159. EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(DYNAMIC_ONLY_NAMES))
  160. TEST_RUNNER?=sh --
  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. verify: | $(EXPECT_BINS)
  181. $(TEST_RUNNER) ./verify.sh $(EXPECT_BINS)
  182. FLAGS=\
  183. -std=c11 \
  184. -fno-builtin \
  185. -fno-stack-protector \
  186. -Wall \
  187. -pedantic \
  188. -g \
  189. -I .
  190. STATIC_FLAGS=\
  191. -static
  192. DYNAMIC_FLAGS=\
  193. -Wl,--enable-new-dtags \
  194. -Wl,-export-dynamic
  195. ../sysroot:
  196. $(MAKE) -C .. sysroot
  197. NATIVE_RELIBC?=0
  198. ifeq ($(NATIVE_RELIBC),0)
  199. FLAGS+=\
  200. -nostdinc \
  201. -nostdlib \
  202. -isystem ../sysroot/include \
  203. ../sysroot/lib/crt0.o \
  204. ../sysroot/lib/crti.o \
  205. ../sysroot/lib/crtn.o
  206. SYSROOT_LIB=$(shell realpath ../sysroot/lib/)
  207. STATIC_FLAGS+=\
  208. $(SYSROOT_LIB)/libc.a
  209. DYNAMIC_FLAGS+=\
  210. -Wl,-dynamic-linker=$(SYSROOT_LIB)/ld64.so.1 \
  211. -Wl,-rpath=$(SYSROOT_LIB):\$$ORIGIN \
  212. -L $(SYSROOT_LIB) \
  213. -lc
  214. DEPS=../sysroot
  215. endif
  216. bins_static/%: %.c $(DEPS)
  217. mkdir -p "$$(dirname "$@")"
  218. $(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS)
  219. bins_dynamic/%: %.c $(DEPS)
  220. mkdir -p "$$(dirname "$@")"
  221. $(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)