Makefile 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  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. # Binaries that may generate varied output
  131. NAMES=\
  132. $(EXPECT_NAMES) \
  133. dirent/main \
  134. pwd \
  135. stdio/tempnam \
  136. stdio/tmpnam \
  137. stdlib/bsearch \
  138. stdlib/mktemp \
  139. stdlib/realpath \
  140. sys_epoll/epoll \
  141. sys_utsname/uname \
  142. time/gettimeofday \
  143. unistd/chdir \
  144. unistd/getcwd \
  145. unistd/gethostname \
  146. unistd/getid \
  147. unistd/getpagesize \
  148. unistd/isatty \
  149. unistd/link \
  150. unistd/pathconf \
  151. unistd/setid \
  152. unistd/stat \
  153. unistd/sysconf
  154. # resource/getrusage
  155. # time/times
  156. BINS=$(patsubst %,bins_static/%,$(NAMES))
  157. BINS+=$(patsubst %,bins_static/%,$(STATIC_ONLY_NAMES))
  158. BINS+=$(patsubst %,bins_dynamic/%,$(NAMES))
  159. EXPECT_BINS=$(patsubst %,bins_static/%,$(EXPECT_NAMES))
  160. EXPECT_BINS+=$(patsubst %,bins_static/%,$(STATIC_ONLY_NAMES))
  161. EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(EXPECT_NAMES))
  162. TEST_RUNNER?=sh --
  163. .PHONY: all clean run expected verify
  164. all: $(BINS)
  165. clean:
  166. rm -rf bins_* gen *.out
  167. run: | $(BINS)
  168. for bin in $(BINS); \
  169. do \
  170. echo "# $${bin} #"; \
  171. "$${bin}" test args || exit $$?; \
  172. done
  173. expected: | $(EXPECT_BINS)
  174. rm -rf expected
  175. mkdir -p expected
  176. for bin in $(EXPECT_BINS); \
  177. do \
  178. echo "# $${bin} #"; \
  179. mkdir -p expected/`dirname $${bin}`; \
  180. "$${bin}" test args > "expected/$${bin}.stdout" 2> "expected/$${bin}.stderr" || exit $$?; \
  181. done
  182. verify: | $(EXPECT_BINS)
  183. $(TEST_RUNNER) ./verify.sh $(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. ../sysroot/lib/libc.a \
  194. -static
  195. NATIVE_RELIBC?=0
  196. ifeq ($(NATIVE_RELIBC),0)
  197. FLAGS+=\
  198. -nostdinc \
  199. -nostdlib \
  200. -isystem ../sysroot/include \
  201. ../sysroot/lib/crt0.o \
  202. ../sysroot/lib/crti.o \
  203. ../sysroot/lib/crtn.o
  204. ../sysroot:
  205. $(MAKE) -C .. sysroot
  206. bins_static/%: %.c ../sysroot
  207. mkdir -p "$$(dirname "$@")"
  208. $(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS)
  209. SYSROOT_LIB=$(shell realpath ../sysroot/lib/)
  210. DYNAMIC_FLAGS=\
  211. -Wl,-dynamic-linker=$(SYSROOT_LIB)/ld64.so.1 \
  212. -Wl,--enable-new-dtags \
  213. -Wl,-rpath=$(SYSROOT_LIB) \
  214. -L $(SYSROOT_LIB) \
  215. -lc
  216. bins_dynamic/%: %.c ../sysroot
  217. mkdir -p "$$(dirname "$@")"
  218. $(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)
  219. else
  220. bins_static/%: %.c
  221. mkdir -p "$$(dirname "$@")"
  222. $(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS)
  223. bins_dynamic/%: %.c
  224. mkdir -p "$$(dirname "$@")"
  225. $(CC) "$<" -o "$@" $(FLAGS)
  226. endif