home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / glibc-1.06 / Makerules < prev    next >
Encoding:
Text File  |  1993-05-22  |  11.4 KB  |  373 lines

  1. # Copyright (C) 1991, 1992, 1993 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. #    Propagated rules for making the GNU C library.
  21. #
  22. ifneq (,)
  23. This makefile requires GNU Make.
  24. endif
  25.  
  26.  
  27. ifdef    subdir
  28. ..    := ../
  29. endif    # subdir
  30.  
  31. # If `sources' was defined by the parent makefile, undefine it so
  32. # we will later get it from wildcard search in this directory.
  33. ifneq    "$(findstring env,$(origin sources))" ""
  34. sources :=
  35. endif
  36.  
  37. headers := $(headers) $(sysdep_headers)
  38.  
  39. # This is benign and useless in GNU make before version 3.63.
  40. export sources := $(sources)
  41. export headers := $(headers)
  42.  
  43. ifneq ($(findstring e,$(MAKEFLAGS)),)
  44. You must not use the -e flag when building the GNU C library.
  45. endif
  46.  
  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. sysdep_dir := $(..)sysdeps
  57. export sysdirs := $(sysdirs)
  58. export sysdep_dir := $(sysdep_dir)
  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. +sysdep-includes := $(addprefix -I,$(+sysdep_dirs))
  67. +includes := $(+includes) $(+sysdep-includes)
  68.  
  69. # Include any system-specific makefiles.
  70. # Also generate an ordered list of implicit rules which find the source
  71. # files in each sysdep directory.  The old method was to use vpath to
  72. # search all the sysdep directories.  However, that had the problem that a
  73. # .S file in a later directory would be chosen over a .c file in an earlier
  74. # directory, which does not preserve the desired sysdeps ordering behavior.
  75.  
  76. # This is here so things in sysdep Makefiles can easily depend on foo.h as
  77. # appropriate and not worry about where foo.h comes from, which may be
  78. # system dependent and not known by that Makefile.
  79. vpath %.h $(subst $(empty) ,:,$(strip $(objpfx) \
  80.                       $(addprefix $(sysdep_dir)/,$(sysdirs)) \
  81.                       $(..)))
  82.  
  83. ifeq ($(wildcard $(+sysdir_pfx)sysd-Makefile),)
  84. # Don't do deps until this exists, because it might change the sources list.
  85. no_deps=t
  86. endif
  87.  
  88. # When making the list of .dep files to include, we can't know which ones
  89. # have source in .s files, and thus do not in fact need a .dep file.
  90. # So we must define rules to make .dep files for .s files.
  91. make-dummy-dep = \
  92.     echo '\# $< cannot contain includes, so it needs no deps.' > $@
  93.  
  94. # Define first rules to find the source files in $(objpfx).
  95. # Generated source files will end up there.
  96. $(objpfx)%.o: $(objpfx)%.S $(before-compile); $(compile-command.S)
  97. $(objpfx)%.dep: $(objpfx)%.S $(before-compile); $(+make-deps)
  98. $(objpfx)%.o: $(objpfx)%.s $(before-compile); $(compile-command.s)
  99. $(objpfx)%.dep: $(objpfx)%.s; $(make-dummy-dep)
  100. $(objpfx)%.o: $(objpfx)%.c $(before-compile); $(compile-command.c)
  101. $(objpfx)%.dep: $(objpfx)%.c $(before-compile); $(+make-deps)
  102.  
  103. include $(+sysdir_pfx)sysd-Makefile
  104. $(+sysdir_pfx)sysd-Makefile: $(+sysdir_pfx)config.make $(..)Makerules
  105.     (for dir in $(sysdirs); do                             \
  106.        file=sysdeps/$$dir/Makefile;                          \
  107.        if [ -f $(..)$$file ]; then                          \
  108.          echo include "\$$(..)$$file";                      \
  109.        else true;                                  \
  110.        fi;                                      \
  111.        dir="\$$(sysdep_dir)/$$dir";                          \
  112.        echo "\$$(objpfx)%.o: $$dir/%.S \$$(before-compile); \
  113.         \$$(compile-command.S)";                      \
  114.        echo "\$$(objpfx)%.dep: $$dir/%.S \$$(before-compile); \
  115.         \$$(+make-deps)";                          \
  116.        echo "\$$(objpfx)%.o: $$dir/%.s \$$(before-compile); \
  117.         \$$(compile-command.s)";                      \
  118.        echo "\$$(objpfx)%.dep: $$dir/%.s; \$$(make-dummy-dep)";          \
  119.        echo "\$$(objpfx)%.o: $$dir/%.c \$$(before-compile); \
  120.         \$$(compile-command.c)";                      \
  121.        echo "\$$(objpfx)%.dep: $$dir/%.c \$$(before-compile); \
  122.         \$$(+make-deps)";                          \
  123.      done) > $@
  124.  
  125. # Maximize efficiency by minimizing the number of rules.
  126. .SUFFIXES:    # Clear the suffix list.
  127. # Add the suffixes we use.
  128. .SUFFIXES: .a .o .S .s .c .h .dep
  129.  
  130. # Generic rule for making directories.
  131. %/:
  132. # mkdir isn't smart enough to strip a trailing /.
  133.     mkdir $(@:%/=%)
  134.  
  135. # Make sure that object files are not removed
  136. # when they are intermediates between sources and library members.
  137. # This can go away with make v4.
  138. .PRECIOUS: %.o
  139.  
  140. # Make sure that the parent library archive is never removed.
  141. .PRECIOUS: $(libc.a)
  142.  
  143. # Use the verbose option of ar and tar when not running silently.
  144. ifeq    "$(findstring s,$(MAKEFLAGS))" ""    # if not -s
  145. verbose := v
  146. else                           # -s
  147. verbose    :=
  148. endif                        # not -s
  149.  
  150. ARFLAGS := r$(verbose)
  151.  
  152. # Figure out the source filenames in this directory.
  153.  
  154. override sources    := $(addsuffix .c,$(routines) $(aux) \
  155.                           $(sysdep_routines))
  156. export sysdep_routines := $(sysdep_routines)
  157.  
  158. # This is the list of all object files, gotten by
  159. # replacing every ".c" in `sources' with a ".o".
  160. override objects    := $(addprefix $(objpfx),$(sources:.c=.o))
  161.  
  162. # The order of these rules is important.
  163.  
  164. $(objpfx)%.o: %.S $(before-compile); $(compile-command.S)
  165. $(objpfx)%.o: %.s $(before-compile); $(compile-command.s)
  166. $(objpfx)%.o: %.c $(before-compile); $(compile-command.c)
  167.  
  168. ifndef compile-command.S
  169. compile-command.S = $(compile.S) $(OUTPUT_OPTION)
  170. endif
  171. ifndef compile-command.s
  172. compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION)
  173. endif
  174. ifndef compile-command.c
  175. compile-command.c = $(compile.c) $(OUTPUT_OPTION)
  176. endif
  177.  
  178. ifeq ($(notdir $(firstword $(CC))),gcc)
  179. # GCC can grok options after the file name.
  180. compile.S = $(CC) $< -c $(CPPFLAGS) $(asm-CPPFLAGS)
  181. compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
  182. else
  183. compile.S = $(COMPILE.S) $(asm-CPPFLAGS) $<
  184. compile.c = $(COMPILE.c) $<
  185. endif
  186.  
  187. ifndef OUTPUT_OPTION
  188. ifdef objpfx
  189. # We need this for the output to go in the right place.  It will default to
  190. # empty if make was configured to work with a cc that can't grok -c and -o
  191. # together.  You can't compile the C library with such a compiler.
  192. OUTPUT_OPTION = -o $@
  193. endif
  194. endif
  195.  
  196. # This makes all the object files in the parent library archive.
  197.  
  198. .PHONY: lib libobjs lib-noranlib
  199. $(libc.a): lib-noranlib
  200.     $(RANLIB) $@
  201. lib: $(libc.a)
  202.  
  203. +libobjs := $(patsubst %,$(libc.a)(%),$(notdir $(objects)))
  204. ifdef +libobjs
  205. $(+libobjs): $(libc.a)(%): $(objpfx)%;
  206. endif
  207. libobjs: $(+libobjs)
  208. lib-noranlib: libobjs ar-it
  209.  
  210. #$(libc.a): %: $(addprefix %,$(patsubst $(objpfx)%,(%),$(objects)))
  211. #    $(AR) $(ARFLAGS) $@ $(patsubst $@(%),%,$?)
  212.  
  213. define +libc_lock_open
  214. @. $(..)libc-lock-open
  215. endef
  216. define +libc_lock_close
  217. @rm -f $(..)LOCK-libc.a
  218. endef
  219.  
  220. # Temporary until I get a better solution.
  221. .PHONY: ar-it
  222. ar-it: $(objects)
  223. #    $(+libc_lock_open)
  224. ifdef objects
  225. ifdef objdir
  226.     cd $(objdir); $(AR) cru$(verbose) libc.a $(patsubst $(objpfx)%,%,$^)
  227. else
  228.     $(AR) cru$(verbose) $(..)libc.a $^
  229. endif
  230. #    $(+libc_lock_close)
  231. endif
  232.  
  233.  
  234.  
  235. # This makes all the object files.
  236. .PHONY: objects objs
  237. objects objs: $(objects)
  238.  
  239. # Installation.
  240.  
  241. # install-lib are installed from the object directory into $(libdir).
  242. # install-data are installed as they are into $(datadir).  headers are
  243. # installed as they are in $(includedir).  install-others are absolute path
  244. # names of files to install; rules to install them are defined elsewhere.
  245.  
  246. do-install = $(INSTALL_DATA) $< $@
  247.  
  248. # Any directory (parent or subdir) that has any object files to build
  249. # should install libc.a; this way "make install" in a subdir is guaranteed
  250. # to install everything it changes.
  251. ifdef objects
  252. install-lib := $(install-lib) libc.a
  253. endif
  254.  
  255. ifdef install
  256. $(addprefix $(bindir)/,$(install)): $(bindir)/%: $(objpfx)%
  257.     $(INSTALL) $< $@
  258. endif
  259. ifdef install-lib
  260. $(addprefix $(libdir)/,$(install-lib)): $(libdir)/%: $(objpfx)%;$(do-install)
  261. endif
  262. ifdef install-data
  263. $(addprefix $(datadir)/,$(install-data)): $(datadir)/%: %;$(do-install)
  264. endif
  265. +install := $(addprefix $(libdir)/,$(install-lib))    \
  266.         $(addprefix $(datadir)/,$(install-data))    \
  267.         $(addprefix $(bindir)/,$(install))        \
  268.         $(install-others)
  269. headers := $(strip $(headers))
  270. ifdef headers
  271. $(addprefix $(includedir)/,$(headers)): \
  272.     $(includedir)/%: %;$(do-install)
  273. +install := $(+install) $(addprefix $(includedir)/,$(headers))
  274. endif    # headers
  275. +install := $(filter-out $(addprefix %/,$(no-install)),$(+install))
  276.  
  277. .PHONY: install installdirs
  278. install: $(+install)
  279. $(+install): installdirs
  280. installdirs: $(..)mkinstalldirs
  281.     $(dir $<)$(notdir $<) $(dir $(+install))
  282.  
  283. S-CPPFLAGS = $(asm-CPPFLAGS)
  284. +make-deps = $(+mkdep) $< $(CPPFLAGS) $($(<:$*.%=%)-CPPFLAGS) | \
  285.          sed $(sed-remove-objpfx) -e 's,$*\.o,$(@:.dep=.o) $@,' > $@
  286. ifneq (,$(objpfx))
  287. sed-remove-objpfx = -e 's,$(objpfx),$$(objpfx),g'
  288. endif
  289.  
  290. # N.B.: The order of these two rules is important.
  291. $(objpfx)%.dep: %.S $(before-compile)
  292.     $(+make-deps)
  293. $(objpfx)%.dep: %.c $(before-compile)
  294.     $(+make-deps)
  295. $(objpfx)%.dep: %.s
  296.     $(make-dummy-dep)
  297.  
  298. +depfiles := $(strip $(sources:.c=.dep) $(addsuffix .dep,$(others) $(tests)))
  299. +depfiles := $(addprefix $(objpfx),$(+depfiles))
  300.  
  301. $(objpfx)depend-$(subdir): Makefile
  302. ifdef +depfiles
  303.     (for file in $(patsubst $(objpfx)%,%,$(+depfiles)); do    \
  304.      echo "include \$$(objpfx)$$file";    \
  305.      done) > $@
  306. else
  307.     cp /dev/null $@
  308. endif
  309.  
  310. ifneq ($(no_deps),t)
  311. # Include the generated dependencies of the sources in this directory.
  312. ifdef have.make.that.groks.multiple.includes
  313. # Avoid the extra file and waiting for it, since we can.
  314. +depfiles := $(strip $(+depfiles))
  315. ifdef +depfiles
  316. include $(+depfiles)
  317. endif
  318. else
  319. include $(objpfx)depend-$(subdir)
  320. endif
  321. endif
  322.  
  323. # Command to compile $< in $(objdir) using the native libraries.
  324. native-compile = cwd=`pwd`; cd $(@D); $(CC) $(native-CFLAGS) \
  325.                         $(addprefix $$cwd/,$^) -o $(@F)
  326.  
  327. # Command to compile $< in $(common-objdir) using the native libraries.
  328. define common-objdir-compile
  329. cd $(@D); $(CC) $(native-CFLAGS) $(<:$(common-objpfx)%=%) -o $(@F)
  330. endef
  331.  
  332. # We always want to use configuration -D switches.
  333. native-CFLAGS = $(config-defines)
  334.  
  335. # Support the GNU standard name for this target.
  336. .PHONY: check
  337. check: tests
  338.  
  339. .PHONY: TAGS
  340. TAGS: $(..)MakeTAGS
  341.     $(MAKE) -f $< $@
  342.  
  343. .PHONY: echo-headers
  344. echo-headers:
  345.     @echo $(headers)
  346.  
  347.  
  348. # Produce a file `stub-$(subdir)' which contains `#define __stub_FUNCTION'
  349. # for each function which is a stub.  We grovel over all the .dep files
  350. # looking for references to source files in sysdeps/stub.  Then we grovel
  351. # over each referenced source file to see what stub function it defines.
  352.  
  353. .PHONY: stubs # The parent Makefile calls this target.
  354. stubs: $(common-objpfx)stub-$(subdir)
  355. $(common-objpfx)stub-$(subdir): $(+depfiles)
  356. # Use /dev/null since `...` might expand to empty.
  357.     sed -n 's/^stub_warning *(\([^)]*\).*$$/#define __stub_\1/p' \
  358.         `sed -n 's@^.*\($(sysdep_dir)/stub/[a-z0-9_]*\.c\).*$$@\1@p' \
  359.          $^ /dev/null` \
  360.         /dev/null > $@T
  361.     mv $@T $@
  362.  
  363. ifdef gpl2lgpl
  364. ifneq (,$(wildcard $(..)gpl2lgpl.sed))
  365. # Snarf from the master source and frob the copying notice.
  366. $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
  367.     sed -f $^ > $@-tmp
  368. # So I don't edit them by mistake.
  369.     chmod a-w $@-tmp
  370.     mv -f $@-tmp $@
  371. endif
  372. endif
  373.