posix: Fix large mmap64 offset for mips64n32 (BZ#24699)
[external/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 # <http://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
30 all: lib others
31 \f
32 ifneq ($(AUTOCONF),no)
33
34 define autoconf-it
35 @-rm -f $@.new
36 $(AUTOCONF) $(ACFLAGS) $< > $@.new
37 chmod a-w$(patsubst %,$(comma)a+x,$(filter .,$(@D))) $@.new
38 mv -f $@.new $@
39 endef
40
41 configure: configure.ac aclocal.m4; $(autoconf-it)
42 %/configure: %/configure.ac aclocal.m4; $(autoconf-it)
43 %/preconfigure: %/preconfigure.ac aclocal.m4; $(autoconf-it)
44
45 endif # $(AUTOCONF) = no
46
47
48 # We don't want to run anything here in parallel.
49 .NOTPARALLEL:
50
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       \
54                    tests xtests                                         \
55                    subdir_update-abi subdir_check-abi                   \
56                    subdir_update-all-abi                                \
57                    subdir_echo-headers                                  \
58                    subdir_install                                       \
59                    subdir_objs subdir_stubs subdir_testclean            \
60                    $(addprefix install-, no-libc.a bin lib data headers others)
61 \f
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
65
66 echo-headers: subdir_echo-headers
67
68 # The headers are in the include directory.
69 subdir-dirs = include
70 vpath %.h $(subdir-dirs)
71
72 # What to install.
73 install-others = $(inst_includedir)/gnu/stubs.h
74 install-bin-script =
75
76 ifeq (yes,$(build-shared))
77 headers += gnu/lib-names.h
78 endif
79
80 include Makerules
81
82 ifeq ($(build-programs),yes)
83 others: $(addprefix $(objpfx),$(install-bin-script))
84 endif
85
86 # Install from subdirectories too.
87 install: subdir_install
88
89 # Explicit dependency so that `make install-headers' works
90 install-headers: install-headers-nosubdir
91
92 # Make sure that the dynamic linker is installed before libc.
93 $(inst_slibdir)/libc-$(version).so: elf/ldso_install
94
95 .PHONY: elf/ldso_install
96 elf/ldso_install:
97         $(MAKE) -C $(@D) $(@F)
98
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)
108
109 install:
110         -test ! -x $(elf-objpfx)ldconfig || LC_ALL=C \
111           $(elf-objpfx)ldconfig $(addprefix -r ,$(install_root)) \
112                                 $(slibdir) $(libdir)
113 ifneq (no,$(PERL))
114 ifeq (/usr,$(prefix))
115 ifeq (,$(install_root))
116         LD_SO=$(ld.so-version) CC="$(CC)" $(PERL) scripts/test-installation.pl $(common-objpfx)
117 endif
118 endif
119 endif
120 endif
121 endif
122
123 # Build subdirectory lib objects.
124 lib-noranlib: subdir_lib
125
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)
130
131 # Used to build testrun.sh.
132 define testrun-script
133 #!/bin/bash
134 builddir=`dirname "$$0"`
135 GCONV_PATH="$${builddir}/iconvdata"
136
137 usage () {
138   echo "usage: $$0 [--tool=strace] PROGRAM [ARGUMENTS...]" 2>&1
139   echo "       $$0 --tool=valgrind PROGRAM [ARGUMENTS...]" 2>&1
140   exit 1
141 }
142
143 toolname=default
144 while test $$# -gt 0 ; do
145   case "$$1" in
146     --tool=*)
147       toolname="$${1:7}"
148       shift
149       ;;
150     --*)
151       usage
152       ;;
153     *)
154       break
155       ;;
156   esac
157 done
158
159 if test $$# -eq 0 ; then
160   usage
161 fi
162
163 case "$$toolname" in
164   default)
165     exec $(subst $(common-objdir),"$${builddir}", $(test-program-prefix)) \
166       $${1+"$$@"}
167     ;;
168   strace)
169     exec strace $(patsubst %, -E%, $(run-program-env)) \
170       $(test-via-rtld-prefix) $${1+"$$@"}
171     ;;
172   valgrind)
173     exec env $(run-program-env) valgrind $(test-via-rtld-prefix) $${1+"$$@"}
174     ;;
175   *)
176     usage
177     ;;
178 esac
179 endef
180
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))
186         chmod a+x $@T
187         mv -f $@T $@
188 postclean-generated += testrun.sh
189
190 others: $(common-objpfx)testrun.sh
191 \f
192 # Makerules creates a file `stubs' in each subdirectory, which
193 # contains `#define __stub_FUNCTION' for each function defined in that
194 # directory which is a stub.
195 # Here we paste all of these together into <gnu/stubs.h>.
196
197 subdir-stubs := $(foreach dir,$(subdirs),$(common-objpfx)$(dir)/stubs)
198
199 ifndef abi-variants
200 installed-stubs = $(inst_includedir)/gnu/stubs.h
201 else
202 installed-stubs = $(inst_includedir)/gnu/stubs-$(default-abi).h
203
204 $(inst_includedir)/gnu/stubs.h: $(+force)
205         $(make-target-directory)
206         { \
207          echo '/* This file is automatically generated.';\
208          echo "   This file selects the right generated file of \`__stub_FUNCTION' macros";\
209          echo '   based on the architecture being compiled for.  */'; \
210          echo ''; \
211          $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
212          echo ''; \
213          $(foreach v,$(abi-variants),\
214          $(if $(abi-$(v)-condition),\
215          echo '#if $(abi-$(v)-condition)'; \
216          echo '# include <gnu/stubs-$(v).h>'); \
217          $(if $(abi-$(v)-condition),echo '#endif';) \
218          rm -f $(@:.d=.h).new$(v); \
219          ) \
220         } > $(@:.d=.h).new
221         mv -f $(@:.d=.h).new $(@:.d=.h)
222
223 install-others-nosubdir: $(installed-stubs)
224 endif
225
226
227 # Since stubs.h is never needed when building the library, we simplify the
228 # hairy installation process by producing it in place only as the last part
229 # of the top-level `make install'.  It depends on subdir_install, which
230 # iterates over all the subdirs; subdir_install in each subdir depends on
231 # the subdir's stubs file.  Having more direct dependencies would result in
232 # extra iterations over the list for subdirs and many recursive makes.
233 $(installed-stubs): include/stubs-prologue.h subdir_install
234         $(make-target-directory)
235         @rm -f $(objpfx)stubs.h
236         (sed '/^@/d' $<; LC_ALL=C sort $(subdir-stubs)) > $(objpfx)stubs.h
237         if test -r $@ && cmp -s $(objpfx)stubs.h $@; \
238         then echo 'stubs.h unchanged'; \
239         else $(INSTALL_DATA) $(objpfx)stubs.h $@; fi
240         rm -f $(objpfx)stubs.h
241 \f
242 # This makes the Info or DVI file of the documentation from the Texinfo source.
243 .PHONY: info dvi pdf html
244 info dvi pdf html:
245         $(MAKE) $(PARALLELMFLAGS) -C manual $@
246 \f
247 # This makes all the subdirectory targets.
248
249 # For each target, make it depend on DIR/target for each subdirectory DIR.
250 $(+subdir_targets): %: $(addsuffix /%,$(subdirs))
251
252 # Compute a list of all those targets.
253 all-subdirs-targets := $(foreach dir,$(subdirs),\
254                                  $(addprefix $(dir)/,$(+subdir_targets)))
255
256 # The action for each of those is to cd into the directory and make the
257 # target there.
258 $(all-subdirs-targets):
259         $(MAKE) $(PARALLELMFLAGS) $(subdir-target-args) $(@F)
260
261 define subdir-target-args
262 subdir=$(@D)$(if $($(@D)-srcdir),\
263 -C $($(@D)-srcdir) ..=`pwd`/,\
264 -C $(@D) ..=../)
265 endef
266
267 .PHONY: $(+subdir_targets) $(all-subdirs-targets)
268 \f
269 # Targets to clean things up to various degrees.
270
271 .PHONY: clean realclean distclean distclean-1 parent-clean parent-mostlyclean \
272         tests-clean
273
274 # Subroutines of all cleaning targets.
275 parent-mostlyclean: common-mostlyclean # common-mostlyclean is in Makerules.
276         -rm -f $(foreach o,$(object-suffixes-for-libc),\
277                    $(common-objpfx)$(patsubst %,$(libtype$o),c)) \
278                $(addprefix $(objpfx),$(install-lib))
279 parent-clean: parent-mostlyclean common-clean
280
281 postclean = $(addprefix $(common-objpfx),$(postclean-generated)) \
282             $(addprefix $(objpfx),sysd-dirs sysd-rules) \
283             $(addprefix $(objpfx),sysd-sorted soversions.mk soversions.i)
284
285 clean: parent-clean
286 # This is done this way rather than having `subdir_clean' be a
287 # dependency of this target so that libc.a will be removed before the
288 # subdirectories are dealt with and so they won't try to remove object
289 # files from it when it's going to be removed anyway.
290         @$(MAKE) subdir_clean no_deps=t
291         -rm -f $(postclean)
292 mostlyclean: parent-mostlyclean
293         @$(MAKE) subdir_mostlyclean no_deps=t
294         -rm -f $(postclean)
295
296 tests-clean:
297         @$(MAKE) subdir_testclean no_deps=t
298
299 ifneq (,$(CXX))
300 vpath c++-types.data $(+sysdep_dirs)
301
302 tests-special += $(objpfx)c++-types-check.out
303 $(objpfx)c++-types-check.out: c++-types.data scripts/check-c++-types.sh
304         scripts/check-c++-types.sh $< $(CXX) $(filter-out -std=gnu11 $(+gccwarn-c),$(CFLAGS)) $(CPPFLAGS) > $@; \
305         $(evaluate-test)
306 endif
307
308 tests-special += $(objpfx)check-local-headers.out
309 $(objpfx)check-local-headers.out: scripts/check-local-headers.sh
310         AWK='$(AWK)' scripts/check-local-headers.sh \
311           "$(includedir)" "$(objpfx)" < /dev/null > $@; \
312         $(evaluate-test)
313
314 ifneq "$(headers)" ""
315 # Special test of all the installed headers in this directory.
316 tests-special += $(objpfx)check-installed-headers-c.out
317 libof-check-installed-headers-c := testsuite
318 $(objpfx)check-installed-headers-c.out: \
319     scripts/check-installed-headers.sh $(headers)
320         $(SHELL) $(..)scripts/check-installed-headers.sh c \
321           "$(CC) $(filter-out -std=%,$(CFLAGS)) -D_ISOMAC $(+includes)" \
322           $(headers) > $@; \
323         $(evaluate-test)
324
325 ifneq "$(CXX)" ""
326 tests-special += $(objpfx)check-installed-headers-cxx.out
327 libof-check-installed-headers-cxx := testsuite
328 $(objpfx)check-installed-headers-cxx.out: \
329     scripts/check-installed-headers.sh $(headers)
330         $(SHELL) $(..)scripts/check-installed-headers.sh c++ \
331           "$(CXX) $(filter-out -std=%,$(CXXFLAGS)) -D_ISOMAC $(+includes)" \
332           $(headers) > $@; \
333         $(evaluate-test)
334 endif # $(CXX)
335
336 tests-special += $(objpfx)check-wrapper-headers.out
337 $(objpfx)check-wrapper-headers.out: scripts/check-wrapper-headers.py $(headers)
338         $(PYTHON) $< --root=. --subdir=. $(headers) \
339           --generated $(common-generated) > $@; $(evaluate-test)
340 endif # $(headers)
341
342 define summarize-tests
343 @egrep -v '^(PASS|XFAIL):' $(objpfx)$1 || true
344 @echo "Summary of test results$2:"
345 @sed 's/:.*//' < $(objpfx)$1 | sort | uniq -c
346 @! egrep -q -v '^(X?PASS|XFAIL|UNSUPPORTED):' $(objpfx)$1
347 endef
348
349 # The intention here is to do ONE install of our build into the
350 # testroot.pristine/ directory, then rsync (internal to
351 # support/test-container) that to testroot.root/ at the start of each
352 # test.  That way we can promise each test a "clean" install, without
353 # having to do the install for each test.
354 #
355 # In addition, we have to copy some files (which we build) into this
356 # root in addition to what glibc installs.  For example, many tests
357 # require additional programs including /bin/sh, /bin/true, and
358 # /bin/echo, all of which we build below to limit library dependencies
359 # to just those things in glibc and language support libraries which
360 # we also copy into the into the rootfs.  To determine what language
361 # support libraries we need we build a "test" program in either C or
362 # (if available) C++ just so we can copy in any shared objects
363 # (which we do not build) that GCC-compiled programs depend on.
364
365
366 ifeq (,$(CXX))
367 LINKS_DSO_PROGRAM = links-dso-program-c
368 else
369 LINKS_DSO_PROGRAM = links-dso-program
370 endif
371
372 $(tests-container) $(addsuffix /tests,$(subdirs)) : \
373                 $(objpfx)testroot.pristine/install.stamp
374 $(objpfx)testroot.pristine/install.stamp :
375         test -d $(objpfx)testroot.pristine || \
376           mkdir $(objpfx)testroot.pristine
377         # We need a working /bin/sh for some of the tests.
378         test -d $(objpfx)testroot.pristine/bin || \
379           mkdir $(objpfx)testroot.pristine/bin
380         cp $(objpfx)support/shell-container $(objpfx)testroot.pristine/bin/sh
381         cp $(objpfx)support/echo-container $(objpfx)testroot.pristine/bin/echo
382         cp $(objpfx)support/true-container $(objpfx)testroot.pristine/bin/true
383 ifeq ($(run-built-tests),yes)
384         # Copy these DSOs first so we can overwrite them with our own.
385         for dso in `$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1  \
386                 $(objpfx)elf/$(rtld-installed-name) \
387                 $(objpfx)testroot.pristine/bin/sh \
388                 | grep / | sed 's/^[^/]*//' | sed 's/ .*//'` ;\
389           do \
390             test -d `dirname $(objpfx)testroot.pristine$$dso` || \
391               mkdir -p `dirname $(objpfx)testroot.pristine$$dso` ;\
392             $(test-wrapper) cp $$dso $(objpfx)testroot.pristine$$dso ;\
393           done
394         for dso in `$(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1  \
395                 $(objpfx)elf/$(rtld-installed-name) \
396                 $(objpfx)support/$(LINKS_DSO_PROGRAM) \
397                 | grep / | sed 's/^[^/]*//' | sed 's/ .*//'` ;\
398           do \
399             test -d `dirname $(objpfx)testroot.pristine$$dso` || \
400               mkdir -p `dirname $(objpfx)testroot.pristine$$dso` ;\
401             $(test-wrapper) cp $$dso $(objpfx)testroot.pristine$$dso ;\
402           done
403 endif
404         $(MAKE) install DESTDIR=$(objpfx)testroot.pristine
405         touch $(objpfx)testroot.pristine/install.stamp
406
407 tests-special-notdir = $(patsubst $(objpfx)%, %, $(tests-special))
408 tests: $(tests-special)
409         $(..)scripts/merge-test-results.sh -s $(objpfx) "" \
410           $(sort $(tests-special-notdir:.out=)) \
411           > $(objpfx)subdir-tests.sum
412         $(..)scripts/merge-test-results.sh -t $(objpfx) subdir-tests.sum \
413           $(sort $(subdirs) .) \
414           > $(objpfx)tests.sum
415         $(call summarize-tests,tests.sum)
416 xtests:
417         $(..)scripts/merge-test-results.sh -t $(objpfx) subdir-xtests.sum \
418           $(sort $(subdirs)) \
419           > $(objpfx)xtests.sum
420         $(call summarize-tests,xtests.sum, for extra tests)
421
422 # The realclean target is just like distclean for the parent, but we want
423 # the subdirs to know the difference in case they care.
424 realclean distclean: parent-clean
425 # This is done this way rather than having `subdir_distclean' be a
426 # dependency of this target so that libc.a will be removed before the
427 # subdirectories are dealt with and so they won't try to remove object
428 # files from it when it's going to be removed anyway.
429         @$(MAKE) distclean-1 no_deps=t distclean-1=$@ avoid-generated=yes \
430                  sysdep-subdirs="$(sysdep-subdirs)"
431         -rm -f $(postclean)
432
433 # Subroutine of distclean and realclean.
434 distclean-1: subdir_$(distclean-1)
435         -rm -f $(config-generated)
436         -rm -f $(addprefix $(objpfx),config.status config.cache config.log)
437         -rm -f $(addprefix $(objpfx),config.make config-name.h config.h)
438 ifdef objdir
439         -rm -f $(objpfx)Makefile
440 endif
441         -rm -f $(sysdep-$(distclean-1))
442 \f
443 # Make the TAGS file for Emacs users.
444
445 .PHONY: TAGS
446 TAGS:
447         scripts/list-sources.sh | sed -n -e '/Makefile/p' \
448           $(foreach S,[chsSyl] cxx sh bash pl,\
449                     $(subst .,\.,-e '/.$S\(.in\)*$$/p')) \
450         | $(ETAGS) -o $@ -
451 \f
452 # Make the distribution tarfile.
453 .PHONY: dist dist-prepare
454
455 generated := $(generated) stubs.h
456
457 files-for-dist := README INSTALL configure ChangeLog NEWS
458
459 # Regenerate stuff, then error if these things are not committed yet.
460 dist-prepare: $(files-for-dist)
461         conf=`find sysdeps -name configure`; \
462         $(MAKE) $$conf && \
463         git diff --stat HEAD -- $^ $$conf \
464         | $(AWK) '{ print; rc=1 } END { exit rc }'
465
466 %.tar: FORCE
467         git archive --prefix=$*/ $* > $@.new
468         mv -f $@.new $@
469
470 # Do `make dist dist-version=X.Y.Z' to make tar files of an older version.
471
472 ifneq (,$(strip $(dist-version)))
473 dist: $(foreach Z,.bz2 .gz .xz,$(dist-version).tar$Z)
474         md5sum $^
475 else
476 dist: dist-prepare
477         @if v=`git describe`; then \
478           echo Distribution version $$v; \
479           $(MAKE) dist dist-version=$$v; \
480         else \
481           false; \
482         fi
483 endif
484
485 INSTALL: manual/install-plain.texi manual/macros.texi \
486          $(common-objpfx)manual/pkgvers.texi manual/install.texi
487         makeinfo --no-validate --plaintext --no-number-sections \
488                  -I$(common-objpfx)manual $< -o $@-tmp
489         $(AWK) 'NF == 0 { ++n; next } \
490                 NF != 0 { while (n-- > 0) print ""; n = 0; print }' \
491           < $@-tmp > $@-tmp2
492         rm -f $@-tmp
493         -chmod a-w $@-tmp2
494         mv -f $@-tmp2 $@
495 $(common-objpfx)manual/%: FORCE
496         $(MAKE) $(PARALLELMFLAGS) -C manual $@
497 FORCE:
498
499 iconvdata/% localedata/% po/%: FORCE
500         $(MAKE) $(PARALLELMFLAGS) -C $(@D) $(@F)