Installed header hygiene (BZ#20366): Test of installed headers.
[platform/upstream/glibc.git] / Makefile
1 # Copyright (C) 1991-2016 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
132 # This is a handy script for running any dynamically linked program against
133 # the current libc build for testing.
134 $(common-objpfx)testrun.sh: $(common-objpfx)config.make \
135                             $(..)Makeconfig $(..)Makefile
136         (echo '#!/bin/sh'; \
137          echo 'builddir=`dirname "$$0"`'; \
138          echo 'GCONV_PATH="$${builddir}/iconvdata" \'; \
139          echo 'exec $(subst $(common-objdir),"$${builddir}",\
140                             $(test-program-prefix)) $${1+"$$@"}'; \
141         ) > $@T
142         chmod a+x $@T
143         mv -f $@T $@
144 postclean-generated += testrun.sh
145
146 others: $(common-objpfx)testrun.sh
147 \f
148 # Makerules creates a file `stubs' in each subdirectory, which
149 # contains `#define __stub_FUNCTION' for each function defined in that
150 # directory which is a stub.
151 # Here we paste all of these together into <gnu/stubs.h>.
152
153 subdir-stubs := $(foreach dir,$(subdirs),$(common-objpfx)$(dir)/stubs)
154
155 ifndef abi-variants
156 installed-stubs = $(inst_includedir)/gnu/stubs.h
157 else
158 installed-stubs = $(inst_includedir)/gnu/stubs-$(default-abi).h
159
160 $(inst_includedir)/gnu/stubs.h: $(+force)
161         $(make-target-directory)
162         { \
163          echo '/* This file is automatically generated.';\
164          echo "   This file selects the right generated file of \`__stub_FUNCTION' macros";\
165          echo '   based on the architecture being compiled for.  */'; \
166          echo ''; \
167          $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
168          echo ''; \
169          $(foreach v,$(abi-variants),\
170          $(if $(abi-$(v)-condition),\
171          echo '#if $(abi-$(v)-condition)'; \
172          echo '# include <gnu/stubs-$(v).h>'); \
173          $(if $(abi-$(v)-condition),echo '#endif';) \
174          rm -f $(@:.d=.h).new$(v); \
175          ) \
176         } > $(@:.d=.h).new
177         mv -f $(@:.d=.h).new $(@:.d=.h)
178
179 install-others-nosubdir: $(installed-stubs)
180 endif
181
182
183 # Since stubs.h is never needed when building the library, we simplify the
184 # hairy installation process by producing it in place only as the last part
185 # of the top-level `make install'.  It depends on subdir_install, which
186 # iterates over all the subdirs; subdir_install in each subdir depends on
187 # the subdir's stubs file.  Having more direct dependencies would result in
188 # extra iterations over the list for subdirs and many recursive makes.
189 $(installed-stubs): include/stubs-prologue.h subdir_install
190         $(make-target-directory)
191         @rm -f $(objpfx)stubs.h
192         (sed '/^@/d' $<; LC_ALL=C sort $(subdir-stubs)) > $(objpfx)stubs.h
193         if test -r $@ && cmp -s $(objpfx)stubs.h $@; \
194         then echo 'stubs.h unchanged'; \
195         else $(INSTALL_DATA) $(objpfx)stubs.h $@; fi
196         rm -f $(objpfx)stubs.h
197 \f
198 # This makes the Info or DVI file of the documentation from the Texinfo source.
199 .PHONY: info dvi pdf html
200 info dvi pdf html:
201         $(MAKE) $(PARALLELMFLAGS) -C manual $@
202 \f
203 # This makes all the subdirectory targets.
204
205 # For each target, make it depend on DIR/target for each subdirectory DIR.
206 $(+subdir_targets): %: $(addsuffix /%,$(subdirs))
207
208 # Compute a list of all those targets.
209 all-subdirs-targets := $(foreach dir,$(subdirs),\
210                                  $(addprefix $(dir)/,$(+subdir_targets)))
211
212 # The action for each of those is to cd into the directory and make the
213 # target there.
214 $(all-subdirs-targets):
215         $(MAKE) $(PARALLELMFLAGS) $(subdir-target-args) $(@F)
216
217 define subdir-target-args
218 subdir=$(@D)$(if $($(@D)-srcdir),\
219 -C $($(@D)-srcdir) ..=`pwd`/,\
220 -C $(@D) ..=../)
221 endef
222
223 .PHONY: $(+subdir_targets) $(all-subdirs-targets)
224 \f
225 # Targets to clean things up to various degrees.
226
227 .PHONY: clean realclean distclean distclean-1 parent-clean parent-mostlyclean \
228         tests-clean
229
230 # Subroutines of all cleaning targets.
231 parent-mostlyclean: common-mostlyclean # common-mostlyclean is in Makerules.
232         -rm -f $(foreach o,$(object-suffixes-for-libc),\
233                    $(common-objpfx)$(patsubst %,$(libtype$o),c)) \
234                $(addprefix $(objpfx),$(install-lib))
235 parent-clean: parent-mostlyclean common-clean
236
237 postclean = $(addprefix $(common-objpfx),$(postclean-generated)) \
238             $(addprefix $(objpfx),sysd-dirs sysd-rules) \
239             $(addprefix $(objpfx),sysd-sorted soversions.mk soversions.i)
240
241 clean: parent-clean
242 # This is done this way rather than having `subdir_clean' be a
243 # dependency of this target so that libc.a will be removed before the
244 # subdirectories are dealt with and so they won't try to remove object
245 # files from it when it's going to be removed anyway.
246         @$(MAKE) subdir_clean no_deps=t
247         -rm -f $(postclean)
248 mostlyclean: parent-mostlyclean
249         @$(MAKE) subdir_mostlyclean no_deps=t
250         -rm -f $(postclean)
251
252 tests-clean:
253         @$(MAKE) subdir_testclean no_deps=t
254
255 ifneq (,$(CXX))
256 vpath c++-types.data $(+sysdep_dirs)
257
258 tests-special += $(objpfx)c++-types-check.out
259 $(objpfx)c++-types-check.out: c++-types.data scripts/check-c++-types.sh
260         scripts/check-c++-types.sh $< $(CXX) $(filter-out -std=gnu11 $(+gccwarn-c),$(CFLAGS)) $(CPPFLAGS) > $@; \
261         $(evaluate-test)
262 endif
263
264 tests-special += $(objpfx)check-local-headers.out
265 $(objpfx)check-local-headers.out: scripts/check-local-headers.sh
266         AWK='$(AWK)' scripts/check-local-headers.sh \
267           "$(includedir)" "$(objpfx)" < /dev/null > $@; \
268         $(evaluate-test)
269
270 ifneq ($(PERL),no)
271 installed-headers = argp/argp.h assert/assert.h catgets/nl_types.h \
272                     crypt/crypt.h ctype/ctype.h debug/execinfo.h \
273                     dirent/dirent.h dlfcn/dlfcn.h elf/elf.h elf/link.h \
274                     gmon/sys/gmon.h gmon/sys/gmon_out.h gmon/sys/profil.h \
275                     grp/grp.h gshadow/gshadow.h iconv/iconv.h iconv/gconv.h \
276                     $(wildcard inet/netinet/*.h) \
277                     $(wildcard inet/arpa/*.h inet/protocols/*.h) \
278                     inet/aliases.h inet/ifaddrs.h inet/netinet/ip6.h \
279                     inet/netinet/icmp6.h intl/libintl.h io/sys/stat.h \
280                     io/sys/statfs.h io/sys/vfs.h io/sys/statvfs.h \
281                     io/fcntl.h io/sys/fcntl.h io/poll.h io/sys/poll.h \
282                     io/utime.h io/ftw.h io/fts.h io/sys/sendfile.h \
283                     libio/stdio.h libio/libio.h locale/locale.h \
284                     locale/langinfo.h locale/xlocale.h login/utmp.h \
285                     login/lastlog.h login/pty.h malloc/malloc.h \
286                     malloc/obstack.h malloc/mcheck.h math/math.h \
287                     math/complex.h math/fenv.h math/tgmath.h misc/sys/uio.h \
288                     $(wildcard nis/rpcsvc/*.h) nptl_db/thread_db.h \
289                     sysdeps/nptl/pthread.h sysdeps/pthread/semaphore.h \
290                     nss/nss.h posix/sys/utsname.h posix/sys/times.h \
291                     posix/sys/wait.h posix/sys/types.h posix/unistd.h \
292                     posix/glob.h posix/regex.h posix/wordexp.h posix/fnmatch.h\
293                     posix/getopt.h posix/tar.h posix/sys/unistd.h \
294                     posix/sched.h posix/re_comp.h posix/wait.h \
295                     posix/cpio.h posix/spawn.h pwd/pwd.h resolv/resolv.h \
296                     resolv/netdb.h $(wildcard resolv/arpa/*.h) \
297                     resource/sys/resource.h resource/sys/vlimit.h \
298                     resource/sys/vtimes.h resource/ulimit.h rt/aio.h \
299                     rt/mqueue.h setjmp/setjmp.h shadow/shadow.h \
300                     signal/signal.h signal/sys/signal.h socket/sys/socket.h \
301                     socket/sys/un.h stdio-common/printf.h \
302                     stdio-common/stdio_ext.h stdlib/stdlib.h stdlib/alloca.h \
303                     stdlib/monetary.h stdlib/fmtmsg.h stdlib/ucontext.h \
304                     sysdeps/generic/inttypes.h sysdeps/generic/stdint.h \
305                     stdlib/errno.h stdlib/sys/errno.h string/string.h \
306                     string/strings.h string/memory.h string/endian.h \
307                     string/argz.h string/envz.h string/byteswap.h \
308                     $(wildcard sunrpc/rpc/*.h sunrpc/rpcsvc/*.h) \
309                     sysvipc/sys/ipc.h sysvipc/sys/msg.h sysvipc/sys/sem.h \
310                     sysvipc/sys/shm.h termios/termios.h \
311                     termios/sys/termios.h termios/sys/ttychars.h time/time.h \
312                     time/sys/time.h time/sys/timeb.h wcsmbs/wchar.h \
313                     wctype/wctype.h
314
315 tests-special += $(objpfx)begin-end-check.out
316 $(objpfx)begin-end-check.out: scripts/begin-end-check.pl
317         $(PERL) scripts/begin-end-check.pl $(installed-headers) > $@; \
318         $(evaluate-test)
319 endif
320
321 ifneq "$(headers)" ""
322 # Special test of all the installed headers in this directory.
323 tests-special += $(objpfx)check-installed-headers-c.out
324 libof-check-installed-headers-c := nonlib
325 $(objpfx)check-installed-headers-c.out: \
326     scripts/check-installed-headers.sh $(headers)
327         $(SHELL) $(..)scripts/check-installed-headers.sh c \
328           "$(CC) $(filter-out -std=%,$(CFLAGS)) -D_ISOMAC $(+includes)" \
329           $(headers) > $@; \
330         $(evaluate-test)
331
332 ifneq "$(CXX)" ""
333 tests-special += $(objpfx)check-installed-headers-cxx.out
334 libof-check-installed-headers-cxx := nonlib
335 $(objpfx)check-installed-headers-cxx.out: \
336     scripts/check-installed-headers.sh $(headers)
337         $(SHELL) $(..)scripts/check-installed-headers.sh c++ \
338           "$(CXX) $(filter-out -std=%,$(CXXFLAGS)) -D_ISOMAC $(+includes)" \
339           $(headers) > $@; \
340         $(evaluate-test)
341 endif
342 endif
343
344 define summarize-tests
345 @egrep -v '^(PASS|XFAIL):' $(objpfx)$1 || true
346 @echo "Summary of test results$2:"
347 @sed 's/:.*//' < $(objpfx)$1 | sort | uniq -c
348 @! egrep -q -v '^(X?PASS|XFAIL|UNSUPPORTED):' $(objpfx)$1
349 endef
350
351 tests-special-notdir = $(patsubst $(objpfx)%, %, $(tests-special))
352 tests: $(tests-special)
353         $(..)scripts/merge-test-results.sh -s $(objpfx) "" \
354           $(sort $(tests-special-notdir:.out=)) \
355           > $(objpfx)subdir-tests.sum
356         $(..)scripts/merge-test-results.sh -t $(objpfx) subdir-tests.sum \
357           $(sort $(subdirs) .) \
358           > $(objpfx)tests.sum
359         $(call summarize-tests,tests.sum)
360 xtests:
361         $(..)scripts/merge-test-results.sh -t $(objpfx) subdir-xtests.sum \
362           $(sort $(subdirs)) \
363           > $(objpfx)xtests.sum
364         $(call summarize-tests,xtests.sum, for extra tests)
365
366 # The realclean target is just like distclean for the parent, but we want
367 # the subdirs to know the difference in case they care.
368 realclean distclean: parent-clean
369 # This is done this way rather than having `subdir_distclean' be a
370 # dependency of this target so that libc.a will be removed before the
371 # subdirectories are dealt with and so they won't try to remove object
372 # files from it when it's going to be removed anyway.
373         @$(MAKE) distclean-1 no_deps=t distclean-1=$@ avoid-generated=yes \
374                  sysdep-subdirs="$(sysdep-subdirs)"
375         -rm -f $(postclean)
376
377 # Subroutine of distclean and realclean.
378 distclean-1: subdir_$(distclean-1)
379         -rm -f $(config-generated)
380         -rm -f $(addprefix $(objpfx),config.status config.cache config.log)
381         -rm -f $(addprefix $(objpfx),config.make config-name.h config.h)
382 ifdef objdir
383         -rm -f $(objpfx)Makefile
384 endif
385         -rm -f $(sysdep-$(distclean-1))
386 \f
387 # Make the TAGS file for Emacs users.
388
389 .PHONY: TAGS
390 TAGS:
391         scripts/list-sources.sh | sed -n -e '/Makefile/p' \
392           $(foreach S,[chsSyl] cxx sh bash pl,\
393                     $(subst .,\.,-e '/.$S\(.in\)*$$/p')) \
394         | $(ETAGS) -o $@ -
395 \f
396 # Make the distribution tarfile.
397 .PHONY: dist dist-prepare
398
399 generated := $(generated) stubs.h
400
401 files-for-dist := README INSTALL configure ChangeLog NEWS
402
403 # Regenerate stuff, then error if these things are not committed yet.
404 dist-prepare: $(files-for-dist)
405         conf=`find sysdeps $(addsuffix /sysdeps,$(sysdeps-add-ons)) \
406                    -name configure`; \
407         $(MAKE) $$conf && \
408         git diff --stat HEAD -- $^ $$conf \
409         | $(AWK) '{ print; rc=1 } END { exit rc }'
410
411 %.tar: FORCE
412         git archive --prefix=$*/ $* > $@.new
413         mv -f $@.new $@
414
415 # Do `make dist dist-version=X.Y.Z' to make tar files of an older version.
416
417 ifneq (,$(strip $(dist-version)))
418 dist: $(foreach Z,.bz2 .gz .xz,$(dist-version).tar$Z)
419         md5sum $^
420 else
421 dist: dist-prepare
422         @if v=`git describe`; then \
423           echo Distribution version $$v; \
424           $(MAKE) dist dist-version=$$v; \
425         else \
426           false; \
427         fi
428 endif
429
430 INSTALL: manual/install-plain.texi manual/macros.texi \
431          $(common-objpfx)manual/pkgvers.texi manual/install.texi
432         makeinfo --no-validate --plaintext --no-number-sections \
433                  -I$(common-objpfx)manual $< -o $@-tmp
434         $(AWK) 'NF == 0 { ++n; next } \
435                 NF != 0 { while (n-- > 0) print ""; n = 0; print }' \
436           < $@-tmp > $@-tmp2
437         rm -f $@-tmp
438         -chmod a-w $@-tmp2
439         mv -f $@-tmp2 $@
440 $(common-objpfx)manual/%: FORCE
441         $(MAKE) $(PARALLELMFLAGS) -C manual $@
442 FORCE:
443
444 iconvdata/% localedata/% po/%: FORCE
445         $(MAKE) $(PARALLELMFLAGS) -C $(@D) $(@F)