summaryrefslogtreecommitdiffstats
path: root/kBuild/footer-pass1.kmk
blob: dc31329ad630b3fc44ca1ff9bf64c8c5d3619aed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
# $Id: footer-pass1.kmk 3417 2020-08-21 10:59:17Z bird $
## @file
# kBuild - Footer - Target lists - Pass 1.
#
#       This pass is for defining variables that might be referenced in
#       properties of other targets.
#

#
# Copyright (c) 2004-2017 knut st. osmundsen <bird-kBuild-spam-xviiv@anduin.net>
#
# This file is part of kBuild.
#
# kBuild is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version source of the License, or
# (at your option) any later version.
#
# kBuild is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with kBuild; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#
# As a special exception you are granted permission to include this file, via
# the kmk include directive, as you wish without this in itself causing the
# resulting makefile, program or whatever to be covered by the GPL license.
# This exception does not however invalidate any other reasons why the makefile,
# program, whatever should not be covered the GPL.
#
#


# Don't do anything for fetch targets (yet).

##
# Link prolog for Pass 1.
#
# @param    $(target)           Normalized target name.
# @param    $(EXT)              EXE,DLL,SYS,LIB.
# @param    $(EXTPRE)           HOST or nothing.
# @param    $(definst)          The default _INST value.
# @param    $(tool_prefix)      LD or AR.
# @param    $(bld_trg_base_var) TARGET or HOST.
define def_pass1_link_common

local bld_type    := $(firstword $($(target)_BLD_TYPE)     $(KBUILD_TYPE))
local bld_trg     := $(firstword $($(target)_BLD_TRG)      $(KBUILD_$(bld_trg_base_var)))
local bld_trg_arch:= $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_$(bld_trg_base_var)_ARCH))
local bld_trg_cpu := $(firstword $($(target)_BLD_TRG_CPU)  $(KBUILD_$(bld_trg_base_var)_CPU))

local tool        := $(call _TARGET_TOOL,$(target),$(tool_prefix))
local name        := $(firstword\
	$($(target)_NAME.$(bld_trg).$(bld_trg_arch).$(bld_type))\
	$($(target)_NAME.$(bld_trg).$(bld_trg_arch))\
	$($(target)_NAME.$(bld_trg).$(bld_type))\
	$($(target)_NAME.$(bld_trg_arch))\
	$($(target)_NAME.$(bld_trg))\
	$($(target)_NAME.$(bld_type))\
	$($(target)_NAME)\
	$(target))
local outbase     := $(call TARGET_BASE,$(name),$(target))
$(target)_0_OUTDIR:= $(patsubst %/,%,$(dir $(outbase)))
$(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)

## @todo fix the fun at the last line (AR != LIB => mess).
local suff := $(firstword \
	$($(target)_$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
	$($(target)_$(EXT)SUFF.$(bld_trg))\
	$($(target)_$(EXT)SUFF)\
	$(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF.$(bld_trg).$(bld_trg_arch))\
	$(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF.$(bld_trg))\
	$(TOOL_$(tool)_$(tool_prefix)$(EXT)SUFF)\
	$(if $(eq $(tool_prefix),AR),$(SUFF_LIB),$($(EXTPRE)SUFF_$(EXT))) )
local out := $(outbase)$(suff)

# Object directory target variable.
$(target)_1_TARGET := $(out)
$(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)

# Staging and install directory target variables.
local insttype := $(firstword \
	$($(target)_INSTTYPE.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
	$($(target)_INSTTYPE.$(bld_trg).$(bld_trg_arch)) \
	$($(target)_INSTTYPE.$(bld_trg).$(bld_type)) \
	$($(target)_INSTTYPE.$(bld_trg_arch)) \
	$($(target)_INSTTYPE.$(bld_trg_cpu)) \
	$($(target)_INSTTYPE.$(bld_trg)) \
	$($(target)_INSTTYPE.$(bld_type)) \
	$($(target)_INSTTYPE) \
	)
ifeq ($(insttype),)
 ifneq ($(firstword \
	$($(target)_NOINST) \
	$($(target)_NOINST.$(bld_trg)) \
	$($(target)_NOINST.$(bld_trg).$(bld_trg_arch)) \
	$($(target)_NOINST.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
	$($(target)_NOINST.$(bld_trg_arch)) \
	$($(target)_NOINST.$(bld_trg_cpu)) \
	$($(target)_NOINST.$(bld_type)) ),)
   local insttype := none
 else
   local insttype := both
 endif
endif
$(target)_1_INSTTYPE := $(insttype)

local inst := $(strip $(firstdefined \
	$(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type) \
	$(target)_INST.$(bld_trg).$(bld_trg_arch) \
	$(target)_INST.$(bld_trg).$(bld_type) \
	$(target)_INST.$(bld_trg_arch) \
	$(target)_INST.$(bld_trg_cpu) \
	$(target)_INST.$(bld_trg) \
	$(target)_INST.$(bld_type) \
	$(target)_INST \
	definst \
	,value))
local stage := $(strip $(firstdefined \
	$(target)_STAGE.$(bld_trg).$(bld_trg_arch).$(bld_type) \
	$(target)_STAGE.$(bld_trg).$(bld_trg_arch) \
	$(target)_STAGE.$(bld_trg).$(bld_type) \
	$(target)_STAGE.$(bld_trg_arch) \
	$(target)_STAGE.$(bld_trg_cpu) \
	$(target)_STAGE.$(bld_trg) \
	$(target)_STAGE.$(bld_type) \
	$(target)_STAGE \
	inst \
	,value))
if1of ($(insttype), stage both)
 $(target)_1_STAGE := $(stage)
 if "$(substr $(stage),-1,1)" == "/" # Multicast support requires addprefix/suffix.
  $(target)_1_STAGE_TARGET := $(addprefix $(PATH_STAGE)/,$(addsuffix $(notdir $(out)),$(stage)))
 else if "$(stage)" == ""
  $(target)_1_STAGE_TARGET := $(PATH_STAGE)/$(notdir $(out))
 else
  $(target)_1_STAGE_TARGET := $(addprefix $(PATH_STAGE)/,$(stage))
 endif
else if1of ($(insttype), none)
 $(target)_1_STAGE :=
 $(target)_1_STAGE_TARGET :=
else
 $(error kBuild: Unknown value '$(insttype)' for '$(target)_INSTTYPE'. Valid values are 'none', 'both' and 'stage'.)
endif
INSTARGET_$(target) := $($(target)_1_STAGE_TARGET)

if1of ($(insttype), both)
 $(target)_1_INST := $(inst)
 if "$(substr $(inst),-1,1)" == "/" # Multicast support requires addprefix/suffix.
  $(target)_1_INST_TARGET := $(addprefix $(PATH_INS)/,$(addsuffix $(notdir $(out)),$(inst)))
 else if "$(inst)" == ""
  $(target)_1_INST_TARGET := $(PATH_INS)/$(notdir $(out))
 else
  $(target)_1_INST_TARGET := $(addprefix $(PATH_INS)/,$(inst))
 endif
else
 $(target)_1_INST :=
 $(target)_1_INST_TARGET :=
endif

# Debug info related stuff.
local debug_insttype := $(firstword \
	$($(target)_DEBUG_INSTTYPE.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
	$($(target)_DEBUG_INSTTYPE.$(bld_trg).$(bld_trg_arch)) \
	$($(target)_DEBUG_INSTTYPE.$(bld_trg).$(bld_type)) \
	$($(target)_DEBUG_INSTTYPE.$(bld_trg_arch)) \
	$($(target)_DEBUG_INSTTYPE.$(bld_trg_cpu)) \
	$($(target)_DEBUG_INSTTYPE.$(bld_trg)) \
	$($(target)_DEBUG_INSTTYPE.$(bld_type)) \
	$($(target)_DEBUG_INSTTYPE) \
	$(insttype) )
$(target)_1_DEBUG_INSTTYPE := $(debug_insttype)

if1of ($(debug_insttype), stage both)
 local debug_stage := $(firstdefined \
	$(target)_DEBUG_STAGE.$(bld_trg).$(bld_trg_arch).$(bld_type) \
	$(target)_DEBUG_STAGE.$(bld_trg).$(bld_trg_arch) \
	$(target)_DEBUG_STAGE.$(bld_trg).$(bld_type) \
	$(target)_DEBUG_STAGE.$(bld_trg_arch) \
	$(target)_DEBUG_STAGE.$(bld_trg_cpu) \
	$(target)_DEBUG_STAGE.$(bld_trg) \
	$(target)_DEBUG_STAGE.$(bld_type) \
	$(target)_DEBUG_STAGE \
	$(target)_DEBUG_INST.$(bld_trg).$(bld_trg_arch).$(bld_type) \
	$(target)_DEBUG_INST.$(bld_trg).$(bld_trg_arch) \
	$(target)_DEBUG_INST.$(bld_trg).$(bld_type) \
	$(target)_DEBUG_INST.$(bld_trg_arch) \
	$(target)_DEBUG_INST.$(bld_trg_cpu) \
	$(target)_DEBUG_INST.$(bld_trg) \
	$(target)_DEBUG_INST.$(bld_type) \
	$(target)_DEBUG_INST)
 ifneq ($(debug_stage),)
  $(target)_1_DEBUG_STAGE := $($(debug_stage))
 else
  $(target)_1_DEBUG_STAGE := $(addprefix $(STAGE_DEBUG),$(stage))
 endif
 ifndef $(target)_1_DEBUG_STAGE
  $(target)_1_DEBUG_STAGE := ./
 endif
else if1of ($(debug_insttype), none)
 $(target)_1_DEBUG_STAGE :=
else
 $(error kBuild: Unknown value '$(debug_insttype)' for '$(target)_DEBUG_INSTTYPE'. Valid values are 'none', 'both' and 'stage'.)
endif

if1of ($(debug_insttype), both)
 local debug_inst := $(firstdefined \
	$(target)_DEBUG_INST.$(bld_trg).$(bld_trg_arch).$(bld_type) \
	$(target)_DEBUG_INST.$(bld_trg).$(bld_trg_arch) \
	$(target)_DEBUG_INST.$(bld_trg).$(bld_type) \
	$(target)_DEBUG_INST.$(bld_trg_arch) \
	$(target)_DEBUG_INST.$(bld_trg_cpu) \
	$(target)_DEBUG_INST.$(bld_trg) \
	$(target)_DEBUG_INST.$(bld_type) \
	$(target)_DEBUG_INST)
 ifneq ($(debug_inst),)
  $(target)_1_DEBUG_INST := $($(debug_inst))
 else
  $(target)_1_DEBUG_INST := $(addprefix $(INST_DEBUG),$(inst))
 endif
 ifndef $(target)_1_DEBUG_INST
  $(target)_1_DEBUG_INST := ./
 endif
else
 $(target)_1_DEBUG_INST :=
endif
#$(warning $(NLTAB)$(target)_1_DEBUG_INST=$($(target)_1_DEBUG_INST)$(NLTAB)$(target)_1_DEBUG_STAGE=$($(target)_1_DEBUG_STAGE)$(NLTAB)insttype=$(insttype)$(NLTAB)debug_insttype=$(debug_insttype))

endef # def_pass1_link_common
$(eval-opt-var def_pass1_link_common)


#
# BLDPROGS (Pass 1)
#
define def_pass1_bldprog
# set NOINST if not forced installation before doing the usual stuff.
ifndef $(target)_INSTTYPE
 ifndef $(target)_INST
  ifndef $(target)_STAGE
$(target)_INSTTYPE := none
  endif
 endif
endif
$(evalvalctx def_pass1_link_common)
endef

EXT     := EXE
EXTPRE  := HOST
definst := $(INST_BIN)
tool_prefix := LD
bld_trg_base_var := HOST
$(foreach target, $(_ALL_BLDPROGS), \
	$(evalvalctx def_pass1_bldprog))


#
# LIBRARIES (Pass 1)
#
EXT     := LIB
EXTPRE  :=
definst := $(INST_LIB)
tool_prefix := AR
bld_trg_base_var := TARGET
$(foreach target, $(_ALL_LIBRARIES), \
	$(evalvalctx def_pass1_link_common))


#
# DLLS  (Pass 1)
#
EXT     := DLL
EXTPRE  :=
definst := $(INST_DLL)
tool_prefix := LD
bld_trg_base_var := TARGET
$(foreach target, $(_ALL_DLLS), \
	$(evalvalctx def_pass1_link_common))


#
# IMPORT LIBRARIES (Pass 1)
#
#   - On OS/2 and windows these are libraries.
#   - On other platforms they are fake DLLs.
#
if1of ($(KBUILD_TARGET), nt os2 win win64 win32)
 EXT     := LIB
 EXTPRE  :=
 definst := $(INST_LIB)
 tool_prefix := AR
 bld_trg_base_var := TARGET
 $(foreach target, $(_ALL_IMPORT_LIBS), \
	$(evalvalctx def_pass1_link_common))
else
 EXT     := DLL
 EXTPRE  :=
 definst := $(INST_DLL)
 tool_prefix := LD
 bld_trg_base_var := TARGET
 $(foreach target, $(_ALL_IMPORT_LIBS), \
	$(evalvalctx def_pass1_link_common))
endif


#
# PROGRAMS (Pass 1)
#
EXT     := EXE
EXTPRE  :=
definst := $(INST_BIN)
tool_prefix := LD
bld_trg_base_var := TARGET
$(foreach target, $(_ALL_PROGRAMS), \
	$(evalvalctx def_pass1_link_common))


#
# SYSMODS (Pass 1)
#
EXT     := SYS
EXTPRE  :=
definst := $(INST_SYS)
tool_prefix := LD
bld_trg_base_var := TARGET
$(foreach target, $(_ALL_SYSMODS), \
	$(evalvalctx def_pass1_link_common))


#
# MISCBINS (Pass 1)
#
EXT     := BIN
EXTPRE  :=
definst := $(INST_BIN)
tool_prefix := LD
bld_trg_base_var := TARGET
$(foreach target, $(_ALL_MISCBINS), \
	$(evalvalctx def_pass1_link_common))


#
# INSTALLS (Pass 1)
# 	Note! INSTARGET_* for INSTALLS aren't available until later.
#
define def_pass1_install
local bld_type     := $(firstword $($(target)_BLD_TYPE)     $(KBUILD_TYPE))
local bld_trg      := $(firstword $($(target)_BLD_TRG)      $(KBUILD_TARGET))
local bld_trg_arch := $(firstword $($(target)_BLD_TRG_ARCH) $(KBUILD_TARGET_ARCH))
local bld_trg_cpu  := $(firstword $($(target)_BLD_TRG_CPU)  $(KBUILD_TARGET_CPU))
# _1_TARGET
$(target)_1_TARGET := $(PATH_TARGET)/$(target).ins
$(call KB_FN_ASSIGN_DEPRECATED,TARGET_$(target),$($(target)_1_TARGET), $(target)_1_TARGET)

# Determine and set 1_INSTTYPE.
local insttype := $(firstword \
	$($(target)_INSTTYPE.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
	$($(target)_INSTTYPE.$(bld_trg).$(bld_trg_arch)) \
	$($(target)_INSTTYPE.$(bld_trg).$(bld_type)) \
	$($(target)_INSTTYPE.$(bld_trg_arch)) \
	$($(target)_INSTTYPE.$(bld_trg_cpu)) \
	$($(target)_INSTTYPE.$(bld_trg)) \
	$($(target)_INSTTYPE.$(bld_type)) \
	$($(target)_INSTTYPE) \
	)
ifeq ($(insttype),)
 ifneq ($(firstword \
	$($(target)_NOINST) \
	$($(target)_NOINST.$(bld_trg)) \
	$($(target)_NOINST.$(bld_trg).$(bld_trg_arch)) \
	$($(target)_NOINST.$(bld_trg).$(bld_trg_arch).$(bld_type)) \
	$($(target)_NOINST.$(bld_trg_arch)) \
	$($(target)_NOINST.$(bld_trg_cpu)) \
	$($(target)_NOINST.$(bld_type)) ),)
   local insttype := none
 else
   local insttype := both
 endif
endif
ifn1of ($(insttype), none both stage)
 $(error kBuild: Unknown value '$(insttype)' for '$(target)_INSTTYPE'. Valid values are 'none', 'both' and 'stage'.)
endif
$(target)_1_INSTTYPE    := $(insttype)

# Determine the actual INST and STAGE sub-dirs to use for this target.
if1of ($(insttype), stage both)
 local stage := $(strip $(firstdefined \
	$(target)_STAGE.$(bld_trg).$(bld_trg_arch).$(bld_type) \
	$(target)_STAGE.$(bld_trg).$(bld_trg_arch) \
	$(target)_STAGE.$(bld_trg).$(bld_type) \
	$(target)_STAGE.$(bld_trg_arch) \
	$(target)_STAGE.$(bld_trg_cpu) \
	$(target)_STAGE.$(bld_trg) \
	$(target)_STAGE.$(bld_type) \
	$(target)_STAGE \
	$(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type) \
	$(target)_INST.$(bld_trg).$(bld_trg_arch) \
	$(target)_INST.$(bld_trg).$(bld_type) \
	$(target)_INST.$(bld_trg_arch) \
	$(target)_INST.$(bld_trg_cpu) \
	$(target)_INST.$(bld_trg) \
	$(target)_INST.$(bld_type) \
	$(target)_INST \
	definst \
	,value))
 if $(words $(stage)) > 1
  $(warning kBuild: The STAGE/INST property of install '$(target)' specifies multiple location, that is not supported.)
  local stage := $(word 1, $(stage))
 endif
 $(target)_1_STAGE := $(stage)
else
 $(target)_1_STAGE = $(error _1_STAGE not used)
endif

if1of ($(insttype), both)
 local inst := $(strip $(firstdefined \
	$(target)_INST.$(bld_trg).$(bld_trg_arch).$(bld_type) \
	$(target)_INST.$(bld_trg).$(bld_trg_arch) \
	$(target)_INST.$(bld_trg).$(bld_type) \
	$(target)_INST.$(bld_trg_arch) \
	$(target)_INST.$(bld_trg_cpu) \
	$(target)_INST.$(bld_trg) \
	$(target)_INST.$(bld_type) \
	$(target)_INST \
	definst \
	,value))
 if $(words $(inst)) > 1
  $(warning kBuild: The INST property of install '$(target)' specifies multiple location, that is not supported.)
  local inst := $(word 1, $(inst))
 endif
 ifneq ($(root $(stage)),)
  $(error kBuild: The effective INST property of install '$(target)' should not start with a root specification)
 endif
 $(target)_1_INST := $(inst)
else
 $(target)_1_INST = $(error _1_INST not used)
endif

# Block properties that we put off setting until pass 2 for INSTALLS.
$(target)_1_STAGE_TARGET = $(error The '_1_STAGE_TARGET' property is not present on install targets.  Use '_2_STAGE_TARGETS' instead (set by pass 2!).)
$(target)_1_INST_TARGET  = $(error The '_1_INST_TARGET' property is not present on install targets.  Use '_2_INST_TARGETS' instead (set by pass 2!).)
INSTARGET_$(target)      = $(error The 'INSTARGET_' is deprecated and besides, it is being accessed to early.  Consider '_2_STAGE_TARGETS' or '_2_INST_TARGETS'.)

# INSTARGET_ later.
# PATH_*
local outbase      := $(call TARGET_BASE,$(target),$(target))
$(target)_0_OUTDIR := $(patsubst %/,%,$(dir $(outbase)))
$(call KB_FN_ASSIGN_DEPRECATED,PATH_$(target),$($(target)_0_OUTDIR), $(target)_0_OUTDIR)
endef # def_pass1_install
$(eval-opt-var def_pass1_install)

$(foreach target, $(_ALL_INSTALLS), \
	$(evalvalctx def_pass1_install))

ifdef KBUILD_PROFILE_SELF
 $(evalcall def_profile_self, done pass 1)
endif