Makefile 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. tls \
  77. unistd/access \
  78. unistd/brk \
  79. unistd/dup \
  80. unistd/exec \
  81. unistd/fchdir \
  82. unistd/fork \
  83. unistd/fsync \
  84. unistd/ftruncate \
  85. unistd/pipe \
  86. unistd/rmdir \
  87. unistd/sleep \
  88. unistd/swab \
  89. unistd/write \
  90. waitpid \
  91. wchar/fwide \
  92. wchar/mbrtowc \
  93. wchar/mbsrtowcs \
  94. wchar/printf-on-wchars \
  95. wchar/putwchar \
  96. wchar/wcrtomb \
  97. wchar/wcscspn \
  98. wchar/wcsrchr \
  99. wchar/wcsstr \
  100. wchar/wcstod \
  101. wchar/wcstol \
  102. wchar/wcscasecmp \
  103. wchar/wcsncasecmp \
  104. # TODO: Fix these
  105. # mkfifo
  106. # netdb/netdb \
  107. # issues with linking stdin, stdout, stderr
  108. STATIC_ONLY_NAMES=\
  109. futimens \
  110. stdio/all \
  111. stdio/buffer \
  112. stdio/fgets \
  113. stdio/freopen \
  114. stdio/getc_unget \
  115. stdio/setvbuf \
  116. stdio/ungetc_multiple \
  117. time/localtime \
  118. wchar/wcstok \
  119. wctype/towlower \
  120. wctype/towupper \
  121. # need to call fini in ld_so's _start
  122. STATIC_ONLY_NAMES+=\
  123. destructor \
  124. # issues with linking optarg, optind etc.
  125. STATIC_ONLY_NAMES+=\
  126. unistd/getopt \
  127. unistd/getopt_long \
  128. # Binaries that may generate varied output
  129. NAMES=\
  130. $(EXPECT_NAMES) \
  131. dirent/main \
  132. pwd \
  133. stdio/tempnam \
  134. stdio/tmpnam \
  135. stdlib/bsearch \
  136. stdlib/mktemp \
  137. stdlib/realpath \
  138. sys_epoll/epoll \
  139. sys_utsname/uname \
  140. time/gettimeofday \
  141. unistd/chdir \
  142. unistd/getcwd \
  143. unistd/gethostname \
  144. unistd/getid \
  145. unistd/getpagesize \
  146. unistd/isatty \
  147. unistd/link \
  148. unistd/pathconf \
  149. unistd/setid \
  150. unistd/stat \
  151. unistd/sysconf
  152. # resource/getrusage
  153. # time/times
  154. BINS=$(patsubst %,bins_static/%,$(NAMES))
  155. BINS+=$(patsubst %,bins_static/%,$(STATIC_ONLY_NAMES))
  156. BINS+=$(patsubst %,bins_dynamic/%,$(NAMES))
  157. EXPECT_BINS=$(patsubst %,bins_static/%,$(EXPECT_NAMES))
  158. EXPECT_BINS+=$(patsubst %,bins_static/%,$(STATIC_ONLY_NAMES))
  159. EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(EXPECT_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. ../sysroot/lib/libc.a \
  192. -static
  193. NATIVE_RELIBC?=0
  194. ifeq ($(NATIVE_RELIBC),0)
  195. FLAGS+=\
  196. -nostdinc \
  197. -nostdlib \
  198. -isystem ../sysroot/include \
  199. ../sysroot/lib/crt0.o \
  200. ../sysroot/lib/crti.o \
  201. ../sysroot/lib/crtn.o
  202. ../sysroot:
  203. $(MAKE) -C .. sysroot
  204. bins_static/%: %.c ../sysroot
  205. mkdir -p "$$(dirname "$@")"
  206. $(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS)
  207. SYSROOT_LIB=$(shell realpath ../sysroot/lib/)
  208. DYNAMIC_FLAGS=\
  209. -Wl,-dynamic-linker=$(SYSROOT_LIB)/ld64.so.1 \
  210. -Wl,--enable-new-dtags \
  211. -Wl,-rpath=$(SYSROOT_LIB) \
  212. -L $(SYSROOT_LIB) \
  213. -lc
  214. bins_dynamic/%: %.c ../sysroot
  215. mkdir -p "$$(dirname "$@")"
  216. $(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)
  217. else
  218. bins_static/%: %.c
  219. mkdir -p "$$(dirname "$@")"
  220. $(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS)
  221. bins_dynamic/%: %.c
  222. mkdir -p "$$(dirname "$@")"
  223. $(CC) "$<" -o "$@" $(FLAGS)
  224. endif