]> git.ipfire.org Git - thirdparty/glibc.git/blob - Makerules
initial import
[thirdparty/glibc.git] / Makerules
1 # Copyright (C) 1991, 1992, 1993, 1994, 1995 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 Library General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # 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 # Library General Public License for more details.
13
14 # You should have received a copy of the GNU Library General Public
15 # License along with the GNU C Library; see the file COPYING.LIB. If
16 # not, write to the Free Software Foundation, Inc., 675 Mass Ave,
17 # Cambridge, MA 02139, USA.
18
19 #
20 # Common rules for making the GNU C library. This file is included
21 # by the top-level Makefile and by all subdirectory makefiles
22 # (through Rules).
23 #
24 ifneq (,)
25 This makefile requires GNU Make.
26 endif
27
28
29 ifdef subdir
30 .. := ../
31 endif # subdir
32
33 # If `sources' was defined by the parent makefile, undefine it so
34 # we will later get it from wildcard search in this directory.
35 ifneq "$(findstring env,$(origin sources))" ""
36 sources :=
37 endif
38
39 headers := $(headers) $(sysdep_headers)
40
41 oPATH := $(PATH)
42 PATH := this definition should take precedence over $(oPATH)
43 ifeq ($(PATH),$(oPATH))
44 You must not use the -e flag when building the GNU C library.
45 else
46 PATH := $(oPATH)
47 endif
48 \f
49 ifndef +included-Makeconfig
50 include $(..)Makeconfig
51 endif
52
53 # `configure' writes a definition of `config-sysdirs' in `config.make'.
54 sysdirs = $(config-sysdirs)
55
56 +sysdir_pfx = $(common-objpfx)
57
58 export sysdirs := $(sysdirs)
59
60 +sysdep_dirs := $(addprefix $(sysdep_dir)/,$(sysdirs))
61 ifdef objdir
62 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
63 endif
64
65 # Add -I switches to get the right sysdep directories.
66 # `+includes' in Makeconfig references $(+sysdep-includes).
67 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
68 \f
69 # Include any system-specific makefiles.
70
71 # This is here so things in sysdep Makefiles can easily depend on foo.h as
72 # appropriate and not worry about where foo.h comes from, which may be
73 # system dependent and not known by that Makefile.
74 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) \
75 $(addprefix $(sysdep_dir)/,$(sysdirs)) \
76 $(..)))
77
78 ifeq ($(wildcard $(+sysdir_pfx)sysd-Makefile),)
79 # Don't do deps until this exists, because it might change the sources list.
80 no_deps=t
81 endif
82
83 # Some sysdep makefiles use this to distinguish being included here from
84 # being included individually by a subdir makefile (hurd/Makefile needs this).
85 in-Makerules := yes
86
87 ifndef avoid-generated
88 include $(+sysdir_pfx)sysd-Makefile
89 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules
90 -@rm -f $@T
91 (for dir in $(sysdirs); do \
92 file=sysdeps/$$dir/Makefile; \
93 if [ -f $(..)$$file ]; then \
94 echo include "\$$(..)$$file"; \
95 else true; fi; \
96 done; \
97 echo 'sysd-Makefile-done=t') > $@T
98 mv -f $@T $@
99 endif
100
101 # Reorder before-compile so that mach things come first, and hurd things
102 # second, before all else. The mach and hurd subdirectories have many
103 # generated header files which the much of rest of the library depends on,
104 # so it is best to build them first (and mach before hurd, at that).
105 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
106 $(before-compile)) \
107 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
108 $(before-compile))
109
110 # Remove existing files from `before-compile'. Things are added there when
111 # they must exist for dependency generation to work right, but once they
112 # exist there is no further need for every single file to depend on them,
113 # and those gratuitous dependencies result in many gratuitous
114 # recompilations.
115 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
116
117 # Don't let any before-compile file be an intermediate and get removed.
118 ifdef before-compile
119 $(before-compile):
120 endif
121 \f
122 # Generate an ordered list of implicit rules which find the source files in
123 # each sysdep directory. The old method was to use vpath to search all the
124 # sysdep directories. However, that had the problem that a .S file in a
125 # later directory would be chosen over a .c file in an earlier directory,
126 # which does not preserve the desired sysdeps ordering behavior.
127
128 # When making the list of .d files to include, we can't know which ones
129 # have source in .s files, and thus do not in fact need a .d file.
130 # So we must define rules to make .d files for .s files.
131 define make-dummy-dep
132 $(addprefix ln $(objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
133 endef
134 $(objpfx)dummy.d:
135 echo '# .s files cannot contain includes, so they need no deps.' > $@
136
137 # It matters that this set of rules, for compiling from sources in
138 # the current directory (the $srcdir/$subdir) come before the
139 # generated sysdep rules in included from sysd-rules below. When
140 # compiling in the source tree, generated sources go into the current
141 # directory, and those should be chosen before any sources in sysdeps.
142 $(objpfx)%.o: %.S $(before-compile); $(compile-command.S)
143 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
144 $(objpfx)%.o: %.s $(before-compile); $(compile-command.s)
145 $(objpfx)%.d: %.s $(objpfx)dummy.d; $(make-dummy-dep)
146 $(objpfx)%.o: %.c $(before-compile); $(compile-command.c)
147 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
148
149 # Omit the objpfx rules when building in the source tree, because
150 # objpfx is empty and so these rules just override the ones above.
151 ifdef objpfx
152 # Define first rules to find the source files in $(objpfx).
153 # Generated source files will end up there.
154 $(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S)
155 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
156 $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s)
157 $(objpfx)%.d: $(objpfx)%.s $(objpfx)dummy.d; $(make-dummy-dep)
158 $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c)
159 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
160 endif
161
162 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
163 # patterns matching sysdep directories whose assembly source files should
164 # be suppressed.
165 ifdef inhibit-sysdep-asm
166 define open-check-inhibit-asm
167 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
168 endef
169 close-check-inhibit-asm = ;; esac
170 endif
171
172 # Don't include sysd-rules until sysd-Makefile is already there and has been
173 # included. It might define inhibit-sysdep-asm, which would affect the
174 # contents of sysd-rules.
175 ifdef sysd-Makefile-done
176 include $(+sysdir_pfx)sysd-rules
177 endif
178 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
179 $(wildcard $(foreach dir,$(sysdirs),\
180 $(sysdep_dir)/$(dir)/Makefile))
181 -@rm -f $@T
182 (for sysdir in $(sysdirs); do \
183 dir="\$$(sysdep_dir)/$$sysdir"; \
184 $(open-check-inhibit-asm) \
185 echo "\$$(objpfx)%.o: $$dir/%.S \$$(before-compile); \
186 \$$(compile-command.S)"; \
187 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
188 \$$(+make-deps)"; \
189 echo "\$$(objpfx)%.o: $$dir/%.s \$$(before-compile); \
190 \$$(compile-command.s)"; \
191 echo "\$$(objpfx)%.d: $$dir/%.s \$$(objpfx)dummy.d; \
192 \$$(make-dummy-dep)" $(close-check-inhibit-asm); \
193 echo "\$$(objpfx)%.o: $$dir/%.c \$$(before-compile); \
194 \$$(compile-command.c)"; \
195 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
196 \$$(+make-deps)"; \
197 done) > $@T
198 mv -f $@T $@
199
200 ifndef compile-command.S
201 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
202 endif
203 ifndef compile-command.s
204 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
205 endif
206 ifndef compile-command.c
207 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
208 endif
209
210 ifneq ($(filter %gcc,$(notdir $(firstword $(CC)))),)
211 # GCC can grok options after the file name, and it looks nicer that way.
212 compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
213 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
214 else
215 compile.S = $(COMPILE.S) -DASSEMBLER $(asm-CPPFLAGS) $<
216 compile.c = $(COMPILE.c) $<
217 endif
218
219 ifndef OUTPUT_OPTION
220 ifdef objpfx
221 # We need this for the output to go in the right place. It will default to
222 # empty if make was configured to work with a cc that can't grok -c and -o
223 # together. You can't compile the C library with such a compiler.
224 OUTPUT_OPTION = -o $@
225 endif
226 endif
227
228 S-CPPFLAGS = $(asm-CPPFLAGS)
229 define +make-deps
230 -@rm -f $@
231 $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
232 sed -e 's,$*\.o,$(@:.d=.o) $@,' $(sed-remove-objpfx) > $(@:.d=.T)
233 mv -f $(@:.d=.T) $@
234 endef
235 ifneq (,$(objpfx))
236 sed-remove-objpfx = -e 's@ $(subst @,\@,$(objpfx))@ $$(objpfx)@g' \
237 -e 's@^$(subst @,\@,$(objpfx))@$$(objpfx)@g'
238 endif
239 \f
240 # Figure out the source filenames in this directory.
241
242 override sources := $(addsuffix .c,$(filter-out $(elided-routines),\
243 $(routines) $(aux) \
244 $(sysdep_routines)))
245 sysdep_routines := $(sysdep_routines)
246
247 # This is the list of all object files, gotten by
248 # replacing every ".c" in `sources' with a ".o".
249 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
250 \f
251 +depfiles := $(strip $(sources:.c=.d) \
252 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs))) \
253 $(addsuffix .d,$(others) $(tests)))
254 +depfiles := $(addprefix $(objpfx),\
255 $(filter-out $(addsuffix .d,$(omit-deps)),\
256 $(+depfiles)))
257
258 $(objpfx)depend-$(subdir): Makefile
259 ifdef +depfiles
260 for file in $(+depfiles:$(objpfx)%=%); do \
261 echo "include \$$(objpfx)$$file"; \
262 done > $@-tmp
263 mv -f $@-tmp $@
264 else
265 cp /dev/null $@
266 endif
267
268 ifneq ($(no_deps),t)
269 # Include the generated dependencies of the sources in this directory.
270 include $(objpfx)depend-$(subdir)
271 endif
272 \f\f
273 # Maximize efficiency by minimizing the number of rules.
274 .SUFFIXES: # Clear the suffix list.
275 # Add the suffixes we use.
276 .SUFFIXES: .a .o .S .s .c .h .d
277
278 # Generic rule for making directories.
279 %/:
280 # mkdir isn't smart enough to strip a trailing /.
281 mkdir $(@:%/=%)
282 \f
283 # Make sure that object files are not removed
284 # when they are intermediates between sources and library members.
285 # This can go away with make v4.
286 .PRECIOUS: %.o
287
288 # Make sure that the parent library archive is never removed.
289 .PRECIOUS: $(libc.a)
290 \f
291 # Use the verbose option of ar and tar when not running silently.
292 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
293 verbose := v
294 else # -s
295 verbose :=
296 endif # not -s
297
298 ARFLAGS := r$(verbose)
299 \f
300 # This makes all the object files in the parent library archive.
301
302 .PHONY: lib libobjs lib-noranlib
303 $(libc.a): $(libc.a)(__.SYMDEF)
304 lib: $(libc.a)
305
306 +libobjs := $(patsubst %,$(libc.a)(%),$(notdir $(objects)))
307 libobjs: $(+libobjs)
308 lib-noranlib: libobjs
309
310 # Define a pattern rule that will match many targets libc.%(foo.o), for
311 # each foo in $(objects) (% will just happen always to match `a'). This is
312 # the only way to define a rule that updates many targets at once with one
313 # sequence of commands.
314 ifdef objects
315 $(patsubst %,$(libc.a:a=)\%(%),$(notdir $(objects))): $(objpfx)stamp-$(subdir);
316 $(objpfx)stamp-$(subdir): $(objects)
317 # $(+libc_lock_open)
318 ifdef objdir
319 cd $(objdir); $(AR) cru$(verbose) libc.a $(patsubst $(objpfx)%,%,$^)
320 else
321 $(AR) cru$(verbose) $(..)libc.a $^
322 endif
323 # $(+libc_lock_close)
324 touch $@
325 endif
326
327 $(libc.a)(__.SYMDEF): $(+libobjs)
328 $(RANLIB) $@
329
330 define +libc_lock_open
331 @. $(..)libc-lock-open
332 endef
333 define +libc_lock_close
334 @rm -f $(..)LOCK-libc.a
335 endef
336
337 # This makes all the object files.
338 .PHONY: objects objs
339 objects objs: $(objects) $(addprefix $(objpfx),$(extra-objs))
340 \f
341 # Installation.
342
343 # $(install-lib) are installed from the object directory into $(libdir);
344 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
345 # unless they also appear in $(non-lib.a). $(install-data) are installed
346 # as they are into $(datadir). $(headers) are installed as they are in
347 # $(includedir). $(install-bin) and $(install-sbin) are installed from the
348 # object directory into $(bindir) and $(sbindir), respectively.
349 # $(install-others) are absolute path names of files to install; rules to
350 # install them are defined elsewhere.
351
352 # The simple library name to install libc.a under.
353 # This could be defined by a sysdep Makefile.
354 ifndef libc-name
355 libc-name := c
356 endif
357
358 define do-install
359 $(make-target-directory)
360 $(INSTALL_DATA) $< $@
361 endef
362
363 # Make the target directory if it doesn't exist. Because of make's
364 # directory cache, this will produce the `mkdir' command when the directory
365 # already exists, if it didn't exist at the start of the `make' run. The
366 # `-' prefix ignores errors from mkdir, so there will just be some
367 # gratuitous but harmless `File exists' messages.
368 define make-target-directory
369 $(addprefix -mkdir ,$(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
370 endef
371
372 # Any directory (parent or subdir) that has any object files to build
373 # should install libc.a; this way "make install" in a subdir is guaranteed
374 # to install everything it changes.
375 ifdef objects
376 install: $(libdir)/lib$(libprefix)$(libc-name).a
377 # We avoid depending on lib-noranlib because that makes the parent make
378 # subdir_lib in all the subdirs, when the make install run they do will
379 # update the library anyway. Running ranlib after installing makes the
380 # __.SYMDEF time stamp up to date, which avoids messages from some linkers.
381 # Depending on subdir_install gets all the subdirs to update the library,
382 # and is optimal for `make install' at top level.
383 $(libdir)/lib$(libprefix)$(libc-name).a: libobjs subdir_install
384 $(make-target-directory)
385 $(INSTALL_DATA) $(libc.a) $@
386 $(RANLIB) $@
387 endif
388
389 ifdef install-bin
390 $(addprefix $(bindir)/,$(install-bin)): $(bindir)/%: $(objpfx)%
391 $(make-target-directory)
392 $(INSTALL_PROGRAM) $< $@
393 endif
394 ifdef install-sbin
395 $(addprefix $(sbindir)/,$(install-sbin)): $(sbindir)/%: $(objpfx)%
396 $(make-target-directory)
397 $(INSTALL_PROGRAM) $< $@
398 endif
399 ifdef install-lib
400 install-lib.a := $(filter lib%.a,$(install-lib))
401 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
402 ifdef install-lib-non.a
403 $(addprefix $(libdir)/$(libprefix),$(install-lib-non.a)): \
404 $(libdir)/$(libprefix)%: $(objpfx)%
405 $(do-install)
406 endif
407 ifdef install-lib.a
408 $(install-lib.a:lib%.a=$(libdir)/lib$(libprefix)%.a): \
409 $(libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
410 $(do-install)
411 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
412 endif
413 endif
414 ifdef install-data
415 $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
416 endif
417 headers := $(strip $(headers))
418 ifdef headers
419 $(addprefix $(includedir)/,$(headers)): \
420 $(includedir)/%: %;$(do-install)
421 endif # headers
422
423 .PHONY: install-bin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
424 install-data-nosubdir install-headers-nosubdir
425 install-bin-nosubdir: $(addprefix $(bindir)/,$(install-bin))
426 install-sbin-nosubdir: $(addprefix $(sbindir)/,$(install-sbin))
427 install-lib-nosubdir: $(addprefix $(libdir)/,\
428 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
429 $(addprefix $(libprefix),$(install-lib-non.a)))
430 install-data-nosubdir: $(addprefix $(datadir)/,$(install-data))
431 install-headers-nosubdir: $(addprefix $(includedir)/,$(headers))
432 install-others-nosubdir: $(install-others)
433
434 # We need all the `-nosubdir' targets so that `install' in the parent
435 # doesn't depend on several things which each iterate over the subdirs.
436 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
437 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
438 install-%:: install-%-nosubdir ;
439
440 .PHONY: install install-no-libc.a-nosubdir
441 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
442 install-bin-nosubdir install-lib-nosubdir \
443 install-others-nosubdir install-sbin-nosubdir
444 install: install-no-libc.a-nosubdir
445 \f
446 # Command to compile $< in $(objdir) using the native libraries.
447 define native-compile
448 cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
449 $(addprefix $$cwd/,$^) -o $(@F)
450 endef
451
452 # Command to compile $< in $(common-objdir) using the native libraries.
453 define common-objdir-compile
454 cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F)
455 endef
456
457 # We always want to use configuration definitions.
458 BUILD_CFLAGS = -include $(common-objpfx)config.h
459
460 # Support the GNU standard name for this target.
461 .PHONY: check
462 check: tests
463 \f
464 .PHONY: TAGS
465 TAGS: distinfo $(..)MakeTAGS
466 $(MAKE) $(addprefix -f ,$^)
467
468 .PHONY: echo-headers
469 echo-headers:
470 @echo $(headers)
471
472 \f
473 # Common cleaning targets.
474
475 .PHONY: common-mostlyclean common-clean mostlyclean clean
476 clean: common-clean
477 mostlyclean: common-mostlyclean
478
479 # Remove the object files.
480 common-mostlyclean:
481 -rm -f $(addprefix $(objpfx),$(tests) $(others) \
482 $(addsuffix .o,$(tests) $(others)) \
483 $(addsuffix .out,$(tests)))
484 -rm -f $(objects) $(addprefix $(objpfx),$(extra-objs) stamp-$(subdir))
485 -rm -f core TAGS
486
487 # Also remove the dependencies and generated source files.
488 common-clean: common-mostlyclean
489 -rm -f $(objpfx)depend-$(subdir) $(+depfiles)
490 -rm -f $(addprefix $(objpfx),$(generated))
491 \f
492 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
493 # for each function which is a stub. We grovel over all the .d files
494 # looking for references to source files in sysdeps/stub. Then we grovel
495 # over each referenced source file to see what stub function it defines.
496
497 .PHONY: stubs # The parent Makefile calls this target.
498 stubs: $(common-objpfx)stub-$(subdir)
499 s = $(sysdep_dir)/stub
500 $(common-objpfx)stub-$(subdir): $(+depfiles)
501 # Use /dev/null since `...` might expand to empty.
502 s=`cd $s; /bin/pwd`; \
503 $(patsubst %,cd %;,$(objdir)) \
504 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
505 `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \
506 $(patsubst $(objpfx)%,%,$^) /dev/null` \
507 /dev/null > $@T
508 mv -f $@T $@
509 \f
510 # Make the distribution tar file.
511
512 .PHONY: dist
513 dist: distinfo $(..)Make-dist
514 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
515
516 dist: $(distribute)
517
518 # We used to simply export all these variables, but that frequently made the
519 # environment get too large. Instead, we write all the information into
520 # a generated makefile fragment `distinfo', and then include it with -f in
521 # the sub-make that makes the distribution (above).
522 distinfo: Makefile $(..)Makerules
523 $(distinfo-vars)
524 mv -f $@.new $@
525
526 define distinfo-vars
527 rm -f $@.new
528 $(foreach var,subdir sources elided-routines headers distribute \
529 dont_distribute generated others tests,
530 echo >> $@.new '$(var) := $($(var))')
531 echo >> $@.new 'sources := $$(sources) $$(addsuffix .c,$$(elided-routines))'
532 endef
533 \f
534 ifneq (,$(strip $(gpl2lgpl)))
535 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
536 # Snarf from the master source and frob the copying notice.
537 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
538 sed -f $^ > $@-tmp
539 # So I don't edit them by mistake.
540 chmod a-w $@-tmp
541 mv -f $@-tmp $@
542 test -d CVS && cvs commit -m'Updated from $^' $@
543 endif
544 endif