Makefile 4.5 KB

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