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