]> sourceware.org Git - glibc.git/blob - Makerules
Thu Jun 13 00:02:25 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
[glibc.git] / Makerules
1 # Copyright (C) 1991, 92, 93, 94, 95, 96 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 oPATH := $(PATH)
40 PATH := this definition should take precedence over $(oPATH)
41 ifeq ($(PATH),$(oPATH))
42 You must not use the -e flag when building the GNU C library.
43 else
44 PATH := $(oPATH)
45 endif
46 \f
47 ifndef +included-Makeconfig
48 include $(..)Makeconfig
49 endif
50
51 # `configure' writes a definition of `config-sysdirs' in `config.make'.
52 sysdirs = $(config-sysdirs)
53
54 +sysdir_pfx = $(common-objpfx)
55
56 export sysdirs := $(sysdirs)
57
58 +sysdep_dirs := $(addprefix $(sysdep_dir)/,$(sysdirs))
59 ifdef objdir
60 +sysdep_dirs := $(objdir) $(+sysdep_dirs)
61 endif
62
63 # Add -I switches to get the right sysdep directories.
64 # `+includes' in Makeconfig references $(+sysdep-includes).
65 +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
66
67 # The name of the symbol table archive member. The default is suitable for
68 # BSD style archives. It can be overridden in sysdep Makefiles when SYSV
69 # style archive are used.
70 ifeq (no,$(elf))
71 ar-symtab-name = __.SYMDEF
72 else
73 ar-symtab-name = # The null name is used in ELF archives.
74 endif
75 \f
76 # Include any system-specific makefiles.
77
78 # This is here so things in sysdep Makefiles can easily depend on foo.h as
79 # appropriate and not worry about where foo.h comes from, which may be
80 # system dependent and not known by that Makefile.
81 vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) \
82 $(addprefix $(sysdep_dir)/,$(sysdirs)) \
83 $(..)))
84
85 # Some sysdep makefiles use this to distinguish being included here from
86 # being included individually by a subdir makefile (hurd/Makefile needs this).
87 in-Makerules := yes
88
89 ifndef avoid-generated
90 -include $(+sysdir_pfx)sysd-Makefile
91 ifneq ($(sysd-Makefile-sysdirs),$(sysdirs))
92 sysd-Makefile-force = FORCE
93 FORCE:
94 endif
95 $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules \
96 $(sysd-Makefile-force)
97 -@rm -f $@T
98 (echo 'sysd-Makefile-sysdirs := $(sysdirs)'; \
99 for dir in $(sysdirs); do \
100 file=sysdeps/$$dir/Makefile; \
101 if [ -f $(..)$$file ]; then \
102 echo include "\$$(..)$$file"; \
103 else true; fi; \
104 done; \
105 echo 'sysd-Makefile-done=t') > $@T
106 mv -f $@T $@
107 endif
108
109 ifndef sysd-Makefile-done
110 # Don't do deps until this exists, because it might change the sources list.
111 no_deps=t
112 endif
113
114
115 # Reorder before-compile so that mach things come first, and hurd things
116 # second, before all else. The mach and hurd subdirectories have many
117 # generated header files which the much of rest of the library depends on,
118 # so it is best to build them first (and mach before hurd, at that).
119 before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
120 $(before-compile)) \
121 $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
122 $(before-compile))
123
124 # Remove existing files from `before-compile'. Things are added there when
125 # they must exist for dependency generation to work right, but once they
126 # exist there is no further need for every single file to depend on them,
127 # and those gratuitous dependencies result in many gratuitous
128 # recompilations.
129 before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
130
131 # Don't let any before-compile file be an intermediate and get removed.
132 ifdef before-compile
133 $(before-compile):
134 endif
135 \f
136 # Generate an ordered list of implicit rules which find the source files in
137 # each sysdep directory. The old method was to use vpath to search all the
138 # sysdep directories. However, that had the problem that a .S file in a
139 # later directory would be chosen over a .c file in an earlier directory,
140 # which does not preserve the desired sysdeps ordering behavior.
141
142 # When making the list of .d files to include, we can't know which ones
143 # have source in .s files, and thus do not in fact need a .d file.
144 # So we must define rules to make .d files for .s files.
145 define make-dummy-dep
146 $(addprefix ln $(objpfx)dummy.d ,$(filter-out $(wildcard $@),$@))
147 endef
148 $(objpfx)dummy.d:
149 echo '# .s files cannot contain includes, so they need no deps.' > $@
150
151 # It matters that this set of rules, for compiling from sources in
152 # the current directory (the $srcdir/$subdir) come before the
153 # generated sysdep rules in included from sysd-rules below. When
154 # compiling in the source tree, generated sources go into the current
155 # directory, and those should be chosen before any sources in sysdeps.
156 $(objpfx)%.o: %.S $(before-compile); $(compile-command.S)
157 $(objpfx)%.so: %.S $(before-compile); $(compile-command.S)
158 $(objpfx)%.po: %.S $(before-compile); $(compile-command.S)
159 $(objpfx)%.go: %.S $(before-compile); $(compile-command.S)
160 $(objpfx)%.d: %.S $(before-compile); $(+make-deps)
161 $(objpfx)%.o: %.s $(before-compile); $(compile-command.s)
162 $(objpfx)%.so: %.s $(before-compile); $(compile-command.s)
163 $(objpfx)%.po: %.s $(before-compile); $(compile-command.s)
164 $(objpfx)%.go: %.s $(before-compile); $(compile-command.s)
165 $(objpfx)%.d: %.s $(objpfx)dummy.d; $(make-dummy-dep)
166 $(objpfx)%.o: %.c $(before-compile); $(compile-command.c)
167 $(objpfx)%.so: %.c $(before-compile); $(compile-command.c)
168 $(objpfx)%.po: %.c $(before-compile); $(compile-command.c)
169 $(objpfx)%.go: %.c $(before-compile); $(compile-command.c)
170 $(objpfx)%.d: %.c $(before-compile); $(+make-deps)
171
172 # Omit the objpfx rules when building in the source tree, because
173 # objpfx is empty and so these rules just override the ones above.
174 ifdef objpfx
175 # Define first rules to find the source files in $(objpfx).
176 # Generated source files will end up there.
177 $(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S)
178 $(objpfx)%.so: $(objpfx)%.S $(before-compile); $(compile-command.S)
179 $(objpfx)%.po: $(objpfx)%.S $(before-compile); $(compile-command.S)
180 $(objpfx)%.go: $(objpfx)%.S $(before-compile); $(compile-command.S)
181 $(objpfx)%.d: $(objpfx)%.S $(before-compile); $(+make-deps)
182 $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s)
183 $(objpfx)%.so: $(objpfx)%.s $(before-compile); $(compile-command.s)
184 $(objpfx)%.po: $(objpfx)%.s $(before-compile); $(compile-command.s)
185 $(objpfx)%.go: $(objpfx)%.s $(before-compile); $(compile-command.s)
186 $(objpfx)%.d: $(objpfx)%.s $(objpfx)dummy.d; $(make-dummy-dep)
187 $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c)
188 $(objpfx)%.so: $(objpfx)%.c $(before-compile); $(compile-command.c)
189 $(objpfx)%.po: $(objpfx)%.c $(before-compile); $(compile-command.c)
190 $(objpfx)%.go: $(objpfx)%.c $(before-compile); $(compile-command.c)
191 $(objpfx)%.d: $(objpfx)%.c $(before-compile); $(+make-deps)
192 endif
193
194 # System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
195 # patterns matching sysdep directories whose assembly source files should
196 # be suppressed.
197 ifdef inhibit-sysdep-asm
198 define open-check-inhibit-asm
199 case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) : ;; *)
200 endef
201 close-check-inhibit-asm = ;; esac ;
202 endif
203
204 # Don't include sysd-rules until sysd-Makefile is already there and has been
205 # included. It might define inhibit-sysdep-asm, which would affect the
206 # contents of sysd-rules.
207 ifdef sysd-Makefile-done
208 -include $(+sysdir_pfx)sysd-rules
209 ifneq ($(sysd-rules-sysdirs),$(sysdirs))
210 # The value of $(sysdirs) the sysd-rules was computed for
211 # differs from the one we are using now. So force a rebuild of sysd-rules.
212 sysd-rules-force = FORCE
213 FORCE:
214 endif
215 endif
216 $(+sysdir_pfx)sysd-rules: $(+sysdir_pfx)config.make $(..)Makerules \
217 $(wildcard $(foreach dir,$(sysdirs),\
218 $(sysdep_dir)/$(dir)/Makefile))\
219 $(sysd-rules-force)
220 -@rm -f $@T
221 (echo 'sysd-rules-sysdirs := $(sysdirs)'; \
222 for sysdir in $(sysdirs); do \
223 dir="\$$(sysdep_dir)/$$sysdir"; \
224 for o in $(object-suffixes); do \
225 $(open-check-inhibit-asm) \
226 echo "\$$(objpfx)%$$o: $$dir/%.S \$$(before-compile); \
227 \$$(compile-command.S)"; \
228 echo "\$$(objpfx)%$$o: $$dir/%.s \$$(before-compile); \
229 \$$(compile-command.s)"; \
230 $(close-check-inhibit-asm) \
231 echo "\$$(objpfx)%$$o: $$dir/%.c \$$(before-compile); \
232 \$$(compile-command.c)"; \
233 done; \
234 $(open-check-inhibit-asm) \
235 echo "\$$(objpfx)%.d: $$dir/%.s \$$(objpfx)dummy.d; \
236 \$$(make-dummy-dep)"; \
237 echo "\$$(objpfx)%.d: $$dir/%.S \$$(before-compile); \
238 \$$(+make-deps)"; \
239 $(close-check-inhibit-asm) \
240 echo "\$$(objpfx)%.d: $$dir/%.c \$$(before-compile); \
241 \$$(+make-deps)"; \
242 done; \
243 echo 'sysd-rules-done = t') > $@T
244 mv -f $@T $@
245
246 ifndef sysd-rules-done
247 # Don't do deps until this exists, because it provides rules to make the deps.
248 no_deps=t
249 endif
250
251
252 ifndef compile-command.S
253 compile-command.S = $(compile.S) $(OUTPUT_OPTION)
254 endif
255 ifndef compile-command.s
256 compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
257 endif
258 ifndef compile-command.c
259 compile-command.c = $(compile.c) $(OUTPUT_OPTION)
260 endif
261
262 # GCC can grok options after the file name, and it looks nicer that way.
263 compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
264 compile.S = $(CC) $< -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
265 COMPILE.S = $(CC) -c $(CPPFLAGS) -DASSEMBLER $(asm-CPPFLAGS)
266 COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
267
268 # We need this for the output to go in the right place. It will default to
269 # empty if make was configured to work with a cc that can't grok -c and -o
270 # together. You can't compile the C library with such a compiler.
271 OUTPUT_OPTION = -o $@
272
273 S-CPPFLAGS = $(asm-CPPFLAGS)
274 define +make-deps
275 -@rm -f $@
276 $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
277 sed -e 's,$(subst .,\.,$*)\.o,$(foreach o,$(object-suffixes),$(@:.d=$o)) $@,' \
278 $(sed-remove-objpfx) > $(@:.d=.T)
279 mv -f $(@:.d=.T) $@
280 endef
281 ifneq (,$(objpfx))
282 # Continuation lines here are dangerous because they introduce spaces!
283 define sed-remove-objpfx
284 -e 's@ $(subst .,\.,$(subst @,\@,$(objpfx)))@ $$(objpfx)@g' \
285 -e 's@^$(subst .,\.,$(subst @,\@,$(objpfx)))@$$(objpfx)@g'
286 endef
287 endif
288 \f
289 # Figure out the source filenames in this directory.
290
291 override sources := $(addsuffix .c,$(filter-out $(elided-routines),\
292 $(routines) $(aux) \
293 $(sysdep_routines)))
294 sysdep_routines := $(sysdep_routines)
295
296 headers := $(headers) $(sysdep_headers)
297
298 # This is the list of all object files, gotten by
299 # replacing every ".c" in `sources' with a ".o".
300 override objects := $(addprefix $(objpfx),$(sources:.c=.o))
301
302
303 # This variable is used in ``include $(o-iterator)'' after defining
304 # $(o-iterator-doit) to produce some desired rule using $o for the object
305 # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
306 # is produced for each object suffix in use.
307 o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
308
309 # The makefile may define $(extra-libs) with `libfoo libbar'
310 # to build libfoo.a et al from the modules listed in $(libfoo-routines).
311 ifdef extra-libs
312 # extra-lib.mk is included once for each extra lib to define rules
313 # to build it, and to add its objects to the various variables.
314 # During its evaluation, $(lib) is set to the name of the library.
315 extra-libs-left := $(extra-libs)
316 include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
317 endif
318 \f
319 +depfiles := $(strip $(sources:.c=.d) \
320 $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.so=.o))) \
321 $(addsuffix .d,$(others) $(tests)))
322 +depfiles := $(addprefix $(objpfx),\
323 $(filter-out $(addsuffix .d,$(omit-deps)),\
324 $(+depfiles)))
325
326 ifdef +depfiles
327 ifneq ($(no_deps),t)
328 -include $(+depfiles)
329 endif
330 endif
331 \f\f
332 # Maximize efficiency by minimizing the number of rules.
333 .SUFFIXES: # Clear the suffix list.
334 # Add the suffixes we use.
335 .SUFFIXES: .a $(object-suffixes) .S .s .c .h .d
336
337 # Generic rule for making directories.
338 %/:
339 # mkdir isn't smart enough to strip a trailing /.
340 mkdir $(@:%/=%)
341 \f
342 # Make sure that object files are not removed
343 # when they are intermediates between sources and library members.
344 .PRECIOUS: $(addprefix $(objpfx)%,$(object-suffixes))
345
346 # Make sure that the parent library archive is never removed.
347 .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
348 \f
349 # Use the verbose option of ar and tar when not running silently.
350 ifeq "$(findstring s,$(MAKEFLAGS))" "" # if not -s
351 verbose := v
352 else # -s
353 verbose :=
354 endif # not -s
355
356 ARFLAGS := r$(verbose)
357 \f
358 # This makes all the object files in the parent library archive.
359
360 .PHONY: lib libobjs lib-noranlib
361 lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
362
363 # Pattern rule for libraries: depend on the __.SYMDEF member updated by ranlib.
364 lib%.a: lib%.a($(ar-symtab-name)) ;
365
366 # For object-suffix $o, the list of objects with that suffix.
367 # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
368 o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
369 $(elide-routines$o)),\
370 $(objects)))
371
372 libobjs: $(foreach o,$(object-suffixes),\
373 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
374 $(notdir $(o-objects))))
375 lib-noranlib: libobjs
376 others: $(addprefix $(objpfx),$(install-lib))
377
378 ifdef objects
379
380 # Define a pattern rule that will match many targets libc.a(foo.%), for
381 # each foo.o in $(objects) (% will just happen always to match `o'). This is
382 # the only way to define a rule that updates many targets at once with one
383 # sequence of commands.
384 define o-iterator-doit
385 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
386 $(addsuffix .%,$(filter-out $(elide-routines$o),$(notdir $(objects:.o=))))): \
387 $(objpfx)stamp.%-$(subdir) ;
388 endef
389 object-suffixes-left := $(object-suffixes)
390 include $(o-iterator)
391
392 # The pattern rule tells Make to remake $(objpfx)stamp.%-$(subdir) as
393 # the way to update all the foo.% object files in $(objects). Now we
394 # define explicit rules to update each $(objpfx)stamp.SUFFIX-$(subdir)
395 # timestamp file; these rules (one explicit rule is generated for each
396 # object suffix) will update the parent archive with ar. Use a static
397 # pattern rule so $* is set to the object type during the commands.
398 define o-iterator-doit
399 $(objpfx)stamp$o-$(subdir): $(objpfx)stamp%-$(subdir): $(o-objects); $$(do-ar)
400 endef
401 object-suffixes-left := $(object-suffixes)
402 include $(o-iterator)
403 define do-ar
404 $(patsubst %,cd %;,$(objdir)) \
405 $(AR) cru$(verbose) ${O%-lib} \
406 $(patsubst $(objpfx)%,%,$^)
407 rm -f $@
408 touch $@
409 endef
410 ifdef subdir
411 O%-lib = $(filter ../,$(firstword $(objdir) ../))$(patsubst %,$(libtype$*),c)
412 else
413 O%-lib = $(patsubst %,$(libtype$*),c)
414 endif
415
416 endif
417
418 # Rules to update the $(ar-symtab-name) member with ranlib,
419 # one for each object flavor.
420 define o-iterator-doit
421 $(common-objpfx)$(patsubst %,$(libtype$o),c)($(ar-symtab-name)): \
422 $(common-objpfx)$(patsubst %,$(libtype$o),c)(\
423 $(patsubst $(objpfx)%,%,$(o-objects))) $(subdirs-stamp-o); \
424 $$(RANLIB) $$(common-objpfx)$$(patsubst %,$$(libtype$o),c)
425 endef
426 ifndef subdir
427 subdirs-stamps := $(foreach d,$(subdirs),\
428 $(firstword $(objdir) $(subdir))/stamp%-$d)
429 subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
430 $(subdirs-stamps): subdir_lib;
431 endif
432 object-suffixes-left = $(object-suffixes)
433 include $(o-iterator)
434
435
436 # This makes all the object files.
437 .PHONY: objects objs
438 objects objs: $(foreach o,$(object-suffixes),$(o-objects)) \
439 $(addprefix $(objpfx),$(extra-objs))
440
441 # Canned sequence for building an extra library archive.
442 define build-extra-lib
443 $(patsubst %,cd %;,$(objdir)) \
444 $(AR) cru$(verbose) $(@:$(objpfx)%=%) \
445 $(patsubst $(objpfx)%,%,$^)
446 $(RANLIB) $@
447 endef
448 \f
449 # Shared library building.
450
451 ifeq (yes,$(build-shared))
452
453 # Process the shlib-versions file, which tells us what shared library
454 # version numbers to use when we install shared objects on this system.
455 -include $(common-objpfx)soversions.mk
456 $(common-objpfx)soversions.mk: $(..)shlib-versions $(..)Makerules \
457 $(common-objpfx)config.make
458 sed 's/#.*$$//' $< | while read conf versions; do \
459 test -n "$$versions" || continue; \
460 case '$(config-machine)-$(config-vendor)-$(config-os)' in $$conf)\
461 for v in $$versions; do \
462 lib="$${v%%=*}"; if eval "test -z \"\$$vers_lib$$lib\""; then \
463 eval vers_lib$${lib}=yes; \
464 echo $$lib.so-version=.$${v##$$lib=}; fi; \
465 done ;; esac; done > $@T
466 mv -f $@T $@
467
468 # Get $(version) defined with the release version number.
469 -include $(common-objpfx)version.mk
470
471
472 # Pattern rule to build a shared object from an archive of PIC objects.
473 # This must come after the installation rules so Make doesn't try to
474 # build shared libraries in place from the installed *_pic.a files.
475 # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
476 # on other shared objects.
477 lib%.so: lib%_pic.a; $(build-shlib)
478
479 ifeq ($(have-no-whole-archive),yes)
480 no-whole-archive = -Wl,--no-whole-archive
481 else
482 no-whole-archive =
483 endif
484
485 define build-shlib
486 $(LINK.o) -shared -o $@ $(sysdep-LDFLAGS) $(config-LDFLAGS) \
487 -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
488 $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
489 -Wl,-rpath-link=$(common-objdir) \
490 -Wl,--whole-archive $^ $(no-whole-archive) \
491 $(LDLIBS-$(@F:lib%.so=%).so)
492 endef
493
494 # Don't try to use -lc when making libc.so itself.
495 # Also omits crti.o and crtn.o, which we do not want
496 # since we define our own `.init' section specially.
497 LDFLAGS-c.so = -nostdlib -nostartfiles
498 # Give libc.so an entry point and make it directly runnable itself.
499 LDFLAGS-c.so += -e __libc_main
500 # Use our own special initializer and finalizer files for libc.so.
501 elfobjdir := $(firstword $(objdir) $(patsubst ../$(subdir),.,$(..)elf))
502 $(common-objpfx)libc.so: $(elfobjdir)/soinit.so \
503 $(common-objpfx)libc_pic.a \
504 $(elfobjdir)/sofini.so $(elfobjdir)/ld.so
505 $(build-shlib)
506
507 ifdef libc.so-version
508 $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
509 rm -f $@
510 ln -s $(<F) $@ || ln $< $@
511 endif
512 endif
513 \f
514 # Installation.
515
516 # $(install-lib) are installed from the object directory into $(libdir);
517 # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
518 # unless they also appear in $(non-lib.a). $(install-data) are installed
519 # as they are into $(datadir). $(headers) are installed as they are in
520 # $(includedir). $(install-bin) and $(install-sbin) are installed from the
521 # object directory into $(bindir) and $(sbindir), respectively.
522 # $(install-others) are absolute path names of files to install; rules to
523 # install them are defined elsewhere.
524
525 # The simple library name to install libc.a under.
526 # This could be defined by a sysdep Makefile.
527 ifndef libc-name
528 libc-name := c
529 endif
530
531 define do-install
532 $(make-target-directory)
533 $(INSTALL_DATA) $< $@
534 endef
535
536 # Make the target directory if it doesn't exist, using the `mkinstalldirs'
537 # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
538 define make-target-directory
539 $(addprefix $(..)./mkinstalldirs ,\
540 $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
541 endef
542
543 # Any directory (parent or subdir) that has any object files to build
544 # should install libc.a; this way "make install" in a subdir is guaranteed
545 # to install everything it changes.
546 ifdef objects
547 installed-libcs := $(foreach o,$(object-suffixes),\
548 $(libdir)/$(patsubst %,$(libtype$o),\
549 $(libprefix)$(libc-name)))
550 installed-libcs := $(filter-out %_pic.a,$(installed-libcs))
551 install: $(installed-libcs)
552 $(installed-libcs): $(libdir)/lib$(libprefix)%: lib
553 $(make-target-directory)
554 $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
555 # Running ranlib after installing makes the __.SYMDEF time stamp up to
556 # date, which avoids messages from some linkers.
557 $(RANLIB) $@
558 endif
559
560 define do-install-program
561 $(make-target-directory)
562 $(INSTALL_PROGRAM) $< $@.new
563 mv -f $@.new $@
564 endef
565
566 install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
567 install-lib := $(filter-out %.so %_pic.a,$(install-lib))
568 ifeq (yes,$(build-shared))
569
570 install-lib-nosubdir: $(install-lib.so:%=$(libdir)/%)
571
572 # Find which .so's have versions.
573 versioned := $(strip $(foreach so,$(install-lib.so),\
574 $(patsubst %,$(so),$($(so)-version))))
575
576 # Install all the unversioned shared libraries.
577 $(addprefix $(libdir)/,$(filter-out $(versioned),$(install-lib.so))): \
578 $(libdir)/%.so: $(objpfx)%.so; $(do-install-program)
579
580 make-link = cd $(@D); rm -f $(@F); $(LN_S) $(<F) $(@F)
581
582 ifdef libc.so-version
583 # For a library specified to be version N, install three files:
584 # libc.so -> libc.so.N (e.g. libc.so.6)
585 # libc.so.6 -> libc-VERSION.so (e.g. libc-1.10.so)
586
587 $(slibdir)/libc.so$(libc.so-version): $(slibdir)/libc-$(version).so
588 $(make-link)
589 $(slibdir)/libc-$(version).so: $(common-objpfx)libc.so; $(do-install-program)
590 install: $(slibdir)/libc.so$(libc.so-version)
591
592 ifndef subdir
593 # What we install as libc.so for programs to link against is in fact an
594 # archive. It contains the various $(static-only-routines) objects, and
595 # the special object libc-syms.so that contains just the dynamic symbol
596 # table of the shared libc object.
597 install: $(libdir)/libc.so
598 $(libdir)/libc.so: $(common-objpfx)libc.so$(libc.so-version) \
599 $(elfobjdir)/$(rtld-installed-name) \
600 $(common-objpfx)libc.a
601 (echo '/* Use the shared library, but some functions are only in';\
602 echo ' the static library, so try that secondarily.'; \
603 echo ' The dynamic linker defines some functions used by $(<F),';\
604 echo ' but ld uses definitions from libc.a before the examining';\
605 echo ' dependencies of $(<F) to find $(rtld-installed-name). */';\
606 echo 'GROUP ( $(^F) )') > $@.new
607 mv -f $@.new $@
608
609 endif
610
611 else
612 install: $(slibdir)/libc.so
613 $(slibdir)/libc.so: $(common-objpfx)libc.so; $(do-install-program)
614 endif
615
616
617 ifneq (,$(versioned))
618 # Produce three sets of rules as above for all the smaller versioned libraries.
619
620 define o-iterator-doit
621 $(libdir)/$o: $(libdir)/$o$($o-version); $$(make-link)
622 endef
623 object-suffixes-left := $(versioned)
624 include $(o-iterator)
625
626 # Make symlinks in the build directory, because the versioned names might
627 # be referenced by a DT_NEEDED in another library.
628 define o-iterator-doit
629 $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
630 endef
631 object-suffixes-left := $(versioned)
632 include $(o-iterator)
633
634
635 define o-iterator-doit
636 $(libdir)/$o$($o-version): $(libdir)/$(o:.so=)-$(version).so; $$(make-link)
637 endef
638 object-suffixes-left := $(versioned)
639 include $(o-iterator)
640
641 define o-iterator-doit
642 $(libdir)/$(o:.so=)-$(version).so: $(objpfx)$o; $$(do-install-program)
643 endef
644 object-suffixes-left := $(versioned)
645 include $(o-iterator)
646 endif
647
648 define do-install-so
649 $(do-install-program)
650 $(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
651 $(filter-out %.so,$@))
652 endef
653
654 so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
655 $(foreach v,$(so-versions),\
656 $(libdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so
657 $(do-install-so)
658 $(foreach v,$(so-versions),\
659 $(libdir)/$(libprefix)%$v): $(common-objpfx)%.so
660 $(do-install-so)
661 endif
662
663 ifdef install-bin
664 $(addprefix $(bindir)/,$(install-bin)): $(bindir)/%: $(objpfx)%
665 $(do-install-program)
666 endif
667 ifdef install-sbin
668 $(addprefix $(sbindir)/,$(install-sbin)): $(sbindir)/%: $(objpfx)%
669 $(do-install-program)
670 endif
671 ifdef install-lib
672 install-lib.a := $(filter lib%.a,$(install-lib))
673 install-lib-non.a := $(filter-out lib%.a,$(install-lib))
674 ifdef install-lib-non.a
675 $(addprefix $(libdir)/$(libprefix),$(install-lib-non.a)): \
676 $(libdir)/$(libprefix)%: $(objpfx)%
677 $(do-install)
678 endif
679 ifdef install-lib.a
680 $(install-lib.a:lib%.a=$(libdir)/lib$(libprefix)%.a): \
681 $(libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a
682 $(do-install)
683 $(patsubst %,$(RANLIB) $@,$(filter-out $(non-lib.a),$(<F)))
684 endif
685 endif
686 ifdef install-data
687 $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
688 endif
689 headers := $(strip $(headers))
690 ifdef headers
691 $(addprefix $(includedir)/,$(headers)): \
692 $(includedir)/%: %;$(do-install)
693 endif # headers
694
695 .PHONY: install-bin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
696 install-data-nosubdir install-headers-nosubdir
697 install-bin-nosubdir: $(addprefix $(bindir)/,$(install-bin))
698 install-sbin-nosubdir: $(addprefix $(sbindir)/,$(install-sbin))
699 install-lib-nosubdir: $(addprefix $(libdir)/,\
700 $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
701 $(addprefix $(libprefix),$(install-lib-non.a)))
702 install-data-nosubdir: $(addprefix $(datadir)/,$(install-data))
703 install-headers-nosubdir: $(addprefix $(includedir)/,$(headers))
704 install-others-nosubdir: $(install-others)
705
706 # We need all the `-nosubdir' targets so that `install' in the parent
707 # doesn't depend on several things which each iterate over the subdirs.
708 # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
709 # subroutine. Then in the parent `install-FOO' also causes subdir makes.
710 install-%:: install-%-nosubdir ;
711
712 .PHONY: install install-no-libc.a-nosubdir
713 install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir\
714 install-bin-nosubdir install-lib-nosubdir \
715 install-others-nosubdir install-sbin-nosubdir
716 install: install-no-libc.a-nosubdir
717 \f
718 # Command to compile $< in $(objdir) using the native libraries.
719 define native-compile
720 cwd=`pwd`; cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) \
721 $(addprefix $$cwd/,$^) -o $(@F)
722 endef
723
724 # Command to compile $< in $(common-objdir) using the native libraries.
725 define common-objdir-compile
726 cd $(@D); $(BUILD_CC) $(BUILD_CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F)
727 endef
728
729 # We always want to use configuration definitions.
730 ifdef objdir
731 # This is always used in $(common-objdir), so we use no directory name.
732 BUILD_CFLAGS = -include config.h
733 else
734 BUILD_CFLAGS = -include $(..)config.h
735 endif
736
737 # Support the GNU standard name for this target.
738 .PHONY: check
739 check: tests
740 \f
741 .PHONY: TAGS
742 TAGS: distinfo $(..)MakeTAGS
743 $(MAKE) $(addprefix -f ,$^) $@
744
745 $(..)po/%.pot: distinfo $(..)MakeTAGS FORCE
746 $(MAKE) $(addprefix -f ,$(filter-out FORCE,$^)) $@
747 FORCE:
748
749
750 .PHONY: echo-headers
751 echo-headers:
752 @echo $(headers)
753
754 \f
755 # Common cleaning targets.
756
757 .PHONY: common-mostlyclean common-clean mostlyclean clean
758 clean: common-clean
759 mostlyclean: common-mostlyclean
760
761 # Remove the object files.
762 common-mostlyclean:
763 -rm -f $(addprefix $(objpfx),$(tests) $(others) \
764 $(addsuffix .o,$(tests) $(others)) \
765 $(addsuffix .out,$(tests)))
766 -rm -f $(addprefix $(objpfx),$(extra-objs) $(install-lib))
767 -rm -f core $(objpfx)stub-$(subdir)
768 $(rmobjs)
769 define rmobjs
770 $(foreach o,$(object-suffixes),
771 -rm -f $(addprefix $(objpfx),stamp$o-$(subdir)) $(o-objects))
772 endef
773
774 # Also remove the dependencies and generated source files.
775 common-clean: common-mostlyclean
776 -rm -f $(addprefix $(objpfx),$(generated)) $(+depfiles)
777 \f
778 # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
779 # for each function which is a stub. We grovel over all the .d files
780 # looking for references to source files in sysdeps/stub. Then we grovel
781 # over each referenced source file to see what stub function it defines.
782
783 .PHONY: stubs # The parent Makefile calls this target.
784 stubs: $(common-objpfx)stub-$(subdir)
785 s = $(sysdep_dir)/stub
786 $(common-objpfx)stub-$(subdir): $(+depfiles)
787 # Use /dev/null since `...` might expand to empty.
788 (s=`cd $s; /bin/pwd`; \
789 $(patsubst %,cd %;,$(objdir)) \
790 sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
791 `sed -n 's@^.*$s/\([a-z0-9_-]*\.c\).*$$@'"$$s"/'\1@p' \
792 $(patsubst $(objpfx)%,%,$^) /dev/null` \
793 /dev/null) > $@T
794 mv -f $@T $@
795 \f
796 # Make the distribution tar file.
797
798 .PHONY: dist
799 dist: distinfo $(..)Make-dist
800 $(MAKE) -f $< -f $(word 2,$^) $(Make-dist-args)
801
802 # Avoid depending on source files found in sysdeps dirs,
803 # because the references affect implicit rule selection.
804 dist: $(filter-out %.c %.S %.s,$(distribute))
805
806 # We used to simply export all these variables, but that frequently made the
807 # environment get too large. Instead, we write all the information into
808 # a generated makefile fragment `distinfo', and then include it with -f in
809 # the sub-make that makes the distribution (above).
810 distinfo: Makefile $(..)Makerules
811 $(distinfo-vars)
812 mv -f $@.new $@
813
814 define distinfo-vars
815 rm -f $@.new
816 $(foreach var,subdir subdir-dirs sources elided-routines sysdep_routines \
817 headers sysdep_headers distribute dont_distribute generated \
818 others tests extra-libs $(extra-libs:%=%-routines) \
819 $(addprefix install-,lib data bin sbin others),
820 echo >> $@.new '$(subdir)-$(var) := $($(var))'
821 echo >> $@.new '$(var) = $$($(subdir)-$(var))')
822 endef
823 \f
824 ifneq (,$(strip $(gpl2lgpl)))
825 ifneq (,$(wildcard $(..)gpl2lgpl.sed))
826 # Snarf from the master source and frob the copying notice.
827 $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
828 sed -f $^ > $@-tmp
829 # So I don't edit them by mistake.
830 chmod a-w $@-tmp
831 mv -f $@-tmp $@
832 test ! -d CVS || cvs commit -m'Updated from $^' $@
833 endif
834 endif
This page took 0.074596 seconds and 5 git commands to generate.