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