Makerules 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416
  1. # Copyright (C) 1991-2026 Free Software Foundation, Inc.
  2. # This file is part of the GNU C Library.
  3. # The GNU C Library is free software; you can redistribute it and/or
  4. # modify it under the terms of the GNU Lesser General Public
  5. # License as published by the Free Software Foundation; either
  6. # version 2.1 of the License, or (at your option) any later version.
  7. # The GNU C Library is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  10. # Lesser General Public License for more details.
  11. # You should have received a copy of the GNU Lesser General Public
  12. # License along with the GNU C Library; if not, see
  13. # <https://www.gnu.org/licenses/>.
  14. #
  15. # Common rules for making the GNU C library. This file is included
  16. # by the top-level Makefile and by all subdirectory makefiles
  17. # (through Rules).
  18. #
  19. ifneq (,)
  20. This makefile requires GNU Make.
  21. endif
  22. REQUIRED_MAKE_VERSION = 3.74
  23. REAL_MAKE_VERSION = $(firstword $(MAKE_VERSION))
  24. ifneq ($(REQUIRED_MAKE_VERSION), \
  25. $(firstword $(sort $(REAL_MAKE_VERSION) $(REQUIRED_MAKE_VERSION))))
  26. Wrong GNU Make version. See above for the version needed.
  27. endif
  28. ifdef subdir
  29. .. := ../
  30. endif # subdir
  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. oPATH := $(PATH)
  37. PATH := this definition should take precedence over $(oPATH)
  38. ifeq ($(PATH),$(oPATH))
  39. You must not use the -e flag when building the GNU C library.
  40. else
  41. PATH := $(oPATH)
  42. endif
  43. ifndef +included-Makeconfig
  44. include $(..)Makeconfig
  45. endif
  46. # This variable is used in ``include $(o-iterator)'' after defining
  47. # $(o-iterator-doit) to produce some desired rule using $o for the object
  48. # suffix, and setting $(object-suffixes-left) to $(object-suffixes); a copy
  49. # is produced for each object suffix in use.
  50. o-iterator = $(patsubst %,$(..)o-iterator.mk,$(object-suffixes-left))
  51. # Include any system-specific makefiles.
  52. # This is here so things in sysdep Makefiles can easily depend on foo.h as
  53. # appropriate and not worry about where foo.h comes from, which may be
  54. # system dependent and not known by that Makefile.
  55. vpath %.h $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
  56. $(+sysdep_dirs) $(..)))
  57. # The same is true for RPC source files.
  58. vpath %.x $(subst $(empty) ,:,$(strip $(common-objpfx) $(objpfx) \
  59. $(+sysdep_dirs) $(..)))
  60. # Some sysdep makefiles use this to distinguish being included here from
  61. # being included individually by a subdir makefile (hurd/Makefile needs this).
  62. in-Makerules := yes
  63. sysdep-makefiles := $(wildcard $(sysdirs:=/Makefile))
  64. ifneq (,$(sysdep-makefiles))
  65. include $(sysdep-makefiles)
  66. endif
  67. # Reorder before-compile so that mach things come first, and hurd things
  68. # second, before all else. The mach and hurd subdirectories have many
  69. # generated header files which the much of rest of the library depends on,
  70. # so it is best to build them first (and mach before hurd, at that).
  71. before-compile := $(filter $(common-objpfx)mach% $(common-objpfx)hurd%,\
  72. $(before-compile)) \
  73. $(filter-out $(common-objpfx)mach% $(common-objpfx)hurd%,\
  74. $(before-compile))
  75. # Even before that, we need abi-versions.h which is generated right here.
  76. ifeq ($(build-shared),yes)
  77. ifndef avoid-generated
  78. before-compile := $(common-objpfx)abi-versions.h $(before-compile)
  79. $(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
  80. $(common-objpfx)Versions.all
  81. LC_ALL=C $(AWK) -f $^ > $@T
  82. mv -f $@T $@
  83. $(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
  84. sed -n '/ VERSION_$*_/{s/^.*_\([A-Z0-9_]*\).*$$/\1/;h;};$${g;p;}' \
  85. $(common-objpfx)abi-versions.h > $@T
  86. mv -f $@T $@
  87. # first-versions.h and ldbl-compat-choose.h provide macros used in
  88. # various symbol versioning macro calls.
  89. before-compile := $(common-objpfx)first-versions.h \
  90. $(common-objpfx)ldbl-compat-choose.h $(before-compile)
  91. $(common-objpfx)first-versions.h: $(common-objpfx)versions.stmp
  92. $(common-objpfx)ldbl-compat-choose.h: $(common-objpfx)versions.stmp
  93. endif # avoid-generated
  94. endif # $(build-shared) = yes
  95. ifndef avoid-generated
  96. ifneq (,$(CXX))
  97. # If C++ headers <cstdlib> or <cmath> are used, GCC 6 will include
  98. # /usr/include/stdlib.h or /usr/include/math.h from "#include_next"
  99. # (instead of stdlib/stdlib.h or math/math.h in the glibc source
  100. # directory), and this turns up as a make dependency. An implicit
  101. # rule will kick in and make will try to install stdlib/stdlib.h or
  102. # math/math.h as /usr/include/stdlib.h or /usr/include/math.h because
  103. # the target is out of date. We make a copy of <cstdlib> and <cmath>
  104. # in the glibc build directory so that stdlib/stdlib.h and math/math.h
  105. # will be used instead of /usr/include/stdlib.h and /usr/include/math.h.
  106. before-compile := $(common-objpfx)cstdlib $(common-objpfx)cmath \
  107. $(before-compile)
  108. $(common-objpfx)cstdlib: $(c++-cstdlib-header)
  109. $(INSTALL_DATA) $< $@T
  110. $(move-if-change) $@T $@
  111. $(common-objpfx)cmath: $(c++-cmath-header)
  112. $(INSTALL_DATA) $< $@T
  113. $(move-if-change) $@T $@
  114. ifneq (,$(c++-bits-std_abs-h))
  115. # Also make a copy of <bits/std_abs.h> from GCC 7 to prevent it from
  116. # including /usr/include/stdlib.h.
  117. before-compile := $(common-objpfx)bits/std_abs.h $(before-compile)
  118. $(common-objpfx)bits/std_abs.h: $(c++-bits-std_abs-h)
  119. $(INSTALL_DATA) $< $@T
  120. $(move-if-change) $@T $@
  121. endif
  122. endif
  123. before-compile := $(common-objpfx)libc-abis.h $(before-compile)
  124. $(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
  125. $(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \
  126. $(firstword $(wildcard $(sysdirs:=/libc-abis)) \
  127. $(..)libc-abis) \
  128. $(..)Makerules
  129. $(SHELL) $< \
  130. $(base-machine)-$(config-vendor)-$(config-os) \
  131. < $(word 2,$^) > $(@:.stamp=.h)T
  132. $(move-if-change) $(@:.stamp=.h)T $(@:.stamp=.h)
  133. touch $@
  134. common-generated += $(common-objpfx)libc-abis.h
  135. endif # avoid-generated
  136. ifeq (yes,$(build-shared))
  137. $(common-objpfx)runtime-linker.h: $(common-objpfx)runtime-linker.stamp; @:
  138. $(common-objpfx)runtime-linker.stamp: $(common-objpfx)config.make
  139. $(make-target-directory)
  140. echo '#define RUNTIME_LINKER "$(rtlddir)/$(rtld-installed-name)"' \
  141. > ${@:stamp=T}
  142. $(move-if-change) ${@:stamp=T} ${@:stamp=h}
  143. touch $@
  144. endif
  145. # Make sure the subdirectory for object files gets created.
  146. ifdef objpfx
  147. ifeq (,$(wildcard $(objpfx).))
  148. before-compile += $(objpfx).
  149. $(objpfx).:
  150. $(make-target-directory)
  151. endif
  152. endif
  153. # Remove existing files from `before-compile'. Things are added there when
  154. # they must exist for dependency generation to work right, but once they
  155. # exist there is no further need for every single file to depend on them,
  156. # and those gratuitous dependencies result in many gratuitous
  157. # recompilations.
  158. before-compile := $(filter-out $(wildcard $(before-compile)),$(before-compile))
  159. # Don't let any before-compile file be an intermediate and get removed.
  160. ifdef before-compile
  161. $(before-compile):
  162. endif
  163. # We don't want $(common-objpfx) files to depend on miscellaneous stuff
  164. # in subdirs.
  165. ifdef subdir
  166. common-before-compile := $(filter-out $(objpfx)%,$(before-compile))
  167. else
  168. common-before-compile = $(before-compile)
  169. endif
  170. ifndef subdir
  171. # If a makefile needs to do something conditional on something that
  172. # can only be figured out from headers, write a FOO.make.c input
  173. # file that uses cpp constructs and contains @@@ LINE @@@ for each LINE
  174. # to emit in the generated makefile, and use -include $(common-objpfx)FOO.make.
  175. #
  176. # We only generate these in the top-level makefile, to avoid any weirdness
  177. # from subdir-specific makefile tweaks creeping in on an update.
  178. $(common-objpfx)%.make: $(..)%.make.c $(..)Makerules $(common-before-compile)
  179. rm -f $@T $@.dT
  180. (echo '# Generated from $*.make.c by Makerules.'; \
  181. $(CC) $(CFLAGS) $(CPPFLAGS) -E -DASSEMBLER $< \
  182. -MD -MP -MT '$$(common-objpfx)$*.make' -MF $@.dT \
  183. | sed -n '/@@@/{s/@@@[ ]*\(.*\)@@@/\1/;s/[ ]*$$//p;}'; \
  184. echo 'common-generated += $(@F)'; \
  185. sed $(sed-remove-objpfx) $(sed-remove-dotdot) $@.dT; \
  186. rm -f $@.dT) > $@T
  187. mv -f $@T $@
  188. endif
  189. ifdef subdir
  190. sed-remove-dotdot := -e 's@ *\.\.\/\([^ \]*\)@ $$(..)\1@g' \
  191. -e 's@^\.\.\/\([^ \]*\)@$$(..)\1@g'
  192. else
  193. sed-remove-dotdot := -e 's@ *\([^ \/$$][^ \]*\)@ $$(..)\1@g' \
  194. -e 's@^\([^ \/$$][^ \]*\)@$$(..)\1@g'
  195. endif
  196. ifdef gen-py-const-headers
  197. # We'll use a static pattern rule to match .pysym files with their
  198. # corresponding generated .py files.
  199. # The generated .py files go in the submodule's dir in the glibc build dir.
  200. py-const-files := $(patsubst %.pysym,%.py,$(gen-py-const-headers))
  201. py-const-dir := $(objpfx)
  202. py-const := $(addprefix $(py-const-dir),$(py-const-files))
  203. py-const-script := $(..)scripts/gen-as-const.py
  204. # This is a hack we use to generate .py files with constants for
  205. # Python code.
  206. #
  207. # $@.tmp is a temporary file we use to store the partial contents of
  208. # the target file. We do this instead of just writing on $@ because,
  209. # if the build process terminates prematurely, re-running Make
  210. # wouldn't run this rule since Make would see that the target file
  211. # already exists (despite it being incomplete).
  212. #
  213. # The output is redirected to a .py file; we'll import it in the main
  214. # Python code to read the constants generated by gen-as-const.py.
  215. $(py-const): $(py-const-dir)%.py: %.pysym $(py-const-script) \
  216. $(common-before-compile)
  217. $(make-target-directory)
  218. $(PYTHON) $(py-const-script) --python \
  219. --cc="$(CC) $(CFLAGS) $(CPPFLAGS)" $< \
  220. > $@.tmp
  221. mv -f $@.tmp $@
  222. generated += $(py-const)
  223. endif # gen-py-const-headers
  224. ifdef gen-as-const-headers
  225. # Generating headers for assembly constants.
  226. # We need this defined early to get into before-compile before
  227. # it's used in sysd-rules, below.
  228. # Define GEN_AS_CONST_HEADERS to avoid circular dependency [BZ #22792].
  229. # NB: <tcb-offsets.h> is generated from tcb-offsets.sym to define
  230. # offsets and sizes of types in <tls.h> and maybe <pthread.h> which
  231. # may include <tcb-offsets.h>. Target header files can check if
  232. # GEN_AS_CONST_HEADERS is defined to avoid circular dependency which
  233. # may lead to build hang on a many-core machine.
  234. $(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.py \
  235. %.sym $(common-before-compile)
  236. $(PYTHON) $< --cc="$(CC) $(CFLAGS) $(CPPFLAGS) -DGEN_AS_CONST_HEADERS \
  237. -MD -MP -MF $(@:.h=.h.d)T \
  238. -MT '$(@:.h=.h.d) $(@:.h.d=.h)'" \
  239. $(filter %.sym,$^) > $(@:.h.d=.h)T
  240. sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
  241. $(@:.h=.h.d)T > $(@:.h=.h.d)T2
  242. rm -f $(@:.h=.h.d)T
  243. mv -f $(@:.h=.h.d)T2 $(@:.h=.h.d)
  244. mv -f $(@:.h.d=.h)T $(@:.h.d=.h)
  245. vpath %.sym $(sysdirs)
  246. before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
  247. tests-internal += $(gen-as-const-headers:%.sym=test-as-const-%)
  248. generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
  249. $(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.py $(..)Makerules \
  250. %.sym $(common-objpfx)%.h
  251. ($(AWK) '{ sub(/^/, "asconst_", $$2); print; }' $(filter %.h,$^); \
  252. $(PYTHON) $< --test $(filter %.sym,$^)) > $@T
  253. mv -f $@T $@
  254. endif
  255. ifeq (yes,$(build-shared))
  256. # Generate the header containing the names of all shared libraries.
  257. # We use a stamp file to avoid unnecessary recompilations.
  258. before-compile += $(common-objpfx)gnu/lib-names.h
  259. ifeq ($(soversions.mk-done),t)
  260. ifndef abi-variants
  261. lib-names-h-abi = gnu/lib-names.h
  262. lib-names-stmp-abi = gnu/lib-names.stmp
  263. else
  264. lib-names-h-abi = gnu/lib-names-$(default-abi).h
  265. lib-names-stmp-abi = gnu/lib-names-$(default-abi).stmp
  266. before-compile += $(common-objpfx)$(lib-names-h-abi)
  267. common-generated += gnu/lib-names.h
  268. install-others-nosubdir: $(inst_includedir)/$(lib-names-h-abi)
  269. $(common-objpfx)gnu/lib-names.h:
  270. $(make-target-directory)
  271. { \
  272. echo '/* This file is automatically generated.';\
  273. echo ' It defines macros to allow user program to find the shared'; \
  274. echo ' library files which come as part of GNU libc. */'; \
  275. echo '#ifndef __GNU_LIB_NAMES_H'; \
  276. echo '#define __GNU_LIB_NAMES_H 1'; \
  277. echo ''; \
  278. $(if $(abi-includes), \
  279. $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
  280. echo '';) \
  281. $(foreach v,$(abi-variants),\
  282. $(if $(abi-$(v)-condition),\
  283. echo '#if $(abi-$(v)-condition)'; \
  284. echo '# include <gnu/lib-names-$(v).h>'); \
  285. $(if $(abi-$(v)-condition),echo '#endif';)) \
  286. echo ''; \
  287. echo '#endif /* gnu/lib-names.h */'; \
  288. } > $@
  289. endif
  290. $(common-objpfx)$(lib-names-h-abi): $(common-objpfx)$(lib-names-stmp-abi); @:
  291. $(common-objpfx)$(lib-names-stmp-abi): $(..)scripts/lib-names.awk \
  292. $(common-objpfx)soversions.i
  293. $(make-target-directory)
  294. { \
  295. $(if $(abi-variants), \
  296. echo '/* This file is automatically generated. */';\
  297. echo '#ifndef __GNU_LIB_NAMES_H'; \
  298. echo '# error "Never use <$(lib-names-h-abi)> directly; include <gnu/lib-names.h> instead."'; \
  299. echo '#endif';, \
  300. echo '/* This file is automatically generated.';\
  301. echo ' It defines macros to allow user program to find the shared'; \
  302. echo ' library files which come as part of GNU libc. */'; \
  303. echo '#ifndef __GNU_LIB_NAMES_H'; \
  304. echo '#define __GNU_LIB_NAMES_H 1';) \
  305. echo ''; \
  306. ($(foreach s,$(all-sonames), echo $(s);)) \
  307. | LC_ALL=C $(AWK) -f $(firstword $^) | LC_ALL=C sort; \
  308. $(if $(abi-variants),, \
  309. echo ''; \
  310. echo '#endif /* gnu/lib-names.h */';) \
  311. } > ${@:stmp=T}
  312. $(move-if-change) ${@:stmp=T} ${@:stmp=h}
  313. touch $@
  314. endif
  315. common-generated += $(lib-names-h-abi) $(lib-names-stmp-abi)
  316. endif
  317. ###############################################################################
  318. # NOTE! Everything adding to before-compile needs to come before this point! #
  319. ###############################################################################
  320. # Generate an ordered list of implicit rules which find the source files in
  321. # each sysdep directory. The old method was to use vpath to search all the
  322. # sysdep directories. However, that had the problem that a .S file in a
  323. # later directory would be chosen over a .c file in an earlier directory,
  324. # which does not preserve the desired sysdeps ordering behavior.
  325. # System-dependent makefiles can put in `inhibit-sysdep-asm' regexps
  326. # matching sysdep directories whose assembly source files should be
  327. # suppressed.
  328. -include $(common-objpfx)sysd-rules
  329. ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
  330. # The value of $(+sysdep_dirs) the sysd-rules was computed for
  331. # differs from the one we are using now. So force a rebuild of sysd-rules.
  332. sysd-rules-force = FORCE
  333. FORCE:
  334. endif
  335. $(common-objpfx)sysd-rules: $(..)scripts/sysd-rules.awk \
  336. $(common-objpfx)config.make $(..)Makerules \
  337. $(sysdep-makefiles) $(sysdep-makeconfigs) \
  338. $(sysd-rules-force)
  339. -@rm -f $@T
  340. LC_ALL=C $(AWK) -f $< > $@T \
  341. -v all_object_suffixes='$(all-object-suffixes)' \
  342. -v inhibit_sysdep_asm='$(inhibit-sysdep-asm)' \
  343. -v sysd_rules_patterns='$(sysd-rules-patterns)' \
  344. -v config_sysdirs='$(config-sysdirs)'
  345. mv -f $@T $@
  346. ifndef sysd-rules-done
  347. # Don't do deps until this exists, because it provides rules to make the deps.
  348. no_deps=t
  349. endif
  350. define o-iterator-doit
  351. $(objpfx)%$o: %.S $(before-compile); $$(compile-command.S)
  352. endef
  353. object-suffixes-left := $(all-object-suffixes)
  354. include $(o-iterator)
  355. define o-iterator-doit
  356. $(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
  357. endef
  358. object-suffixes-left := $(all-object-suffixes)
  359. include $(o-iterator)
  360. define o-iterator-doit
  361. $(objpfx)%$o: %.cc $(before-compile); $$(compile-command.cc)
  362. endef
  363. object-suffixes-left := $(all-object-suffixes)
  364. include $(o-iterator)
  365. # Omit the objpfx rules when building in the source tree, because
  366. # objpfx is empty and so these rules just override the ones above.
  367. ifdef objpfx
  368. # Define first rules to find the source files in $(objpfx).
  369. # Generated source files will end up there.
  370. define o-iterator-doit
  371. $(objpfx)%$o: $(objpfx)%.S $(before-compile); $$(compile-command.S)
  372. endef
  373. object-suffixes-left := $(all-object-suffixes)
  374. include $(o-iterator)
  375. define o-iterator-doit
  376. $(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
  377. endef
  378. object-suffixes-left := $(all-object-suffixes)
  379. include $(o-iterator)
  380. define o-iterator-doit
  381. $(objpfx)%$o: $(objpfx)%.cc $(before-compile); $$(compile-command.cc)
  382. endef
  383. object-suffixes-left := $(all-object-suffixes)
  384. include $(o-iterator)
  385. endif
  386. # Generate .dT files as we compile.
  387. compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
  388. compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
  389. compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
  390. compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
  391. # Like compile-mkdep-flags, but for use with $(BUILD_CC). We don't want to
  392. # track system includes here, they may spuriously trigger an install rule,
  393. # and would cause the check-local-headers test to fail.
  394. native-compile-mkdep-flags = -MMD -MP -MF $@.dt -MT $@
  395. # GCC can grok options after the file name, and it looks nicer that way.
  396. compile.c = $(CC) $< -c $(CFLAGS) $(CPPFLAGS)
  397. compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
  398. compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
  399. $(ASFLAGS) $(ASFLAGS-$(suffix $@)) $(sysdep-ASFLAGS) \
  400. $(ASFLAGS-$(<F)) $(ASFLAGS-$(@F))
  401. COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
  402. COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
  403. $(ASFLAGS) $(ASFLAGS-$(suffix $@)) $(sysdep-ASFLAGS) \
  404. $(ASFLAGS-$(<F)) $(ASFLAGS-$(@F))
  405. # We need this for the output to go in the right place. It will default to
  406. # empty if make was configured to work with a cc that can't grok -c and -o
  407. # together. You can't compile the C library with such a compiler.
  408. OUTPUT_OPTION = -o $@
  409. # This is the end of the pipeline for compiling generated C code.
  410. compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
  411. # We need the $(CFLAGS) to be in there to have the right predefines during
  412. # the dependency run for C sources. But having it for assembly sources can
  413. # get the wrong predefines.
  414. S-CPPFLAGS = -DASSEMBLER $(asm-CPPFLAGS)
  415. ifneq (,$(objpfx))
  416. # Continuation lines here are dangerous because they introduce spaces!
  417. # Also remove the /usr/include/tgmath.h dependency generated by Clang
  418. # even though Clang never reads /usr/include/tgmath.h.
  419. # https://github.com/llvm/llvm-project/issues/120891
  420. define sed-remove-objpfx
  421. -e 's@ $(subst .,\.,$(subst @,\@,$(common-objpfx)))@ $$(common-objpfx)@g' \
  422. -e 's@^$(subst .,\.,$(subst @,\@,$(common-objpfx)))@$$(common-objpfx)@g' \
  423. -e 's@/usr/include/tgmath.h:@@' \
  424. -e 's@ /usr/include/tgmath.h@@'
  425. endef
  426. endif
  427. # Modify the list of routines we build for different targets
  428. ifeq (yes,$(build-shared))
  429. ifndef libc.so-version
  430. # Undefine this because it can't work when we libc.so is unversioned.
  431. static-only-routines =
  432. endif
  433. endif
  434. elide-routines.oS += $(filter-out $(static-only-routines),\
  435. $(routines) $(aux) $(sysdep_routines))
  436. elide-routines.os += $(static-only-routines)
  437. # If we have versioned code we don't need the old versions in any of the
  438. # static libraries.
  439. elide-routines.o += $(shared-only-routines)
  440. elide-routines.op += $(shared-only-routines)
  441. # Shared library building.
  442. ifeq (yes,$(build-shared))
  443. # Reference map file only when shared libraries are built and a map file name
  444. # is given.
  445. ifeq ($(build-shared),yes)
  446. map-file = $(firstword $($(@F:.so=-map)) \
  447. $(addprefix $(common-objpfx), \
  448. $(filter $(@F:.so=.map),$(version-maps))))
  449. # The map version is created with multiple symbols that might not be
  450. # exported depending of the ABI.
  451. load-map-file = $(map-file:%=-Wl,--version-script=%) $(have-undefined-version)
  452. endif
  453. # Compiler arguments to use to link a shared object with libc and
  454. # ld.so. This is intended to be as similar as possible to a default
  455. # link with an installed libc.
  456. link-libc-args = -Wl,--start-group \
  457. $(libc-for-link) \
  458. $(common-objpfx)libc_nonshared.a \
  459. -Wl,--as-needed $(elf-objpfx)ld.so -Wl,--no-as-needed \
  460. -Wl,--end-group
  461. # The corresponding shared libc to use. This may be modified for a
  462. # particular target.
  463. libc-for-link = $(common-objpfx)libc.so
  464. # The corresponding dependencies. As these are used in dependencies,
  465. # not just commands, they cannot use target-specific variables so need
  466. # to name both possible libc.so objects.
  467. link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \
  468. $(common-objpfx)libc_nonshared.a $(elf-objpfx)ld.so
  469. # Pattern rule to build a shared object from an archive of PIC objects.
  470. # This must come after the installation rules so Make doesn't try to
  471. # build shared libraries in place from the installed *_pic.a files.
  472. # $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
  473. # on other shared objects. The linking with libc and ld.so is intended
  474. # to be as similar as possible to a default link with an installed libc.
  475. lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(link-libc-deps)
  476. $(build-shlib) $(link-libc-args)
  477. $(call after-link,$@)
  478. define build-shlib-helper
  479. $(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \
  480. $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
  481. $(if $($(@F)-no-dt-relr),$(no-dt-relr-ldflag),$(dt-relr-ldflag)) \
  482. $(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
  483. $(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
  484. -Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
  485. $(LDFLAGS.so) $(LDFLAGS-lib.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
  486. -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
  487. endef
  488. define build-shlib
  489. $(build-shlib-helper) -o $@ \
  490. $(csu-objpfx)abi-note.o $(build-shlib-objlist)
  491. endef
  492. define build-module-helper
  493. $(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
  494. $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
  495. $(if $($(@F)-no-dt-relr),$(no-dt-relr-ldflag),$(dt-relr-ldflag)) \
  496. -B$(csu-objpfx) $(load-map-file) \
  497. $(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
  498. $(link-test-modules-rpath-link) \
  499. -L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
  500. endef
  501. # This macro is similar to build-shlib but it does not define a soname
  502. # and it does not depend on the destination name to start with `lib'.
  503. # binutils only position loadable notes into the first page for binaries,
  504. # not for shared objects
  505. define build-module
  506. $(build-module-helper) -o $@ \
  507. $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args)
  508. $(call after-link,$@)
  509. endef
  510. define build-module-asneeded
  511. $(build-module-helper) -o $@ \
  512. $(csu-objpfx)abi-note.o \
  513. -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \
  514. $(link-libc-args)
  515. $(call after-link,$@)
  516. endef
  517. # sofini.os must be placed last since it terminates .eh_frame section.
  518. build-module-helper-objlist = \
  519. $(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
  520. $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
  521. $(elf-objpfx)sofini.os $(+nolink-deps) \
  522. $(link-libc-deps),$^))
  523. build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
  524. build-shlib-objlist = $(build-module-helper-objlist) \
  525. $(LDLIBS-$(@F:lib%.so=%).so) \
  526. $(filter $(elf-objpfx)sofini.os,$^)
  527. # Don't try to use -lc when making libc.so itself.
  528. # Also omits crti.o and crtn.o, which we do not want
  529. # since we define our own `.init' section specially.
  530. LDFLAGS-c.so = -nostdlib -nostartfiles
  531. # But we still want to link libc.so against $(libc.so-gnulib).
  532. LDLIBS-c.so += $(libc.so-gnulib)
  533. # Give libc.so an entry point and make it directly runnable itself.
  534. LDFLAGS-c.so += -e __libc_main
  535. # Pre-link the objects of libc_pic.a for .gnu.glibc-stub.* processing.
  536. $(common-objpfx)libc_pic.os: $(common-objpfx)libc_pic.a
  537. $(LINK.o) -nostdlib -nostartfiles -r -o $@ \
  538. $(LDFLAGS-c_pic.os) $(whole-archive) $^ -o $@
  539. # Generate a list of -R options to excise .gnu.glibc-stub.* sections.
  540. $(common-objpfx)libc_pic.opts: $(common-objpfx)libc_pic.os
  541. $(OBJDUMP) -h $< | \
  542. $(AWK) '$$2 ~ /\.gnu\.glibc-stub\./ { print "-R", $$2 }' \
  543. > $@T
  544. mv -f $@T $@
  545. # Apply those -R options.
  546. $(common-objpfx)libc_pic.os.clean: $(common-objpfx)libc_pic.opts \
  547. $(common-objpfx)libc_pic.os
  548. $(OBJCOPY) @$^ $@
  549. generated += libc_pic.opts libc_pic.os.clean
  550. libc_pic_clean := .clean
  551. # Build a possibly-modified version of libc_pic.a for use in building
  552. # linkobj/libc.so.
  553. ifeq (,$(filter sunrpc,$(subdirs)))
  554. $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a
  555. $(make-target-directory)
  556. ln -f $< $@
  557. else
  558. $(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a \
  559. $(common-objpfx)sunrpc/librpc_compat_pic.a
  560. $(make-target-directory)
  561. (cd $(common-objpfx)linkobj; \
  562. $(AR) x ../libc_pic.a; \
  563. rm $$($(AR) t ../sunrpc/librpc_compat_pic.a | sed 's/^compat-//'); \
  564. $(AR) x ../sunrpc/librpc_compat_pic.a; \
  565. $(AR) cr libc_pic.a *.os; \
  566. rm *.os)
  567. endif # $(subdirs) contains sunrpc
  568. # Clear link-libc-deps for the libc.so libraries so build-shlibs does not
  569. # filter ld.so out of the list of linked objects.
  570. $(common-objpfx)libc.so: link-libc-deps = # empty
  571. $(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
  572. # Use our own special initializer and finalizer files for the libc.so
  573. # libraries.
  574. $(common-objpfx)libc.so: $(common-objpfx)libc_pic.os$(libc_pic_clean) \
  575. $(elf-objpfx)sofini.os \
  576. $(elf-objpfx)interp.os \
  577. $(elf-objpfx)ld.so
  578. $(build-shlib)
  579. $(call after-link,$@)
  580. $(common-objpfx)linkobj/libc.so: $(common-objpfx)linkobj/libc_pic.a \
  581. $(elf-objpfx)sofini.os \
  582. $(elf-objpfx)interp.os \
  583. $(elf-objpfx)ld.so
  584. $(build-shlib)
  585. $(call after-link,$@)
  586. ifeq ($(build-shared),yes)
  587. $(common-objpfx)libc.so: $(common-objpfx)libc.map
  588. endif
  589. common-generated += libc.so libc_pic.os
  590. ifdef libc.so-version
  591. $(common-objpfx)libc.so$(libc.so-version): $(common-objpfx)libc.so
  592. $(make-link)
  593. common-generated += libc.so$(libc.so-version)
  594. endif
  595. endif
  596. # Figure out the source filenames in this directory.
  597. override sources := $(addsuffix .c,\
  598. $(filter-out $(elided-routines),\
  599. $(routines) $(aux) \
  600. $(sysdep_routines)))
  601. sysdep_routines := $(sysdep_routines)
  602. headers := $(headers) $(sysdep_headers)
  603. # This is the list of all object files, gotten by
  604. # replacing every ".c" in `sources' with a ".o".
  605. override objects := $(addprefix $(objpfx),$(sources:.c=.o))
  606. # The makefile may define $(extra-libs) with `libfoo libbar'
  607. # to build libfoo.a et al from the modules listed in $(libfoo-routines).
  608. ifdef extra-libs
  609. # extra-lib.mk is included once for each extra lib to define rules
  610. # to build it, and to add its objects to the various variables.
  611. # During its evaluation, $(lib) is set to the name of the library.
  612. extra-libs-left := $(extra-libs)
  613. include $(patsubst %,$(..)extra-lib.mk,$(extra-libs))
  614. endif
  615. # The makefile may define $(modules-names) to build additional modules.
  616. # These are built with $(build-module), except any in $(modules-names-nobuild).
  617. # MODULE_NAME=extramodules, except any in $(modules-names-tests).
  618. ifdef modules-names
  619. cpp-srcs-left := $(filter-out $(modules-names-tests),$(modules-names))
  620. ifneq (,$(cpp-srcs-left))
  621. lib := extramodules
  622. include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
  623. endif
  624. ifdef modules-names-tests
  625. cpp-srcs-left := $(filter $(modules-names-tests),$(modules-names))
  626. ifneq (,$(cpp-srcs-left))
  627. lib := testsuite
  628. include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
  629. endif
  630. endif
  631. extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
  632. $(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
  633. $(objpfx)%.os $(link-libs-deps)
  634. $(build-module)
  635. endif
  636. +depfiles := $(sources:.c=.d) \
  637. $(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
  638. $(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
  639. $(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
  640. $(addsuffix .d,$(tests) $(tests-internal) $(xtests) \
  641. $(tests-container) $(tests-printers) \
  642. $(test-srcs) $(tests-time64) $(xtests-time64))
  643. ifeq ($(build-programs),yes)
  644. +depfiles += $(addsuffix .d,$(others) $(sysdep-others))
  645. endif
  646. +depfiles := $(addprefix $(objpfx),\
  647. $(filter-out $(addsuffix .d,$(omit-deps)),\
  648. $(+depfiles)))
  649. all-dt-files := $(foreach o,$(object-suffixes-for-libc),$(+depfiles:.d=$o.dt))
  650. +depfiles := $(patsubst %.dt,%.d,$(wildcard $(all-dt-files))) \
  651. $(wildcard $(all-dt-files:.dt=.d))
  652. # This is a funny rule in that it removes its input file.
  653. %.d: %.dt
  654. @sed $(sed-remove-objpfx) $< > $(@:.d=.T) && \
  655. mv -f $(@:.d=.T) $@ && \
  656. rm -f $<
  657. # Avoid the .h.d files for any .sym files whose .h files don't exist yet.
  658. # They will be generated when they're needed, and trying too early won't work.
  659. +gen-as-const := $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
  660. +depfiles += $(addsuffix .d,$(filter $(wildcard $(+gen-as-const)),\
  661. $(+gen-as-const)))
  662. ifdef +depfiles
  663. ifneq ($(no_deps),t)
  664. -include $(+depfiles)
  665. endif
  666. endif
  667. # Maximize efficiency by minimizing the number of rules.
  668. .SUFFIXES: # Clear the suffix list. We don't use suffix rules.
  669. # Don't define any builtin rules.
  670. MAKEFLAGS := $(MAKEFLAGS) -r
  671. # Generic rule for making directories.
  672. %/:
  673. # mkdir isn't smart enough to strip a trailing /.
  674. # We always require a mkdir which supports the -p option to avoid error
  675. # messages in case of races.
  676. mkdir -p $(@:%/=%)
  677. # Make sure that object files are not removed
  678. # when they are intermediates between sources and library members.
  679. .PRECIOUS: $(addprefix $(objpfx)%,$(all-object-suffixes))
  680. # Make sure that the parent library archive is never removed.
  681. .PRECIOUS: $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
  682. # Use the verbose option of ar and tar when not running silently.
  683. ifeq ($(silent-make),no) # if not -s
  684. verbose := v
  685. else # -s
  686. verbose :=
  687. endif # not -s
  688. ARFLAGS := r$(verbose)
  689. CREATE_ARFLAGS := cru$(verbose)
  690. # This makes all the object files in the parent library archive.
  691. .PHONY: lib lib-noranlib
  692. lib: lib-noranlib $(foreach l,$(libtypes),$(patsubst %,$(common-objpfx)$l,c))
  693. lib-noranlib: libobjs
  694. # For object-suffix $o, the list of objects with that suffix.
  695. # Makefiles can define `elide-routines.so = foo' to leave foo.so out.
  696. o-objects = $(patsubst %.o,%$o,$(filter-out $(patsubst %,$(objpfx)%.o,\
  697. $(elide-routines$o)),\
  698. $(objects))) \
  699. $(addprefix $(objpfx),$(o-objects$o))
  700. others: $(addprefix $(objpfx),$(install-lib))
  701. ifndef objects
  702. # Create the stamp$o files to keep the parent makefile happy.
  703. subdir_lib: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
  704. $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o):
  705. $(make-target-directory)
  706. rm -f $@; > $@
  707. else
  708. # Define explicit rules to update each $(objpfx)stamp.SUFFIX
  709. # timestamp file; these rules (one explicit rule is generated for each
  710. # object suffix) write a list of objects to update in the stamp file.
  711. # The parent will then actually add them all to the archive in the
  712. # archive rule, below.
  713. define o-iterator-doit
  714. $(objpfx)stamp$o: $(o-objects); $$(do-stamp)
  715. endef
  716. define do-stamp
  717. $(make-target-directory)
  718. echo '$(patsubst $(objpfx)%,$(addsuffix /,$(subdir))%,$^)' > $@T
  719. mv -f $@T $@
  720. endef
  721. object-suffixes-left := $(object-suffixes-for-libc)
  722. include $(o-iterator)
  723. endif
  724. # Now define explicit rules to build the library archives; these depend
  725. # on the stamp files built above.
  726. define o-iterator-doit
  727. $(common-objpfx)$(patsubst %,$(libtype$o),c): \
  728. $(subdirs-stamp-o) $(common-objpfx)stamp$o; $$(do-makelib)
  729. endef
  730. define do-makelib
  731. cd $(common-objdir) && \
  732. $(AR) $(CREATE_ARFLAGS) $(@F) `cat $(patsubst $(common-objpfx)%,%,$^)`
  733. endef
  734. subdirs-stamps := $(foreach d,$(subdirs),$(common-objpfx)$d/stamp%)
  735. subdirs-stamp-o = $(subst %,$o,$(subdirs-stamps))
  736. ifndef subdir
  737. $(subdirs-stamps): subdir_lib;
  738. endif
  739. object-suffixes-left = $(object-suffixes-for-libc)
  740. include $(o-iterator)
  741. # This makes all the object files.
  742. .PHONY: objects objs libobjs extra-objs
  743. objects objs: libobjs extra-objs
  744. libobjs: $(foreach o,$(object-suffixes-for-libc),$(objpfx)stamp$o)
  745. extra-objs: $(addprefix $(objpfx),$(extra-objs))
  746. # Canned sequence for building an extra library archive.
  747. define build-extra-lib
  748. $(patsubst %/,cd % &&,$(objpfx)) \
  749. $(AR) $(CREATE_ARFLAGS) $(@:$(objpfx)%=%) \
  750. $(patsubst $(objpfx)%,%,$^)
  751. endef
  752. # Installation.
  753. .PHONY: force-install
  754. force-install:
  755. # $(install-lib) are installed from the object directory into $(libdir);
  756. # files in $(install-lib) matching `lib%.a' are ranlib'd after installation
  757. # unless they also appear in $(non-lib.a). $(install-data) are installed as
  758. # they are into $(datadir). $(headers) are installed as they are in
  759. # $(includedir). $(install-bin), $(install-bin-script) and $(install-sbin)
  760. # are installed from the object directory into $(bindir), $(bindir) and
  761. # $(sbindir), respectively. $(install-others) and $(install-others-programs)
  762. # are absolute path names of files to install; rules to install them are
  763. # defined elsewhere.
  764. # The simple library name to install libc.a under.
  765. # This could be defined by a sysdep Makefile.
  766. ifndef libc-name
  767. libc-name := c
  768. endif
  769. define do-install
  770. $(make-target-directory)
  771. $(INSTALL_DATA) $< $@
  772. endef
  773. # Make the target directory if it doesn't exist, using the `mkinstalldirs'
  774. # script that does `mkdir -p' even if `mkdir' doesn't support that flag.
  775. define make-target-directory
  776. $(addprefix $(..)./scripts/mkinstalldirs ,\
  777. $(filter-out $(wildcard $(@D:%/=%)),$(@D:%/=%)))
  778. endef
  779. # Any directory (parent or subdir) should install libc.a; this way
  780. # "make install" in a subdir is guaranteed to install everything it changes.
  781. installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
  782. $(inst_libdir)/$(patsubst %,$(libtype$o),\
  783. $(libprefix)$(libc-name)))
  784. .PHONY: check-install-supported
  785. check-install-supported:
  786. # Check to see if the prefix or exec_prefix GNU standard variable
  787. # has been overridden on the command line and, if so, fail with
  788. # an error message since doing so is not supported (set DESTDIR
  789. # instead).
  790. ifeq ($(origin prefix),command line)
  791. check-install-supported:
  792. $(error Overriding prefix is not supported. Set DESTDIR instead.)
  793. endif
  794. ifeq ($(origin exec_prefix),command line)
  795. check-install-supported:
  796. $(error Overriding exec_prefix is not supported. Set DESTDIR instead.)
  797. endif
  798. install: check-install-supported
  799. install: $(installed-libcs)
  800. $(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
  801. $(make-target-directory)
  802. $(INSTALL_DATA) $(common-objpfx)lib$(*:$(libc-name)%=c%) $@
  803. define do-install-program
  804. $(make-target-directory)
  805. $(INSTALL_PROGRAM) $< $@.new
  806. mv -f $@.new $@
  807. endef
  808. define do-install-script
  809. $(make-target-directory)
  810. $(INSTALL_SCRIPT) $< $@.new
  811. mv -f $@.new $@
  812. endef
  813. install-lib.so := $(filter %.so,$(install-lib:%_pic.a=%.so))
  814. install-lib := $(filter-out %.so %_pic.a,$(install-lib))
  815. ifeq (yes,$(build-shared))
  816. # Find which .so's have a version number in their soname.
  817. versioned := $(strip $(foreach so,$(install-lib.so),\
  818. $(patsubst %,$(so),$($(so)-version))))
  819. install-lib.so-versioned := $(filter $(versioned), $(install-lib.so))
  820. install-lib.so-unversioned := $(filter-out $(versioned), $(install-lib.so))
  821. # For libraries whose soname have version numbers, we install two files:
  822. # $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
  823. # $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME
  824. install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
  825. $(foreach L,$(install-lib.so-versioned),\
  826. $(inst_libdir)/$L \
  827. $(inst_slibdir)/$L$($L-version))
  828. # Install all the unversioned shared libraries.
  829. $(install-lib.so-unversioned:%=$(inst_slibdir)/%): $(inst_slibdir)/%.so: \
  830. $(objpfx)%.so $(+force)
  831. $(do-install-program)
  832. ifneq ($(findstring -s,$(LN_S)),)
  833. define make-link
  834. rm -f $@.new
  835. $(SHELL) $(..)scripts/rellns-sh $< $@.new
  836. mv -f $@.new $@
  837. endef
  838. define make-link-multidir
  839. $(patsubst %/,cd %,$(objpfx)); \
  840. $(addprefix $(abspath $(..)scripts/mkinstalldirs) ,$(dir $(multidir))); \
  841. $(LN_S) . $(multidir) 2> /dev/null; \
  842. test -L $(multidir)
  843. endef
  844. else
  845. # If we have no symbolic links don't bother with rellns-sh.
  846. define make-link
  847. rm -f $@.new
  848. $(LN_S) $< $@.new
  849. mv -f $@.new $@
  850. endef
  851. define make-link-multidir
  852. $(make-target-directory)
  853. ln -f $(objpfx)/$(@F) $@
  854. endef
  855. endif
  856. ifdef libc.so-version
  857. $(inst_slibdir)/libc.so$(libc.so-version): $(common-objpfx)libc.so $(+force)
  858. $(do-install-program)
  859. install: $(inst_slibdir)/libc.so$(libc.so-version)
  860. # This fragment of linker script gives the OUTPUT_FORMAT statement
  861. # for the configuration we are building. We put this statement into
  862. # the linker scripts we install for -lc et al so that they will not be
  863. # used by a link for a different format on a multi-architecture system.
  864. $(common-objpfx)format.lds: $(common-objpfx)config.make \
  865. $(common-objpfx)config.h $(..)Makerules
  866. $(LINK.o) -shared -nostdlib -nostartfiles \
  867. -x assembler /dev/null -o $@.so
  868. $(OBJDUMP) -f $@.so | sed -n 's/.*file format \(.*\)/OUTPUT_FORMAT(\1)/;T;p' > $@
  869. rm -f $@.so
  870. common-generated += format.lds
  871. ifndef subdir
  872. # What we install as libc.so for programs to link against is in fact a
  873. # link script. It contains references for the various libraries we need.
  874. # The libc.so object is not complete since some functions are only defined
  875. # in libc_nonshared.a.
  876. # We need to use absolute paths since otherwise local copies (if they exist)
  877. # of the files are taken by the linker.
  878. install: $(inst_libdir)/libc.so
  879. $(inst_libdir)/libc.so: $(common-objpfx)format.lds \
  880. $(common-objpfx)libc.so$(libc.so-version) \
  881. $(inst_libdir)/$(patsubst %,$(libtype.oS),\
  882. $(libprefix)$(libc-name)) \
  883. $(+force)
  884. (echo '/* GNU ld script';\
  885. echo ' Use the shared library, but some functions are only in';\
  886. echo ' the static library, so try that secondarily. */';\
  887. cat $<; \
  888. echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
  889. '$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
  890. ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
  891. ) > $@.new
  892. mv -f $@.new $@
  893. endif
  894. else
  895. install: $(inst_slibdir)/libc.so
  896. $(inst_slibdir)/libc.so: $(common-objpfx)libc.so $(+force)
  897. $(do-install-program)
  898. endif
  899. ifneq (,$(versioned))
  900. # Produce three sets of rules as above for all the smaller versioned libraries.
  901. define o-iterator-doit
  902. $(inst_libdir)/$o: $(inst_slibdir)/$o$($o-version) $(+force); $$(make-link)
  903. endef
  904. object-suffixes-left := $(filter-out $(install-lib-ldscripts),$(versioned))
  905. ifneq (,$(object-suffixes-left))
  906. include $(o-iterator)
  907. endif
  908. # Make symlinks in the build directory, because the versioned names might
  909. # be referenced by a DT_NEEDED in another library.
  910. define o-iterator-doit
  911. $(objpfx)$o$($o-version): $(objpfx)$o; $$(make-link)
  912. endef
  913. object-suffixes-left := $(versioned)
  914. include $(o-iterator)
  915. generated += $(foreach o,$(versioned),$o$($o-version))
  916. define o-iterator-doit
  917. $(inst_slibdir)/$o$($o-version): $(objpfx)$o $(+force);
  918. $$(do-install-program)
  919. endef
  920. object-suffixes-left := $(versioned)
  921. include $(o-iterator)
  922. endif # ifneq (,$(versioned))
  923. define do-install-so
  924. $(do-install-program)
  925. $(patsubst %,$(LN_S) -f $(@F) \
  926. $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
  927. $(filter-out %.so,$@))
  928. endef
  929. so-versions := $(sort $(foreach so,$(install-lib.so),.so$($(so)-version)))
  930. $(foreach v,$(so-versions),\
  931. $(inst_slibdir)/lib$(libprefix)%$v): $(common-objpfx)lib%.so \
  932. $(+force)
  933. $(do-install-so)
  934. $(foreach v,$(so-versions),\
  935. $(inst_slibdir)/$(libprefix)%$v): $(common-objpfx)%.so $(+force)
  936. $(do-install-so)
  937. endif
  938. ifdef install-bin
  939. $(addprefix $(inst_bindir)/,$(install-bin)): \
  940. $(inst_bindir)/%: $(objpfx)% $(+force)
  941. $(do-install-program)
  942. endif
  943. ifdef install-bin-script
  944. $(addprefix $(inst_bindir)/,$(install-bin-script)): \
  945. $(inst_bindir)/%: $(objpfx)% $(+force)
  946. $(do-install-script)
  947. endif
  948. ifdef install-rootsbin
  949. $(addprefix $(inst_rootsbindir)/,$(install-rootsbin)): \
  950. $(inst_rootsbindir)/%: $(objpfx)% $(+force)
  951. $(do-install-program)
  952. endif
  953. ifdef install-sbin
  954. $(addprefix $(inst_sbindir)/,$(install-sbin)): \
  955. $(inst_sbindir)/%: $(objpfx)% $(+force)
  956. $(do-install-program)
  957. endif
  958. ifdef install-lib
  959. install-lib.a := $(filter lib%.a,$(install-lib))
  960. install-lib.a := $(filter-out $(install-lib-ldscripts),$(install-lib.a))
  961. install-lib-non.a := $(filter-out lib%.a,$(install-lib))
  962. ifdef install-lib-non.a
  963. $(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
  964. $(inst_libdir)/$(libprefix)%: $(objpfx)% $(+force)
  965. $(do-install)
  966. endif
  967. ifdef install-lib.a
  968. $(install-lib.a:lib%.a=$(inst_libdir)/lib$(libprefix)%.a): \
  969. $(inst_libdir)/lib$(libprefix)%.a: $(objpfx)lib%.a $(+force)
  970. $(do-install)
  971. endif
  972. endif
  973. ifdef install-data
  974. $(addprefix $(inst_datadir)/,$(install-data)): $(inst_datadir)/%: % $(+force)
  975. $(do-install)
  976. endif
  977. headers := $(strip $(headers))
  978. ifdef headers
  979. # This implicit rule installs headers from the source directory.
  980. # It may be ignored in preference to rules from sysd-rules to find
  981. # headers in the sysdeps tree.
  982. $(inst_includedir)/%.h: $(objpfx)%.h $(+force)
  983. $(do-install)
  984. $(inst_includedir)/%.h: $(common-objpfx)%.h $(+force)
  985. $(do-install)
  986. $(inst_includedir)/%.h: %.h $(+force)
  987. $(do-install)
  988. headers-nonh := $(filter-out %.h,$(headers))
  989. ifdef headers-nonh
  990. $(addprefix $(inst_includedir)/,$(headers-nonh)): $(inst_includedir)/%: \
  991. % $(+force)
  992. $(do-install)
  993. endif # headers-nonh
  994. endif # headers
  995. .PHONY: install-bin-nosubdir install-bin-script-nosubdir \
  996. install-rootsbin-nosubdir install-sbin-nosubdir install-lib-nosubdir \
  997. install-data-nosubdir install-headers-nosubdir
  998. install-bin-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin))
  999. install-bin-script-nosubdir: $(addprefix $(inst_bindir)/,$(install-bin-script))
  1000. install-rootsbin-nosubdir: \
  1001. $(addprefix $(inst_rootsbindir)/,$(install-rootsbin))
  1002. install-sbin-nosubdir: $(addprefix $(inst_sbindir)/,$(install-sbin))
  1003. install-lib-nosubdir: $(addprefix $(inst_libdir)/,\
  1004. $(patsubst lib%.a,lib$(libprefix)%.a,$(install-lib.a)) \
  1005. $(addprefix $(libprefix),$(install-lib-non.a)))
  1006. install-data-nosubdir: $(addprefix $(inst_datadir)/,$(install-data))
  1007. install-headers-nosubdir: $(addprefix $(inst_includedir)/,$(headers))
  1008. install-others-nosubdir: $(install-others)
  1009. install-others-programs-nosubdir: $(install-others-programs)
  1010. # We need all the `-nosubdir' targets so that `install' in the parent
  1011. # doesn't depend on several things which each iterate over the subdirs.
  1012. # This rule makes `install-FOO' always use `install-FOO-nosubdir' as a
  1013. # subroutine. Then in the parent `install-FOO' also causes subdir makes.
  1014. install-%:: install-%-nosubdir ;
  1015. .PHONY: install install-no-libc.a-nosubdir
  1016. install-no-libc.a-nosubdir: install-headers-nosubdir install-data-nosubdir \
  1017. install-lib-nosubdir install-others-nosubdir
  1018. ifeq ($(build-programs),yes)
  1019. install-no-libc.a-nosubdir: install-bin-nosubdir install-bin-script-nosubdir \
  1020. install-rootsbin-nosubdir install-sbin-nosubdir \
  1021. install-others-programs-nosubdir
  1022. endif
  1023. install: install-no-libc.a-nosubdir
  1024. # Command to compile $< using the native libraries.
  1025. define native-compile
  1026. $(make-target-directory)
  1027. $(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
  1028. $< $(OUTPUT_OPTION) $(BUILD_LDFLAGS)
  1029. endef
  1030. # We always want to use configuration definitions.
  1031. ALL_BUILD_CFLAGS = $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -D_GNU_SOURCE \
  1032. -DIS_IN_build -include $(common-objpfx)config.h
  1033. # Support the GNU standard name for this target.
  1034. .PHONY: check
  1035. check: tests
  1036. # Special target to run tests which cannot be run unconditionally.
  1037. # Maintainers should use this target.
  1038. .PHONY: xcheck
  1039. xcheck: xtests
  1040. # Also handle test inputs in sysdeps.
  1041. vpath %.input $(sysdirs)
  1042. # Handle tests-time64 and xtests-time64 that should built with LFS
  1043. # and 64-bit time support.
  1044. include $(o-iterator)
  1045. define o-iterator-doit
  1046. $(foreach f,$(tests-time64) $(xtests-time64),\
  1047. $(objpfx)$(f)$(o)): CFLAGS += -D_TIME_BITS=64 -D_FILE_OFFSET_BITS=64
  1048. endef
  1049. object-suffixes-left := $(all-object-suffixes)
  1050. include $(o-iterator)
  1051. ifeq ($(have-time64-compat),yes)
  1052. tests += $(foreach t,$(tests-time64),$(t))
  1053. xtests += $(foreach t,$(xtests-time64),$(t))
  1054. endif
  1055. # The only difference between MODULE_NAME=testsuite and MODULE_NAME=nonlib is
  1056. # that almost all internal declarations from config.h, libc-symbols.h, and
  1057. # include/*.h are not available to 'testsuite' code, but are to 'nonlib' code.
  1058. all-testsuite := $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) \
  1059. $(tests-container))
  1060. ifneq (,$(all-testsuite))
  1061. cpp-srcs-left = $(all-testsuite)
  1062. lib := testsuite
  1063. include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
  1064. endif
  1065. all-nonlib := $(strip $(others) $(others-extras))
  1066. ifneq (,$(all-nonlib))
  1067. cpp-srcs-left = $(all-nonlib)
  1068. lib := nonlib
  1069. include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
  1070. endif
  1071. # All internal tests use testsuite-internal module since for 64 bit time
  1072. # support is set as default for MODULE_NAME=nonlib (which include some
  1073. # installed programs).
  1074. all-testsuite-internal := $(strip $(tests-internal) $(test-internal-extras))
  1075. ifneq (,$(all-testsuite-internal))
  1076. cpp-srcs-left = $(all-testsuite-internal)
  1077. lib := testsuite-internal
  1078. include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
  1079. endif
  1080. ifeq ($(build-shared),yes)
  1081. # Generate normalized lists of symbols, versions, and data sizes.
  1082. # This is handy for checking against existing library binaries.
  1083. %.symlist: $(..)scripts/abilist.awk %.dynsym
  1084. LC_ALL=C $(AWK) -f $^ > $@T
  1085. mv -f $@T $@
  1086. %.dynsym: %.so
  1087. LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
  1088. mv -f $@T $@
  1089. vpath %.abilist $(+sysdep_dirs)
  1090. # The .PRECIOUS rule prevents the files built by an implicit rule whose
  1091. # target pattern is %.symlist from being considered "intermediate files"
  1092. # and automatically removed. We only want these files to be removed by
  1093. # 'make clean', which is handled by the 'generated' variable.
  1094. .PRECIOUS: %.symlist
  1095. generated += $(extra-libs:=.symlist)
  1096. $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
  1097. $(objpfx)%.symlist
  1098. $(check-abi); \
  1099. $(evaluate-test)
  1100. $(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
  1101. $(common-objpfx)%.symlist
  1102. $(check-abi); \
  1103. $(evaluate-test)
  1104. define check-abi
  1105. diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^) > $@
  1106. endef
  1107. update-abi-%: $(objpfx)%.symlist %.abilist
  1108. $(update-abi)
  1109. update-abi-%: $(common-objpfx)%.symlist %.abilist
  1110. $(update-abi)
  1111. define update-abi
  1112. @if cmp -s $^ 2> /dev/null; \
  1113. then \
  1114. echo '+++ $(filter %.abilist,$^) is unchanged'; \
  1115. else cp -f $^; \
  1116. echo '*** Now check $(filter %.abilist,$^) changes for correctness ***'; \
  1117. fi
  1118. endef
  1119. # Patch all .abilist files for one DSO. The find command locates abilist
  1120. # files for all architectures. The abilist files in /generic/ are
  1121. # filtered out because these are expected to remain empty.
  1122. define update-all-abi
  1123. $(SHELL) $(..)scripts/update-abilist.sh $^ \
  1124. $$(find $(..)sysdeps -name '$*.abilist' \! -path '*/generic/*')
  1125. endef
  1126. update-all-abi-%: %.abilist $(objpfx)%.symlist
  1127. $(update-all-abi)
  1128. update-all-abi-%: %.abilist $(common-objpfx)%.symlist
  1129. $(update-all-abi)
  1130. .PHONY: update-abi update-all-abi check-abi
  1131. update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
  1132. update-all-abi: $(patsubst %.so,update-all-abi-%,$(install-lib.so-versioned))
  1133. check-abi-list = $(patsubst %.so,$(objpfx)check-abi-%.out, \
  1134. $(install-lib.so-versioned))
  1135. check-abi: $(check-abi-list)
  1136. ifdef subdir
  1137. subdir_check-abi: check-abi
  1138. subdir_update-abi: update-abi
  1139. subdir_update-all-abi: update-all-abi
  1140. else
  1141. check-abi: subdir_check-abi
  1142. if grep -q '^FAIL:' $(objpfx)*/check-abi*.test-result; then \
  1143. cat $(objpfx)*/check-abi*.out && exit 1; fi
  1144. update-abi: subdir_update-abi
  1145. update-all-abi: subdir_update-all-abi
  1146. endif
  1147. ifeq ($(subdir),elf)
  1148. check-abi: $(objpfx)check-abi-libc.out
  1149. tests-special += $(objpfx)check-abi-libc.out
  1150. update-abi: update-abi-libc
  1151. update-all-abi: update-all-abi-libc
  1152. common-generated += libc.symlist
  1153. endif
  1154. ifeq ($(build-shared),yes)
  1155. ifdef subdir
  1156. tests-special += $(check-abi-list)
  1157. endif
  1158. endif
  1159. endif
  1160. FORCE:
  1161. .PHONY: echo-headers
  1162. echo-headers:
  1163. @echo $(headers)
  1164. %.bz2: %; bzip2 -9vk $<
  1165. %.gz: %; gzip -9vnc $< > $@.new && mv -f $@.new $@
  1166. %.xz: %; xz -9evk $<
  1167. # Common cleaning targets.
  1168. .PHONY: common-mostlyclean common-clean mostlyclean clean do-tests-clean
  1169. clean: common-clean
  1170. mostlyclean: common-mostlyclean
  1171. # Remove test artifacts from a given directory
  1172. do-tests-clean:
  1173. -find $(objpfx) -name '*.out' -delete
  1174. -find $(objpfx) -name '*.test-result' -delete
  1175. # Remove the object files.
  1176. common-mostlyclean: do-tests-clean
  1177. -rm -f $(addprefix $(objpfx),$(tests) $(tests-internal) $(xtests) \
  1178. $(test-srcs) \
  1179. $(others) $(sysdep-others) stubs \
  1180. $(addsuffix .o,$(tests) \
  1181. $(tests-internal) \
  1182. $(xtests) \
  1183. $(test-srcs) \
  1184. $(others) \
  1185. $(sysdep-others)))
  1186. -rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
  1187. $(install-lib) $(install-lib.so) \
  1188. $(install-lib.so:%.so=%_pic.a))
  1189. -rm -f core
  1190. -rm -f $(objpfx)rtld-*.os
  1191. $(rmobjs)
  1192. define rmobjs
  1193. $(foreach o,$(object-suffixes-for-libc),
  1194. -rm -f $(objpfx)stamp$o $(o-objects))
  1195. endef
  1196. # Also remove the dependencies and generated source files.
  1197. common-clean: common-mostlyclean
  1198. -rm -f $(addprefix $(objpfx),$(generated))
  1199. -rm -f $(objpfx)*.d $(objpfx)*.dt
  1200. -rm -fr $(addprefix $(objpfx),$(generated-dirs))
  1201. -rm -f $(addprefix $(common-objpfx),$(common-generated))
  1202. -rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
  1203. # Produce a file `stubs' which contains `#define __stub_FUNCTION'
  1204. # for each function which is a stub.
  1205. ifdef objpfx
  1206. .PHONY: stubs # The parent Makefile calls this target.
  1207. stubs: $(objpfx)stubs
  1208. endif
  1209. objs-for-stubs := $(foreach o,$(object-suffixes-for-libc),$(o-objects)) \
  1210. $(addprefix $(objpfx),$(extra-objs))
  1211. $(objpfx)stubs: $(objs-for-stubs)
  1212. ifneq (,$(strip $(objs-for-stubs)))
  1213. (cd $(objpfx).; $(OBJDUMP) -h $(patsubst $(objpfx)%,%,$^)) | \
  1214. $(AWK) '/\.gnu\.glibc-stub\./ { \
  1215. sub(/\.gnu\.glibc-stub\./, "", $$2); \
  1216. stubs[$$2] = 1; } \
  1217. END { for (s in stubs) print "#define __stub_" s }' > $@T
  1218. mv -f $@T $@
  1219. else
  1220. > $@
  1221. endif
  1222. ifneq (,$(strip $(gpl2lgpl)))
  1223. ifneq (,$(wildcard $(..)gpl2lgpl.sed))
  1224. # Snarf from the original source and frob the copying notice.
  1225. $(gpl2lgpl): %: $(..)gpl2lgpl.sed /home/gd/gnu/lib/%
  1226. sed -f $^ > $@-tmp
  1227. # So I don't edit them by mistake.
  1228. chmod a-w $@-tmp
  1229. mv -f $@-tmp $@
  1230. endif
  1231. endif
  1232. # Local Variables:
  1233. # mode: makefile
  1234. # End: