1 # Copyright (C) 1991-2019 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.
32 ifneq ($(AUTOCONF
),no
)
36 $(AUTOCONF
) $(ACFLAGS
) $< > $@.new
37 chmod a-w
$(patsubst %,$(comma
)a
+x
,$(filter .
,$(@D
))) $@.new
41 configure
: configure.ac aclocal.m4
; $(autoconf-it
)
42 %/configure
: %/configure.ac aclocal.m4
; $(autoconf-it
)
43 %/preconfigure
: %/preconfigure.ac aclocal.m4
; $(autoconf-it
)
45 endif # $(AUTOCONF) = no
48 # We don't want to run anything here in parallel.
51 # These are the targets that are made by making them in each subdirectory.
52 +subdir_targets
:= subdir_lib objects objs others subdir_mostlyclean \
53 subdir_clean subdir_distclean subdir_realclean \
55 subdir_update-abi subdir_check-abi \
56 subdir_update-all-abi \
59 subdir_objs subdir_stubs subdir_testclean \
60 $(addprefix install-
, no-libc.a bin lib data headers others
)
62 headers
:= limits.h values.h features.h gnu-versions.h \
63 bits
/xopen_lim.h gnu
/libc-version.h stdc-predef.h \
64 bits
/libc-header-start.h
66 echo-headers
: subdir_echo-headers
68 # The headers are in the include directory.
70 vpath
%.h
$(subdir-dirs
)
73 install-others
= $(inst_includedir
)/gnu
/stubs.h
76 ifeq (yes
,$(build-shared
))
77 headers
+= gnu
/lib-names.h
82 ifeq ($(build-programs
),yes
)
83 others
: $(addprefix $(objpfx
),$(install-bin-script
))
86 # Install from subdirectories too.
87 install: subdir_install
89 # Explicit dependency so that `make install-headers' works
90 install-headers
: install-headers-nosubdir
92 # Make sure that the dynamic linker is installed before libc.
93 $(inst_slibdir
)/libc-
$(version
).so
: elf
/ldso_install
95 .PHONY
: elf
/ldso_install
97 $(MAKE
) -C
$(@D
) $(@F
)
99 # Create links for shared libraries using the `ldconfig' program if possible.
100 # Ignore the error if we cannot update /etc/ld.so.cache.
101 ifeq (no
,$(cross-compiling
))
102 ifeq (yes
,$(build-shared
))
103 install: install-symbolic-link
104 .PHONY
: install-symbolic-link
105 install-symbolic-link
: subdir_install
106 $(symbolic-link-prog
) $(symbolic-link-list
)
107 rm -f
$(symbolic-link-list
)
110 -test ! -x
$(elf-objpfx
)ldconfig || LC_ALL
=C \
111 $(elf-objpfx
)ldconfig
$(addprefix -r
,$(install_root
)) \
114 ifeq (/usr
,$(prefix))
115 ifeq (,$(install_root
))
116 LD_SO
=$(ld.so-version
) CC
="$(CC)" $(PERL
) scripts
/test-installation.pl
$(common-objpfx
)
123 # Build subdirectory lib objects.
124 lib-noranlib
: subdir_lib
126 ifeq (yes
,$(build-shared
))
127 # Build the shared object from the PIC object library.
128 lib
: $(common-objpfx
)libc.so
$(common-objpfx
)linkobj
/libc.so
129 endif # $(build-shared)
131 # Used to build testrun.sh.
132 define testrun-script
134 builddir
=`dirname "$$0"`
135 GCONV_PATH
="$${builddir}/iconvdata"
138 echo
"usage: $$0 [--tool=strace] PROGRAM [ARGUMENTS...]" 2>&1
139 echo
" $$0 --tool=valgrind PROGRAM [ARGUMENTS...]" 2>&1
144 while
test $$# -gt 0 ; do
159 if
test $$# -eq 0 ; then
165 exec
$(subst $(common-objdir
),"$${builddir}", $(test-program-prefix
)) \
169 exec strace
$(patsubst %, -E
%, $(run-program-env
)) \
170 $(test-via-rtld-prefix
) $${1+"$$@"}
173 exec env
$(run-program-env
) valgrind
$(test-via-rtld-prefix
) $${1+"$$@"}
181 # This is a handy script for running any dynamically linked program against
182 # the current libc build for testing.
183 $(common-objpfx
)testrun.sh
: $(common-objpfx
)config.make \
184 $(..
)Makeconfig
$(..
)Makefile
185 $(file
>$@T
,$(testrun-script
))
188 postclean-generated
+= testrun.sh
193 SOURCE_DIR
="$(CURDIR)"
194 BUILD_DIR
="$(common-objpfx)"
195 CMD_FILE
="$(common-objpfx)debugglibc.gdb"
205 Usage
: $$0 [OPTIONS
] <testcase
>
207 where
<testcase
> is the path to the program being tested.
212 Prints this message and leaves.
214 The following options require one argument
:
217 Breakpoints to set at the beginning of the execution
218 (each breakpoint demands its own
-b option
, e.g.
-b foo
-b bar
)
219 -e
, --environment-variable
220 Environment variables to be set with
'exec-wrapper env' in GDB
221 (each environment variable demands its own
-e option
, e.g.
222 -e FOO
=foo
-e BAR
=bar
)
224 The following options do not take arguments
:
227 Selects whether to pass the flag
--direct to gdb.
228 Required for glibc
test cases and not allowed for non-glibc tests.
229 Default behaviour is to pass the flag
--direct to gdb.
230 -s
, --no-symbols-file
231 Do not tell GDB to load debug symbols from the testcase.
235 # Parse input options
245 BREAKPOINTS
="break $$2\n$$BREAKPOINTS"
248 -e|
--environment-variable
)
249 ENVVARS
="$$2 $$ENVVARS"
255 -s|
--no-symbols-file
)
265 # Check for required argument
272 # Expand environment setup command
275 ENVVARSCMD
="set exec-wrapper env $$ENVVARS"
278 # Expand direct argument
279 if
[ "$$DIRECT" == true
]
286 # Expand symbols loading command
287 if
[ "$$SYMBOLSFILE" == true
]
289 SYMBOLSFILE
="add-symbol-file $${TESTCASE}"
294 # GDB commands template
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
304 run
--library-path
$(rpath-link
):$${BUILD_DIR}/nptl_db \
305 __TESTCASE__ __DIRECT__
310 # Generate the commands file for gdb initialization
312 -e
"s|__ENVVARS__|$$ENVVARSCMD|" \
313 -e
"s|__SYMBOLSFILE__|$$SYMBOLSFILE|" \
314 -e
"s|__TESTCASE__|$$TESTCASE|" \
315 -e
"s|__DIRECT__|$$DIRECT|" \
316 -e
"s|__BREAKPOINTS__|$$BREAKPOINTS|" \
320 echo
"Debugging glibc..."
321 echo
"Build directory : $$BUILD_DIR"
322 echo
"Source directory : $$SOURCE_DIR"
323 echo
"GLIBC Testcase : $$TESTCASE"
324 echo
"GDB Commands : $$CMD_FILE"
325 echo
"Env vars : $$ENVVARS"
328 # Start the test case debugging in two steps:
329 # 1. the following command invokes gdb to run the loader;
330 # 2. the commands file tells the loader to run the test case.
334 $${BUILD_DIR}/elf
/ld.so
337 # This is another handy script for debugging dynamically linked program
338 # against the current libc build for testing.
339 $(common-objpfx
)debugglibc.sh
: $(common-objpfx
)config.make \
340 $(..
)Makeconfig
$(..
)Makefile
341 $(file
>$@T
,$(debugglibc
))
344 postclean-generated
+= debugglibc.sh debugglibc.gdb
346 others
: $(common-objpfx
)testrun.sh
$(common-objpfx
)debugglibc.sh
348 # Makerules creates a file `stubs' in each subdirectory, which
349 # contains `#define __stub_FUNCTION' for each function defined in that
350 # directory which is a stub.
351 # Here we paste all of these together into <gnu/stubs.h>.
353 subdir-stubs
:= $(foreach dir,$(subdirs
),$(common-objpfx
)$(dir)/stubs
)
356 installed-stubs
= $(inst_includedir
)/gnu
/stubs.h
358 installed-stubs
= $(inst_includedir
)/gnu
/stubs-
$(default-abi
).h
360 $(inst_includedir
)/gnu
/stubs.h
: $(+force)
361 $(make-target-directory
)
363 echo
'/* This file is automatically generated.';\
364 echo
" This file selects the right generated file of \`__stub_FUNCTION' macros";\
365 echo
' based on the architecture being compiled for. */'; \
367 $(foreach h
,$(abi-includes
), echo
'#include <$(h)>';) \
369 $(foreach v
,$(abi-variants
),\
370 $(if
$(abi-
$(v
)-condition
),\
371 echo
'#if $(abi-$(v)-condition)'; \
372 echo
'# include <gnu/stubs-$(v).h>'); \
373 $(if
$(abi-
$(v
)-condition
),echo
'#endif';) \
374 rm -f
$(@
:.d
=.h
).new
$(v
); \
377 mv
-f
$(@
:.d
=.h
).new
$(@
:.d
=.h
)
379 install-others-nosubdir
: $(installed-stubs
)
383 # Since stubs.h is never needed when building the library, we simplify the
384 # hairy installation process by producing it in place only as the last part
385 # of the top-level `make install'. It depends on subdir_install, which
386 # iterates over all the subdirs; subdir_install in each subdir depends on
387 # the subdir's stubs file. Having more direct dependencies would result in
388 # extra iterations over the list for subdirs and many recursive makes.
389 $(installed-stubs
): include/stubs-prologue.h subdir_install
390 $(make-target-directory
)
391 @
rm -f
$(objpfx
)stubs.h
392 (sed
'/^@/d' $<; LC_ALL
=C
sort $(subdir-stubs
)) > $(objpfx
)stubs.h
393 if
test -r
$@
&& cmp
-s
$(objpfx
)stubs.h
$@
; \
394 then echo
'stubs.h unchanged'; \
395 else $(INSTALL_DATA
) $(objpfx
)stubs.h
$@
; fi
396 rm -f
$(objpfx
)stubs.h
398 # This makes the Info or DVI file of the documentation from the Texinfo source.
399 .PHONY
: info dvi pdf html
401 $(MAKE
) $(PARALLELMFLAGS
) -C manual
$@
403 # This makes all the subdirectory targets.
405 # For each target, make it depend on DIR/target for each subdirectory DIR.
406 $(+subdir_targets
): %: $(addsuffix /%,$(subdirs
))
408 # Compute a list of all those targets.
409 all-subdirs-targets
:= $(foreach dir,$(subdirs
),\
410 $(addprefix $(dir)/,$(+subdir_targets
)))
412 # The action for each of those is to cd into the directory and make the
414 $(all-subdirs-targets
):
415 $(MAKE
) $(PARALLELMFLAGS
) $(subdir-target-args
) $(@F
)
417 define subdir-target-args
418 subdir
=$(@D
)$(if
$($(@D
)-srcdir),\
419 -C
$($(@D
)-srcdir) ..
=`pwd`/,\
423 .PHONY
: $(+subdir_targets
) $(all-subdirs-targets
)
425 # Targets to clean things up to various degrees.
427 .PHONY
: clean realclean distclean distclean-1 parent-clean parent-mostlyclean \
430 # Subroutines of all cleaning targets.
431 parent-mostlyclean
: common-mostlyclean
# common-mostlyclean is in Makerules.
432 -rm -f
$(foreach o
,$(object-suffixes-for-libc
),\
433 $(common-objpfx
)$(patsubst %,$(libtype
$o),c
)) \
434 $(addprefix $(objpfx
),$(install-lib
))
435 parent-clean
: parent-mostlyclean common-clean
437 postclean
= $(addprefix $(common-objpfx
),$(postclean-generated
)) \
438 $(addprefix $(objpfx
),sysd-dirs sysd-rules
) \
439 $(addprefix $(objpfx
),sysd-sorted soversions.mk soversions.i
)
442 # This is done this way rather than having `subdir_clean' be a
443 # dependency of this target so that libc.a will be removed before the
444 # subdirectories are dealt with and so they won't try to remove object
445 # files from it when it's going to be removed anyway.
446 @
$(MAKE
) subdir_clean no_deps
=t
448 mostlyclean: parent-mostlyclean
449 @
$(MAKE
) subdir_mostlyclean no_deps
=t
453 @
$(MAKE
) subdir_testclean no_deps
=t
456 vpath c
++-types.data
$(+sysdep_dirs
)
458 tests-special
+= $(objpfx
)c
++-types-check.out
459 $(objpfx
)c
++-types-check.out
: c
++-types.data scripts
/check-c
++-types.sh
460 scripts
/check-c
++-types.sh
$< $(CXX
) $(filter-out -std
=gnu11
$(+gccwarn-c
),$(CFLAGS
)) $(CPPFLAGS
) > $@
; \
464 tests-special
+= $(objpfx
)check-local-headers.out
465 $(objpfx
)check-local-headers.out
: scripts
/check-local-headers.sh
466 AWK
='$(AWK)' scripts
/check-local-headers.sh \
467 "$(includedir)" "$(objpfx)" < /dev
/null
> $@
; \
470 ifneq "$(headers)" ""
471 # Special test of all the installed headers in this directory.
472 tests-special
+= $(objpfx
)check-installed-headers-c.out
473 libof-check-installed-headers-c
:= testsuite
474 $(objpfx
)check-installed-headers-c.out
: \
475 scripts
/check-installed-headers.sh
$(headers
)
476 $(SHELL
) $(..
)scripts
/check-installed-headers.sh c \
477 "$(CC) $(filter-out -std=%,$(CFLAGS)) -D_ISOMAC $(+includes)" \
482 tests-special
+= $(objpfx
)check-installed-headers-cxx.out
483 libof-check-installed-headers-cxx
:= testsuite
484 $(objpfx
)check-installed-headers-cxx.out
: \
485 scripts
/check-installed-headers.sh
$(headers
)
486 $(SHELL
) $(..
)scripts
/check-installed-headers.sh c
++ \
487 "$(CXX) $(filter-out -std=%,$(CXXFLAGS)) -D_ISOMAC $(+includes)" \
492 tests-special
+= $(objpfx
)check-wrapper-headers.out
493 $(objpfx
)check-wrapper-headers.out
: scripts
/check-wrapper-headers.py
$(headers
)
494 $(PYTHON
) $< --root
=.
--subdir
=.
$(headers
) \
495 --generated
$(common-generated
) > $@
; $(evaluate-test
)
498 define summarize-tests
499 @egrep
-v
'^(PASS|XFAIL):' $(objpfx
)$1 || true
500 @echo
"Summary of test results$2:"
501 @sed
's/:.*//' < $(objpfx
)$1 |
sort | uniq
-c
502 @
! egrep
-q
-v
'^(X?PASS|XFAIL|UNSUPPORTED):' $(objpfx
)$1
505 # The intention here is to do ONE install of our build into the
506 # testroot.pristine/ directory, then rsync (internal to
507 # support/test-container) that to testroot.root/ at the start of each
508 # test. That way we can promise each test a "clean" install, without
509 # having to do the install for each test.
511 # In addition, we have to copy some files (which we build) into this
512 # root in addition to what glibc installs. For example, many tests
513 # require additional programs including /bin/sh, /bin/true, and
514 # /bin/echo, all of which we build below to limit library dependencies
515 # to just those things in glibc and language support libraries which
516 # we also copy into the into the rootfs. To determine what language
517 # support libraries we need we build a "test" program in either C or
518 # (if available) C++ just so we can copy in any shared objects
519 # (which we do not build) that GCC-compiled programs depend on.
523 LINKS_DSO_PROGRAM
= links-dso-program-c
525 LINKS_DSO_PROGRAM
= links-dso-program
528 $(tests-container
) $(addsuffix /tests
,$(subdirs
)) : \
529 $(objpfx
)testroot.pristine
/install.stamp
530 $(objpfx
)testroot.pristine
/install.stamp
:
531 test -d
$(objpfx
)testroot.pristine || \
532 mkdir
$(objpfx
)testroot.pristine
533 # We need a working /bin/sh for some of the tests.
534 test -d
$(objpfx
)testroot.pristine
/bin || \
535 mkdir
$(objpfx
)testroot.pristine
/bin
536 cp
$(objpfx
)support
/shell-container
$(objpfx
)testroot.pristine
/bin
/sh
537 cp
$(objpfx
)support
/echo-container
$(objpfx
)testroot.pristine
/bin
/echo
538 cp
$(objpfx
)support
/true-container
$(objpfx
)testroot.pristine
/bin
/true
539 ifeq ($(run-built-tests
),yes
)
540 # Copy these DSOs first so we can overwrite them with our own.
541 for dso in
`$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1 \
543 $(objpfx)testroot.pristine/bin/sh \
544 | grep / | sed 's/^[^/]*//' | sed 's/ .*//'` ;\
546 test -d
`dirname $(objpfx)testroot.pristine$$dso` || \
547 mkdir
-p
`dirname $(objpfx)testroot.pristine$$dso` ;\
548 $(test-wrapper
) cp
$$dso $(objpfx
)testroot.pristine
$$dso ;\
550 for dso in
`$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1 \
552 $(objpfx)support/$(LINKS_DSO_PROGRAM) \
553 | grep / | sed 's/^[^/]*//' | sed 's/ .*//'` ;\
555 test -d
`dirname $(objpfx)testroot.pristine$$dso` || \
556 mkdir
-p
`dirname $(objpfx)testroot.pristine$$dso` ;\
557 $(test-wrapper
) cp
$$dso $(objpfx
)testroot.pristine
$$dso ;\
560 $(MAKE
) install DESTDIR
=$(objpfx
)testroot.pristine \
561 subdirs
='$(sorted-subdirs)'
562 touch
$(objpfx
)testroot.pristine
/install.stamp
564 tests-special-notdir
= $(patsubst $(objpfx
)%, %, $(tests-special
))
565 tests
: $(tests-special
)
566 $(..
)scripts
/merge-test-results.sh
-s
$(objpfx
) "" \
567 $(sort $(tests-special-notdir
:.out
=)) \
568 > $(objpfx
)subdir-tests.sum
569 $(..
)scripts
/merge-test-results.sh
-t
$(objpfx
) subdir-tests.sum \
570 $(sort $(subdirs
) .
) \
572 $(call summarize-tests
,tests.sum
)
574 $(..
)scripts
/merge-test-results.sh
-t
$(objpfx
) subdir-xtests.sum \
576 > $(objpfx
)xtests.sum
577 $(call summarize-tests
,xtests.sum
, for extra tests
)
579 # The realclean target is just like distclean for the parent, but we want
580 # the subdirs to know the difference in case they care.
581 realclean distclean: parent-clean
582 # This is done this way rather than having `subdir_distclean' be a
583 # dependency of this target so that libc.a will be removed before the
584 # subdirectories are dealt with and so they won't try to remove object
585 # files from it when it's going to be removed anyway.
586 @
$(MAKE
) distclean-1 no_deps
=t distclean-1
=$@ avoid-generated
=yes \
587 sysdep-subdirs
="$(sysdep-subdirs)"
590 # Subroutine of distclean and realclean.
591 distclean-1
: subdir_
$(distclean-1
)
592 -rm -f
$(config-generated
)
593 -rm -f
$(addprefix $(objpfx
),config.status config.cache config.log
)
594 -rm -f
$(addprefix $(objpfx
),config.make config-name.h config.h
)
596 -rm -f
$(objpfx
)Makefile
598 -rm -f
$(sysdep-
$(distclean-1
))
600 # Make the TAGS file for Emacs users.
604 scripts
/list-sources.sh | sed
-n
-e
'/Makefile/p' \
605 $(foreach S
,[chsSyl
] cxx sh bash pl
,\
606 $(subst .
,\.
,-e
'/.$S\(.in\)*$$/p')) \
609 # Make the distribution tarfile.
610 .PHONY
: dist dist-prepare
612 generated
:= $(generated
) stubs.h
614 files-for-dist
:= README INSTALL configure ChangeLog NEWS
616 # Regenerate stuff, then error if these things are not committed yet.
617 dist-prepare
: $(files-for-dist
)
618 conf
=`find sysdeps -name configure`; \
620 git diff
--stat HEAD
-- $^
$$conf \
621 |
$(AWK
) '{ print; rc=1 } END { exit rc }'
624 git archive
--prefix=$*/ $* > $@.new
627 # Do `make dist dist-version=X.Y.Z' to make tar files of an older version.
629 ifneq (,$(strip $(dist-version
)))
630 dist: $(foreach Z
,.bz2 .gz .xz
,$(dist-version
).
tar$Z)
634 @if v
=`git describe`; then \
635 echo Distribution version
$$v; \
636 $(MAKE
) dist dist-version
=$$v; \
642 INSTALL
: manual
/install-plain.texi manual
/macros.texi \
643 $(common-objpfx
)manual
/pkgvers.texi manual
/install.texi
644 makeinfo --no-validate
--plaintext
--no-number-sections \
645 -I
$(common-objpfx
)manual
$< -o
$@
-tmp
646 $(AWK
) 'NF == 0 { ++n; next } \
647 NF != 0 { while (n-- > 0) print ""; n = 0; print }' \
652 $(common-objpfx
)manual
/%: FORCE
653 $(MAKE
) $(PARALLELMFLAGS
) -C manual
$@
656 iconvdata
/% localedata
/% po
/%: FORCE
657 $(MAKE
) $(PARALLELMFLAGS
) -C
$(@D
) $(@F
)