Makefile 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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/gmtime \
  81. time/localtime \
  82. time/macros \
  83. time/mktime \
  84. time/strftime \
  85. time/time \
  86. tls \
  87. unistd/access \
  88. unistd/brk \
  89. unistd/dup \
  90. unistd/exec \
  91. unistd/fchdir \
  92. unistd/fork \
  93. unistd/fsync \
  94. unistd/ftruncate \
  95. unistd/getopt \
  96. unistd/getopt_long \
  97. unistd/pipe \
  98. unistd/rmdir \
  99. unistd/sleep \
  100. unistd/swab \
  101. unistd/write \
  102. waitpid \
  103. wchar/fwide \
  104. wchar/mbrtowc \
  105. wchar/mbsrtowcs \
  106. wchar/printf-on-wchars \
  107. wchar/putwchar \
  108. wchar/wcrtomb \
  109. wchar/wcscspn \
  110. wchar/wcsrchr \
  111. wchar/wcsstr \
  112. wchar/wcstod \
  113. wchar/wcstok \
  114. wchar/wcstol \
  115. wchar/wcscasecmp \
  116. wchar/wcsncasecmp \
  117. wctype/towlower \
  118. wctype/towupper
  119. # TODO: Fix these
  120. # mkfifo
  121. # netdb/netdb \
  122. DYNAMIC_ONLY_NAMES=\
  123. dlfcn
  124. # Binaries that may generate varied output
  125. NAMES=\
  126. $(EXPECT_NAMES) \
  127. dirent/main \
  128. pwd \
  129. stdio/tempnam \
  130. stdio/tmpnam \
  131. stdlib/bsearch \
  132. stdlib/mktemp \
  133. stdlib/realpath \
  134. sys_epoll/epoll \
  135. sys_utsname/uname \
  136. time/gettimeofday \
  137. unistd/chdir \
  138. unistd/getcwd \
  139. unistd/gethostname \
  140. unistd/getid \
  141. unistd/getpagesize \
  142. unistd/isatty \
  143. unistd/link \
  144. unistd/pathconf \
  145. unistd/setid \
  146. unistd/stat \
  147. unistd/sysconf
  148. # resource/getrusage
  149. # time/times
  150. BINS=$(patsubst %,bins_static/%,$(NAMES))
  151. BINS+=$(patsubst %,bins_dynamic/%,$(NAMES))
  152. BINS+=$(patsubst %,bins_dynamic/%,$(DYNAMIC_ONLY_NAMES))
  153. EXPECT_BINS=$(patsubst %,bins_static/%,$(EXPECT_NAMES))
  154. EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(EXPECT_NAMES))
  155. EXPECT_BINS+=$(patsubst %,bins_dynamic/%,$(DYNAMIC_ONLY_NAMES))
  156. TEST_RUNNER?=sh --
  157. .PHONY: all clean run expected verify
  158. all: $(BINS)
  159. clean:
  160. rm -rf bins_* gen *.out
  161. run: | $(BINS)
  162. for bin in $(BINS); \
  163. do \
  164. echo "# $${bin} #"; \
  165. "$${bin}" test args || exit $$?; \
  166. done
  167. expected: | $(EXPECT_BINS)
  168. rm -rf expected
  169. mkdir -p expected
  170. for bin in $(EXPECT_BINS); \
  171. do \
  172. echo "# $${bin} #"; \
  173. mkdir -p expected/`dirname $${bin}`; \
  174. "$${bin}" test args > "expected/$${bin}.stdout" 2> "expected/$${bin}.stderr" || exit $$?; \
  175. done
  176. verify: | $(EXPECT_BINS)
  177. $(TEST_RUNNER) ./verify.sh $(EXPECT_BINS)
  178. FLAGS=\
  179. -std=c11 \
  180. -fno-builtin \
  181. -fno-stack-protector \
  182. -Wall \
  183. -pedantic \
  184. -g \
  185. -I .
  186. STATIC_FLAGS=\
  187. -static
  188. DYNAMIC_FLAGS=\
  189. -Wl,--enable-new-dtags \
  190. -Wl,-export-dynamic
  191. ../sysroot:
  192. $(MAKE) -C .. sysroot
  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_LIB=$(shell realpath ../sysroot/lib/)
  203. STATIC_FLAGS+=\
  204. $(SYSROOT_LIB)/libc.a
  205. DYNAMIC_FLAGS+=\
  206. -Wl,-dynamic-linker=$(SYSROOT_LIB)/ld64.so.1 \
  207. -Wl,-rpath=$(SYSROOT_LIB):\$$ORIGIN \
  208. -L $(SYSROOT_LIB) \
  209. -lc
  210. DEPS=../sysroot
  211. else
  212. DYNAMIC_FLAGS+=\
  213. -Wl,-rpath=\$$ORIGIN
  214. endif
  215. bins_static/%: %.c $(DEPS)
  216. mkdir -p "$$(dirname "$@")"
  217. $(CC) "$<" -o "$@" $(FLAGS) $(STATIC_FLAGS)
  218. bins_dynamic/%.so: %.c $(DEPS)
  219. mkdir -p "$$(dirname "$@")"
  220. $(CC) "$<" -o "$@" -shared -fpic $(FLAGS) $(DYNAMIC_FLAGS)
  221. bins_dynamic/dlfcn: dlfcn.c bins_dynamic/sharedlib.so $(DEPS)
  222. mkdir -p "$$(dirname "$@")"
  223. $(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)
  224. bins_dynamic/%: %.c $(DEPS)
  225. mkdir -p "$$(dirname "$@")"
  226. $(CC) "$<" -o "$@" $(FLAGS) $(DYNAMIC_FLAGS)