Makefile 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. # Copyright (C) 1991-2026 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. # <https://www.gnu.org/licenses/>.
  14. #
  15. # Master Makefile for the GNU C library
  16. #
  17. ifneq (,)
  18. This makefile requires GNU Make.
  19. endif
  20. include Makeconfig
  21. # This is the default target; it makes everything except the tests.
  22. .PHONY: all help minihelp
  23. all: minihelp lib others
  24. help:
  25. @sed '0,/^help-starts-here$$/d' Makefile.help
  26. minihelp:
  27. @echo
  28. @echo type \"make help\" for help with common glibc makefile targets
  29. @echo
  30. ifneq ($(AUTOCONF),no)
  31. define autoconf-it
  32. @-rm -f $@.new
  33. $(AUTOCONF) $(ACFLAGS) $< > $@.new
  34. chmod a-w$(patsubst %,$(comma)a+x,$(filter .,$(@D))) $@.new
  35. mv -f $@.new $@
  36. endef
  37. configure: configure.ac aclocal.m4; $(autoconf-it)
  38. %/configure: %/configure.ac aclocal.m4; $(autoconf-it)
  39. %/preconfigure: %/preconfigure.ac aclocal.m4; $(autoconf-it)
  40. endif # $(AUTOCONF) = no
  41. # We don't want to run anything here in parallel.
  42. .NOTPARALLEL:
  43. # These are the targets that are made by making them in each subdirectory.
  44. +subdir_targets := subdir_lib objects objs others subdir_mostlyclean \
  45. subdir_clean subdir_distclean subdir_realclean \
  46. tests xtests \
  47. subdir_update-abi subdir_check-abi \
  48. subdir_update-all-abi \
  49. subdir_echo-headers \
  50. subdir_install \
  51. subdir_objs subdir_stubs subdir_testclean \
  52. $(addprefix install-, no-libc.a bin lib data headers others)
  53. headers := limits.h values.h features.h features-time64.h gnu-versions.h \
  54. bits/xopen_lim.h gnu/libc-version.h stdc-predef.h \
  55. bits/libc-header-start.h
  56. echo-headers: subdir_echo-headers
  57. # The headers are in the include directory.
  58. subdir-dirs = include
  59. vpath %.h $(subdir-dirs)
  60. # What to install.
  61. install-others = $(inst_includedir)/gnu/stubs.h
  62. install-bin-script =
  63. ifeq (yes,$(build-shared))
  64. headers += gnu/lib-names.h
  65. endif
  66. include Makerules
  67. ifeq ($(build-programs),yes)
  68. others: $(addprefix $(objpfx),$(install-bin-script))
  69. endif
  70. # Install from subdirectories too.
  71. install: subdir_install
  72. # Explicit dependency so that `make install-headers' works
  73. install-headers: install-headers-nosubdir
  74. # Make sure that the dynamic linker is installed before libc.
  75. $(inst_slibdir)/libc-$(version).so: elf/ldso_install
  76. .PHONY: elf/ldso_install
  77. elf/ldso_install:
  78. $(MAKE) -C $(@D) $(@F)
  79. # Create links for shared libraries using the `ldconfig' program if possible.
  80. # Ignore the error if we cannot update /etc/ld.so.cache.
  81. ifeq (no,$(cross-compiling))
  82. ifeq (yes,$(build-shared))
  83. install:
  84. -test ! -x $(elf-objpfx)ldconfig || LC_ALL=C \
  85. $(elf-objpfx)ldconfig $(addprefix -r ,$(install_root)) \
  86. $(slibdir) $(libdir)
  87. ifneq (no,$(PERL))
  88. ifeq (/usr,$(prefix))
  89. ifeq (,$(install_root))
  90. LD_SO=$(ld.so-version) CC="$(CC)" $(PERL) scripts/test-installation.pl $(common-objpfx)
  91. endif
  92. endif
  93. endif
  94. endif
  95. endif
  96. # Build subdirectory lib objects.
  97. lib-noranlib: subdir_lib
  98. ifeq (yes,$(build-shared))
  99. # Build the shared object from the PIC object library.
  100. lib: $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so
  101. endif # $(build-shared)
  102. # Used to build testrun.sh.
  103. define testrun-script
  104. #!/bin/bash
  105. builddir=`dirname "$$0"`
  106. GCONV_PATH="$${builddir}/iconvdata"
  107. usage () {
  108. cat << EOF
  109. Usage: $$0 [OPTIONS] <program> [ARGUMENTS...]
  110. --tool=TOOL Run with the specified TOOL. It can be strace, rpctrace,
  111. valgrind or container. The container will run within
  112. support/test-container. For strace and valgrind,
  113. additional arguments can be passed after the tool name.
  114. EOF
  115. exit 1
  116. }
  117. toolname=default
  118. while test $$# -gt 0 ; do
  119. case "$$1" in
  120. --tool=*)
  121. toolname="$${1:7}"
  122. shift
  123. ;;
  124. --*)
  125. usage
  126. ;;
  127. *)
  128. break
  129. ;;
  130. esac
  131. done
  132. if test $$# -eq 0 ; then
  133. usage
  134. fi
  135. case "$$toolname" in
  136. default)
  137. exec $(subst $(common-objdir),"$${builddir}", $(test-program-prefix)) \
  138. $${1+"$$@"}
  139. ;;
  140. strace*)
  141. exec $$toolname $(patsubst %, -E%, $(run-program-env)) \
  142. $(test-via-rtld-prefix) $${1+"$$@"}
  143. ;;
  144. rpctrace)
  145. exec rpctrace $(patsubst %, -E%, $(run-program-env)) \
  146. $(test-via-rtld-prefix) $${1+"$$@"}
  147. ;;
  148. valgrind*)
  149. exec env $(run-program-env) $$toolname $(test-via-rtld-prefix) $${1+"$$@"}
  150. ;;
  151. container)
  152. exec env $(run-program-env) $(test-via-rtld-prefix) \
  153. $(common-objdir)/support/test-container \
  154. env $(run-program-env) $(test-via-rtld-prefix) $${1+"$$@"}
  155. ;;
  156. *)
  157. usage
  158. ;;
  159. esac
  160. endef
  161. # This is a handy script for running any dynamically linked program against
  162. # the current libc build for testing.
  163. $(common-objpfx)testrun.sh: $(common-objpfx)config.make \
  164. $(..)Makeconfig $(..)Makefile
  165. $(file >$@T,$(testrun-script))
  166. chmod a+x $@T
  167. mv -f $@T $@
  168. postclean-generated += testrun.sh
  169. define debugglibc
  170. #!/bin/bash
  171. SOURCE_DIR="$(CURDIR)"
  172. BUILD_DIR="$(common-objpfx)"
  173. CMD_FILE="$(common-objpfx)debugglibc.gdb"
  174. CONTAINER=false
  175. DIRECT=true
  176. STATIC=false
  177. SYMBOLSFILE=true
  178. unset TESTCASE
  179. unset BREAKPOINTS
  180. unset ENVVARS
  181. usage()
  182. {
  183. cat << EOF
  184. Usage: $$0 [OPTIONS] <program>
  185. Or: $$0 [OPTIONS] -- <program> [<args>]...
  186. where <program> is the path to the program being tested,
  187. and <args> are the arguments to be passed to it.
  188. Options:
  189. -h, --help
  190. Prints this message and leaves.
  191. The following options require one argument:
  192. -b, --breakpoint
  193. Breakpoints to set at the beginning of the execution
  194. (each breakpoint demands its own -b option, e.g. -b foo -b bar)
  195. -e, --environment-variable
  196. Environment variables to be set with 'exec-wrapper env' in GDB
  197. (each environment variable demands its own -e option, e.g.
  198. -e FOO=foo -e BAR=bar)
  199. The following options do not take arguments:
  200. -c, --in-container
  201. Run the test case inside a container and automatically attach
  202. GDB to it.
  203. -i, --no-direct
  204. Selects whether to pass the --direct flag to the program.
  205. --direct is useful when debugging glibc test cases. It inhibits the
  206. tests from forking and executing in a subprocess.
  207. Default behaviour is to pass the --direct flag, except when the
  208. program is run with user specified arguments using the "--" separator.
  209. -s, --no-symbols-file
  210. Do not tell GDB to load debug symbols from the program.
  211. EOF
  212. }
  213. # Parse input options
  214. while [[ $$# > 0 ]]
  215. do
  216. key="$$1"
  217. case $$key in
  218. -h|--help)
  219. usage
  220. exit 0
  221. ;;
  222. -b|--breakpoint)
  223. BREAKPOINTS="break $$2\n$$BREAKPOINTS"
  224. shift
  225. ;;
  226. -e|--environment-variable)
  227. ENVVARS="$$2 $$ENVVARS"
  228. shift
  229. ;;
  230. -c|--in-container)
  231. CONTAINER=true
  232. ;;
  233. -i|--no-direct)
  234. DIRECT=false
  235. ;;
  236. -s|--no-symbols-file)
  237. SYMBOLSFILE=false
  238. ;;
  239. --)
  240. shift
  241. TESTCASE=$$1
  242. COMMANDLINE="$$@"
  243. # Don't add --direct when user specifies program arguments
  244. DIRECT=false
  245. break
  246. ;;
  247. *)
  248. TESTCASE=$$1
  249. COMMANDLINE=$$TESTCASE
  250. ;;
  251. esac
  252. shift
  253. done
  254. # Check for required argument and if the testcase exists
  255. if [ ! -v TESTCASE ] || [ ! -f $${TESTCASE} ]
  256. then
  257. usage
  258. exit 1
  259. fi
  260. # Container tests needing locale data should install them in-container.
  261. # Other tests/binaries need to use locale data from the build tree.
  262. if [ "$$CONTAINER" = false ]
  263. then
  264. ENVVARS="GCONV_PATH=$${BUILD_DIR}/iconvdata $$ENVVARS"
  265. ENVVARS="LOCPATH=$${BUILD_DIR}/localedata $$ENVVARS"
  266. ENVVARS="LC_ALL=C $$ENVVARS"
  267. fi
  268. # Expand environment setup command
  269. if [ -v ENVVARS ]
  270. then
  271. ENVVARSCMD="set exec-wrapper env $$ENVVARS"
  272. fi
  273. # Expand direct argument
  274. if [ "$$DIRECT" == true ]
  275. then
  276. DIRECT="--direct"
  277. else
  278. DIRECT=""
  279. fi
  280. # Check if the test case is static
  281. if file $${TESTCASE} | grep "statically linked" >/dev/null
  282. then
  283. STATIC=true
  284. else
  285. STATIC=false
  286. fi
  287. # Expand symbols loading command
  288. if [ "$$SYMBOLSFILE" == true ]
  289. then
  290. SYMBOLSFILE="add-symbol-file $${TESTCASE}"
  291. else
  292. SYMBOLSFILE=""
  293. fi
  294. # GDB commands template
  295. template ()
  296. {
  297. cat <<EOF
  298. set environment C -E -x c-header
  299. set auto-load safe-path $${BUILD_DIR}/nptl_db:\$$debugdir:\$$datadir/auto-load
  300. set libthread-db-search-path $${BUILD_DIR}/nptl_db
  301. __ENVVARS__
  302. __SYMBOLSFILE__
  303. break _dl_start_user
  304. run --library-path $(rpath-link):$${BUILD_DIR}/nptl_db \
  305. __COMMANDLINE__ __DIRECT__
  306. __BREAKPOINTS__
  307. EOF
  308. }
  309. # Generate the commands file for gdb initialization
  310. template | sed \
  311. -e "s|__ENVVARS__|$$ENVVARSCMD|" \
  312. -e "s|__SYMBOLSFILE__|$$SYMBOLSFILE|" \
  313. -e "s|__COMMANDLINE__|$$COMMANDLINE|" \
  314. -e "s|__DIRECT__|$$DIRECT|" \
  315. -e "s|__BREAKPOINTS__|$$BREAKPOINTS|" \
  316. > $$CMD_FILE
  317. echo
  318. echo "Debugging glibc..."
  319. echo "Build directory : $$BUILD_DIR"
  320. echo "Source directory : $$SOURCE_DIR"
  321. echo "GLIBC Testcase : $$TESTCASE"
  322. echo "GDB Commands : $$CMD_FILE"
  323. echo "Env vars : $$ENVVARS"
  324. echo
  325. if [ "$$CONTAINER" == true ]
  326. then
  327. # Use testrun.sh to start the test case with WAIT_FOR_DEBUGGER=1, then
  328. # automatically attach GDB to it.
  329. WAIT_FOR_DEBUGGER=1 $(common-objpfx)testrun.sh --tool=container $${TESTCASE} &
  330. gdb -x $${TESTCASE}.gdb
  331. elif [ "$$STATIC" == true ]
  332. then
  333. gdb $${TESTCASE}
  334. else
  335. # Start the test case debugging in two steps:
  336. # 1. the following command invokes gdb to run the loader;
  337. # 2. the commands file tells the loader to run the test case.
  338. gdb -q \
  339. -x $${CMD_FILE} \
  340. -d $${SOURCE_DIR} \
  341. $${BUILD_DIR}/elf/ld.so
  342. fi
  343. endef
  344. # This is another handy script for debugging dynamically linked program
  345. # against the current libc build for testing.
  346. $(common-objpfx)debugglibc.sh: $(common-objpfx)config.make \
  347. $(..)Makeconfig $(..)Makefile
  348. $(file >$@T,$(debugglibc))
  349. chmod a+x $@T
  350. mv -f $@T $@
  351. postclean-generated += debugglibc.sh debugglibc.gdb
  352. others: $(common-objpfx)testrun.sh $(common-objpfx)debugglibc.sh
  353. # Makerules creates a file `stubs' in each subdirectory, which
  354. # contains `#define __stub_FUNCTION' for each function defined in that
  355. # directory which is a stub.
  356. # Here we paste all of these together into <gnu/stubs.h>.
  357. subdir-stubs := $(foreach dir,$(subdirs),$(common-objpfx)$(dir)/stubs)
  358. ifndef abi-variants
  359. installed-stubs = $(inst_includedir)/gnu/stubs.h
  360. else
  361. installed-stubs = $(inst_includedir)/gnu/stubs-$(default-abi).h
  362. $(inst_includedir)/gnu/stubs.h: $(+force)
  363. $(make-target-directory)
  364. { \
  365. echo '/* This file is automatically generated.';\
  366. echo " This file selects the right generated file of \`__stub_FUNCTION' macros";\
  367. echo ' based on the architecture being compiled for. */'; \
  368. echo ''; \
  369. $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
  370. echo ''; \
  371. $(foreach v,$(abi-variants),\
  372. $(if $(abi-$(v)-condition),\
  373. echo '#if $(abi-$(v)-condition)'; \
  374. echo '# include <gnu/stubs-$(v).h>'); \
  375. $(if $(abi-$(v)-condition),echo '#endif';) \
  376. rm -f $(@:.d=.h).new$(v); \
  377. ) \
  378. } > $(@:.d=.h).new
  379. mv -f $(@:.d=.h).new $(@:.d=.h)
  380. install-others-nosubdir: $(installed-stubs)
  381. endif
  382. # Since stubs.h is never needed when building the library, we simplify the
  383. # hairy installation process by producing it in place only as the last part
  384. # of the top-level `make install'. It depends on subdir_install, which
  385. # iterates over all the subdirs; subdir_install in each subdir depends on
  386. # the subdir's stubs file. Having more direct dependencies would result in
  387. # extra iterations over the list for subdirs and many recursive makes.
  388. $(installed-stubs): include/stubs-prologue.h subdir_install
  389. $(make-target-directory)
  390. @rm -f $(objpfx)stubs.h
  391. (sed '/^@/d' $<; LC_ALL=C sort $(subdir-stubs)) > $(objpfx)stubs.h
  392. if test -r $@ && cmp -s $(objpfx)stubs.h $@; \
  393. then echo 'stubs.h unchanged'; \
  394. else $(INSTALL_DATA) $(objpfx)stubs.h $@; fi
  395. rm -f $(objpfx)stubs.h
  396. # This makes the Info or DVI file of the documentation from the Texinfo source.
  397. .PHONY: info dvi pdf html
  398. info dvi pdf html:
  399. $(MAKE) $(PARALLELMFLAGS) -C manual $@
  400. # This makes all the subdirectory targets.
  401. # For each target, make it depend on DIR/target for each subdirectory DIR.
  402. $(+subdir_targets): %: $(addsuffix /%,$(subdirs))
  403. # Compute a list of all those targets.
  404. all-subdirs-targets := $(foreach dir,$(subdirs),\
  405. $(addprefix $(dir)/,$(+subdir_targets)))
  406. # The action for each of those is to cd into the directory and make the
  407. # target there.
  408. $(all-subdirs-targets):
  409. $(MAKE) $(PARALLELMFLAGS) $(subdir-target-args) $(@F)
  410. define subdir-target-args
  411. subdir=$(@D)$(if $($(@D)-srcdir),\
  412. -C $($(@D)-srcdir) ..=`pwd`/,\
  413. -C $(@D) ..=../)
  414. endef
  415. .PHONY: $(+subdir_targets) $(all-subdirs-targets)
  416. # Targets to clean things up to various degrees.
  417. .PHONY: clean realclean distclean distclean-1 parent-clean parent-mostlyclean \
  418. tests-clean
  419. # Subroutines of all cleaning targets.
  420. parent-mostlyclean: common-mostlyclean # common-mostlyclean is in Makerules.
  421. -rm -f $(foreach o,$(object-suffixes-for-libc),\
  422. $(common-objpfx)$(patsubst %,$(libtype$o),c)) \
  423. $(addprefix $(objpfx),$(install-lib))
  424. parent-clean: parent-mostlyclean common-clean
  425. postclean = $(addprefix $(common-objpfx),$(postclean-generated)) \
  426. $(addprefix $(objpfx),sysd-dirs sysd-rules) \
  427. $(addprefix $(objpfx),sysd-sorted soversions.mk soversions.i)
  428. clean: parent-clean
  429. # This is done this way rather than having `subdir_clean' be a
  430. # dependency of this target so that libc.a will be removed before the
  431. # subdirectories are dealt with and so they won't try to remove object
  432. # files from it when it's going to be removed anyway.
  433. @$(MAKE) subdir_clean no_deps=t
  434. -rm -f $(postclean)
  435. mostlyclean: parent-mostlyclean
  436. @$(MAKE) subdir_mostlyclean no_deps=t
  437. -rm -f $(postclean)
  438. # Remove test artifacts from the whole glibc build.
  439. # do-tests-clean removes test artifacts from top-level directory, and
  440. # subdir_testclean removes them from individual sub-directories.
  441. tests-clean: do-tests-clean
  442. @$(MAKE) subdir_testclean no_deps=t
  443. ifneq (,$(CXX))
  444. vpath c++-types.data $(+sysdep_dirs)
  445. tests-special += $(objpfx)c++-types-check.out
  446. $(objpfx)c++-types-check.out: c++-types.data scripts/check-c++-types.sh
  447. scripts/check-c++-types.sh $< $(CXX) $(filter-out -std=gnu11 $(+gccwarn-c),$(CFLAGS)) $(CPPFLAGS) > $@; \
  448. $(evaluate-test)
  449. endif
  450. tests-special += $(objpfx)check-local-headers.out
  451. $(objpfx)check-local-headers.out: scripts/check-local-headers.sh
  452. AWK='$(AWK)' scripts/check-local-headers.sh \
  453. "$(includedir)" "$(objpfx)" < /dev/null > $@; \
  454. $(evaluate-test)
  455. ifneq "$(headers)" ""
  456. # Special test of all the installed headers in this directory.
  457. tests-special += $(objpfx)check-installed-headers-c.out
  458. libof-check-installed-headers-c := testsuite
  459. $(objpfx)check-installed-headers-c.out: \
  460. scripts/check-installed-headers.sh $(headers)
  461. $(SHELL) $(..)scripts/check-installed-headers.sh c $(supported-fortify) \
  462. "$(CC) $(test-config-cflags-finput-charset-ascii) \
  463. $(filter-out -std=%,$(CFLAGS)) -D_ISOMAC $(+includes)" \
  464. $(headers) > $@; \
  465. $(evaluate-test)
  466. ifneq "$(CXX)" ""
  467. tests-special += $(objpfx)check-installed-headers-cxx.out
  468. libof-check-installed-headers-cxx := testsuite
  469. $(objpfx)check-installed-headers-cxx.out: \
  470. scripts/check-installed-headers.sh $(headers)
  471. $(SHELL) $(..)scripts/check-installed-headers.sh c++ $(supported-fortify) \
  472. "$(CXX) $(test-config-cxxflags-finput-charset-ascii) \
  473. $(filter-out -std=%,$(CXXFLAGS)) -D_ISOMAC $(+includes)" \
  474. $(headers) > $@; \
  475. $(evaluate-test)
  476. endif # $(CXX)
  477. tests-special += $(objpfx)check-wrapper-headers.out
  478. $(objpfx)check-wrapper-headers.out: scripts/check-wrapper-headers.py $(headers)
  479. $(PYTHON) $< --root=. --subdir=. $(headers) \
  480. --generated $(common-generated) > $@; $(evaluate-test)
  481. endif # $(headers)
  482. # Lint all Makefiles; including this one. Pass `pwd` as the source
  483. # directory since the top-level Makefile is in the root of the source
  484. # tree and these tests are run from there. We add light-weight linting
  485. # to the 'check' target to support the existing developer workflow of:
  486. # edit -> make -> make check; without needing an additional step.
  487. tests-special += $(objpfx)lint-makefiles.out
  488. $(objpfx)lint-makefiles.out: scripts/lint-makefiles.sh
  489. $(SHELL) $< "$(PYTHON)" `pwd` > $@ ; \
  490. $(evaluate-test)
  491. # Link libc.a as a whole to verify that it does not contain multiple
  492. # definitions of any symbols.
  493. tests-special += $(objpfx)link-static-libc.out
  494. $(objpfx)link-static-libc.out:
  495. $(LINK.o) $(whole-archive) -nostdlib -nostartfiles -r \
  496. $(objpfx)libc.a -o /dev/null > $@ 2>&1; \
  497. $(evaluate-test)
  498. # Print test summary for tests in $1 .sum file;
  499. # $2 is optional test identifier.
  500. # Fail if there are unexpected failures in the test results.
  501. define summarize-tests
  502. @grep -E '^[A-Z]+:' $(objpfx)$1 | grep -E -v '^(PASS|XFAIL):' || true
  503. @echo " === Summary of results$2 ==="
  504. @sed -e '/:.*/!d' -e 's/:.*//' < $(objpfx)$1 | sort | uniq -c
  505. @! grep -E '^[A-Z]+:' $(objpfx)$1 | grep -E -q -v '^(X?PASS|XFAIL|UNSUPPORTED):'
  506. endef
  507. # The intention here is to do ONE install of our build into the
  508. # testroot.pristine/ directory, then rsync (internal to
  509. # support/test-container) that to testroot.root/ at the start of each
  510. # test. That way we can promise each test a "clean" install, without
  511. # having to do the install for each test.
  512. #
  513. # In addition, we have to copy some files (which we build) into this
  514. # root in addition to what glibc installs. For example, many tests
  515. # require additional programs including /bin/sh, /bin/true, and
  516. # /bin/echo, all of which we build below to limit library dependencies
  517. # to just those things in glibc and language support libraries which
  518. # we also copy into the into the rootfs. To determine what language
  519. # support libraries we need we build a "test" program in either C or
  520. # (if available) C++ just so we can copy in any shared objects
  521. # (which we do not build) that GCC-compiled programs depend on.
  522. ifeq (,$(CXX))
  523. LINKS_DSO_PROGRAM = links-dso-program-c
  524. else
  525. LINKS_DSO_PROGRAM = links-dso-program
  526. endif
  527. $(tests-container) $(addsuffix /tests,$(subdirs)) : \
  528. $(objpfx)testroot.pristine/install.stamp
  529. $(objpfx)testroot.pristine/install.stamp :
  530. test -d $(objpfx)testroot.pristine || \
  531. mkdir $(objpfx)testroot.pristine
  532. # We need a working /bin/sh for some of the tests.
  533. test -d $(objpfx)testroot.pristine/bin || \
  534. mkdir $(objpfx)testroot.pristine/bin
  535. # We need the compiled locale dir for localedef tests.
  536. test -d $(objpfx)testroot.pristine/$(complocaledir) || \
  537. mkdir -p $(objpfx)testroot.pristine/$(complocaledir)
  538. cp $(objpfx)support/shell-container $(objpfx)testroot.pristine/bin/sh
  539. cp $(objpfx)support/echo-container $(objpfx)testroot.pristine/bin/echo
  540. cp $(objpfx)support/true-container $(objpfx)testroot.pristine/bin/true
  541. # We need to be able to load extra language libraries.
  542. mkdir -p $(objpfx)testroot.pristine/etc/ld.so.conf.d
  543. echo 'include ld.so.conf.d/*.conf' > $(objpfx)testroot.pristine/etc/ld.so.conf
  544. echo $(gnulib-extralibdir) >> $(objpfx)testroot.pristine/etc/ld.so.conf
  545. echo '# file without content' > $(objpfx)testroot.pristine/etc/ld.so.conf.d/999-empty.conf
  546. ifeq ($(run-built-tests),yes)
  547. # Copy these DSOs first so we can overwrite them with our own.
  548. for dso in `$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1 \
  549. $(rtld-prefix) --inhibit-cache \
  550. $(objpfx)testroot.pristine/bin/sh \
  551. | sed -n '/\//{s@.*=> /@/@;s/^[^/]*//;s/ .*//p;}'` ;\
  552. do \
  553. test -d `dirname $(objpfx)testroot.pristine$$dso` || \
  554. mkdir -p `dirname $(objpfx)testroot.pristine$$dso` ;\
  555. $(test-wrapper) cp $$dso $(objpfx)testroot.pristine$$dso ;\
  556. done
  557. for dso in `$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1 \
  558. $(rtld-prefix) --inhibit-cache \
  559. $(objpfx)support/$(LINKS_DSO_PROGRAM) \
  560. | sed -n '/\//{s@.*=> /@/@;s/^[^/]*//;s/ .*//p;}'` ;\
  561. do \
  562. test -d `dirname $(objpfx)testroot.pristine$$dso` || \
  563. mkdir -p `dirname $(objpfx)testroot.pristine$$dso` ;\
  564. $(test-wrapper) cp $$dso $(objpfx)testroot.pristine$$dso ;\
  565. done
  566. endif
  567. # $(symbolic-link-list) is a file that encodes $(DESTDIR) so we
  568. # have to purge it
  569. rm -f $(symbolic-link-list)
  570. # Setting INSTALL_UNCOMPRESSED causes localedata/Makefile to
  571. # install the charmaps uncompressed, as the testroot does not
  572. # provide a gunzip program.
  573. $(MAKE) install DESTDIR=$(objpfx)testroot.pristine \
  574. INSTALL_UNCOMPRESSED=yes subdirs='$(sorted-subdirs)'
  575. rm -f $(symbolic-link-list)
  576. touch $(objpfx)testroot.pristine/install.stamp
  577. tests-special-notdir = $(patsubst $(objpfx)%, %, $(tests-special))
  578. tests: $(tests-special)
  579. $(..)scripts/merge-test-results.sh -s $(objpfx) "" \
  580. $(sort $(tests-special-notdir:.out=)) \
  581. > $(objpfx)subdir-tests.sum
  582. $(..)scripts/merge-test-results.sh -t $(objpfx) subdir-tests.sum \
  583. $(sort $(subdirs) .) \
  584. > $(objpfx)tests.sum
  585. $(call summarize-tests,tests.sum)
  586. xtests:
  587. $(..)scripts/merge-test-results.sh -t $(objpfx) subdir-xtests.sum \
  588. $(sort $(subdirs)) \
  589. > $(objpfx)xtests.sum
  590. $(call summarize-tests,xtests.sum, for extra tests)
  591. # The realclean target is just like distclean for the parent, but we want
  592. # the subdirs to know the difference in case they care.
  593. realclean distclean: parent-clean
  594. # This is done this way rather than having `subdir_distclean' be a
  595. # dependency of this target so that libc.a will be removed before the
  596. # subdirectories are dealt with and so they won't try to remove object
  597. # files from it when it's going to be removed anyway.
  598. @$(MAKE) distclean-1 no_deps=t distclean-1=$@ avoid-generated=yes \
  599. sysdep-subdirs="$(sysdep-subdirs)"
  600. -rm -f $(postclean)
  601. # Subroutine of distclean and realclean.
  602. distclean-1: subdir_$(distclean-1)
  603. -rm -f $(config-generated)
  604. -rm -f $(addprefix $(objpfx),config.status config.cache config.log)
  605. -rm -f $(addprefix $(objpfx),config.make config-name.h config.h)
  606. ifdef objdir
  607. -rm -f $(objpfx)Makefile
  608. endif
  609. -rm -f $(sysdep-$(distclean-1))
  610. # Make the TAGS file for Emacs users.
  611. .PHONY: TAGS
  612. TAGS:
  613. scripts/list-sources.sh | sed -n -e '/Makefile/p' \
  614. $(foreach S,[chsSyl] cxx sh bash pl,\
  615. $(subst .,\.,-e '/.$S\(.in\)*$$/p')) \
  616. | $(ETAGS) -o $@ -
  617. # Make the distribution tarfile.
  618. .PHONY: dist dist-prepare
  619. generated := $(generated) stubs.h
  620. files-for-dist := README INSTALL configure NEWS
  621. # Regenerate stuff, then error if these things are not committed yet.
  622. dist-prepare: $(files-for-dist)
  623. conf=`find sysdeps -name configure`; \
  624. $(MAKE) $$conf && \
  625. git diff --stat HEAD -- $^ $$conf \
  626. | $(AWK) '{ print; rc=1 } END { exit rc }'
  627. %.tar: FORCE
  628. git archive --prefix=$*/ $* > $@.new
  629. mv -f $@.new $@
  630. # Do `make dist dist-version=X.Y.Z' to make tar files of an older version.
  631. ifneq (,$(strip $(dist-version)))
  632. dist: $(foreach Z,.bz2 .gz .xz,$(dist-version).tar$Z)
  633. md5sum $^
  634. else
  635. dist: dist-prepare
  636. @if v=`git describe`; then \
  637. echo Distribution version $$v; \
  638. $(MAKE) dist dist-version=$$v; \
  639. else \
  640. false; \
  641. fi
  642. endif
  643. INSTALL: manual/install-plain.texi manual/macros.texi \
  644. $(common-objpfx)manual/pkgvers.texi manual/install.texi
  645. makeinfo --no-validate --plaintext --no-number-sections \
  646. --disable-encoding -I$(common-objpfx)manual $< -o $@-tmp
  647. $(AWK) 'NF == 0 { ++n; next } \
  648. NF != 0 { while (n-- > 0) print ""; n = 0; print }' \
  649. < $@-tmp > $@-tmp2
  650. rm -f $@-tmp
  651. -chmod a-w $@-tmp2
  652. mv -f $@-tmp2 $@
  653. $(common-objpfx)manual/%: FORCE
  654. $(MAKE) $(PARALLELMFLAGS) -C manual $@
  655. FORCE:
  656. iconvdata/% localedata/% po/%: FORCE
  657. $(MAKE) $(PARALLELMFLAGS) -C $(@D) $(@F)
  658. # Convenience target to rerun one test, from the top of the build tree
  659. # Example: make test t=wcsmbs/test-wcsnlen
  660. .PHONY: test
  661. test :
  662. @-rm -f $(objpfx)$t.out
  663. $(MAKE) subdir=$(patsubst %/,%,$(dir $t)) -C $(dir $t) ..=../ $(objpfx)$t.out
  664. @cat $(objpfx)$t.test-result
  665. @cat $(objpfx)$t.out