1 # Copyright (C) 1991-2022 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, see
16 # <https://www.gnu.org/licenses/>.
19 # Master Makefile for the GNU C library
22 This makefile requires GNU Make.
28 # This is the default target; it makes everything except the tests.
29 .PHONY: all help minihelp
30 all: minihelp lib others
33 @sed '0,/^help-starts-here$$/d' Makefile.help
37 @echo type \"make help\" for help with common glibc makefile targets
41 ifneq ($(AUTOCONF),no)
45 $(AUTOCONF) $(ACFLAGS) $< > $@.new
46 chmod a-w$(patsubst %,$(comma)a+x,$(filter .,$(@D))) $@.new
50 configure: configure.ac aclocal.m4; $(autoconf-it)
51 %/configure: %/configure.ac aclocal.m4; $(autoconf-it)
52 %/preconfigure: %/preconfigure.ac aclocal.m4; $(autoconf-it)
54 endif # $(AUTOCONF) = no
57 # We don't want to run anything here in parallel.
60 # These are the targets that are made by making them in each subdirectory.
61 +subdir_targets := subdir_lib objects objs others subdir_mostlyclean \
62 subdir_clean subdir_distclean subdir_realclean \
64 subdir_update-abi subdir_check-abi \
65 subdir_update-all-abi \
68 subdir_objs subdir_stubs subdir_testclean \
69 $(addprefix install-, no-libc.a bin lib data headers others)
71 headers := limits.h values.h features.h features-time64.h gnu-versions.h \
72 bits/xopen_lim.h gnu/libc-version.h stdc-predef.h \
73 bits/libc-header-start.h
75 echo-headers: subdir_echo-headers
77 # The headers are in the include directory.
79 vpath %.h $(subdir-dirs)
82 install-others = $(inst_includedir)/gnu/stubs.h
85 ifeq (yes,$(build-shared))
86 headers += gnu/lib-names.h
91 ifeq ($(build-programs),yes)
92 others: $(addprefix $(objpfx),$(install-bin-script))
95 # Install from subdirectories too.
96 install: subdir_install
98 # Explicit dependency so that `make install-headers' works
99 install-headers: install-headers-nosubdir
101 # Make sure that the dynamic linker is installed before libc.
102 $(inst_slibdir)/libc-$(version).so: elf/ldso_install
104 .PHONY: elf/ldso_install
106 $(MAKE) -C $(@D) $(@F)
108 # Create links for shared libraries using the `ldconfig' program if possible.
109 # Ignore the error if we cannot update /etc/ld.so.cache.
110 ifeq (no,$(cross-compiling))
111 ifeq (yes,$(build-shared))
113 -test ! -x $(elf-objpfx)ldconfig || LC_ALL=C \
114 $(elf-objpfx)ldconfig $(addprefix -r ,$(install_root)) \
117 ifeq (/usr,$(prefix))
118 ifeq (,$(install_root))
119 LD_SO=$(ld.so-version) CC="$(CC)" $(PERL) scripts/test-installation.pl $(common-objpfx)
126 # Build subdirectory lib objects.
127 lib-noranlib: subdir_lib
129 ifeq (yes,$(build-shared))
130 # Build the shared object from the PIC object library.
131 lib: $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so
132 endif # $(build-shared)
134 # Used to build testrun.sh.
135 define testrun-script
137 builddir=`dirname "$$0"`
138 GCONV_PATH="$${builddir}/iconvdata"
142 Usage: $$0 [OPTIONS] <program> [ARGUMENTS...]
144 --tool=TOOL Run with the specified TOOL. It can be strace, rpctrace,
145 valgrind or container. The container will run within
146 support/test-container.
153 while test $$# -gt 0 ; do
168 if test $$# -eq 0 ; then
174 exec $(subst $(common-objdir),"$${builddir}", $(test-program-prefix)) \
178 exec strace $(patsubst %, -E%, $(run-program-env)) \
179 $(test-via-rtld-prefix) $${1+"$$@"}
182 exec rpctrace $(patsubst %, -E%, $(run-program-env)) \
183 $(test-via-rtld-prefix) $${1+"$$@"}
186 exec env $(run-program-env) valgrind $(test-via-rtld-prefix) $${1+"$$@"}
189 exec env $(run-program-env) $(test-via-rtld-prefix) \
190 $(common-objdir)/support/test-container \
191 env $(run-program-env) $(test-via-rtld-prefix) $${1+"$$@"}
199 # This is a handy script for running any dynamically linked program against
200 # the current libc build for testing.
201 $(common-objpfx)testrun.sh: $(common-objpfx)config.make \
202 $(..)Makeconfig $(..)Makefile
203 $(file >$@T,$(testrun-script))
206 postclean-generated += testrun.sh
211 SOURCE_DIR="$(CURDIR)"
212 BUILD_DIR="$(common-objpfx)"
213 CMD_FILE="$(common-objpfx)debugglibc.gdb"
225 Usage: $$0 [OPTIONS] <program>
227 Or: $$0 [OPTIONS] -- <program> [<args>]...
229 where <program> is the path to the program being tested,
230 and <args> are the arguments to be passed to it.
235 Prints this message and leaves.
237 The following options require one argument:
240 Breakpoints to set at the beginning of the execution
241 (each breakpoint demands its own -b option, e.g. -b foo -b bar)
242 -e, --environment-variable
243 Environment variables to be set with 'exec-wrapper env' in GDB
244 (each environment variable demands its own -e option, e.g.
245 -e FOO=foo -e BAR=bar)
247 The following options do not take arguments:
250 Run the test case inside a container and automatically attach
253 Selects whether to pass the --direct flag to the program.
254 --direct is useful when debugging glibc test cases. It inhibits the
255 tests from forking and executing in a subprocess.
256 Default behaviour is to pass the --direct flag, except when the
257 program is run with user specified arguments using the "--" separator.
258 -s, --no-symbols-file
259 Do not tell GDB to load debug symbols from the program.
263 # Parse input options
273 BREAKPOINTS="break $$2\n$$BREAKPOINTS"
276 -e|--environment-variable)
277 ENVVARS="$$2 $$ENVVARS"
286 -s|--no-symbols-file)
293 # Don't add --direct when user specifies program arguments
299 COMMANDLINE=$$TESTCASE
305 # Check for required argument and if the testcase exists
306 if [ ! -v TESTCASE ] || [ ! -f $${TESTCASE} ]
312 # Container tests needing locale data should install them in-container.
313 # Other tests/binaries need to use locale data from the build tree.
314 if [ "$$CONTAINER" = false ]
316 ENVVARS="GCONV_PATH=$${BUILD_DIR}/iconvdata $$ENVVARS"
317 ENVVARS="LOCPATH=$${BUILD_DIR}/localedata $$ENVVARS"
318 ENVVARS="LC_ALL=C $$ENVVARS"
321 # Expand environment setup command
324 ENVVARSCMD="set exec-wrapper env $$ENVVARS"
327 # Expand direct argument
328 if [ "$$DIRECT" == true ]
335 # Check if the test case is static
336 if file $${TESTCASE} | grep "statically linked" >/dev/null
343 # Expand symbols loading command
344 if [ "$$SYMBOLSFILE" == true ]
346 SYMBOLSFILE="add-symbol-file $${TESTCASE}"
351 # GDB commands template
355 set environment C -E -x c-header
356 set auto-load safe-path $${BUILD_DIR}/nptl_db:\$$debugdir:\$$datadir/auto-load
357 set libthread-db-search-path $${BUILD_DIR}/nptl_db
361 run --library-path $(rpath-link):$${BUILD_DIR}/nptl_db \
362 __COMMANDLINE__ __DIRECT__
367 # Generate the commands file for gdb initialization
369 -e "s|__ENVVARS__|$$ENVVARSCMD|" \
370 -e "s|__SYMBOLSFILE__|$$SYMBOLSFILE|" \
371 -e "s|__COMMANDLINE__|$$COMMANDLINE|" \
372 -e "s|__DIRECT__|$$DIRECT|" \
373 -e "s|__BREAKPOINTS__|$$BREAKPOINTS|" \
377 echo "Debugging glibc..."
378 echo "Build directory : $$BUILD_DIR"
379 echo "Source directory : $$SOURCE_DIR"
380 echo "GLIBC Testcase : $$TESTCASE"
381 echo "GDB Commands : $$CMD_FILE"
382 echo "Env vars : $$ENVVARS"
385 if [ "$$CONTAINER" == true ]
387 # Use testrun.sh to start the test case with WAIT_FOR_DEBUGGER=1, then
388 # automatically attach GDB to it.
389 WAIT_FOR_DEBUGGER=1 $(common-objpfx)testrun.sh --tool=container $${TESTCASE} &
390 gdb -x $${TESTCASE}.gdb
391 elif [ "$$STATIC" == true ]
395 # Start the test case debugging in two steps:
396 # 1. the following command invokes gdb to run the loader;
397 # 2. the commands file tells the loader to run the test case.
401 $${BUILD_DIR}/elf/ld.so
405 # This is another handy script for debugging dynamically linked program
406 # against the current libc build for testing.
407 $(common-objpfx)debugglibc.sh: $(common-objpfx)config.make \
408 $(..)Makeconfig $(..)Makefile
409 $(file >$@T,$(debugglibc))
412 postclean-generated += debugglibc.sh debugglibc.gdb
414 others: $(common-objpfx)testrun.sh $(common-objpfx)debugglibc.sh
416 # Makerules creates a file `stubs' in each subdirectory, which
417 # contains `#define __stub_FUNCTION' for each function defined in that
418 # directory which is a stub.
419 # Here we paste all of these together into <gnu/stubs.h>.
421 subdir-stubs := $(foreach dir,$(subdirs),$(common-objpfx)$(dir)/stubs)
424 installed-stubs = $(inst_includedir)/gnu/stubs.h
426 installed-stubs = $(inst_includedir)/gnu/stubs-$(default-abi).h
428 $(inst_includedir)/gnu/stubs.h: $(+force)
429 $(make-target-directory)
431 echo '/* This file is automatically generated.';\
432 echo " This file selects the right generated file of \`__stub_FUNCTION' macros";\
433 echo ' based on the architecture being compiled for. */'; \
435 $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
437 $(foreach v,$(abi-variants),\
438 $(if $(abi-$(v)-condition),\
439 echo '#if $(abi-$(v)-condition)'; \
440 echo '# include <gnu/stubs-$(v).h>'); \
441 $(if $(abi-$(v)-condition),echo '#endif';) \
442 rm -f $(@:.d=.h).new$(v); \
445 mv -f $(@:.d=.h).new $(@:.d=.h)
447 install-others-nosubdir: $(installed-stubs)
451 # Since stubs.h is never needed when building the library, we simplify the
452 # hairy installation process by producing it in place only as the last part
453 # of the top-level `make install'. It depends on subdir_install, which
454 # iterates over all the subdirs; subdir_install in each subdir depends on
455 # the subdir's stubs file. Having more direct dependencies would result in
456 # extra iterations over the list for subdirs and many recursive makes.
457 $(installed-stubs): include/stubs-prologue.h subdir_install
458 $(make-target-directory)
459 @rm -f $(objpfx)stubs.h
460 (sed '/^@/d' $<; LC_ALL=C sort $(subdir-stubs)) > $(objpfx)stubs.h
461 if test -r $@ && cmp -s $(objpfx)stubs.h $@; \
462 then echo 'stubs.h unchanged'; \
463 else $(INSTALL_DATA) $(objpfx)stubs.h $@; fi
464 rm -f $(objpfx)stubs.h
466 # This makes the Info or DVI file of the documentation from the Texinfo source.
467 .PHONY: info dvi pdf html
469 $(MAKE) $(PARALLELMFLAGS) -C manual $@
471 # This makes all the subdirectory targets.
473 # For each target, make it depend on DIR/target for each subdirectory DIR.
474 $(+subdir_targets): %: $(addsuffix /%,$(subdirs))
476 # Compute a list of all those targets.
477 all-subdirs-targets := $(foreach dir,$(subdirs),\
478 $(addprefix $(dir)/,$(+subdir_targets)))
480 # The action for each of those is to cd into the directory and make the
482 $(all-subdirs-targets):
483 $(MAKE) $(PARALLELMFLAGS) $(subdir-target-args) $(@F)
485 define subdir-target-args
486 subdir=$(@D)$(if $($(@D)-srcdir),\
487 -C $($(@D)-srcdir) ..=`pwd`/,\
491 .PHONY: $(+subdir_targets) $(all-subdirs-targets)
493 # Targets to clean things up to various degrees.
495 .PHONY: clean realclean distclean distclean-1 parent-clean parent-mostlyclean \
498 # Subroutines of all cleaning targets.
499 parent-mostlyclean: common-mostlyclean # common-mostlyclean is in Makerules.
500 -rm -f $(foreach o,$(object-suffixes-for-libc),\
501 $(common-objpfx)$(patsubst %,$(libtype$o),c)) \
502 $(addprefix $(objpfx),$(install-lib))
503 parent-clean: parent-mostlyclean common-clean
505 postclean = $(addprefix $(common-objpfx),$(postclean-generated)) \
506 $(addprefix $(objpfx),sysd-dirs sysd-rules) \
507 $(addprefix $(objpfx),sysd-sorted soversions.mk soversions.i)
510 # This is done this way rather than having `subdir_clean' be a
511 # dependency of this target so that libc.a will be removed before the
512 # subdirectories are dealt with and so they won't try to remove object
513 # files from it when it's going to be removed anyway.
514 @$(MAKE) subdir_clean no_deps=t
516 mostlyclean: parent-mostlyclean
517 @$(MAKE) subdir_mostlyclean no_deps=t
521 @$(MAKE) subdir_testclean no_deps=t
524 vpath c++-types.data $(+sysdep_dirs)
526 tests-special += $(objpfx)c++-types-check.out
527 $(objpfx)c++-types-check.out: c++-types.data scripts/check-c++-types.sh
528 scripts/check-c++-types.sh $< $(CXX) $(filter-out -std=gnu11 $(+gccwarn-c),$(CFLAGS)) $(CPPFLAGS) > $@; \
532 tests-special += $(objpfx)check-local-headers.out
533 $(objpfx)check-local-headers.out: scripts/check-local-headers.sh
534 AWK='$(AWK)' scripts/check-local-headers.sh \
535 "$(includedir)" "$(objpfx)" < /dev/null > $@; \
538 ifneq "$(headers)" ""
539 # Special test of all the installed headers in this directory.
540 tests-special += $(objpfx)check-installed-headers-c.out
541 libof-check-installed-headers-c := testsuite
542 $(objpfx)check-installed-headers-c.out: \
543 scripts/check-installed-headers.sh $(headers)
544 $(SHELL) $(..)scripts/check-installed-headers.sh c \
545 "$(CC) $(filter-out -std=%,$(CFLAGS)) -D_ISOMAC $(+includes)" \
550 tests-special += $(objpfx)check-installed-headers-cxx.out
551 libof-check-installed-headers-cxx := testsuite
552 $(objpfx)check-installed-headers-cxx.out: \
553 scripts/check-installed-headers.sh $(headers)
554 $(SHELL) $(..)scripts/check-installed-headers.sh c++ \
555 "$(CXX) $(filter-out -std=%,$(CXXFLAGS)) -D_ISOMAC $(+includes)" \
560 tests-special += $(objpfx)check-wrapper-headers.out
561 $(objpfx)check-wrapper-headers.out: scripts/check-wrapper-headers.py $(headers)
562 $(PYTHON) $< --root=. --subdir=. $(headers) \
563 --generated $(common-generated) > $@; $(evaluate-test)
566 define summarize-tests
567 @egrep -v '^(PASS|XFAIL):' $(objpfx)$1 || true
568 @echo "Summary of test results$2:"
569 @sed 's/:.*//' < $(objpfx)$1 | sort | uniq -c
570 @! egrep -q -v '^(X?PASS|XFAIL|UNSUPPORTED):' $(objpfx)$1
573 # The intention here is to do ONE install of our build into the
574 # testroot.pristine/ directory, then rsync (internal to
575 # support/test-container) that to testroot.root/ at the start of each
576 # test. That way we can promise each test a "clean" install, without
577 # having to do the install for each test.
579 # In addition, we have to copy some files (which we build) into this
580 # root in addition to what glibc installs. For example, many tests
581 # require additional programs including /bin/sh, /bin/true, and
582 # /bin/echo, all of which we build below to limit library dependencies
583 # to just those things in glibc and language support libraries which
584 # we also copy into the into the rootfs. To determine what language
585 # support libraries we need we build a "test" program in either C or
586 # (if available) C++ just so we can copy in any shared objects
587 # (which we do not build) that GCC-compiled programs depend on.
591 LINKS_DSO_PROGRAM = links-dso-program-c
593 LINKS_DSO_PROGRAM = links-dso-program
596 $(tests-container) $(addsuffix /tests,$(subdirs)) : \
597 $(objpfx)testroot.pristine/install.stamp
598 $(objpfx)testroot.pristine/install.stamp :
599 test -d $(objpfx)testroot.pristine || \
600 mkdir $(objpfx)testroot.pristine
601 # We need a working /bin/sh for some of the tests.
602 test -d $(objpfx)testroot.pristine/bin || \
603 mkdir $(objpfx)testroot.pristine/bin
604 # We need the compiled locale dir for localedef tests.
605 test -d $(objpfx)testroot.pristine/$(complocaledir) || \
606 mkdir -p $(objpfx)testroot.pristine/$(complocaledir)
607 cp $(objpfx)support/shell-container $(objpfx)testroot.pristine/bin/sh
608 cp $(objpfx)support/echo-container $(objpfx)testroot.pristine/bin/echo
609 cp $(objpfx)support/true-container $(objpfx)testroot.pristine/bin/true
610 ifeq ($(run-built-tests),yes)
611 # Copy these DSOs first so we can overwrite them with our own.
612 for dso in `$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1 \
614 $(objpfx)testroot.pristine/bin/sh \
615 | sed -n '/\//{s@.*=> /@/@;s/^[^/]*//;s/ .*//p;}'` ;\
617 test -d `dirname $(objpfx)testroot.pristine$$dso` || \
618 mkdir -p `dirname $(objpfx)testroot.pristine$$dso` ;\
619 $(test-wrapper) cp $$dso $(objpfx)testroot.pristine$$dso ;\
621 for dso in `$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1 \
623 $(objpfx)support/$(LINKS_DSO_PROGRAM) \
624 | sed -n '/\//{s@.*=> /@/@;s/^[^/]*//;s/ .*//p;}'` ;\
626 test -d `dirname $(objpfx)testroot.pristine$$dso` || \
627 mkdir -p `dirname $(objpfx)testroot.pristine$$dso` ;\
628 $(test-wrapper) cp $$dso $(objpfx)testroot.pristine$$dso ;\
631 # $(symbolic-link-list) is a file that encodes $(DESTDIR) so we
633 rm -f $(symbolic-link-list)
634 # Setting INSTALL_UNCOMPRESSED causes localedata/Makefile to
635 # install the charmaps uncompressed, as the testroot does not
636 # provide a gunzip program.
637 $(MAKE) install DESTDIR=$(objpfx)testroot.pristine \
638 INSTALL_UNCOMPRESSED=yes subdirs='$(sorted-subdirs)'
639 rm -f $(symbolic-link-list)
640 touch $(objpfx)testroot.pristine/install.stamp
642 tests-special-notdir = $(patsubst $(objpfx)%, %, $(tests-special))
643 tests: $(tests-special)
644 $(..)scripts/merge-test-results.sh -s $(objpfx) "" \
645 $(sort $(tests-special-notdir:.out=)) \
646 > $(objpfx)subdir-tests.sum
647 $(..)scripts/merge-test-results.sh -t $(objpfx) subdir-tests.sum \
648 $(sort $(subdirs) .) \
650 $(call summarize-tests,tests.sum)
652 $(..)scripts/merge-test-results.sh -t $(objpfx) subdir-xtests.sum \
654 > $(objpfx)xtests.sum
655 $(call summarize-tests,xtests.sum, for extra tests)
657 # The realclean target is just like distclean for the parent, but we want
658 # the subdirs to know the difference in case they care.
659 realclean distclean: parent-clean
660 # This is done this way rather than having `subdir_distclean' be a
661 # dependency of this target so that libc.a will be removed before the
662 # subdirectories are dealt with and so they won't try to remove object
663 # files from it when it's going to be removed anyway.
664 @$(MAKE) distclean-1 no_deps=t distclean-1=$@ avoid-generated=yes \
665 sysdep-subdirs="$(sysdep-subdirs)"
668 # Subroutine of distclean and realclean.
669 distclean-1: subdir_$(distclean-1)
670 -rm -f $(config-generated)
671 -rm -f $(addprefix $(objpfx),config.status config.cache config.log)
672 -rm -f $(addprefix $(objpfx),config.make config-name.h config.h)
674 -rm -f $(objpfx)Makefile
676 -rm -f $(sysdep-$(distclean-1))
678 # Make the TAGS file for Emacs users.
682 scripts/list-sources.sh | sed -n -e '/Makefile/p' \
683 $(foreach S,[chsSyl] cxx sh bash pl,\
684 $(subst .,\.,-e '/.$S\(.in\)*$$/p')) \
687 # Make the distribution tarfile.
688 .PHONY: dist dist-prepare
690 generated := $(generated) stubs.h
692 files-for-dist := README INSTALL configure NEWS
694 # Regenerate stuff, then error if these things are not committed yet.
695 dist-prepare: $(files-for-dist)
696 conf=`find sysdeps -name configure`; \
698 git diff --stat HEAD -- $^ $$conf \
699 | $(AWK) '{ print; rc=1 } END { exit rc }'
702 git archive --prefix=$*/ $* > $@.new
705 # Do `make dist dist-version=X.Y.Z' to make tar files of an older version.
707 ifneq (,$(strip $(dist-version)))
708 dist: $(foreach Z,.bz2 .gz .xz,$(dist-version).tar$Z)
712 @if v=`git describe`; then \
713 echo Distribution version $$v; \
714 $(MAKE) dist dist-version=$$v; \
720 INSTALL: manual/install-plain.texi manual/macros.texi \
721 $(common-objpfx)manual/pkgvers.texi manual/install.texi
722 makeinfo --no-validate --plaintext --no-number-sections \
723 -I$(common-objpfx)manual $< -o $@-tmp
724 $(AWK) 'NF == 0 { ++n; next } \
725 NF != 0 { while (n-- > 0) print ""; n = 0; print }' \
730 $(common-objpfx)manual/%: FORCE
731 $(MAKE) $(PARALLELMFLAGS) -C manual $@
734 iconvdata/% localedata/% po/%: FORCE
735 $(MAKE) $(PARALLELMFLAGS) -C $(@D) $(@F)
737 # Convenience target to rerun one test, from the top of the build tree
738 # Example: make test t=wcsmbs/test-wcsnlen
741 @-rm -f $(objpfx)$t.out
742 $(MAKE) subdir=$(patsubst %/,%,$(dir $t)) -C $(dir $t) ..=../ $(objpfx)$t.out
743 @cat $(objpfx)$t.test-result