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