]> git.ipfire.org Git - thirdparty/glibc.git/blame - Makefile
posix/glob.c: update from gnulib
[thirdparty/glibc.git] / Makefile
CommitLineData
581c785b 1# Copyright (C) 1991-2022 Free Software Foundation, Inc.
28f540f4
RM
2# This file is part of the GNU C Library.
3
4# The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
28f540f4
RM
8
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
41bdb6e2 12# Lesser General Public License for more details.
28f540f4 13
41bdb6e2 14# You should have received a copy of the GNU Lesser General Public
59ba27a6 15# License along with the GNU C Library; if not, see
5a82c748 16# <https://www.gnu.org/licenses/>.
28f540f4
RM
17
18#
19# Master Makefile for the GNU C library
20#
21ifneq (,)
22This makefile requires GNU Make.
23endif
24
aa802e96
UD
25include Makeconfig
26
28f540f4
RM
27
28# This is the default target; it makes everything except the tests.
2ac579f9
DD
29.PHONY: all help minihelp
30all: minihelp lib others
31
32help:
33 @sed '0,/^help-starts-here$$/d' Makefile.help
34
35minihelp:
36 @echo
37 @echo type \"make help\" for help with common glibc makefile targets
38 @echo
39
28f540f4 40\f
1400de2e
RM
41ifneq ($(AUTOCONF),no)
42
4d06461a
UD
43define autoconf-it
44@-rm -f $@.new
1400de2e 45$(AUTOCONF) $(ACFLAGS) $< > $@.new
7967983f 46chmod a-w$(patsubst %,$(comma)a+x,$(filter .,$(@D))) $@.new
4d06461a
UD
47mv -f $@.new $@
48endef
c8d32817 49
cb8a6dbd
MF
50configure: configure.ac aclocal.m4; $(autoconf-it)
51%/configure: %/configure.ac aclocal.m4; $(autoconf-it)
52%/preconfigure: %/preconfigure.ac aclocal.m4; $(autoconf-it)
28f540f4 53
1400de2e
RM
54endif # $(AUTOCONF) = no
55
56
57# We don't want to run anything here in parallel.
58.NOTPARALLEL:
59
28f540f4 60# These are the targets that are made by making them in each subdirectory.
edf5b2d7
UD
61+subdir_targets := subdir_lib objects objs others subdir_mostlyclean \
62 subdir_clean subdir_distclean subdir_realclean \
dd7b064c 63 tests xtests \
7b57bfe5 64 subdir_update-abi subdir_check-abi \
c100dca3 65 subdir_update-all-abi \
7b57bfe5 66 subdir_echo-headers \
57ba7bb4 67 subdir_install \
5d9e8991 68 subdir_objs subdir_stubs subdir_testclean \
57ba7bb4 69 $(addprefix install-, no-libc.a bin lib data headers others)
28f540f4 70\f
47f24c21 71headers := limits.h values.h features.h features-time64.h gnu-versions.h \
48789000
JM
72 bits/xopen_lim.h gnu/libc-version.h stdc-predef.h \
73 bits/libc-header-start.h
28f540f4
RM
74
75echo-headers: subdir_echo-headers
76
762a2918
UD
77# The headers are in the include directory.
78subdir-dirs = include
79vpath %.h $(subdir-dirs)
80
28f540f4 81# What to install.
8d57beea 82install-others = $(inst_includedir)/gnu/stubs.h
fe54a69c 83install-bin-script =
56552e42 84
a18f587d 85ifeq (yes,$(build-shared))
6736e93b 86headers += gnu/lib-names.h
a18f587d 87endif
28f540f4 88
28f540f4
RM
89include Makerules
90
737547be 91ifeq ($(build-programs),yes)
6c3ebebd 92others: $(addprefix $(objpfx),$(install-bin-script))
737547be
UD
93endif
94
28f540f4
RM
95# Install from subdirectories too.
96install: subdir_install
8d57beea 97
6736e93b
UD
98# Explicit dependency so that `make install-headers' works
99install-headers: install-headers-nosubdir
100
5148d49f
UD
101# Make sure that the dynamic linker is installed before libc.
102$(inst_slibdir)/libc-$(version).so: elf/ldso_install
103
104.PHONY: elf/ldso_install
105elf/ldso_install:
106 $(MAKE) -C $(@D) $(@F)
107
b43b13ac 108# Create links for shared libraries using the `ldconfig' program if possible.
7cc27f44 109# Ignore the error if we cannot update /etc/ld.so.cache.
1ef32c3d
UD
110ifeq (no,$(cross-compiling))
111ifeq (yes,$(build-shared))
8d57beea 112install:
686554bf 113 -test ! -x $(elf-objpfx)ldconfig || LC_ALL=C \
4134b50d
JM
114 $(elf-objpfx)ldconfig $(addprefix -r ,$(install_root)) \
115 $(slibdir) $(libdir)
cc3fa755
UD
116ifneq (no,$(PERL))
117ifeq (/usr,$(prefix))
118ifeq (,$(install_root))
d22e28b0 119 LD_SO=$(ld.so-version) CC="$(CC)" $(PERL) scripts/test-installation.pl $(common-objpfx)
cc3fa755
UD
120endif
121endif
122endif
1ef32c3d
UD
123endif
124endif
28f540f4 125
01a36ad3
RM
126# Build subdirectory lib objects.
127lib-noranlib: subdir_lib
28f540f4 128
01a36ad3
RM
129ifeq (yes,$(build-shared))
130# Build the shared object from the PIC object library.
5f855e35 131lib: $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so
bd81123a 132endif # $(build-shared)
9bfce4bf 133
f2873d2d
FW
134# Used to build testrun.sh.
135define testrun-script
136#!/bin/bash
137builddir=`dirname "$$0"`
138GCONV_PATH="$${builddir}/iconvdata"
139
140usage () {
709e3709
LM
141cat << EOF
142Usage: $$0 [OPTIONS] <program> [ARGUMENTS...]
143
27ae52e4
SB
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.
709e3709
LM
147EOF
148
5e10136b 149 exit 1
f2873d2d
FW
150}
151
152toolname=default
153while test $$# -gt 0 ; do
154 case "$$1" in
155 --tool=*)
156 toolname="$${1:7}"
157 shift
158 ;;
159 --*)
160 usage
161 ;;
162 *)
163 break
164 ;;
165 esac
166done
167
168if test $$# -eq 0 ; then
169 usage
170fi
171
172case "$$toolname" in
173 default)
174 exec $(subst $(common-objdir),"$${builddir}", $(test-program-prefix)) \
175 $${1+"$$@"}
176 ;;
177 strace)
178 exec strace $(patsubst %, -E%, $(run-program-env)) \
179 $(test-via-rtld-prefix) $${1+"$$@"}
180 ;;
27ae52e4
SB
181 rpctrace)
182 exec rpctrace $(patsubst %, -E%, $(run-program-env)) \
183 $(test-via-rtld-prefix) $${1+"$$@"}
184 ;;
f2873d2d
FW
185 valgrind)
186 exec env $(run-program-env) valgrind $(test-via-rtld-prefix) $${1+"$$@"}
187 ;;
6ef1bab6
GG
188 container)
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+"$$@"}
192 ;;
f2873d2d
FW
193 *)
194 usage
195 ;;
196esac
197endef
9bfce4bf
RM
198
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
46341286 203 $(file >$@T,$(testrun-script))
9bfce4bf
RM
204 chmod a+x $@T
205 mv -f $@T $@
206postclean-generated += testrun.sh
207
79ced5a8
GG
208define debugglibc
209#!/bin/bash
210
211SOURCE_DIR="$(CURDIR)"
212BUILD_DIR="$(common-objpfx)"
213CMD_FILE="$(common-objpfx)debugglibc.gdb"
6ef1bab6 214CONTAINER=false
79ced5a8 215DIRECT=true
d0bc5b72 216STATIC=false
79ced5a8
GG
217SYMBOLSFILE=true
218unset TESTCASE
219unset BREAKPOINTS
220unset ENVVARS
221
222usage()
223{
224cat << EOF
21417aaa 225Usage: $$0 [OPTIONS] <program>
79ced5a8 226
21417aaa
AS
227 Or: $$0 [OPTIONS] -- <program> [<args>]...
228
229 where <program> is the path to the program being tested,
230 and <args> are the arguments to be passed to it.
79ced5a8
GG
231
232Options:
233
234 -h, --help
235 Prints this message and leaves.
236
237 The following options require one argument:
238
239 -b, --breakpoint
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)
246
247 The following options do not take arguments:
248
6ef1bab6
GG
249 -c, --in-container
250 Run the test case inside a container and automatically attach
251 GDB to it.
79ced5a8 252 -i, --no-direct
21417aaa
AS
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.
79ced5a8 258 -s, --no-symbols-file
21417aaa 259 Do not tell GDB to load debug symbols from the program.
79ced5a8
GG
260EOF
261}
262
263# Parse input options
264while [[ $$# > 0 ]]
265do
266 key="$$1"
267 case $$key in
268 -h|--help)
269 usage
270 exit 0
271 ;;
272 -b|--breakpoint)
273 BREAKPOINTS="break $$2\n$$BREAKPOINTS"
274 shift
275 ;;
276 -e|--environment-variable)
277 ENVVARS="$$2 $$ENVVARS"
278 shift
279 ;;
6ef1bab6
GG
280 -c|--in-container)
281 CONTAINER=true
282 ;;
79ced5a8
GG
283 -i|--no-direct)
284 DIRECT=false
285 ;;
286 -s|--no-symbols-file)
287 SYMBOLSFILE=false
288 ;;
21417aaa
AS
289 --)
290 shift
291 TESTCASE=$$1
292 COMMANDLINE="$$@"
293 # Don't add --direct when user specifies program arguments
294 DIRECT=false
295 break
296 ;;
79ced5a8
GG
297 *)
298 TESTCASE=$$1
21417aaa 299 COMMANDLINE=$$TESTCASE
79ced5a8
GG
300 ;;
301 esac
302 shift
303done
304
d0bc5b72
GG
305# Check for required argument and if the testcase exists
306if [ ! -v TESTCASE ] || [ ! -f $${TESTCASE} ]
79ced5a8
GG
307then
308 usage
309 exit 1
310fi
311
b3b0b691
AS
312# Container tests needing locale data should install them in-container.
313# Other tests/binaries need to use locale data from the build tree.
314if [ "$$CONTAINER" = false ]
315then
316 ENVVARS="GCONV_PATH=$${BUILD_DIR}/iconvdata $$ENVVARS"
317 ENVVARS="LOCPATH=$${BUILD_DIR}/localedata $$ENVVARS"
318 ENVVARS="LC_ALL=C $$ENVVARS"
319fi
320
79ced5a8
GG
321# Expand environment setup command
322if [ -v ENVVARS ]
323then
324 ENVVARSCMD="set exec-wrapper env $$ENVVARS"
325fi
326
327# Expand direct argument
328if [ "$$DIRECT" == true ]
329then
330 DIRECT="--direct"
331else
332 DIRECT=""
333fi
334
d0bc5b72
GG
335# Check if the test case is static
336if file $${TESTCASE} | grep "statically linked" >/dev/null
337then
338 STATIC=true
339else
340 STATIC=false
341fi
342
79ced5a8
GG
343# Expand symbols loading command
344if [ "$$SYMBOLSFILE" == true ]
345then
346 SYMBOLSFILE="add-symbol-file $${TESTCASE}"
347else
348 SYMBOLSFILE=""
349fi
350
351# GDB commands template
352template ()
353{
354cat <<EOF
355set environment C -E -x c-header
356set auto-load safe-path $${BUILD_DIR}/nptl_db:\$$debugdir:\$$datadir/auto-load
357set libthread-db-search-path $${BUILD_DIR}/nptl_db
358__ENVVARS__
359__SYMBOLSFILE__
360break _dl_start_user
361run --library-path $(rpath-link):$${BUILD_DIR}/nptl_db \
21417aaa 362__COMMANDLINE__ __DIRECT__
79ced5a8
GG
363__BREAKPOINTS__
364EOF
365}
366
367# Generate the commands file for gdb initialization
368template | sed \
369 -e "s|__ENVVARS__|$$ENVVARSCMD|" \
370 -e "s|__SYMBOLSFILE__|$$SYMBOLSFILE|" \
21417aaa 371 -e "s|__COMMANDLINE__|$$COMMANDLINE|" \
79ced5a8
GG
372 -e "s|__DIRECT__|$$DIRECT|" \
373 -e "s|__BREAKPOINTS__|$$BREAKPOINTS|" \
374 > $$CMD_FILE
375
376echo
377echo "Debugging glibc..."
378echo "Build directory : $$BUILD_DIR"
379echo "Source directory : $$SOURCE_DIR"
380echo "GLIBC Testcase : $$TESTCASE"
381echo "GDB Commands : $$CMD_FILE"
382echo "Env vars : $$ENVVARS"
383echo
384
6ef1bab6
GG
385if [ "$$CONTAINER" == true ]
386then
387# Use testrun.sh to start the test case with WAIT_FOR_DEBUGGER=1, then
388# automatically attach GDB to it.
389WAIT_FOR_DEBUGGER=1 $(common-objpfx)testrun.sh --tool=container $${TESTCASE} &
390gdb -x $${TESTCASE}.gdb
d0bc5b72
GG
391elif [ "$$STATIC" == true ]
392then
393gdb $${TESTCASE}
6ef1bab6 394else
79ced5a8
GG
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.
398gdb -q \
399 -x $${CMD_FILE} \
400 -d $${SOURCE_DIR} \
401 $${BUILD_DIR}/elf/ld.so
6ef1bab6 402fi
79ced5a8
GG
403endef
404
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))
410 chmod a+x $@T
411 mv -f $@T $@
412postclean-generated += debugglibc.sh debugglibc.gdb
413
414others: $(common-objpfx)testrun.sh $(common-objpfx)debugglibc.sh
28f540f4 415\f
97a47867
UD
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.
6bc31da0 419# Here we paste all of these together into <gnu/stubs.h>.
28f540f4 420
97a47867 421subdir-stubs := $(foreach dir,$(subdirs),$(common-objpfx)$(dir)/stubs)
28f540f4 422
0ab0291b 423ifndef abi-variants
3e1e123d
RM
424installed-stubs = $(inst_includedir)/gnu/stubs.h
425else
0ab0291b 426installed-stubs = $(inst_includedir)/gnu/stubs-$(default-abi).h
3e1e123d 427
691bc9c1 428$(inst_includedir)/gnu/stubs.h: $(+force)
f0cf0902 429 $(make-target-directory)
0ab0291b
L
430 { \
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. */'; \
434 echo ''; \
435 $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
436 echo ''; \
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); \
443 ) \
444 } > $(@:.d=.h).new
445 mv -f $(@:.d=.h).new $(@:.d=.h)
3e1e123d
RM
446
447install-others-nosubdir: $(installed-stubs)
448endif
449
450
28f540f4
RM
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
b9b49b44
UD
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.
3e1e123d 457$(installed-stubs): include/stubs-prologue.h subdir_install
5107cf1d 458 $(make-target-directory)
28f540f4 459 @rm -f $(objpfx)stubs.h
d62507dd 460 (sed '/^@/d' $<; LC_ALL=C sort $(subdir-stubs)) > $(objpfx)stubs.h
13a0be88 461 if test -r $@ && cmp -s $(objpfx)stubs.h $@; \
ba1ffaa1 462 then echo 'stubs.h unchanged'; \
d36e7692 463 else $(INSTALL_DATA) $(objpfx)stubs.h $@; fi
28f540f4
RM
464 rm -f $(objpfx)stubs.h
465\f
466# This makes the Info or DVI file of the documentation from the Texinfo source.
fef0b717
UD
467.PHONY: info dvi pdf html
468info dvi pdf html:
c0e45674 469 $(MAKE) $(PARALLELMFLAGS) -C manual $@
28f540f4
RM
470\f
471# This makes all the subdirectory targets.
472
473# For each target, make it depend on DIR/target for each subdirectory DIR.
474$(+subdir_targets): %: $(addsuffix /%,$(subdirs))
475
476# Compute a list of all those targets.
477all-subdirs-targets := $(foreach dir,$(subdirs),\
478 $(addprefix $(dir)/,$(+subdir_targets)))
479
480# The action for each of those is to cd into the directory and make the
481# target there.
482$(all-subdirs-targets):
e0a3ed4f
RM
483 $(MAKE) $(PARALLELMFLAGS) $(subdir-target-args) $(@F)
484
485define subdir-target-args
486subdir=$(@D)$(if $($(@D)-srcdir),\
487-C $($(@D)-srcdir) ..=`pwd`/,\
488-C $(@D) ..=../)
489endef
28f540f4
RM
490
491.PHONY: $(+subdir_targets) $(all-subdirs-targets)
492\f
493# Targets to clean things up to various degrees.
494
3c5edd4d
UD
495.PHONY: clean realclean distclean distclean-1 parent-clean parent-mostlyclean \
496 tests-clean
28f540f4
RM
497
498# Subroutines of all cleaning targets.
499parent-mostlyclean: common-mostlyclean # common-mostlyclean is in Makerules.
4ddde9ee 500 -rm -f $(foreach o,$(object-suffixes-for-libc),\
60092701
RM
501 $(common-objpfx)$(patsubst %,$(libtype$o),c)) \
502 $(addprefix $(objpfx),$(install-lib))
28f540f4 503parent-clean: parent-mostlyclean common-clean
da2d1bc5
UD
504
505postclean = $(addprefix $(common-objpfx),$(postclean-generated)) \
4ae73ca0 506 $(addprefix $(objpfx),sysd-dirs sysd-rules) \
4fcddf8e 507 $(addprefix $(objpfx),sysd-sorted soversions.mk soversions.i)
28f540f4
RM
508
509clean: parent-clean
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
b5c69d99 515 -rm -f $(postclean)
28f540f4
RM
516mostlyclean: parent-mostlyclean
517 @$(MAKE) subdir_mostlyclean no_deps=t
da2d1bc5 518 -rm -f $(postclean)
28f540f4 519
3c5edd4d
UD
520tests-clean:
521 @$(MAKE) subdir_testclean no_deps=t
522
00db8bf4 523ifneq (,$(CXX))
bd29910a
JM
524vpath c++-types.data $(+sysdep_dirs)
525
684ce7e0 526tests-special += $(objpfx)c++-types-check.out
bd29910a 527$(objpfx)c++-types-check.out: c++-types.data scripts/check-c++-types.sh
783dd2d3 528 scripts/check-c++-types.sh $< $(CXX) $(filter-out -std=gnu11 $(+gccwarn-c),$(CFLAGS)) $(CPPFLAGS) > $@; \
f0881698 529 $(evaluate-test)
2750c39c 530endif
806e4a4a 531
1241b50b 532tests-special += $(objpfx)check-local-headers.out
16feadf2 533$(objpfx)check-local-headers.out: scripts/check-local-headers.sh
ea5ee9f7 534 AWK='$(AWK)' scripts/check-local-headers.sh \
3b2cc56d 535 "$(includedir)" "$(objpfx)" < /dev/null > $@; \
f0881698 536 $(evaluate-test)
16feadf2 537
47755784
ZW
538ifneq "$(headers)" ""
539# Special test of all the installed headers in this directory.
540tests-special += $(objpfx)check-installed-headers-c.out
7c3018f9 541libof-check-installed-headers-c := testsuite
47755784
ZW
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)" \
546 $(headers) > $@; \
547 $(evaluate-test)
548
549ifneq "$(CXX)" ""
550tests-special += $(objpfx)check-installed-headers-cxx.out
7c3018f9 551libof-check-installed-headers-cxx := testsuite
47755784
ZW
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)" \
556 $(headers) > $@; \
557 $(evaluate-test)
ad18dade
FW
558endif # $(CXX)
559
560tests-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)
564endif # $(headers)
47755784 565
44a6213c
RM
566define 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
99db95db 570@! egrep -q -v '^(X?PASS|XFAIL|UNSUPPORTED):' $(objpfx)$1
44a6213c
RM
571endef
572
561b0bec
DD
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.
578#
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.
588
589
590ifeq (,$(CXX))
591LINKS_DSO_PROGRAM = links-dso-program-c
592else
593LINKS_DSO_PROGRAM = links-dso-program
594endif
595
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
033362cf
CD
604 # We need the compiled locale dir for localedef tests.
605 test -d $(objpfx)testroot.pristine/$(complocaledir) || \
606 mkdir -p $(objpfx)testroot.pristine/$(complocaledir)
561b0bec
DD
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
bd598da9 610ifeq ($(run-built-tests),yes)
561b0bec
DD
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 \
95da14da 613 $(rtld-prefix) \
561b0bec 614 $(objpfx)testroot.pristine/bin/sh \
7db1fe38 615 | sed -n '/\//{s@.*=> /@/@;s/^[^/]*//;s/ .*//p;}'` ;\
561b0bec
DD
616 do \
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 ;\
620 done
621 for dso in `$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1 \
95da14da 622 $(rtld-prefix) \
561b0bec 623 $(objpfx)support/$(LINKS_DSO_PROGRAM) \
7db1fe38 624 | sed -n '/\//{s@.*=> /@/@;s/^[^/]*//;s/ .*//p;}'` ;\
561b0bec
DD
625 do \
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 ;\
629 done
bd598da9 630endif
97476447
DD
631 # $(symbolic-link-list) is a file that encodes $(DESTDIR) so we
632 # have to purge it
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.
35e038c1 637 $(MAKE) install DESTDIR=$(objpfx)testroot.pristine \
97476447
DD
638 INSTALL_UNCOMPRESSED=yes subdirs='$(sorted-subdirs)'
639 rm -f $(symbolic-link-list)
561b0bec
DD
640 touch $(objpfx)testroot.pristine/install.stamp
641
265d52ab 642tests-special-notdir = $(patsubst $(objpfx)%, %, $(tests-special))
f214606a 643tests: $(tests-special)
265d52ab
JM
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) .) \
649 > $(objpfx)tests.sum
44a6213c 650 $(call summarize-tests,tests.sum)
265d52ab
JM
651xtests:
652 $(..)scripts/merge-test-results.sh -t $(objpfx) subdir-xtests.sum \
653 $(sort $(subdirs)) \
654 > $(objpfx)xtests.sum
44a6213c 655 $(call summarize-tests,xtests.sum, for extra tests)
f214606a 656
28f540f4
RM
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.
659realclean 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.
da2d1bc5
UD
664 @$(MAKE) distclean-1 no_deps=t distclean-1=$@ avoid-generated=yes \
665 sysdep-subdirs="$(sysdep-subdirs)"
666 -rm -f $(postclean)
28f540f4
RM
667
668# Subroutine of distclean and realclean.
669distclean-1: subdir_$(distclean-1)
670 -rm -f $(config-generated)
60092701
RM
671 -rm -f $(addprefix $(objpfx),config.status config.cache config.log)
672 -rm -f $(addprefix $(objpfx),config.make config-name.h config.h)
28f540f4
RM
673ifdef objdir
674 -rm -f $(objpfx)Makefile
675endif
676 -rm -f $(sysdep-$(distclean-1))
677\f
9de06f3c
RM
678# Make the TAGS file for Emacs users.
679
680.PHONY: TAGS
681TAGS:
77c84aeb 682 scripts/list-sources.sh | sed -n -e '/Makefile/p' \
9de06f3c 683 $(foreach S,[chsSyl] cxx sh bash pl,\
77c84aeb 684 $(subst .,\.,-e '/.$S\(.in\)*$$/p')) \
9de06f3c
RM
685 | $(ETAGS) -o $@ -
686\f
28f540f4 687# Make the distribution tarfile.
6cfe8609 688.PHONY: dist dist-prepare
28f540f4 689
c7562c74 690generated := $(generated) stubs.h
28f540f4 691
97ff54d2 692files-for-dist := README INSTALL configure NEWS
6cfe8609
RM
693
694# Regenerate stuff, then error if these things are not committed yet.
695dist-prepare: $(files-for-dist)
644d3857 696 conf=`find sysdeps -name configure`; \
6cfe8609
RM
697 $(MAKE) $$conf && \
698 git diff --stat HEAD -- $^ $$conf \
699 | $(AWK) '{ print; rc=1 } END { exit rc }'
700
701%.tar: FORCE
702 git archive --prefix=$*/ $* > $@.new
703 mv -f $@.new $@
62780824 704
7c0cf356 705# Do `make dist dist-version=X.Y.Z' to make tar files of an older version.
7c0cf356 706
6cfe8609
RM
707ifneq (,$(strip $(dist-version)))
708dist: $(foreach Z,.bz2 .gz .xz,$(dist-version).tar$Z)
62780824 709 md5sum $^
6cfe8609
RM
710else
711dist: dist-prepare
712 @if v=`git describe`; then \
713 echo Distribution version $$v; \
714 $(MAKE) dist dist-version=$$v; \
715 else \
716 false; \
717 fi
718endif
62780824 719
d136c6dc
SP
720INSTALL: manual/install-plain.texi manual/macros.texi \
721 $(common-objpfx)manual/pkgvers.texi manual/install.texi
4e87147f 722 makeinfo --no-validate --plaintext --no-number-sections \
b31469d0
JM
723 -I$(common-objpfx)manual $< -o $@-tmp
724 $(AWK) 'NF == 0 { ++n; next } \
725 NF != 0 { while (n-- > 0) print ""; n = 0; print }' \
726 < $@-tmp > $@-tmp2
727 rm -f $@-tmp
728 -chmod a-w $@-tmp2
729 mv -f $@-tmp2 $@
8b748aed
JM
730$(common-objpfx)manual/%: FORCE
731 $(MAKE) $(PARALLELMFLAGS) -C manual $@
f671aeab 732FORCE:
6a441471 733
8b748aed 734iconvdata/% localedata/% po/%: FORCE
f4017d20 735 $(MAKE) $(PARALLELMFLAGS) -C $(@D) $(@F)
2ac579f9
DD
736
737# Convenience target to rerun one test, from the top of the build tree
738# Example: make test t=wcsmbs/test-wcsnlen
739.PHONY: test
740test :
741 @-rm -f $(objpfx)$t.out
81a1fa6c 742 $(MAKE) subdir=$(patsubst %/,%,$(dir $t)) -C $(dir $t) ..=../ $(objpfx)$t.out
2ac579f9
DD
743 @cat $(objpfx)$t.test-result
744 @cat $(objpfx)$t.out