Rules 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. # Copyright (C) 1991-2019 Free Software Foundation, Inc.
  2. # This file is part of the GNU C Library.
  3. # The GNU C Library is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU Lesser General Public
  5. # License as published by the Free Software Foundation; either
  6. # version 2.1 of the License, or (at your option) any later version.
  7. # The GNU C Library is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. # Lesser General Public License for more details.
  11. # You should have received a copy of the GNU Lesser General Public
  12. # License along with the GNU C Library; if not, see
  13. # <http://www.gnu.org/licenses/>.
  14. #
  15. # Rules for making a subdirectory in the GNU C library.
  16. # Each subdirectory Makefile defines some variables and includes this.
  17. #
  18. ifneq (,)
  19. This makefile requires GNU Make.
  20. endif
  21. all: # Don't let the default goal come from Makeconfig.
  22. include $(firstword $(..) ../)Makeconfig
  23. ifndef subdir
  24. Each subdirectory makefile must define the `subdir' variable.
  25. endif
  26. # This ` unconfuses emacs.
  27. # This is benign and useless in GNU make before 3.63.
  28. export subdir := $(subdir)
  29. # This is the default target; it makes the library and auxiliary programs.
  30. .PHONY: all
  31. all: objs lib others
  32. ifeq ($(build-programs),yes)
  33. others: $(addprefix $(objpfx),$(extra-objs) \
  34. $(install-lib) \
  35. $(install-bin) $(install-bin-script) \
  36. $(install-rootsbin) $(install-sbin))
  37. else
  38. others: $(addprefix $(objpfx),$(extra-objs) \
  39. $(install-lib))
  40. endif
  41. ifneq "$(findstring env,$(origin headers))" ""
  42. headers :=
  43. endif
  44. ifneq "$(findstring env,$(origin generated))" ""
  45. generated :=
  46. endif
  47. ifneq "$(findstring env,$(origin common-generated))" ""
  48. common-generated :=
  49. endif
  50. # See below. This must be set before Makerules processes it.
  51. before-compile += $(common-objpfx)bits/stdio_lim.h
  52. include $(..)Makerules
  53. .PHONY: subdir_lib
  54. subdir_lib: lib-noranlib
  55. # Some subdirs need to install a dummy library.
  56. # They can use "$(objpfx)libfnord.a: $(dep-dummy-lib); $(make-dummy-lib)".
  57. dep-dummy-lib = $(common-objpfx)dummy.o
  58. define make-dummy-lib
  59. $(AR) cr$(verbose) $@ $<
  60. endef
  61. $(common-objpfx)dummy.c:
  62. rm -f $@
  63. (echo 'extern void __dummy__ (void);'; \
  64. echo 'void __dummy__ (void) { }') > $@
  65. common-generated += dummy.o dummy.c
  66. ifneq "$(headers)" ""
  67. # Special test of all the installed headers in this directory.
  68. tests-special += $(objpfx)check-installed-headers-c.out
  69. libof-check-installed-headers-c := testsuite
  70. $(objpfx)check-installed-headers-c.out: \
  71. $(..)scripts/check-installed-headers.sh $(headers)
  72. $(SHELL) $(..)scripts/check-installed-headers.sh c \
  73. "$(CC) $(filter-out -std=%,$(CFLAGS)) -D_ISOMAC $(+includes)" \
  74. $(headers) > $@; \
  75. $(evaluate-test)
  76. ifneq "$(CXX)" ""
  77. tests-special += $(objpfx)check-installed-headers-cxx.out
  78. libof-check-installed-headers-cxx := testsuite
  79. $(objpfx)check-installed-headers-cxx.out: \
  80. $(..)scripts/check-installed-headers.sh $(headers)
  81. $(SHELL) $(..)scripts/check-installed-headers.sh c++ \
  82. "$(CXX) $(filter-out -std=%,$(CXXFLAGS)) -D_ISOMAC $(+includes)" \
  83. $(headers) > $@; \
  84. $(evaluate-test)
  85. endif
  86. endif
  87. # This makes all the auxiliary and test programs.
  88. .PHONY: others tests bench bench-build
  89. # Test programs for the pretty printers.
  90. tests-printers-programs := $(addprefix $(objpfx),$(tests-printers))
  91. # .out files with the output of running the pretty printer tests.
  92. tests-printers-out := $(patsubst %,$(objpfx)%.out,$(tests-printers))
  93. ifeq ($(build-programs),yes)
  94. others: $(addprefix $(objpfx),$(others) $(sysdep-others) $(extra-objs))
  95. else
  96. others: $(addprefix $(objpfx),$(extra-objs))
  97. endif
  98. # Generate constant files for Python pretty printers if required.
  99. others: $(py-const)
  100. ifeq ($(run-built-tests),no)
  101. tests: $(addprefix $(objpfx),$(filter-out $(tests-unsupported), \
  102. $(tests) $(tests-internal) \
  103. $(tests-container)) \
  104. $(test-srcs)) $(tests-special) \
  105. $(tests-printers-programs)
  106. xtests: tests $(xtests-special)
  107. else
  108. tests: $(tests:%=$(objpfx)%.out) $(tests-internal:%=$(objpfx)%.out) \
  109. $(tests-container:%=$(objpfx)%.out) \
  110. $(tests-special) $(tests-printers-out)
  111. xtests: tests $(xtests:%=$(objpfx)%.out) $(xtests-special)
  112. endif
  113. tests-special-notdir = $(patsubst $(objpfx)%, %, $(tests-special))
  114. xtests-special-notdir = $(patsubst $(objpfx)%, %, $(xtests-special))
  115. ifeq ($(run-built-tests),no)
  116. tests-expected =
  117. else
  118. tests-expected = $(tests) $(tests-internal) $(tests-printers) \
  119. $(tests-container)
  120. endif
  121. tests:
  122. $(..)scripts/merge-test-results.sh -s $(objpfx) $(subdir) \
  123. $(sort $(tests-expected) $(tests-special-notdir:.out=)) \
  124. > $(objpfx)subdir-tests.sum
  125. xtests:
  126. $(..)scripts/merge-test-results.sh -s $(objpfx) $(subdir) \
  127. $(sort $(xtests) $(xtests-special-notdir:.out=)) \
  128. > $(objpfx)subdir-xtests.sum
  129. ifeq ($(build-programs),yes)
  130. binaries-all-notests = $(others) $(sysdep-others)
  131. binaries-all-tests = $(tests) $(tests-internal) $(xtests) $(test-srcs) \
  132. $(tests-container)
  133. binaries-all = $(binaries-all-notests) $(binaries-all-tests)
  134. binaries-static-notests = $(others-static)
  135. binaries-static-tests = $(tests-static) $(xtests-static)
  136. binaries-static = $(binaries-static-notests) $(binaries-static-tests)
  137. ifeq (yesyes,$(have-fpie)$(build-shared))
  138. binaries-pie-tests = $(tests-pie) $(xtests-pie)
  139. binaries-pie-notests = $(others-pie)
  140. else
  141. binaries-pie-tests =
  142. binaries-pie-notests =
  143. endif
  144. else
  145. binaries-all-notests =
  146. binaries-all-tests = $(tests) $(tests-internal) $(xtests) $(test-srcs)
  147. binaries-all = $(binaries-all-tests)
  148. binaries-static-notests =
  149. binaries-static-tests =
  150. binaries-static =
  151. binaries-pie-tests =
  152. binaries-pie-notests =
  153. endif
  154. binaries-pie = $(binaries-pie-tests) $(binaries-pie-notests)
  155. binaries-shared-tests = $(filter-out $(binaries-pie) $(binaries-static), \
  156. $(binaries-all-tests))
  157. binaries-shared-notests = $(filter-out $(binaries-pie) $(binaries-static), \
  158. $(binaries-all-notests))
  159. ifneq "$(strip $(binaries-shared-notests))" ""
  160. $(addprefix $(objpfx),$(binaries-shared-notests)): %: %.o \
  161. $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
  162. $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
  163. $(+link)
  164. endif
  165. ifneq "$(strip $(binaries-shared-tests))" ""
  166. $(addprefix $(objpfx),$(binaries-shared-tests)): %: %.o \
  167. $(link-extra-libs-tests) \
  168. $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
  169. $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
  170. $(+link-tests)
  171. endif
  172. ifneq "$(strip $(binaries-pie-tests))" ""
  173. $(addprefix $(objpfx),$(binaries-pie-tests)): %: %.o \
  174. $(link-extra-libs-tests) \
  175. $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
  176. $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
  177. $(+link-pie-tests)
  178. endif
  179. ifneq "$(strip $(binaries-pie-notests))" ""
  180. $(addprefix $(objpfx),$(binaries-pie-notests)): %: %.o \
  181. $(sort $(filter $(common-objpfx)lib%,$(link-libc))) \
  182. $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
  183. $(+link-pie)
  184. endif
  185. ifneq "$(strip $(binaries-static-notests))" ""
  186. $(addprefix $(objpfx),$(binaries-static-notests)): %: %.o \
  187. $(sort $(filter $(common-objpfx)lib%,$(link-libc-static))) \
  188. $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
  189. $(+link-static)
  190. endif
  191. ifneq "$(strip $(binaries-static-tests))" ""
  192. $(addprefix $(objpfx),$(binaries-static-tests)): %: %.o \
  193. $(link-extra-libs-tests) \
  194. $(sort $(filter $(common-objpfx)lib%,$(link-libc-static-tests))) \
  195. $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
  196. $(+link-static-tests)
  197. endif
  198. ifneq "$(strip $(tests) $(tests-internal) $(xtests) $(test-srcs))" ""
  199. # These are the implicit rules for making test outputs
  200. # from the test programs and whatever input files are present.
  201. define make-test-out
  202. $(if $($*-ENV-only),$(test-wrapper-env-only) $($*-ENV-only),\
  203. $(test-wrapper-env) $(run-program-env) $($*-ENV)) \
  204. $(host-test-program-cmd) $($*-ARGS)
  205. endef
  206. $(objpfx)%.out: %.input $(objpfx)%
  207. $(make-test-out) > $@ < $(word 1,$^); \
  208. $(evaluate-test)
  209. $(objpfx)%.out: /dev/null $(objpfx)% # Make it 2nd arg for canned sequence.
  210. $(make-test-out) > $@; \
  211. $(evaluate-test)
  212. # Any tests that require an isolated container (filesystem, network
  213. # and pid namespaces) in which to run, should be added to
  214. # tests-container.
  215. $(tests-container:%=$(objpfx)%.out): $(objpfx)%.out : $(if $(wildcard $(objpfx)%.files),$(objpfx)%.files,/dev/null) $(objpfx)%
  216. $(test-wrapper-env) $(run-program-env) $(run-via-rtld-prefix) \
  217. $(common-objpfx)support/test-container env $(run-program-env) $($*-ENV) \
  218. $(host-test-program-cmd) $($*-ARGS) > $@; \
  219. $(evaluate-test)
  220. # tests-unsupported lists tests that we will not try to build at all in
  221. # this configuration. Note this runs every time because it does not
  222. # actually create its target. The dependency on Makefile is meant to
  223. # ensure that it runs after a Makefile change to add a test to the list
  224. # when it previously ran and produced a .out file (probably for a failure).
  225. ifneq "$(strip $(tests-unsupported))" ""
  226. $(tests-unsupported:%=$(objpfx)%.out): $(objpfx)%.out: Makefile
  227. @rm -f $@
  228. $(..)scripts/evaluate-test.sh $(patsubst $(common-objpfx)%.out,%,$@) \
  229. 77 false false > $(@:.out=.test-result)
  230. endif
  231. endif # tests
  232. ifneq "$(strip $(tests-printers))" ""
  233. # Static pattern rule for building the test programs for the pretty printers.
  234. $(tests-printers-programs): %: %.o $(tests-printers-libs) \
  235. $(sort $(filter $(common-objpfx)lib%,$(link-libc-static-tests))) \
  236. $(addprefix $(csu-objpfx),start.o) $(+preinit) $(+postinit)
  237. $(+link-printers-tests)
  238. # Add the paths to the generated constants file and test_common_printers.py
  239. # to PYTHONPATH so the test scripts can find them.
  240. py-env := PYTHONPATH=$(py-const-dir):$(..)scripts:$${PYTHONPATH}
  241. # Static pattern rule that matches the test-* targets to their .c and .py
  242. # prerequisites. It'll run the corresponding test script for each test program
  243. # we compiled and place its output in the corresponding .out file.
  244. # The pretty printer files and test_common_printers.py must be present for all.
  245. $(tests-printers-out): $(objpfx)%.out: $(objpfx)% %.py %.c $(pretty-printers) \
  246. $(..)scripts/test_printers_common.py
  247. $(test-wrapper-env) $(py-env) \
  248. $(PYTHON) $*.py $*.c $(objpfx)$* $(pretty-printers) > $@; \
  249. $(evaluate-test)
  250. endif
  251. .PHONY: distclean realclean subdir_distclean subdir_realclean \
  252. subdir_clean subdir_mostlyclean subdir_testclean
  253. subdir_mostlyclean: mostlyclean
  254. subdir_clean: clean
  255. subdir_distclean: distclean
  256. subdir_realclean: realclean
  257. subdir_testclean: do-tests-clean
  258. realclean: distclean
  259. distclean: clean
  260. # We want to install everything except the library itself, but update all
  261. # our portions of the library because the parent make will install it later
  262. # (likewise the stubs file).
  263. .PHONY: subdir_install
  264. subdir_install: install-no-libc.a lib-noranlib stubs
  265. .PHONY: subdir_objs subdir_stubs
  266. subdir_objs: objs
  267. subdir_stubs: stubs
  268. # Target required by the Hurd to ensure that all the MiG-generated
  269. # headers are in place before building a subdirectory.
  270. .PHONY: before-compile
  271. before-compile: $(before-compile)
  272. $(common-objpfx)dummy.o: $(common-objpfx)dummy.c $(before-compile);
  273. $(compile-command.c)
  274. # Local Variables:
  275. # mode: makefile
  276. # End: