xref: /aoo4110/main/solenv/gbuild/LinkTarget.mk (revision b1cdbd2c)
1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22
23
24
25# CObject class
26
27gb_CObject_REPOS := $(gb_REPOS)
28
29gb_CObject_get_source = $(1)/$(2).c
30# defined by platform
31#  gb_CObject__command
32
33# this rule generates an "always rebuild" dep file, to have something to include.
34# the dep file will be overridden on the fly, when the object is compiled
35ifeq ($(gb_FULLDEPS),$(true))
36define gb_CObject__command_dep
37mkdir -p $(dir $(1)) && \
38	echo '$(call gb_CObject_get_target,$(2)) : $$(gb_Helper_PHONY)' > $(1)
39
40endef
41else
42gb_CObject__command_dep =
43endif
44
45define gb_CObject__rules
46$$(call gb_CObject_get_target,%) : $$(call gb_CObject_get_source,$(1),%)
47	$$(call gb_CObject__command,$$@,$$*,$$<,$$(DEFS),$$(CFLAGS),$$(INCLUDE))
48
49ifeq ($(gb_FULLDEPS),$(true))
50$$(call gb_CObject_get_dep_target,%) : $$(call gb_CObject_get_source,$(1),%)
51	$$(call gb_CObject__command_dep,$$@,$$*,$$<,$$(DEFS),$$(CFLAGS),$$(INCLUDE))
52endif
53
54endef
55
56$(foreach repo,$(gb_CObject_REPOS),$(eval $(call gb_CObject__rules,$(repo))))
57
58$(call gb_CObject_get_dep_target,%) :
59	$(eval $(call gb_Output_error,Unable to find plain C file $(call gb_CObject_get_source,,$*) in the repositories: $(gb_CObject_REPOS)))
60
61gb_CObject_CObject =
62
63
64# CxxObject class
65
66gb_CxxObject_REPOS := $(gb_REPOS)
67
68gb_CxxObject_get_source = $(1)/$(2).cxx
69# defined by platform
70#  gb_CxxObject__command
71
72# This rule generates an "always rebuild" dep file, to have something to
73# include. The dep file will be overridden on the fly, when the object is
74# compiled.
75ifeq ($(gb_FULLDEPS),$(true))
76define gb_CxxObject__command_dep
77mkdir -p $(dir $(1)) && \
78	echo '$(call gb_CxxObject_get_target,$(2)) : $$(gb_Helper_PHONY)' > $(1)
79
80endef
81else
82gb_CxxObject__command_dep =
83endif
84
85# Only enable PCH if the PCH_CXXFLAGS and the PCH_DEFS (from the linktarget)
86# are the same as the CXXFLAGS and DEFS we want to use for this object. This
87# should usually be the case.  The DEFS/CXXFLAGS would have too be manually
88# overridden for one object file for them to differ.  PCH_CXXFLAGS/PCH_DEFS
89# should never be overridden on an object -- they should be the same as for the
90# whole linktarget. In general it should be cleaner to use a static library
91# compiled with different flags and link that in rather than mixing different
92# flags in one linktarget.
93define gb_CxxObject__set_pchflags
94ifeq ($(gb_ENABLE_PCH),$(true))
95ifneq ($(strip $$(PCH_NAME)),)
96ifeq ($$(sort $$(PCH_CXXFLAGS) $$(PCH_DEFS) $$(gb_LinkTarget_EXCEPTIONFLAGS)),$$(sort $$(CXXFLAGS) $$(DEFS)))
97$$@ : PCHFLAGS := $$(call gb_PrecompiledHeader_get_enableflags,$$(PCH_NAME))
98else
99ifeq ($$(sort $$(PCH_CXXFLAGS) $$(PCH_DEFS) $$(gb_LinkTarget_NOEXCEPTIONFLAGS)),$$(sort $$(CXXFLAGS) $$(DEFS)))
100$$@ : PCHFLAGS := $$(call gb_NoexPrecompiledHeader_get_enableflags,$$(PCH_NAME))
101else
102$$(info No precompiled header available for $$*.)
103$$(info precompiled header flags (  ex) : $$(sort $$(PCH_CXXFLAGS) $$(PCH_DEFS) $$(gb_LinkTarget_EXCEPTIONFLAGS)))
104$$(info precompiled header flags (noex) : $$(sort $$(PCH_CXXFLAGS) $$(PCH_DEFS) $$(gb_LinkTarget_NOEXCEPTIONFLAGS)))
105$$(info .           object flags        : $$(sort $$(CXXFLAGS) $$(DEFS)))
106$$@ : PCHFLAGS :=
107endif
108endif
109endif
110endif
111endef
112
113define gb_CxxObject__rules
114$$(call gb_CxxObject_get_target,%) : $$(call gb_CxxObject_get_source,$(1),%)
115	$$(eval $$(gb_CxxObject__set_pchflags))
116	$$(call gb_CxxObject__command,$$@,$$*,$$<)
117
118ifeq ($(gb_FULLDEPS),$(true))
119$$(call gb_CxxObject_get_dep_target,%) : $$(call gb_CxxObject_get_source,$(1),%)
120	$$(eval $$(gb_CxxObject__set_pchflags))
121	$$(call gb_CxxObject__command_dep,$$@,$$*,$$<)
122endif
123
124endef
125
126$(foreach repo,$(gb_CxxObject_REPOS),$(eval $(call gb_CxxObject__rules,$(repo))))
127
128ifeq ($(gb_FULLDEPS),$(true))
129$(call gb_CxxObject_get_dep_target,%) :
130	$(eval $(call gb_Output_error,Unable to find C++ file $(call gb_CxxObject_get_source,,$*) in repositories: $(gb_CxxObject_REPOS)))
131
132endif
133
134gb_CxxObject_CxxObject =
135
136
137# GenCxxObject class
138
139gb_GenCxxObject_get_source = $(WORKDIR)/$(1).cxx
140# defined by platform
141#  gb_CxxObject__command
142
143# This rule generates an "always rebuild" dep file, to have something to
144# include. The dep file will be overridden on the fly, when the object is
145# compiled.
146ifeq ($(gb_FULLDEPS),$(true))
147define gb_GenCxxObject__command_dep
148mkdir -p $(dir $(1)) && \
149	echo '$(call gb_GenCxxObject_get_target,$(2)) : $$(gb_Helper_PHONY)' > $(1)
150endef
151else
152gb_GenCxxObject__command_dep =
153endif
154
155$(call gb_GenCxxObject_get_target,%) : $(call gb_GenCxxObject_get_source,%)
156	$(call gb_CxxObject__command,$@,$*,$<)
157
158ifeq ($(gb_FULLDEPS),$(true))
159$(call gb_GenCxxObject_get_dep_target,%) : $(call gb_GenCxxObject_get_source,%)
160	$(call gb_GenCxxObject__command_dep,$@,$*,$<)
161
162$(call gb_GenCxxObject_get_dep_target,%) :
163	$(eval $(call gb_Output_error,Unable to find generated C++ file $(call gb_GenCxxObject_get_source,$*) in WORKDIR.))
164endif
165
166gb_GenCxxObject_GenCxxObject =
167
168
169# ObjCxxObject class
170#
171gb_ObjCxxObject_REPOS := $(gb_REPOS)
172
173gb_ObjCxxObject_get_source = $(1)/$(2).mm
174# defined by platform
175#  gb_ObjCxxObject__command
176
177# this rule generates an "always rebuild" dep file, to have something to include.
178# the dep file will be overridden on the fly, when the object is compiled
179ifeq ($(gb_FULLDEPS),$(true))
180define gb_ObjCxxObject__command_dep
181mkdir -p $(dir $(1)) && \
182	echo '$(call gb_ObjCxxObject_get_target,$(2)) : $$(gb_Helper_PHONY)' > $(1)
183
184endef
185else
186gb_ObjCxxObject__command_dep =
187endif
188
189define gb_ObjCxxObject__rules
190$$(call gb_ObjCxxObject_get_target,%) : $$(call gb_ObjCxxObject_get_source,$(1),%)
191	$$(call gb_ObjCxxObject__command,$$@,$$*,$$<,$$(DEFS),$$(OBJCXXFLAGS),$$(INCLUDE_STL) $$(INCLUDE))
192
193ifeq ($(gb_FULLDEPS),$(true))
194$$(call gb_ObjCxxObject_get_dep_target,%) : $$(call gb_ObjCxxObject_get_source,$(1),%)
195	$$(call gb_ObjCxxObject__command_dep,$$@,$$*,$$<,$$(DEFS),$$(OBJCXXFLAGS),$$(INCLUDE_STL) $$(INCLUDE))
196endif
197
198endef
199
200$(foreach repo,$(gb_ObjCxxObject_REPOS),$(eval $(call gb_ObjCxxObject__rules,$(repo))))
201
202ifeq ($(gb_FULLDEPS),$(true))
203$(call gb_ObjCxxObject_get_dep_target,%) :
204	$(eval $(call gb_Output_error,Unable to find Objective C++ file $(call gb_ObjCxxObject_get_source,,$*) in repositories: $(gb_ObjCxxObject_REPOS)))
205endif
206
207gb_ObjCxxObject_ObjCxxObject =
208
209
210
211# LinkTarget class
212
213gb_LinkTarget_DEFAULTDEFS := $(gb_GLOBALDEFS)
214# defined by platform
215#  gb_LinkTarget_CXXFLAGS
216#  gb_LinkTarget_LDFLAGS
217#  gb_LinkTarget_INCLUDE
218#  gb_LinkTarget_INCLUDE_STL
219
220.PHONY : $(call gb_LinkTarget_get_clean_target,%)
221$(call gb_LinkTarget_get_clean_target,%) :
222	$(call gb_Output_announce,$*,$(false),LNK,4)
223	RESPONSEFILE=$(call var2file,$(shell $(gb_MKTEMP)),200,\
224		$(foreach object,$(COBJECTS),$(call gb_CObject_get_target,$(object))) \
225		$(foreach object,$(COBJECTS),$(call gb_CObject_get_dep_target,$(object))) \
226		$(foreach object,$(CXXOBJECTS),$(call gb_CxxObject_get_target,$(object))) \
227		$(foreach object,$(CXXOBJECTS),$(call gb_CxxObject_get_dep_target,$(object))) \
228		$(foreach object,$(OBJCXXOBJECTS),$(call gb_ObjCxxObject_get_target,$(object))) \
229		$(foreach object,$(OBJCXXOBJECTS),$(call gb_ObjCxxObject_get_dep_target,$(object))) \
230		$(foreach object,$(GENCXXOBJECTS),$(call gb_GenCxxObject_get_target,$(object))) \
231		$(foreach object,$(GENCXXOBJECTS),$(call gb_GenCxxObject_get_dep_target,$(object))) \
232		$(call gb_LinkTarget_get_target,$*) \
233		$(call gb_LinkTarget_get_dep_target,$*) \
234		$(call gb_LinkTarget_get_headers_target,$*) \
235		$(call gb_LinkTarget_get_external_headers_target,$*) \
236		$(DLLTARGET) \
237		$(AUXTARGETS)) && \
238	cat $${RESPONSEFILE} /dev/null | xargs -n 200 rm -f && \
239	rm -f $${RESPONSEFILE}
240
241
242# cat the deps of all objects in one file, then we need only open that one file
243define gb_LinkTarget__command_dep
244$(call gb_Output_announce,LNK:$(2),$(true),DEP,1)
245$(call gb_Helper_abbreviate_dirs,\
246	mkdir -p $(dir $(1)) && \
247	RESPONSEFILE=$(call var2file,$(shell $(gb_MKTEMP)),200,\
248		$(foreach object,$(3),$(call gb_CObject_get_dep_target,$(object))) \
249		$(foreach object,$(4),$(call gb_CxxObject_get_dep_target,$(object))) \
250		$(foreach object,$(5),$(call gb_ObjCxxObject_get_dep_target,$(object)))\
251		$(foreach object,$(6),$(call gb_GenCxxObject_get_dep_target,$(object)))\
252		) && \
253	cat $${RESPONSEFILE} /dev/null | xargs -n 200 cat > $(1)) && \
254	rm -f $${RESPONSEFILE}
255
256endef
257
258$(call gb_LinkTarget_get_target,%) : $(call gb_LinkTarget_get_headers_target,%) $(gb_Helper_MISCDUMMY)
259	$(call gb_LinkTarget__command,$@,$*)
260
261ifeq ($(gb_FULLDEPS),$(true))
262$(call gb_LinkTarget_get_target,%) : $(call gb_LinkTarget_get_dep_target,%)
263$(call gb_LinkTarget_get_dep_target,%) : | $(call gb_LinkTarget_get_headers_target,%)
264	$(call gb_LinkTarget__command_dep,$@,$*,$(COBJECTS),$(CXXOBJECTS),$(OBJCXXOBJECTS),$(GENCXXOBJECTS))
265endif
266
267# Ok, this is some dark voodoo: When declaring a linktarget with
268# gb_LinkTarget_LinkTarget we set SELF in the headertarget to name of the
269# target. When the rule for the headertarget is executed and SELF does not
270# match the target name, we are depending on a linktarget that was never
271# declared. In a full build exclusively in gbuild that should never happen.
272# However, partial gbuild build will not know about how to build lower level
273# linktargets, just as gbuild can not know about linktargets generated in the
274# old build.pl/dmake system. Once all is migrated, gbuild should error out
275# when is is told to depend on a linktarget it does not know about and not
276# only warn.
277define gb_LinkTarget__get_external_headers_check
278ifneq ($$(SELF),$$*)
279$$(eval $$(call gb_Output_info,LinkTarget $$* not defined: Assuming headers to be there!,ALL))
280endif
281$$@ : COMMAND := $$(call gb_Helper_abbreviate_dirs, mkdir -p $$(dir $$@) && touch $$@ && mkdir -p $(call gb_LinkTarget_get_target,)pdb/$$(dir $$*))
282
283endef
284
285$(call gb_LinkTarget_get_external_headers_target,%) :
286	$(eval $(gb_LinkTarget__get_external_headers_check))
287	$(COMMAND)
288
289$(call gb_LinkTarget_get_headers_target,%) : $(call gb_LinkTarget_get_external_headers_target,%)
290	$(call gb_Helper_abbreviate_dirs,\
291		mkdir -p $(dir $@) && touch $@)
292
293# Explanation of some of the targets:
294# - gb_LinkTarget_get_external_headers_target is the targets that guarantees all
295#   headers from linked against libraries are in OUTDIR.
296# - gb_LinkTarget_get_headers_target is the target that guarantees all headers
297#   from the linked against the libraries and the linktargets own headers
298#   (including generated headers) are in the OUTDIR.
299# - gb_LinkTarget_get_target links the objects into a file in WORKDIR.
300# gb_LinkTarget_get_target depends on gb_LinkTarget_get_headers_target which in
301# turn depends gb_LinkTarget_get_external_headers_target.
302# gb_LinkTarget_get_target depends additionally on the objects, which in turn
303# depend build-order only on the gb_LinkTarget_get_headers_target. The build
304# order-only dependency ensures all headers to be there for compiling and
305# dependency generation without causing all objects to be rebuild when one
306# header changes. Only the ones with an explicit dependency in their generated
307# dependency file will be rebuild.
308#
309# gb_LinkTarget_get_target is the target that links the objects into a file in
310# WORKDIR
311# Explanation of some of the variables:
312# - AUXTARGETS are the additionally generated files that need to be cleaned out
313#   on clean.
314# - PCH_CXXFLAGS and PCH_DEFS are the flags that the precompiled headers will
315#   be compiled with.  They should never be overridden in a single object
316#   files.
317# - TARGETTYPE is the type of linktarget as some platforms need very different
318#   command to link different targettypes.
319#
320# Since most variables are set on the linktarget and not on the object, the
321# object learns about these setting via GNU makes scoping of target variables.
322# Therefore it is important that objects are only directly depended on by the
323# linktarget. This for example means that you cannot build a single object
324# alone, because then you would directly depend on the object.
325define gb_LinkTarget_LinkTarget
326$(call gb_LinkTarget_get_clean_target,$(1)) : AUXTARGETS :=
327$(call gb_LinkTarget_get_external_headers_target,$(1)) : SELF := $(1)
328$(call gb_LinkTarget_get_target,$(1)) : DLLTARGET :=
329$(call gb_LinkTarget_get_clean_target,$(1)) \
330$(call gb_LinkTarget_get_target,$(1)) : COBJECTS :=
331$(call gb_LinkTarget_get_clean_target,$(1)) \
332$(call gb_LinkTarget_get_target,$(1)) : CXXOBJECTS :=
333$(call gb_LinkTarget_get_clean_target,$(1)) \
334$(call gb_LinkTarget_get_target,$(1)) : OBJCXXOBJECTS :=
335$(call gb_LinkTarget_get_clean_target,$(1)) \
336$(call gb_LinkTarget_get_target,$(1)) : GENCXXOBJECTS :=
337$(call gb_LinkTarget_get_headers_target,$(1)) \
338$(call gb_LinkTarget_get_target,$(1)) : CFLAGS := $$(gb_LinkTarget_CFLAGS)
339$(call gb_LinkTarget_get_headers_target,$(1)) \
340$(call gb_LinkTarget_get_target,$(1)) : CXXFLAGS := $$(gb_LinkTarget_CXXFLAGS)
341$(call gb_LinkTarget_get_headers_target,$(1)) \
342$(call gb_LinkTarget_get_target,$(1)) : PCH_CXXFLAGS := $$(gb_LinkTarget_CXXFLAGS) $(gb_COMPILEROPTFLAGS)
343$(call gb_LinkTarget_get_target,$(1)) : OBJCXXFLAGS := $$(gb_LinkTarget_OBJCXXFLAGS)
344$(call gb_LinkTarget_get_headers_target,$(1)) \
345$(call gb_LinkTarget_get_target,$(1)) : DEFS := $$(gb_LinkTarget_DEFAULTDEFS)
346$(call gb_LinkTarget_get_headers_target,$(1)) \
347$(call gb_LinkTarget_get_target,$(1)) : PCH_DEFS := $$(gb_LinkTarget_DEFAULTDEFS)
348$(call gb_LinkTarget_get_headers_target,$(1)) \
349$(call gb_LinkTarget_get_target,$(1)) : INCLUDE := $$(gb_LinkTarget_INCLUDE)
350$(call gb_LinkTarget_get_headers_target,$(1)) \
351$(call gb_LinkTarget_get_target,$(1)) : INCLUDE_STL := $$(gb_LinkTarget_INCLUDE_STL)
352$(call gb_LinkTarget_get_target,$(1)) : LDFLAGS := $$(gb_LinkTarget_LDFLAGS)
353$(call gb_LinkTarget_get_target,$(1)) : LINKED_LIBS :=
354$(call gb_LinkTarget_get_target,$(1)) : LINKED_STATIC_LIBS :=
355$(call gb_LinkTarget_get_target,$(1)) : EXTERNAL_LIBS :=
356$(call gb_LinkTarget_get_target,$(1)) : TARGETTYPE :=
357$(call gb_LinkTarget_get_headers_target,$(1)) \
358$(call gb_LinkTarget_get_target,$(1)) : PCH_NAME :=
359$(call gb_LinkTarget_get_target,$(1)) : PCHOBJS :=
360$(call gb_LinkTarget_get_headers_target,$(1)) \
361$(call gb_LinkTarget_get_target,$(1)) : PDBFILE :=
362$(call gb_LinkTarget_get_target,$(1)) : NATIVERES :=
363
364ifeq ($(gb_FULLDEPS),$(true))
365ifneq ($(wildcard $(call gb_LinkTarget_get_dep_target,$(1))),)
366include $(call gb_LinkTarget_get_dep_target,$(1))
367else
368$(firstword $(MAKEFILE_LIST)) : $(call gb_LinkTarget_get_dep_target,$(1))
369endif
370$(call gb_LinkTarget_get_dep_target,$(1)) : COBJECTS :=
371$(call gb_LinkTarget_get_dep_target,$(1)) : CXXOBJECTS :=
372$(call gb_LinkTarget_get_dep_target,$(1)) : OBJCXXOBJECTS :=
373$(call gb_LinkTarget_get_dep_target,$(1)) : GENCXXOBJECTS :=
374$(call gb_LinkTarget_get_dep_target,$(1)) : CFLAGS := $$(gb_LinkTarget_CFLAGS)
375$(call gb_LinkTarget_get_dep_target,$(1)) : CXXFLAGS := $$(gb_LinkTarget_CXXFLAGS)
376$(call gb_LinkTarget_get_dep_target,$(1)) : PCH_CXXFLAGS := $$(gb_LinkTarget_CXXFLAGS) $(gb_COMPILEROPTFLAGS)
377$(call gb_LinkTarget_get_dep_target,$(1)) : OBJCXXFLAGS := $$(gb_LinkTarget_OBJCXXFLAGS)
378$(call gb_LinkTarget_get_dep_target,$(1)) : DEFS := $$(gb_LinkTarget_DEFAULTDEFS)
379$(call gb_LinkTarget_get_dep_target,$(1)) : PCH_DEFS := $$(gb_LinkTarget_DEFAULTDEFS)
380$(call gb_LinkTarget_get_dep_target,$(1)) : INCLUDE := $$(gb_LinkTarget_INCLUDE)
381$(call gb_LinkTarget_get_dep_target,$(1)) : INCLUDE_STL := $$(gb_LinkTarget_INCLUDE_STL)
382$(call gb_LinkTarget_get_dep_target,$(1)) : TARGETTYPE :=
383$(call gb_LinkTarget_get_dep_target,$(1)) : PCH_NAME :=
384endif
385
386endef
387
388define gb_LinkTarget_set_defs
389$(call gb_LinkTarget_get_headers_target,$(1)) \
390$(call gb_LinkTarget_get_target,$(1)) : DEFS := $(2)
391$(call gb_LinkTarget_get_headers_target,$(1)) \
392$(call gb_LinkTarget_get_target,$(1)) : PCH_DEFS := $(2)
393
394ifeq ($(gb_FULLDEPS),$(true))
395$(call gb_LinkTarget_get_dep_target,$(1)) : DEFS := $(2)
396$(call gb_LinkTarget_get_dep_target,$(1)) : PCH_DEFS := $(2)
397endif
398
399endef
400
401define gb_LinkTarget_set_cflags
402$(call gb_LinkTarget_get_target,$(1)) : CFLAGS := $(2)
403ifeq ($(gb_FULLDEPS),$(true))
404$(call gb_LinkTarget_get_dep_target,$(1)) : CFLAGS := $(2)
405endif
406
407endef
408
409define gb_LinkTarget_set_cxxflags
410$(call gb_LinkTarget_get_headers_target,$(1)) \
411$(call gb_LinkTarget_get_target,$(1)) : CXXFLAGS := $(2)
412$(call gb_LinkTarget_get_headers_target,$(1)) \
413$(call gb_LinkTarget_get_target,$(1)) : PCH_CXXFLAGS := $(2)
414ifeq ($(gb_FULLDEPS),$(true))
415$(call gb_LinkTarget_get_dep_target,$(1)) : CXXFLAGS := $(2)
416$(call gb_LinkTarget_get_dep_target,$(1)) : PCH_CXXFLAGS := $(2)
417endif
418
419endef
420
421define gb_LinkTarget_set_objcxxflags
422$(call gb_LinkTarget_get_target,$(1)) : OBJCXXFLAGS := $(2)
423ifeq ($(gb_FULLDEPS),$(true))
424$(call gb_LinkTarget_get_dep_target,$(1)) : OBJCXXFLAGS := $(2)
425endif
426
427endef
428
429define gb_LinkTarget_set_include
430$(call gb_LinkTarget_get_headers_target,$(1)) \
431$(call gb_LinkTarget_get_target,$(1)) : INCLUDE := $(2)
432ifeq ($(gb_FULLDEPS),$(true))
433$(call gb_LinkTarget_get_dep_target,$(1)) : INCLUDE := $(2)
434endif
435
436endef
437
438define gb_LinkTarget_set_include_stl
439$(call gb_LinkTarget_get_headers_target,$(1)) \
440$(call gb_LinkTarget_get_target,$(1)) : INCLUDE_STL := $(2)
441ifeq ($(gb_FULLDEPS),$(true))
442$(call gb_LinkTarget_get_dep_target,$(1)) : INCLUDE_STL := $(2)
443endif
444
445endef
446
447define gb_LinkTarget_set_ldflags
448$(call gb_LinkTarget_get_target,$(1)) : LDFLAGS := $(2)
449endef
450
451define gb_LinkTarget_add_linked_libs
452ifneq (,$$(filter-out $(gb_Library_KNOWNLIBS),$(2)))
453$$(eval $$(call gb_Output_info,currently known libraries are: $(sort $(gb_Library_KNOWNLIBS)),ALL))
454$$(eval $$(call gb_Output_error,Cannot link against library/libraries $$(filter-out $(gb_Library_KNOWNLIBS),$(2)). Libraries must be registered in Repository.mk))
455endif
456
457$(call gb_LinkTarget_get_target,$(1)) : LINKED_LIBS += $(2)
458
459$(call gb_LinkTarget_get_target,$(1)) : $$(foreach lib,$(2),$$(call gb_Library_get_target,$$(lib)))
460$(call gb_LinkTarget_get_external_headers_target,$(1)) : \
461$$(foreach lib,$(2),$$(call gb_Library_get_headers_target,$$(lib)))
462
463endef
464
465define gb_LinkTarget_add_linked_static_libs
466ifneq (,$$(filter-out $(gb_StaticLibrary_KNOWNLIBS),$(2)))
467$$(eval $$(call gb_Output_info, currently known static libraries are: $(sort $(gb_StaticLibrary_KNOWNLIBS)),ALL))
468$$(eval $$(call gb_Output_error,Cannot link against static library/libraries $$(filter-out $(gb_StaticLibrary_KNOWNLIBS),$(2)). Static libraries must be registered in Repository.mk))
469endif
470
471$(call gb_LinkTarget_get_target,$(1)) : LINKED_STATIC_LIBS += $(2)
472
473$(call gb_LinkTarget_get_target,$(1)) : $$(foreach lib,$(2),$$(call gb_StaticLibrary_get_target,$$(lib)))
474$(call gb_LinkTarget_get_external_headers_target,$(1)) : \
475$$(foreach lib,$(2),$$(call gb_StaticLibrary_get_headers_target,$$(lib)))
476
477endef
478
479#
480# Add external libs for linking.  External libaries are not built by any module.
481#
482# The list of libraries is used as is, ie it is not filtered with gb_Library_KNOWNLIBS.
483#
484# An error is signaled, when any of the library names does not look like
485# a base name, ie is prefixed by -l or lib or is folled by .lib or .so.
486#
487# @param target
488# @param libraries
489#     A list of (base names of) libraries that will be added to the target
490#     local EXTERNAL_LIBS variable and eventually linked in when the
491#     target is made.
492#
493define gb_LinkTarget_add_external_libs
494
495# Make sure that all libraries are given as base names.
496ifneq (,$$(filter -l% lib% %.so %.lib, $(2)))
497$$(eval $$(call gb_Output_announce,ERROR: Please give only libary basenames to gb_LinkTarget_add_external_libs))
498$$(eval $$(call gb_Output_announce,ERROR:    (no prefixes -l% or lib%, no suffixes %.so or %.lib)))
499$$(eval $$(call gb_Output_announce,ERROR:    libraries given: $(2)))
500$$(eval $$(call gb_Output_announce,ERROR:    offending: $$(filter -l% lib% %.so %.lib, $(2))))
501$$(eval $$(call gb_Output_error,  ))
502endif
503
504$(call gb_LinkTarget_get_target,$(1)) : EXTERNAL_LIBS += $(2)
505
506$(call gb_LinkTarget_get_target,$(1)) : $$(foreach lib,$(2),$$(call gb_Library_get_target,$$(lib)))
507$(call gb_LinkTarget_get_external_headers_target,$(1)) : \
508$$(foreach lib,$(2),$$(call gb_Library_get_headers_target,$$(lib)))
509
510endef
511
512
513define gb_LinkTarget_add_cobject
514$(call gb_LinkTarget_get_target,$(1)) : COBJECTS += $(2)
515$(call gb_LinkTarget_get_clean_target,$(1)) : COBJECTS += $(2)
516
517$(call gb_LinkTarget_get_target,$(1)) : $(call gb_CObject_get_target,$(2))
518$(call gb_CObject_get_target,$(2)) : | $(call gb_LinkTarget_get_headers_target,$(1))
519$(call gb_CObject_get_target,$(2)) : CFLAGS += $(3)
520
521ifeq ($(gb_FULLDEPS),$(true))
522$(call gb_LinkTarget_get_dep_target,$(1)) : COBJECTS += $(2)
523$(call gb_LinkTarget_get_dep_target,$(1)) : $(call gb_CObject_get_dep_target,$(2))
524endif
525
526endef
527
528define gb_LinkTarget_add_cxxobject
529$(call gb_LinkTarget_get_target,$(1)) : CXXOBJECTS += $(2)
530$(call gb_LinkTarget_get_clean_target,$(1)) : CXXOBJECTS += $(2)
531
532$(call gb_LinkTarget_get_target,$(1)) : $(call gb_CxxObject_get_target,$(2))
533$(call gb_CxxObject_get_target,$(2)) : | $(call gb_LinkTarget_get_headers_target,$(1))
534$(call gb_CxxObject_get_target,$(2)) : CXXFLAGS += $(3)
535
536ifeq ($(gb_FULLDEPS),$(true))
537$(call gb_LinkTarget_get_dep_target,$(1)) : CXXOBJECTS += $(2)
538$(call gb_LinkTarget_get_dep_target,$(1)) : $(call gb_CxxObject_get_dep_target,$(2))
539endif
540
541endef
542
543define gb_LinkTarget_add_objcxxobject
544$(call gb_LinkTarget_get_target,$(1)) : OBJCXXOBJECTS += $(2)
545$(call gb_LinkTarget_get_clean_target,$(1)) : OBJCXXOBJECTS += $(2)
546
547$(call gb_LinkTarget_get_target,$(1)) : $(call gb_ObjCxxObject_get_target,$(2))
548$(call gb_ObjCxxObject_get_target,$(2)) : | $(call gb_LinkTarget_get_headers_target,$(1))
549$(call gb_ObjCxxObject_get_target,$(2)) : OBJCXXFLAGS += $(3)
550
551ifeq ($(gb_FULLDEPS),$(true))
552$(call gb_LinkTarget_get_dep_target,$(1)) : OBJCXXOBJECTS += $(2)
553$(call gb_LinkTarget_get_dep_target,$(1)) : $(call gb_ObjCxxObject_get_dep_target,$(2))
554endif
555
556endef
557
558define gb_LinkTarget_add_generated_cxx_object
559$(call gb_LinkTarget_get_target,$(1)) : GENCXXOBJECTS += $(2)
560$(call gb_LinkTarget_get_clean_target,$(1)) : GENCXXOBJECTS += $(2)
561
562$(call gb_LinkTarget_get_target,$(1)) : $(call gb_GenCxxObject_get_target,$(2))
563$(call gb_GenCxxObject_get_source,$(2)) : | $(call gb_LinkTarget_get_headers_target,$(1))
564$(call gb_GenCxxObject_get_target,$(2)) : CXXFLAGS += $(3) $(gb_COMPILEROPTFLAGS)
565
566ifeq ($(gb_FULLDEPS),$(true))
567$(call gb_LinkTarget_get_dep_target,$(1)) : GENCXXOBJECTS += $(2)
568$(call gb_LinkTarget_get_dep_target,$(1)) : $(call gb_GenCxxObject_get_dep_target,$(2))
569endif
570
571endef
572
573define gb_LinkTarget_add_noexception_object
574$(call gb_LinkTarget_add_cxxobject,$(1),$(2),$(gb_LinkTarget_NOEXCEPTIONFLAGS) $(gb_COMPILEROPTFLAGS))
575endef
576
577define gb_LinkTarget_add_exception_object
578$(call gb_LinkTarget_add_cxxobject,$(1),$(2),$(gb_LinkTarget_EXCEPTIONFLAGS) $(gb_COMPILEROPTFLAGS))
579endef
580
581define gb_LinkTarget_add_cobjects
582$(foreach obj,$(2),$(call gb_LinkTarget_add_cobject,$(1),$(obj),$(3)))
583endef
584
585define gb_LinkTarget_add_cxxobjects
586$(foreach obj,$(2),$(call gb_LinkTarget_add_cxxobject,$(1),$(obj),$(3)))
587endef
588
589define gb_LinkTarget_add_objcxxobjects
590$(foreach obj,$(2),$(call gb_LinkTarget_add_objcxxobject,$(1),$(obj),$(3)))
591endef
592
593define gb_LinkTarget_add_noexception_objects
594$(foreach obj,$(2),$(call gb_LinkTarget_add_noexception_object,$(1),$(obj)))
595endef
596
597define gb_LinkTarget_add_exception_objects
598$(foreach obj,$(2),$(call gb_LinkTarget_add_exception_object,$(1),$(obj)))
599endef
600
601define gb_LinkTarget_add_generated_exception_object
602$(call gb_LinkTarget_add_generated_cxx_object,$(1),$(2),$(gb_LinkTarget_EXCEPTIONFLAGS))
603endef
604
605define gb_LinkTarget_add_generated_exception_objects
606$(foreach obj,$(2),$(call gb_LinkTarget_add_generated_exception_object,$(1),$(obj)))
607endef
608
609define gb_LinkTarget_set_targettype
610$(call gb_LinkTarget_get_target,$(1)) \
611$(call gb_LinkTarget_get_dep_target,$(1)) : TARGETTYPE := $(2)
612endef
613
614define gb_LinkTarget_set_dlltarget
615$(call gb_LinkTarget_get_clean_target,$(1)) \
616$(call gb_LinkTarget_get_target,$(1)) : DLLTARGET := $(2)
617endef
618
619define gb_LinkTarget_set_auxtargets
620$(call gb_LinkTarget_get_clean_target,$(1)) : AUXTARGETS := $(2)
621endef
622
623define gb_LinkTarget__add_internal_headers
624$(call gb_LinkTarget_get_headers_target,$(1)) : $(2)
625$(2) :|	$(call gb_LinkTarget_get_external_headers_target,$(1))
626
627endef
628
629define gb_LinkTarget_add_package_headers
630$(foreach package,$(2),$(call gb_LinkTarget__add_internal_headers,$(1),$(call gb_Package_get_target,$(package))))
631$(call gb_LinkTarget_get_clean_target,$(1)) : $(foreach package,$(2),$(call gb_Package_get_clean_target,$(package)))
632
633endef
634
635define gb_LinkTarget_add_sdi_headers
636$(call gb_LinkTarget__add_internal_headers,$(1),$(foreach sdi,$(2),$(call gb_SdiTarget_get_target,$(sdi))))
637$(call gb_LinkTarget_get_clean_target,$(1)) : $(foreach sdi,$(2),$(call gb_SdiTarget_get_clean_target,$(sdi)))
638endef
639
640define gb_LinkTarget__add_precompiled_header_impl
641$(call gb_LinkTarget__add_internal_headers,$(1),$(call gb_PrecompiledHeader_get_target,$(3)))
642$(call gb_LinkTarget_get_clean_target,$(1)) : $(call gb_PrecompiledHeader_get_clean_target,$(3))
643$(call gb_PrecompiledHeader_get_target,$(3)) : $(2).cxx
644
645$(call gb_LinkTarget__add_internal_headers,$(1),$(call gb_NoexPrecompiledHeader_get_target,$(3)))
646$(call gb_LinkTarget_get_clean_target,$(1)) : $(call gb_NoexPrecompiledHeader_get_clean_target,$(3))
647$(call gb_NoexPrecompiledHeader_get_target,$(3)) : $(2).cxx
648
649$(call gb_LinkTarget_get_target,$(1)) : PCH_NAME := $(3)
650$(call gb_LinkTarget_get_target,$(1)) : PCHOBJS = $(call gb_PrecompiledHeader_get_target,$(3)).obj $(call gb_NoexPrecompiledHeader_get_target,$(3)).obj
651
652$(call gb_LinkTarget_get_headers_target,$(1)) \
653$(call gb_LinkTarget_get_target,$(1)) : DEFS := $$(DEFS) -DPRECOMPILED_HEADERS
654$(call gb_LinkTarget_get_headers_target,$(1)) \
655$(call gb_LinkTarget_get_target,$(1)) : PCH_DEFS = $$(DEFS)
656ifeq ($(gb_FULLDEPS),$(true))
657-include \
658	$(call gb_PrecompiledHeader_get_dep_target,$(3)) \
659	$(call gb_NoexPrecompiledHeader_get_dep_target,$(3))
660$(call gb_LinkTarget_get_dep_target,$(1)) : DEFS := $$(DEFS) -DPRECOMPILED_HEADERS
661$(call gb_LinkTarget_get_dep_target,$(1)) : PCH_DEFS = $$(DEFS)
662endif
663
664endef
665
666define gb_LinkTarget_add_precompiled_header
667ifeq ($(gb_ENABLE_PCH),$(true))
668$(call gb_LinkTarget__add_precompiled_header_impl,$(1),$(2),$(notdir $(2)))
669endif
670
671endef
672
673# vim: set noet sw=4 ts=4:
674