summaryrefslogtreecommitdiff
path: root/build-0.3/bootstrap.make
blob: 44eb57e115470f204dbcc6fdd430776fc0dd872f (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
# file      : build/bootstrap.make
# copyright : Copyright (c) 2004-2012 Code Synthesis Tools CC
# license   : GNU GPL v2; see accompanying LICENSE file

# First time bootstrap.make is read
#
ifndef %makefile%

# Configure make.
#

# Forces make to delete targets whos rebuild commands failed but
# updated the target.
#
.DELETE_ON_ERROR:

# Remove all built-in rules.
#
.SUFFIXES:

ifeq ($(filter -r,$(MAKEFLAGS)),)
MAKEFLAGS += -r
endif


# Disable implicit phony misfeature.
#
#ifeq ($(filter --no-implicit-phony,$(MAKEFLAGS)),)
#MAKEFLAGS += --no-implicit-phony
#endif

# Enable second expansion.
#
.SECONDEXPANSION:

# Force target. Used to force rule executions.
#
.PHONY: FORCE


# Export variables that could be useful for configuration scripts.
#
export bld_root
export MAKE

%replica%     :=
%foreign%     :=
%interactive% := t

# List of realpath'ed include-once files.
#
%included_files% :=

#$(warning init %included_files%: $(%included_files%))

# @@ maybe I should set makefile to bootstrap and restore it at the end.
#    This way I will be able to use %makefile% below (instead of _self) and
#    also it will be consistent.
#

# By convention, the makefile name is the second or third last word from
# the end. If it is the third, then the second one should be end with
# bootstrap.make
#
%makefile%          := $(subst $(lastword $(MAKEFILE_LIST)),,$(MAKEFILE_LIST))
ifneq ($(filter %bootstrap.make,$(lastword $(%makefile%))),)
%makefile%          := $(subst $(lastword $(%makefile%)),,$(%makefile%))
endif
%makefile%          := $(abspath $(lastword $(%makefile%)))

%makefile_realpath% := $(realpath $(%makefile%))


#
# include facility
#

# Execute makefile search algorithm. Return abspath of the makefile if found
# and empty string otherwise.
#
%frame_exclude% += include-find-makefile
define include-find-makefile
$(if $(wildcard $1),\
$(abspath $1),\
$(if $(filter-out /%,$1),\
$(call include-search-dirs,$1,$(.INCLUDE_DIRS))))
endef

# Search for $1 in the list of directoris $2
#
%frame_exclude% += include-search-dirs
define include-search-dirs
$(if $(strip $2),\
$(if $(wildcard $(firstword $2)/$1),\
$(abspath $(firstword $2)/$1),\
$(call include-search-dirs,$1,$(wordlist 2,$(words $2),$2))))
endef

# Test if $1 is a 'foreign' makefile, i.e., does not reside in
# src_root, out_root, or bld_root. Use shadows for src and out
# roots to catch cases where these were reset before inclusion.
# This happens in import stubs.
#
%frame_exclude% += include-test-foreign
define include-test-foreign
$(if $(%foreign%),t,$(if $(filter $(bld_root)/% $(src_root_shadow)/% $(out_root_shadow)/%,$1),,t))
endef

%frame_exclude% += include-body
define include-body
%interactive%       :=
%makefile%          := $(call include-find-makefile,$2)
%makefile_realpath% := $$(realpath $$(%makefile%))
%foreign%           := $$(call include-test-foreign,$$(%makefile%))

$1 $$(if $$(%makefile%),$$(%makefile%),$2)

%makefile_realpath% := $3
%makefile%          := $4
%interactive%       := $5
%foreign%           := $6
endef

%frame_exclude% += include
define include
$(eval $(foreach f,$1,\
  $(call include-body,\
    include,$f,$(%makefile_realpath%),$(%makefile%),$(%interactive%),$(%foreign%))))
endef

%frame_exclude% += -include
define -include
$(eval $(foreach f,$1,\
  $(call include-body,\
    -include,$f,$(%makefile_realpath%),$(%makefile%),$(%interactive%),$(%foreign%))))
endef


#
# include-once
#

# This one simply delegates to the include directive to get the
# error message.
#
# $1 : include/-include
# $2 : file
#
%frame_exclude% += include-once-failed-body
define include-once-failed-body
$1 $2
endef

#
# $1 : include/-include
# $2 : file
#
%frame_exclude% += include-once-file-body
define include-once-file-body
%interactive%       :=
%makefile%          := $2
%makefile_realpath% := $(realpath $2)
%foreign%           := $$(call include-test-foreign,$$(%makefile%))

%included_files%    += $$(%makefile_realpath%)

$1 $2

%makefile_realpath% := $3
%makefile%          := $4
%interactive%       := $5
%foreign%           := $6
endef


%frame_exclude% += include-once-file-filter
define include-once-file-filter
$(if $(filter $(realpath $2),$(%included_files%)),,\
  $(call include-once-file-body,\
    $1,$2,$(%makefile_realpath%),$(%makefile%),$(%interactive%),$(%foreign%)))
endef

#
# $1 : include/-include
# $2 : file
# $6 : value
#

%frame_exclude% += include-once-value-body
define include-once-value-body
%interactive%       :=
%makefile%          := $2
%makefile_realpath% := $(realpath $2)
%foreign%           := $$(call include-test-foreign,$$(%makefile%))

%include_once_$$(%makefile_realpath%)% += $7

$1 $2

%makefile_realpath% := $3
%makefile%          := $4
%interactive%       := $5
%foreign%           := $6
endef


%frame_exclude% += include-once-value-filter
define include-once-value-filter
$(if $(filter $3,$(value %include_once_$(realpath $2)%)),,\
  $(call include-once-value-body,\
    $1,$2,$(%makefile_realpath%),$(%makefile%),$(%interactive%),$(%foreign%),$3))
endef


# $1 - include/-include
# $2 - abspath or empty if not found
# $3 - orginal path
# $4 - value [optional]
#
%frame_exclude% += include-once-filter
define include-once-filter
$(if $2,\
$(if $4,\
$(call include-once-value-filter,$1,$2,$4),\
$(call include-once-file-filter,$1,$2)),\
$(call include-once-failed-body,$1,$3))
endef

%frame_exclude% += include-once
define include-once
$(eval $(call include-once-filter,\
include,$(call include-find-makefile,$1),$1,$(strip $2)))
endef

%frame_exclude% += -include-once
define -include-once
$(eval $(call include-once-filter,\
-include,$(call include-find-makefile,$1),$1,$(strip $2)))
endef


#$(warning include facility is up)

endif # %makefile%

#
#
bld_root := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))


# initialize {src,out}_{root,base}
#
%frame_exclude% += find-bootstrap-base
define find-bootstrap-base
$(if $(findstring $(abspath $(lastword $1)),$(%makefile%)),$2,\
$(call find-bootstrap-base,\
$(wordlist 1,$(words $(wordlist 2,$(words $1),$1)),$1),\
$(lastword $1)))
endef

src_root := $(abspath $(dir $(call find-bootstrap-base,$(MAKEFILE_LIST)))..)
src_base := $(abspath $(dir $(%makefile%)))

ifneq ($(src_root),$(src_base))

# In recursive make invocation, out_root may come from the environment
# in which case we need to override it.
#
ifneq ($(origin out_root),file)
  out_root := $(abspath $(patsubst \
    %$(subst $(src_root)/,,$(src_base)),%,$(CURDIR)))
endif

out_base := $(out_root)/$(subst $(src_root)/,,$(src_base))

else

# In recursive make invocation, out_root may come from the environment
# in which case we need to override it.
#
ifneq ($(origin out_root),file)
  out_root := $(abspath $(CURDIR))
endif

out_base := $(out_root)

endif

scf_root := $(src_root)/build
dcf_root := $(out_root)/build

src_root_shadow := $(src_root)
out_root_shadow := $(out_root)

$(out_root)/%: export out_root := $(out_root)
$(out_root)/%: export src_root := $(src_root)
$(out_root)/%: export scf_root := $(scf_root)
$(out_root)/%: export dcf_root := $(dcf_root)
$(out_root)/%: export project_name := $(project_name)

# @@ Why do I need out_root here?
#
$(out_base)/%: out_root := $(out_root)
$(out_base)/%: export out_base := $(out_base)
$(out_base)/%: export src_base := $(src_base)

ifdef build_debug

$(warning "bld root: $(bld_root)")
$(warning "scf root: $(scf_root)")
$(warning "dcf root: $(dcf_root)")
$(warning "src root: $(src_root)")
$(warning "src base: $(src_base)")
$(warning "out root: $(out_root)")
$(warning "out base: $(out_base)")

endif

#$(warning paths are set)

# frame facility
#
$(call include-once,$(bld_root)/frame.make)

# import facility
#
$(call include-once,$(bld_root)/import.make)

# Load some common facilities.
#
$(call include-once,$(bld_root)/literals.make)
$(call include-once,$(bld_root)/message.make)
$(call include-once,$(bld_root)/dir.make)


# Static configuration.
#
$(call include,$(bld_root)/configuration-static.make)

ifneq ($(bld_root),$(scf_root))
$(call -include,$(scf_root)/configuration-static.make)
endif

# `disfigure' target.
#
.PHONY: disfigure
.PHONY: $(dcf_root)/.disfigure $(out_root)/.disfigure

disfigure:: $(build_absolute_clean_target)
disfigure:: $(dcf_root)/.disfigure
disfigure:: $(out_root)/.disfigure

ifneq ($(out_root),$(out_base))
.PHONY: $(out_base)/.disfigure
$(out_root)/.disfigure:: $(out_base)/.disfigure
endif

# Clean up generated makefiles.
#
ifndef %foreign%
ifneq ($(out_root),$(src_root))
$(out_base)/.disfigure::
	$(call message, rm $$1,rm -f $$1,$(out_base)/makefile)
endif
endif

# Dynamic configuration (interactive check is to make sure we only do
# this once).
#
ifdef %interactive%
ifneq ($(out_root),$(src_root))

$(call -include,$(dcf_root)/bootstrap-dynamic.make)

$(dcf_root)/bootstrap-dynamic.make: | $(dcf_root)/.
	$(call message,,echo "src_root := $(src_root)" >$@)

$(dcf_root)/.disfigure::
	$(call message, rm $$1,rm -f $$1,$(dcf_root)/bootstrap-dynamic.make)
endif
endif

ifeq ($(.DEFAULT_GOAL),disfigure)
.DEFAULT_GOAL :=
endif