~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to roms/ipxe/src/Makefile.housekeeping

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- makefile -*- : Force emacs to use Makefile mode
 
2
#
 
3
# This file contains various boring housekeeping functions that would
 
4
# otherwise seriously clutter up the main Makefile.
 
5
 
 
6
###############################################################################
 
7
#
 
8
# Find a usable "echo -e" substitute.
 
9
#
 
10
TAB                     := $(shell $(PRINTF) '\t')
 
11
ECHO_E_ECHO             := $(ECHO)
 
12
ECHO_E_ECHO_E           := $(ECHO) -e
 
13
ECHO_E_BIN_ECHO         := /bin/echo
 
14
ECHO_E_BIN_ECHO_E       := /bin/echo -e
 
15
ECHO_E_ECHO_TAB         := $(shell $(ECHO_E_ECHO) '\t' | cat)
 
16
ECHO_E_ECHO_E_TAB       := $(shell $(ECHO_E_ECHO_E) '\t' | cat)
 
17
ECHO_E_BIN_ECHO_TAB     := $(shell $(ECHO_E_BIN_ECHO) '\t')
 
18
ECHO_E_BIN_ECHO_E_TAB   := $(shell $(ECHO_E_BIN_ECHO_E) '\t')
 
19
 
 
20
ifeq ($(ECHO_E_ECHO_TAB),$(TAB))
 
21
ECHO_E          := $(ECHO_E_ECHO)
 
22
endif
 
23
ifeq ($(ECHO_E_ECHO_E_TAB),$(TAB))
 
24
ECHO_E          := $(ECHO_E_ECHO_E)
 
25
endif
 
26
ifeq ($(ECHO_E_BIN_ECHO_TAB),$(TAB))
 
27
ECHO_E          := $(ECHO_E_BIN_ECHO)
 
28
endif
 
29
ifeq ($(ECHO_E_BIN_ECHO_E_TAB),$(TAB))
 
30
ECHO_E          := $(ECHO_E_BIN_ECHO_E)
 
31
endif
 
32
 
 
33
.echocheck :
 
34
ifdef ECHO_E
 
35
        @$(TOUCH) $@
 
36
else
 
37
        @$(PRINTF) '%24s : x%sx\n' 'tab' '$(TAB)'
 
38
        @$(PRINTF) '%24s : x%sx\n' '"$(ECHO_E_ECHO) \t"' \
 
39
                                    '$(ECHO_E_ECHO_TAB)'
 
40
        @$(PRINTF) '%24s : x%sx\n' '"$(ECHO_E_ECHO_E) \t"' \
 
41
                                    '$(ECHO_E_ECHO_E_TAB)'
 
42
        @$(PRINTF) '%24s : x%sx\n' '"$(ECHO_E_BIN_ECHO) \t"' \
 
43
                                    '$(ECHO_E_BIN_ECHO_TAB)'
 
44
        @$(PRINTF) '%24s : x%sx\n' '"$(ECHO_E_BIN_ECHO_E) \t"' \
 
45
                                    '$(ECHO_E_BIN_ECHO_E_TAB)'
 
46
        @$(ECHO) "No usable \"echo -e\" substitute found"
 
47
        @exit 1
 
48
endif
 
49
MAKEDEPS        += .echocheck
 
50
VERYCLEANUP     += .echocheck
 
51
 
 
52
echo :
 
53
        @$(ECHO) "Using \"$(ECHO_E)\" for \"echo -e\""
 
54
 
 
55
###############################################################################
 
56
#
 
57
# Generate a usable "seq" substitute
 
58
#
 
59
define seq
 
60
        $(shell awk 'BEGIN { for ( i = $(1) ; i <= $(2) ; i++ ) print i }')
 
61
endef
 
62
 
 
63
###############################################################################
 
64
#
 
65
# Determine host OS
 
66
#
 
67
HOST_OS         := $(shell uname -s)
 
68
hostos :
 
69
        @$(ECHO) $(HOST_OS)
 
70
 
 
71
###############################################################################
 
72
#
 
73
# Determine compiler
 
74
 
 
75
CCDEFS          := $(shell $(CC) -E -x c -c /dev/null -dM | cut -d" " -f2)
 
76
ccdefs:
 
77
        @$(ECHO) $(CCDEFS)
 
78
 
 
79
ifeq ($(filter __ICC,$(CCDEFS)),__ICC)
 
80
CCTYPE          := icc
 
81
else
 
82
CCTYPE          := gcc
 
83
endif
 
84
cctype:
 
85
        @$(ECHO) $(CCTYPE)
 
86
 
 
87
###############################################################################
 
88
#
 
89
# Check for tools that can cause failed builds
 
90
#
 
91
 
 
92
ifeq ($(CCTYPE),gcc)
 
93
GCC_2_96_BANNER := $(shell $(CC) -v 2>&1 | grep -is 'gcc version 2\.96')
 
94
ifneq ($(GCC_2_96_BANNER),)
 
95
$(warning gcc 2.96 is unsuitable for compiling iPXE)
 
96
$(warning Use gcc 2.95 or a newer version instead)
 
97
$(error Unsuitable build environment found)
 
98
endif
 
99
endif
 
100
 
 
101
PERL_UNICODE_CHECK := $(shell $(PERL) -e 'use bytes; print chr(255)' | wc -c)
 
102
ifeq ($(PERL_UNICODE_CHECK),2)
 
103
$(warning Your Perl version has a Unicode handling bug)
 
104
$(warning Execute this command before building iPXE:)
 
105
$(warning export LANG=$${LANG%.UTF-8})
 
106
$(error Unsuitable build environment found)
 
107
endif
 
108
 
 
109
LD_GOLD_BANNER := $(shell $(LD) -v 2>&1 | grep 'GNU gold')
 
110
ifneq ($(LD_GOLD_BANNER),)
 
111
$(warning GNU gold is unsuitable for building iPXE)
 
112
$(warning Use GNU ld instead)
 
113
$(error Unsuitable build environment found)
 
114
endif
 
115
 
 
116
###############################################################################
 
117
#
 
118
# Check if $(eval ...) is available to use
 
119
#
 
120
 
 
121
HAVE_EVAL :=
 
122
ifndef NO_EVAL
 
123
$(eval HAVE_EVAL := yes)
 
124
endif
 
125
eval :
 
126
        @$(ECHO) $(HAVE_EVAL)
 
127
 
 
128
###############################################################################
 
129
#
 
130
# Check for various tool workarounds
 
131
#
 
132
 
 
133
WORKAROUND_CFLAGS :=
 
134
WORKAROUND_ASFLAGS :=
 
135
WORKAROUND_LDFLAGS :=
 
136
 
 
137
# Make syntax does not allow use of comma or space in certain places.
 
138
# This ugly workaround is suggested in the manual.
 
139
#
 
140
COMMA   := ,
 
141
EMPTY   :=
 
142
SPACE   := $(EMPTY) $(EMPTY)
 
143
HASH    := \#
 
144
define NEWLINE
 
145
 
 
146
 
 
147
endef
 
148
 
 
149
# Some widespread patched versions of gcc include -fstack-protector by
 
150
# default, even when -ffreestanding is specified.  We therefore need
 
151
# to disable -fstack-protector if the compiler supports it.
 
152
#
 
153
ifeq ($(CCTYPE),gcc)
 
154
SP_TEST = $(CC) -fno-stack-protector -x c -c /dev/null \
 
155
                -o /dev/null >/dev/null 2>&1
 
156
SP_FLAGS := $(shell $(SP_TEST) && $(ECHO) '-fno-stack-protector')
 
157
WORKAROUND_CFLAGS += $(SP_FLAGS)
 
158
endif
 
159
 
 
160
# gcc 4.4 generates .eh_frame sections by default, which distort the
 
161
# output of "size".  Inhibit this.
 
162
#
 
163
ifeq ($(CCTYPE),gcc)
 
164
CFI_TEST = $(CC) -fno-dwarf2-cfi-asm -fno-exceptions -fno-unwind-tables \
 
165
                 -fno-asynchronous-unwind-tables -x c -c /dev/null \
 
166
                 -o /dev/null >/dev/null 2>&1
 
167
CFI_FLAGS := $(shell $(CFI_TEST) && \
 
168
               $(ECHO) '-fno-dwarf2-cfi-asm -fno-exceptions ' \
 
169
                       '-fno-unwind-tables -fno-asynchronous-unwind-tables')
 
170
WORKAROUND_CFLAGS += $(CFI_FLAGS)
 
171
endif
 
172
 
 
173
# gcc 4.6 generates spurious warnings if -Waddress is in force.
 
174
# Inhibit this.
 
175
#
 
176
ifeq ($(CCTYPE),gcc)
 
177
WNA_TEST = $(CC) -Wno-address -x c -c /dev/null -o /dev/null >/dev/null 2>&1
 
178
WNA_FLAGS := $(shell $(WNA_TEST) && $(ECHO) '-Wno-address')
 
179
WORKAROUND_CFLAGS += $(WNA_FLAGS)
 
180
endif
 
181
 
 
182
# Some versions of gas choke on division operators, treating them as
 
183
# comment markers.  Specifying --divide will work around this problem,
 
184
# but isn't available on older gas versions.
 
185
#
 
186
DIVIDE_TEST = $(AS) --divide /dev/null -o /dev/null 2>/dev/null
 
187
DIVIDE_FLAGS := $(shell $(DIVIDE_TEST) && $(ECHO) '--divide')
 
188
WORKAROUND_ASFLAGS += $(DIVIDE_FLAGS)
 
189
 
 
190
###############################################################################
 
191
#
 
192
# Build verbosity
 
193
#
 
194
ifeq ($(V),1)
 
195
Q :=
 
196
QM := @\#
 
197
else
 
198
Q := @
 
199
QM := @
 
200
endif
 
201
 
 
202
###############################################################################
 
203
#
 
204
# Checker
 
205
#
 
206
ifeq ($(C),1)
 
207
export REAL_CC := $(CC)
 
208
CC := cgcc
 
209
CFLAGS += -Wno-decl
 
210
endif
 
211
 
 
212
###############################################################################
 
213
#
 
214
# Set BIN according to whatever was specified on the command line as
 
215
# the build target.
 
216
#
 
217
 
 
218
# Determine how many different BIN directories are mentioned in the
 
219
# make goals.
 
220
#
 
221
BIN_GOALS       := $(filter bin bin/% bin-%,$(MAKECMDGOALS))
 
222
BIN_GOALS_BINS  := $(sort $(foreach BG,$(BIN_GOALS),\
 
223
                                    $(firstword $(subst /, ,$(BG)))))
 
224
NUM_BINS        := $(words $(BIN_GOALS_BINS))
 
225
 
 
226
ifeq ($(NUM_BINS),0)
 
227
 
 
228
# No BIN directory was specified.  Set BIN to "bin" as a sensible
 
229
# default.
 
230
 
 
231
BIN             := bin
 
232
 
 
233
else # NUM_BINS == 0
 
234
 
 
235
ifeq ($(NUM_BINS),1)
 
236
 
 
237
# If exactly one BIN directory was specified, set BIN to match this
 
238
# directory.
 
239
#
 
240
BIN             := $(firstword $(BIN_GOALS_BINS))
 
241
 
 
242
else # NUM_BINS == 1
 
243
 
 
244
# More than one BIN directory was specified.  We cannot handle the
 
245
# latter case within a single make invocation, so set up recursive
 
246
# targets for each BIN directory.  Use exactly one target for each BIN
 
247
# directory since running multiple make invocations within the same
 
248
# BIN directory is likely to cause problems.
 
249
#
 
250
# Leave $(BIN) undefined.  This has implications for any target that
 
251
# depends on $(BIN); such targets should be made conditional upon the
 
252
# existence of $(BIN).
 
253
#
 
254
BIN_GOALS_FIRST := $(foreach BGB,$(BIN_GOALS_BINS),\
 
255
                             $(firstword $(filter $(BGB)/%,$(BIN_GOALS))))
 
256
BIN_GOALS_OTHER := $(filter-out $(BIN_GOALS_FIRST),$(BIN_GOALS))
 
257
 
 
258
$(BIN_GOALS_FIRST) : % : BIN_RECURSE
 
259
        $(Q)$(MAKE) --no-print-directory BIN=$(firstword $(subst /, ,$@)) \
 
260
            $(filter $(firstword $(subst /, ,$@))/%, $(BIN_GOALS))
 
261
$(BIN_GOALS_OTHER) : % : BIN_RECURSE
 
262
        $(Q)$(TRUE)
 
263
.PHONY : BIN_RECURSE
 
264
 
 
265
endif # NUM_BINS == 1
 
266
endif # NUM_BINS == 0
 
267
 
 
268
ifdef BIN
 
269
 
 
270
# Create $(BIN) directory if it doesn't exist yet
 
271
#
 
272
ifeq ($(wildcard $(BIN)),)
 
273
$(shell $(MKDIR) -p $(BIN))
 
274
endif
 
275
 
 
276
# Target to allow e.g. "make bin-efi arch"
 
277
#
 
278
$(BIN) :
 
279
        @# Do nothing, silently
 
280
.PHONY : $(BIN)
 
281
 
 
282
# Remove everything in $(BIN) for a "make clean"
 
283
#
 
284
CLEANUP += $(BIN)/*.* # Avoid picking up directories
 
285
 
 
286
endif # defined(BIN)
 
287
 
 
288
# Determine whether or not we need to include the dependency files
 
289
#
 
290
NO_DEP_TARGETS  := $(BIN) clean veryclean
 
291
ifeq ($(MAKECMDGOALS),)
 
292
NEED_DEPS       := 1
 
293
endif
 
294
ifneq ($(strip $(filter-out $(NO_DEP_TARGETS),$(MAKECMDGOALS))),)
 
295
NEED_DEPS       := 1
 
296
endif
 
297
 
 
298
###############################################################################
 
299
#
 
300
# Select build architecture and platform based on $(BIN)
 
301
#
 
302
# BIN has the form bin[-[arch-]platform]
 
303
 
 
304
ARCHS           := $(patsubst arch/%,%,$(wildcard arch/*))
 
305
PLATFORMS       := $(patsubst config/defaults/%.h,%,\
 
306
                     $(wildcard config/defaults/*.h))
 
307
archs :
 
308
        @$(ECHO) $(ARCHS)
 
309
 
 
310
platforms :
 
311
        @$(ECHO) $(PLATFORMS)
 
312
 
 
313
ifdef BIN
 
314
 
 
315
# Determine architecture portion of $(BIN), if present
 
316
BIN_ARCH        := $(strip $(foreach A,$(ARCHS),\
 
317
                             $(patsubst bin-$(A)-%,$(A),\
 
318
                               $(filter bin-$(A)-%,$(BIN)))))
 
319
 
 
320
# Determine platform portion of $(BIN), if present
 
321
ifeq ($(BIN_ARCH),)
 
322
BIN_PLATFORM    := $(patsubst bin-%,%,$(filter bin-%,$(BIN)))
 
323
else
 
324
BIN_PLATFORM    := $(patsubst bin-$(BIN_ARCH)-%,%,$(BIN))
 
325
endif
 
326
 
 
327
# Determine build architecture
 
328
DEFAULT_ARCH    := i386
 
329
ARCH            := $(firstword $(BIN_ARCH) $(DEFAULT_ARCH))
 
330
CFLAGS          += -DARCH=$(ARCH)
 
331
arch :
 
332
        @$(ECHO) $(ARCH)
 
333
.PHONY : arch
 
334
 
 
335
# Determine build platform
 
336
DEFAULT_PLATFORM := pcbios
 
337
PLATFORM        := $(firstword $(BIN_PLATFORM) $(DEFAULT_PLATFORM))
 
338
CFLAGS          += -DPLATFORM=$(PLATFORM)
 
339
platform :
 
340
        @$(ECHO) $(PLATFORM)
 
341
 
 
342
endif # defined(BIN)
 
343
 
 
344
# Include architecture-specific Makefile
 
345
ifdef ARCH
 
346
MAKEDEPS        += arch/$(ARCH)/Makefile
 
347
include arch/$(ARCH)/Makefile
 
348
endif
 
349
 
 
350
# Include architecture-specific include path
 
351
ifdef ARCH
 
352
INCDIRS         += arch/$(ARCH)/include
 
353
INCDIRS         += arch/$(ARCH)/include/$(PLATFORM)
 
354
endif
 
355
 
 
356
###############################################################################
 
357
#
 
358
# Source file handling
 
359
 
 
360
# SRCDIRS lists all directories containing source files.
 
361
srcdirs :
 
362
        @$(ECHO) $(SRCDIRS)
 
363
 
 
364
# SRCS lists all .c or .S files found in any SRCDIR
 
365
#
 
366
SRCS    += $(wildcard $(patsubst %,%/*.c,$(SRCDIRS)))
 
367
SRCS    += $(wildcard $(patsubst %,%/*.S,$(SRCDIRS)))
 
368
srcs :
 
369
        @$(ECHO) $(SRCS)
 
370
 
 
371
# AUTO_SRCS lists all files in SRCS that are not mentioned in
 
372
# NON_AUTO_SRCS.  Files should be added to NON_AUTO_SRCS if they
 
373
# cannot be built using the standard build template.
 
374
#
 
375
AUTO_SRCS = $(filter-out $(NON_AUTO_SRCS),$(SRCS))
 
376
autosrcs :
 
377
        @$(ECHO) $(AUTO_SRCS)
 
378
 
 
379
# Just about everything else in this section depends upon having
 
380
# $(BIN) set
 
381
 
 
382
ifdef BIN
 
383
 
 
384
# INCDIRS lists the include path
 
385
incdirs :
 
386
        @$(ECHO) $(INCDIRS)
 
387
 
 
388
# Common flags
 
389
#
 
390
CFLAGS          += $(foreach INC,$(INCDIRS),-I$(INC))
 
391
CFLAGS          += -Os
 
392
CFLAGS          += -g
 
393
ifeq ($(CCTYPE),gcc)
 
394
CFLAGS          += -ffreestanding
 
395
CFLAGS          += -Wall -W -Wformat-nonliteral
 
396
HOST_CFLAGS     += -Wall -W -Wformat-nonliteral
 
397
endif
 
398
ifeq ($(CCTYPE),icc)
 
399
CFLAGS          += -fno-builtin
 
400
CFLAGS          += -no-ip
 
401
CFLAGS          += -no-gcc
 
402
CFLAGS          += -diag-disable 111 # Unreachable code
 
403
CFLAGS          += -diag-disable 128 # Unreachable loop
 
404
CFLAGS          += -diag-disable 170 # Array boundary checks
 
405
CFLAGS          += -diag-disable 177 # Unused functions
 
406
CFLAGS          += -diag-disable 181 # printf() format checks
 
407
CFLAGS          += -diag-disable 188 # enum strictness
 
408
CFLAGS          += -diag-disable 193 # Undefined preprocessor identifiers
 
409
CFLAGS          += -diag-disable 280 # switch ( constant )
 
410
CFLAGS          += -diag-disable 310 # K&R parameter lists
 
411
CFLAGS          += -diag-disable 424 # Extra semicolon
 
412
CFLAGS          += -diag-disable 589 # Declarations mid-code
 
413
CFLAGS          += -diag-disable 593 # Unused variables
 
414
CFLAGS          += -diag-disable 810 # Casting ints to smaller ints
 
415
CFLAGS          += -diag-disable 981 # Sequence point violations
 
416
CFLAGS          += -diag-disable 1292 # Ignored attributes
 
417
CFLAGS          += -diag-disable 1338 # void pointer arithmetic
 
418
CFLAGS          += -diag-disable 1361 # Variable-length arrays
 
419
CFLAGS          += -diag-disable 1418 # Missing prototypes
 
420
CFLAGS          += -diag-disable 1419 # Missing prototypes
 
421
CFLAGS          += -diag-disable 1599 # Hidden variables
 
422
CFLAGS          += -Wall -Wmissing-declarations
 
423
endif
 
424
CFLAGS          += $(WORKAROUND_CFLAGS) $(EXTRA_CFLAGS)
 
425
ASFLAGS         += $(WORKAROUND_ASFLAGS) $(EXTRA_ASFLAGS)
 
426
LDFLAGS         += $(WORKAROUND_LDFLAGS) $(EXTRA_LDFLAGS)
 
427
HOST_CFLAGS     += -O2 -g
 
428
 
 
429
# Inhibit -Werror if NO_WERROR is specified on make command line
 
430
#
 
431
ifneq ($(NO_WERROR),1)
 
432
CFLAGS          += -Werror
 
433
ASFLAGS         += --fatal-warnings
 
434
HOST_CFLAGS     += -Werror
 
435
endif
 
436
 
 
437
# Function trace recorder state in the last build.  This is needed
 
438
# in order to correctly rebuild whenever the function recorder is
 
439
# enabled/disabled.
 
440
#
 
441
FNREC_STATE     := $(BIN)/.fnrec.state
 
442
ifeq ($(wildcard $(FNREC_STATE)),)
 
443
FNREC_OLD       := <invalid>
 
444
else
 
445
FNREC_OLD       := $(shell cat $(FNREC_STATE))
 
446
endif
 
447
ifeq ($(FNREC_OLD),$(FNREC))
 
448
$(FNREC_STATE) :
 
449
else
 
450
$(FNREC_STATE) : clean
 
451
$(shell $(ECHO) "$(FNREC)" > $(FNREC_STATE))
 
452
endif
 
453
 
 
454
VERYCLEANUP     += $(FNREC_STATE)
 
455
MAKEDEPS        += $(FNREC_STATE)
 
456
 
 
457
ifeq ($(FNREC),1)
 
458
# Enabling -finstrument-functions affects gcc's analysis and leads to spurious
 
459
# warnings about use of uninitialised variables.
 
460
#
 
461
CFLAGS          += -Wno-uninitialized
 
462
CFLAGS          += -finstrument-functions
 
463
CFLAGS          += -finstrument-functions-exclude-file-list=core/fnrec.c
 
464
endif
 
465
 
 
466
# Enable per-item sections and section garbage collection.  Note that
 
467
# some older versions of gcc support -fdata-sections but treat it as
 
468
# implying -fno-common, which would break our build.  Some other older
 
469
# versions issue a spurious and uninhibitable warning if
 
470
# -ffunction-sections is used with -g, which would also break our
 
471
# build since we use -Werror.
 
472
#
 
473
ifeq ($(CCTYPE),gcc)
 
474
DS_TEST         = $(ECHO) 'char x;' | \
 
475
                  $(CC) -fdata-sections -S -x c - -o - 2>/dev/null | \
 
476
                  grep -E '\.comm' > /dev/null
 
477
DS_FLAGS        := $(shell $(DS_TEST) && $(ECHO) '-fdata-sections')
 
478
FS_TEST         = $(CC) -ffunction-sections -g -c -x c /dev/null \
 
479
                  -o /dev/null 2>/dev/null
 
480
FS_FLAGS        := $(shell $(FS_TEST) && $(ECHO) '-ffunction-sections')
 
481
CFLAGS          += $(FS_FLAGS) $(DS_FLAGS)
 
482
endif
 
483
LDFLAGS         += --gc-sections
 
484
 
 
485
# Force creation of static binaries (required for OpenBSD, does no
 
486
# harm on other platforms).
 
487
#
 
488
LDFLAGS         += -static
 
489
 
 
490
# compiler.h is needed for our linking and debugging system
 
491
#
 
492
CFLAGS          += -include include/compiler.h
 
493
 
 
494
# The section type character (e.g. "@" in "@progbits") varies by
 
495
# architecture.
 
496
#
 
497
CFLAGS          += -DASM_TCHAR='$(ASM_TCHAR)' -DASM_TCHAR_OPS='$(ASM_TCHAR_OPS)'
 
498
 
 
499
# CFLAGS for specific object types
 
500
#
 
501
CFLAGS_c        +=
 
502
CFLAGS_S        += -DASSEMBLY
 
503
 
 
504
# Base object name of the current target
 
505
#
 
506
OBJECT          = $(firstword $(subst ., ,$(@F)))
 
507
 
 
508
# CFLAGS for specific object files.  You can define
 
509
# e.g. CFLAGS_rtl8139, and have those flags automatically used when
 
510
# compiling bin/rtl8139.o.
 
511
#
 
512
OBJ_CFLAGS      = $(CFLAGS_$(OBJECT)) -DOBJECT=$(subst -,_,$(OBJECT))
 
513
$(BIN)/%.flags :
 
514
        @$(ECHO) $(OBJ_CFLAGS)
 
515
 
 
516
# ICC requires postprocessing objects to fix up table alignments
 
517
#
 
518
ifeq ($(CCTYPE),icc)
 
519
POST_O          = && $(ICCFIX) $@
 
520
POST_O_DEPS     := $(ICCFIX)
 
521
else
 
522
POST_O          :=
 
523
POST_O_DEPS     :=
 
524
endif
 
525
 
 
526
# Debug level calculations
 
527
#
 
528
DBGLVL_MAX      = -DDBGLVL_MAX=$(firstword $(subst ., ,$(1)))
 
529
DBGLVL_DFLT     = -DDBGLVL_DFLT=$(lastword $(subst ., ,$(1)))
 
530
DBGLVL          = $(call DBGLVL_MAX,$(1)) $(call DBGLVL_DFLT,$(1))
 
531
 
 
532
# Rules for specific object types.
 
533
#
 
534
COMPILE_c       = $(CC) $(CFLAGS) $(CFLAGS_c) $(OBJ_CFLAGS)
 
535
RULE_c          = $(Q)$(COMPILE_c) -c $< -o $@ $(POST_O)
 
536
RULE_c_to_ids.o = $(Q)$(ECHO_E) '$(OBJ_IDS_ASM_NL)' | $(ASSEMBLE_S) -o $@
 
537
RULE_c_to_dbg%.o= $(Q)$(COMPILE_c) $(call DBGLVL,$*) -c $< -o $@ $(POST_O)
 
538
RULE_c_to_c     = $(Q)$(COMPILE_c) -E -c $< > $@
 
539
RULE_c_to_s     = $(Q)$(COMPILE_c) -S -g0 -c $< -o $@
 
540
 
 
541
PREPROCESS_S    = $(CPP) $(CFLAGS) $(CFLAGS_S) $(OBJ_CFLAGS)
 
542
ASSEMBLE_S      = $(AS) $(ASFLAGS)
 
543
RULE_S          = $(Q)$(PREPROCESS_S) $< | $(ASSEMBLE_S) -o $@
 
544
RULE_S_to_dbg%.o= $(Q)$(PREPROCESS_S) $(call DBGLVL,$*) $< | $(ASSEMBLE_S) -o $@
 
545
RULE_S_to_s     = $(Q)$(PREPROCESS_S) $< > $@
 
546
 
 
547
GENERIC_TARGETS += ids.o dbg%.o c s
 
548
 
 
549
# List of embedded images included in the last build of embedded.o.
 
550
# This is needed in order to correctly rebuild embedded.o whenever the
 
551
# list of objects changes.
 
552
#
 
553
EMBED           := $(EMBEDDED_IMAGE) # Maintain backwards compatibility
 
554
EMBEDDED_LIST   := $(BIN)/.embedded.list
 
555
ifeq ($(wildcard $(EMBEDDED_LIST)),)
 
556
EMBED_OLD := <invalid>
 
557
else
 
558
EMBED_OLD := $(shell cat $(EMBEDDED_LIST))
 
559
endif
 
560
ifneq ($(EMBED_OLD),$(EMBED))
 
561
$(shell $(ECHO) "$(EMBED)" > $(EMBEDDED_LIST))
 
562
endif
 
563
 
 
564
$(EMBEDDED_LIST) : $(MAKEDEPS)
 
565
 
 
566
VERYCLEANUP     += $(EMBEDDED_LIST)
 
567
 
 
568
EMBEDDED_FILES  := $(subst $(COMMA), ,$(EMBED))
 
569
EMBED_ALL       := $(foreach i,$(call seq,1,$(words $(EMBEDDED_FILES))),\
 
570
                     EMBED ( $(i), \"$(word $(i), $(EMBEDDED_FILES))\",\
 
571
                             \"$(notdir $(word $(i),$(EMBEDDED_FILES)))\" ))
 
572
 
 
573
embedded_DEPS += $(EMBEDDED_FILES) $(EMBEDDED_LIST)
 
574
 
 
575
CFLAGS_embedded = -DEMBED_ALL="$(EMBED_ALL)"
 
576
 
 
577
# List of trusted root certificates
 
578
#
 
579
TRUSTED_LIST    := $(BIN)/.trusted.list
 
580
ifeq ($(wildcard $(TRUSTED_LIST)),)
 
581
TRUST_OLD := <invalid>
 
582
else
 
583
TRUST_OLD := $(shell cat $(TRUSTED_LIST))
 
584
endif
 
585
ifneq ($(TRUST_OLD),$(TRUST))
 
586
$(shell $(ECHO) "$(TRUST)" > $(TRUSTED_LIST))
 
587
endif
 
588
 
 
589
$(TRUSTED_LIST) : $(MAKEDEPS)
 
590
 
 
591
VERYCLEANUP     += $(TRUSTED_LIST)
 
592
 
 
593
# Trusted root certificate fingerprints
 
594
#
 
595
TRUSTED_CERTS   := $(subst $(COMMA), ,$(TRUST))
 
596
TRUSTED_FPS     := $(foreach CERT,$(TRUSTED_CERTS),\
 
597
                     0x$(subst :,$(COMMA) 0x,$(lastword $(subst =, ,\
 
598
                         $(shell $(OPENSSL) x509 -in $(CERT) -noout -sha256 \
 
599
                                 -fingerprint))))$(COMMA))
 
600
 
 
601
rootcert_DEPS += $(TRUSTED_FILES) $(TRUSTED_LIST)
 
602
 
 
603
CFLAGS_rootcert = $(if $(TRUSTED_FPS),-DTRUSTED="$(TRUSTED_FPS)")
 
604
 
 
605
# List of embedded certificates
 
606
#
 
607
CERT_LIST := $(BIN)/.certificate.list
 
608
ifeq ($(wildcard $(CERT_LIST)),)
 
609
CERT_OLD := <invalid>
 
610
else
 
611
CERT_OLD := $(shell cat $(CERT_LIST))
 
612
endif
 
613
ifneq ($(CERT_OLD),$(CERT))
 
614
$(shell $(ECHO) "$(CERT)" > $(CERT_LIST))
 
615
endif
 
616
 
 
617
$(CERT_LIST) : $(MAKEDEPS)
 
618
 
 
619
VERYCLEANUP += $(CERT_LIST)
 
620
 
 
621
# Embedded certificates concatenated and then split into one file per
 
622
# certificate (even if original files contained certificate chains)
 
623
#
 
624
CERT_FILES := $(subst $(COMMA), ,$(CERT))
 
625
CERT_CONCAT := $(BIN)/.certificates.pem
 
626
 
 
627
ifneq ($(CERT),)
 
628
 
 
629
CERT_COUNT := $(shell grep "BEGIN CERTIFICATE" $(CERT_FILES) | wc -l)
 
630
 
 
631
$(CERT_CONCAT) : $(CERT_FILES) $(CERT_LIST)
 
632
        $(Q)cat $(CERT_FILES) > $@
 
633
 
 
634
# We must use an (otherwise unnecessary) pattern rule here to encode
 
635
# the fact that one "csplit" command generates multiple targets
 
636
CERT_PEMS := $(foreach i,$(call seq,1,$(CERT_COUNT)),\
 
637
               $(BIN)/.certificate.pem.$(i))
 
638
$(subst .pem.,.%.,$(CERT_PEMS)) : $(BIN)/.certificates.%
 
639
        $(Q)$(CSPLIT) -q -n 1 -f $(BIN)/.certificate.pem. $< \
 
640
                '/BEGIN CERTIFICATE/' '{*}'
 
641
 
 
642
CERT_DERS := $(subst .certificate.pem.,.certificate.der.,$(CERT_PEMS))
 
643
$(BIN)/.certificate.der.% : $(BIN)/.certificate.pem.%
 
644
        $(Q)$(OPENSSL) x509 -in $< -outform DER -out $@
 
645
 
 
646
CERT_ALL := $(foreach i,$(call seq,1,$(CERT_COUNT)),\
 
647
              CERT ( $(i), \"$(word $(i),$(CERT_DERS))\" ))
 
648
 
 
649
endif
 
650
 
 
651
certstore_DEPS += $(CERT_LIST) $(CERT_FILES) $(CERT_PEMS) $(CERT_DERS)
 
652
 
 
653
CFLAGS_certstore += -DCERT_ALL="$(CERT_ALL)"
 
654
 
 
655
CLEANUP += $(BIN)/.certificate.* $(BIN)/.certificates.*
 
656
 
 
657
# (Single-element) list of private keys
 
658
#
 
659
ifdef KEY
 
660
PRIVKEY := $(KEY) # Maintain backwards compatibility
 
661
endif
 
662
PRIVKEY_LIST := $(BIN)/.private_key.list
 
663
ifeq ($(wildcard $(PRIVKEY_LIST)),)
 
664
PRIVKEY_OLD := <invalid>
 
665
else
 
666
PRIVKEY_OLD := $(shell cat $(PRIVKEY_LIST))
 
667
endif
 
668
ifneq ($(PRIVKEY_OLD),$(PRIVKEY))
 
669
$(shell $(ECHO) "$(PRIVKEY)" > $(PRIVKEY_LIST))
 
670
endif
 
671
 
 
672
$(PRIVKEY_LIST) : $(MAKEDEPS)
 
673
 
 
674
VERYCLEANUP += $(PRIVKEY_LIST)
 
675
 
 
676
# Embedded private key
 
677
#
 
678
PRIVKEY_INC := $(BIN)/.private_key.der
 
679
 
 
680
ifdef PRIVKEY
 
681
$(PRIVKEY_INC) : $(PRIVKEY) $(PRIVKEY_LIST)
 
682
        $(Q)$(OPENSSL) rsa -in $< -outform DER -out $@
 
683
 
 
684
privkey_DEPS += $(PRIVKEY_INC)
 
685
endif
 
686
 
 
687
CLEANUP += $(BIN)/.private_key.*
 
688
 
 
689
privkey_DEPS += $(PRIVKEY_LIST)
 
690
 
 
691
CFLAGS_privkey += $(if $(PRIVKEY),-DPRIVATE_KEY="\"$(PRIVKEY_INC)\"")
 
692
 
 
693
# (Single-element) list of named configurations
 
694
#
 
695
CONFIG_LIST := $(BIN)/.config.list
 
696
ifeq ($(wildcard $(CONFIG_LIST)),)
 
697
CONFIG_OLD := <invalid>
 
698
else
 
699
CONFIG_OLD := $(shell cat $(CONFIG_LIST))
 
700
endif
 
701
ifneq ($(CONFIG_OLD),$(CONFIG))
 
702
$(shell $(ECHO) "$(CONFIG)" > $(CONFIG_LIST))
 
703
endif
 
704
 
 
705
$(CONFIG_LIST) : $(MAKEDEPS)
 
706
 
 
707
VERYCLEANUP += $(CONFIG_LIST)
 
708
 
 
709
# Named configurations
 
710
#
 
711
ifneq ($(CONFIG),)
 
712
ifneq ($(wildcard config/$(CONFIG)),)
 
713
CFLAGS  += -DCONFIG=$(CONFIG)
 
714
endif
 
715
CFLAGS  += -DLOCAL_CONFIG=$(CONFIG)
 
716
endif
 
717
 
 
718
config/named.h : $(CONFIG_LIST)
 
719
        $(Q)$(TOUCH) $@
 
720
 
 
721
.PRECIOUS : config/named.h
 
722
 
 
723
# (Single-element) list of assertion configuration
 
724
#
 
725
ASSERT_LIST := $(BIN)/.assert.list
 
726
ifeq ($(wildcard $(ASSERT_LIST)),)
 
727
ASSERT_OLD := <invalid>
 
728
else
 
729
ASSERT_OLD := $(shell cat $(ASSERT_LIST))
 
730
endif
 
731
ifneq ($(ASSERT_OLD),$(ASSERT))
 
732
$(shell $(ECHO) "$(ASSERT)" > $(ASSERT_LIST))
 
733
endif
 
734
 
 
735
$(ASSERT_LIST) : $(MAKEDEPS)
 
736
 
 
737
VERYCLEANUP += $(ASSERT_LIST)
 
738
 
 
739
# Assertion configuration
 
740
#
 
741
ifneq ($(ASSERT),)
 
742
CFLAGS  += -DASSERTING=$(ASSERT)
 
743
endif
 
744
 
 
745
include/assert.h : $(ASSERT_LIST)
 
746
        $(Q)$(TOUCH) $@
 
747
 
 
748
.PRECIOUS : include/assert.h
 
749
 
 
750
# (Single-element) list of profiling configuration
 
751
#
 
752
PROFILE_LIST := $(BIN)/.profile.list
 
753
ifeq ($(wildcard $(PROFILE_LIST)),)
 
754
PROFILE_OLD := <invalid>
 
755
else
 
756
PROFILE_OLD := $(shell cat $(PROFILE_LIST))
 
757
endif
 
758
ifneq ($(PROFILE_OLD),$(PROFILE))
 
759
$(shell $(ECHO) "$(PROFILE)" > $(PROFILE_LIST))
 
760
endif
 
761
 
 
762
$(PROFILE_LIST) : $(MAKEDEPS)
 
763
 
 
764
VERYCLEANUP += $(PROFILE_LIST)
 
765
 
 
766
# Profiling configuration
 
767
#
 
768
ifneq ($(PROFILE),)
 
769
CFLAGS  += -DPROFILING=$(PROFILE)
 
770
endif
 
771
 
 
772
include/ipxe/profile.h : $(PROFILE_LIST)
 
773
        $(Q)$(TOUCH) $@
 
774
 
 
775
.PRECIOUS : include/ipxe/profile.h
 
776
 
 
777
# These files use .incbin inline assembly to include a binary file.
 
778
# Unfortunately ccache does not detect this dependency and caches
 
779
# builds even when the binary file has changed.
 
780
#
 
781
$(BIN)/embedded.% : override CC := env CCACHE_DISABLE=1 $(CC)
 
782
$(BIN)/certstore.% : override CC := env CCACHE_DISABLE=1 $(CC)
 
783
$(BIN)/privkey.% : override CC := env CCACHE_DISABLE=1 $(CC)
 
784
 
 
785
# Debug message autocolourisation range
 
786
#
 
787
DBGCOL_LIST     := $(BIN)/.dbgcol.list
 
788
ifeq ($(wildcard $(DBGCOL_LIST)),)
 
789
DBGCOL_OLD := <invalid>
 
790
else
 
791
DBGCOL_OLD := $(shell cat $(DBGCOL_LIST))
 
792
endif
 
793
ifneq ($(DBGCOL_OLD),$(DBGCOL))
 
794
$(shell $(ECHO) "$(DBGCOL)" > $(DBGCOL_LIST))
 
795
endif
 
796
 
 
797
$(DBGCOL_LIST) : $(MAKEDEPS)
 
798
 
 
799
VERYCLEANUP += $(DBGCOL_LIST)
 
800
 
 
801
DBGCOL_COLOURS := $(subst -, ,$(DBGCOL))
 
802
DBGCOL_MIN := $(firstword $(DBGCOL_COLOURS))
 
803
DBGCOL_MAX := $(lastword $(DBGCOL_COLOURS))
 
804
 
 
805
debug_DEPS += $(DBGCOL_LIST)
 
806
 
 
807
CFLAGS_debug += $(if $(DBGCOL_MIN),-DDBGCOL_MIN=$(DBGCOL_MIN))
 
808
CFLAGS_debug += $(if $(DBGCOL_MAX),-DDBGCOL_MAX=$(DBGCOL_MAX))
 
809
 
 
810
# We automatically generate rules for any file mentioned in AUTO_SRCS
 
811
# using the following set of templates.  We use $(eval ...) if
 
812
# available, otherwise we generate separate Makefile fragments and
 
813
# include them.
 
814
 
 
815
# deps_template : generate dependency list for a given source file
 
816
#
 
817
# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
 
818
#
 
819
define deps_template_file
 
820
$(call deps_template_parts,$(1),$(subst .,,$(suffix $(1))),$(basename $(notdir $(1))))
 
821
endef
 
822
#
 
823
# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
 
824
# $(2) is the source type (e.g. "c")
 
825
# $(3) is the source base name (e.g. "rtl8139")
 
826
#
 
827
define deps_template_parts
 
828
        @$(ECHO) "  [DEPS] $(1)"
 
829
        @$(MKDIR) -p $(BIN)/deps/$(dir $(1))
 
830
        $(Q)$(CPP) $(CFLAGS) $(CFLAGS_$(2)) $(CFLAGS_$(3)) -DOBJECT=$(3) \
 
831
                -Wno-error -M $(1) -MG -MP | \
 
832
                sed 's/\.o\s*:/_DEPS +=/' > $(BIN)/deps/$(1).d
 
833
endef
 
834
 
 
835
# rules_template : generate rules for a given source file
 
836
#
 
837
# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
 
838
#
 
839
define rules_template
 
840
$(call rules_template_parts,$(1),$(subst .,,$(suffix $(1))),$(basename $(notdir $(1))))
 
841
endef
 
842
#
 
843
# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
 
844
# $(2) is the source type (e.g. "c")
 
845
# $(3) is the source base name (e.g. "rtl8139")
 
846
#
 
847
define rules_template_parts
 
848
$$(BIN)/$(3).o : $(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)
 
849
        $$(QM)$(ECHO) "  [BUILD] $$@"
 
850
        $$(RULE_$(2))
 
851
BOBJS += $$(BIN)/$(3).o
 
852
$(foreach TGT,$(GENERIC_TARGETS),$(if $(RULE_$(2)_to_$(TGT)),$(NEWLINE)$(call rules_template_target,$(1),$(2),$(3),$(TGT))))
 
853
$$(BIN)/deps/$(1).d : $$($(3)_DEPS)
 
854
TAGS : $$($(3)_DEPS)
 
855
endef
 
856
#
 
857
# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
 
858
# $(2) is the source type (e.g. "c")
 
859
# $(3) is the source base name (e.g. "rtl8139")
 
860
# $(4) is the destination type (e.g. "dbg%.o")
 
861
#
 
862
define rules_template_target
 
863
$$(BIN)/$(3).$(4) : $(1) $$(MAKEDEPS) $$(POST_O_DEPS) $$($(3)_DEPS)
 
864
        $$(QM)$(ECHO) "  [BUILD] $$@"
 
865
        $$(RULE_$(2)_to_$(4))
 
866
$(TGT)_OBJS += $$(BIN)/$(3).$(4)
 
867
endef
 
868
#
 
869
# $(1) is the full path to the source file (e.g. "drivers/net/rtl8139.c")
 
870
#
 
871
define rules_template_file
 
872
        @$(ECHO) "  [RULES] $(1)"
 
873
        @$(MKDIR) -p $(BIN)/rules/$(dir $(1))
 
874
        @$(ECHO_E) '$(subst $(NEWLINE),\n,$(call rules_template,$(1)))' \
 
875
                 > $(BIN)/rules/$(1).r
 
876
endef
 
877
 
 
878
# Generate the dependency files
 
879
#
 
880
$(BIN)/deps/%.d : % $(MAKEDEPS)
 
881
        $(call deps_template_file,$<)
 
882
 
 
883
# Calculate list of dependency files
 
884
#
 
885
AUTO_DEPS       = $(patsubst %,$(BIN)/deps/%.d,$(AUTO_SRCS))
 
886
autodeps :
 
887
        @$(ECHO) $(AUTO_DEPS)
 
888
VERYCLEANUP     += $(BIN)/deps
 
889
 
 
890
# Include dependency files
 
891
#
 
892
ifdef NEED_DEPS
 
893
ifneq ($(AUTO_DEPS),)
 
894
-include $(AUTO_DEPS)
 
895
endif
 
896
endif
 
897
 
 
898
# Generate the rules files
 
899
#
 
900
$(BIN)/rules/%.r : % $(MAKEDEPS)
 
901
        $(call rules_template_file,$<)
 
902
 
 
903
# Calculate list of rules files
 
904
#
 
905
AUTO_RULES      = $(patsubst %,$(BIN)/rules/%.r,$(AUTO_SRCS))
 
906
autorules :
 
907
        @$(ECHO) $(AUTO_RULES)
 
908
VERYCLEANUP     += $(BIN)/rules
 
909
 
 
910
# Evaluate rules (or include rules files)
 
911
#
 
912
ifdef NEED_DEPS
 
913
ifneq ($(AUTO_RULES),)
 
914
ifneq ($(HAVE_EVAL),)
 
915
$(foreach SRC,$(AUTO_SRCS),$(eval $(call rules_template,$(SRC))))
 
916
else
 
917
-include $(AUTO_RULES)
 
918
endif
 
919
endif
 
920
endif
 
921
 
 
922
# Files to be parsed using parserom.pl
 
923
#
 
924
ROM_SRCS        = $(foreach SRC,$(AUTO_SRCS),\
 
925
                    $(if $(findstring drivers/,$(SRC)),$(SRC)))
 
926
romsrcs :
 
927
        @$(ECHO) $(ROM_SRCS)
 
928
 
 
929
# List of files to be parsed using parserom.pl
 
930
#
 
931
ROM_SRCS_LIST   := $(BIN)/.rom.list
 
932
ifeq ($(wildcard $(ROM_SRCS_LIST)),)
 
933
ROM_SRCS_OLD := <invalid>
 
934
else
 
935
ROM_SRCS_OLD := $(shell cat $(ROM_SRCS_LIST))
 
936
endif
 
937
ifneq ($(ROM_SRCS_OLD),$(ROM_SRCS))
 
938
$(shell $(ECHO) "$(ROM_SRCS)" > $(ROM_SRCS_LIST))
 
939
endif
 
940
 
 
941
$(ROM_SRCS_LIST) : $(MAKEDEPS)
 
942
 
 
943
VERYCLEANUP     += $(ROM_SRCS_LIST)
 
944
 
 
945
# ROM definition file
 
946
#
 
947
ROMDEFS         = $(BIN)/.rom.defs
 
948
$(ROMDEFS) : $(ROM_SRCS) $(ROM_SRCS_LIST) $(PARSEROM) $(MAKEDEPS)
 
949
        $(QM)$(ECHO) "  [PARSEROM]"
 
950
        $(Q)$(PERL) $(PARSEROM) $(ROM_SRCS) > $@
 
951
 
 
952
VERYCLEANUP     += $(ROMDEFS)
 
953
 
 
954
# Evaluate ROM definition file
 
955
ifdef NEED_DEPS
 
956
ifneq ($(ROM_SRCS),)
 
957
-include $(ROMDEFS)
 
958
endif
 
959
endif
 
960
 
 
961
# Device ID tables (using IDs from ROM definition file)
 
962
#
 
963
define obj_pci_id_asm
 
964
        .section ".pci_devlist.$(1)", "a", $(ASM_TCHAR)progbits
 
965
        .globl pci_devlist_$(1)
 
966
pci_devlist_$(1):
 
967
        .short ( 0x$(1) & 0xffff )
 
968
 
 
969
endef
 
970
define obj_isa_id_asm
 
971
endef
 
972
OBJ_IDS_ASM     = $(foreach ROM,$(ROMS_$(OBJECT)),$(call obj_$(ROM_TYPE_$(ROM))_id_asm,$(ROM)))
 
973
OBJ_IDS_ASM_NL  = $(subst $(NEWLINE),\n,$(OBJ_IDS_ASM))
 
974
$(BIN)/%.ids :
 
975
        @$(ECHO_E) '$(OBJ_IDS_ASM_NL)'
 
976
 
 
977
BOBJS   += $(patsubst %,$(BIN)/%.ids.o,$(DRIVERS))
 
978
 
 
979
# The following variables are created by the autogenerated rules
 
980
#
 
981
bobjs :
 
982
        @$(ECHO) $(BOBJS)
 
983
drivers_% :
 
984
        @$(ECHO) $(DRIVERS_$*)
 
985
drivers :
 
986
        @$(ECHO) $(DRIVERS)
 
987
.PHONY : drivers
 
988
roms :
 
989
        @$(ECHO) $(ROMS)
 
990
 
 
991
# Generate error usage information
 
992
#
 
993
$(BIN)/%.einfo : $(BIN)/%.o
 
994
        $(QM)$(ECHO) "  [EINFO] $@"
 
995
        $(Q)$(OBJCOPY) -O binary -j .einfo --set-section-flags .einfo=alloc \
 
996
                $< $@
 
997
 
 
998
EINFOS          := $(patsubst $(BIN)/%.o,$(BIN)/%.einfo,$(BOBJS))
 
999
$(BIN)/errors : $(EINFOS) $(EINFO)
 
1000
        $(QM)$(ECHO) "  [EINFO] $@"
 
1001
        $(Q)$(EINFO) $(EINFOS) | sort > $@
 
1002
CLEANUP         += $(BIN)/errors        # Doesn't match the $(BIN)/*.* pattern
 
1003
 
 
1004
# Generate the NIC file from the parsed source files.  The NIC file is
 
1005
# only for rom-o-matic.
 
1006
#
 
1007
$(BIN)/NIC : $(AUTO_DEPS)
 
1008
        @$(ECHO) '# This is an automatically generated file, do not edit' > $@
 
1009
        @$(ECHO) '# It does not affect anything in the build, ' \
 
1010
             'it is only for rom-o-matic' >> $@
 
1011
        @$(ECHO) >> $@
 
1012
        @perl -ne 'chomp; print "$$1\n" if /\# NIC\t(.*)$$/' $^ >> $@
 
1013
CLEANUP         += $(BIN)/NIC   # Doesn't match the $(BIN)/*.* pattern
 
1014
 
 
1015
# Select drivers to be included in the all-drivers build
 
1016
#
 
1017
DRIVERS_ipxe    = $(DRIVERS_net) $(DRIVERS_infiniband) \
 
1018
                  $(DRIVERS_xen) $(DRIVERS_hyperv)
 
1019
 
 
1020
# Analyse a target name (e.g. "bin/dfe538--prism2_pci.rom.tmp") and
 
1021
# derive the variables:
 
1022
 
1023
# TGT_ELEMENTS : the elements of the target (e.g. "dfe538 prism2_pci")
 
1024
# TGT_PREFIX   : the prefix type (e.g. "pcirom")
 
1025
# TGT_DRIVERS  : the driver for each element (e.g. "rtl8139 prism2_pci")
 
1026
# TGT_ROM_NAME : the ROM name (e.g. "dfe538")
 
1027
#
 
1028
TGT_ELEMENTS    = $(subst --, ,$(firstword $(subst ., ,$(notdir $@))))
 
1029
TGT_ROM_NAME    = $(firstword $(TGT_ELEMENTS))
 
1030
TGT_DRIVERS     = $(strip $(foreach TGT_ELEMENT,$(TGT_ELEMENTS), \
 
1031
                                    $(if $(DRIVERS_$(TGT_ELEMENT)), \
 
1032
                                         $(DRIVERS_$(TGT_ELEMENT)), \
 
1033
                                         $(firstword $(DRIVER_$(TGT_ELEMENT)) \
 
1034
                                                     $(TGT_ELEMENT)))))
 
1035
TGT_PREFIX_NAME = $(word 2,$(subst ., ,$(notdir $@)))
 
1036
TGT_PREFIX      = $(strip $(if $(filter rom,$(TGT_PREFIX_NAME)), \
 
1037
                               $(ROM_TYPE_$(TGT_ROM_NAME))rom, \
 
1038
                               $(TGT_PREFIX_NAME)))
 
1039
 
 
1040
# Look up ROM IDs for the current target
 
1041
# (e.g. "bin/dfe538--prism2_pci.rom.tmp") and derive the variables:
 
1042
#
 
1043
# TGT_PCI_VENDOR : the PCI vendor ID (e.g. "0x1186")
 
1044
# TGT_PCI_DEVICE : the PCI device ID (e.g. "0x1300")
 
1045
#
 
1046
TGT_PCI_VENDOR  = $(PCI_VENDOR_$(TGT_ROM_NAME))
 
1047
TGT_PCI_DEVICE  = $(PCI_DEVICE_$(TGT_ROM_NAME))
 
1048
 
 
1049
# Calculate link-time options for the current target
 
1050
# (e.g. "bin/dfe538--prism2_pci.rom.tmp") and derive the variables:
 
1051
#
 
1052
# TGT_LD_DRIVERS : symbols to require in order to drag in the relevant drivers
 
1053
#                  (e.g. "obj_rtl8139 obj_prism2_pci")
 
1054
# TGT_LD_IDS :     symbols to define in order to fill in ID structures in the
 
1055
#                  ROM header (e.g."pci_vendor_id=0x1186 pci_device_id=0x1300")
 
1056
#
 
1057
TGT_LD_DRIVERS  = $(subst -,_,$(patsubst %,obj_%,$(TGT_DRIVERS)))
 
1058
TGT_LD_IDS      = pci_vendor_id=$(firstword $(TGT_PCI_VENDOR) 0) \
 
1059
                  pci_device_id=$(firstword $(TGT_PCI_DEVICE) 0)
 
1060
TGT_LD_DEVLIST  = $(foreach ELEM,$(TGT_ELEMENTS),$(if $(PCI_VENDOR_$(ELEM)),\
 
1061
                    pci_devlist_$(patsubst 0x%,%,$(PCI_VENDOR_$(ELEM)))$(patsubst 0x%,%,$(PCI_DEVICE_$(ELEM)))))
 
1062
TGT_LD_ENTRY    = _$(TGT_PREFIX)_start
 
1063
 
 
1064
# Calculate linker flags based on link-time options for the current
 
1065
# target type (e.g. "bin/dfe538--prism2_pci.rom.tmp") and derive the
 
1066
# variables:
 
1067
#
 
1068
# TGT_LD_FLAGS : target-specific flags to pass to linker (e.g.
 
1069
#                "-u obj_zpciprefix -u obj_rtl8139 -u obj_prism2_pci
 
1070
#                 --defsym pci_vendor=0x1186 --defsym pci_device=0x1300")
 
1071
#
 
1072
TGT_LD_FLAGS    = $(foreach SYM,$(TGT_LD_ENTRY) $(TGT_LD_DRIVERS) \
 
1073
                    $(TGT_LD_DEVLIST) obj_config obj_config_$(PLATFORM),\
 
1074
                    -u $(SYM) --defsym check_$(SYM)=$(SYM) ) \
 
1075
                  $(patsubst %,--defsym %,$(TGT_LD_IDS)) \
 
1076
                  -e $(TGT_LD_ENTRY)
 
1077
 
 
1078
# Calculate list of debugging versions of objects to be included in
 
1079
# the target.
 
1080
#
 
1081
DEBUG_LIST      = $(subst $(COMMA), ,$(DEBUG))
 
1082
DEBUG_MAX       = $(firstword $(word 2,$(subst :, ,$(1))) 1)
 
1083
DEBUG_DFLT      = $(if $(word 3,$(subst :, ,$(1))),.$(word 3,$(subst :, ,$(1))))
 
1084
DEBUG_LEVEL     = $(call DEBUG_MAX,$(1))$(call DEBUG_DFLT,$(1))
 
1085
DEBUG_BASE      = $(firstword $(subst :, ,$(1))).dbg$(call DEBUG_LEVEL,$(1))
 
1086
DEBUG_OBJ       = $(BIN)/$(call DEBUG_BASE,$(1)).o
 
1087
DEBUG_ORIG_OBJ  = $(BIN)/$(firstword $(subst :, ,$(1))).o
 
1088
DEBUG_OBJS      = $(foreach D,$(DEBUG_LIST),$(call DEBUG_OBJ,$(D)))
 
1089
DEBUG_ORIG_OBJS = $(foreach D,$(DEBUG_LIST),$(call DEBUG_ORIG_OBJ,$(D)))
 
1090
BLIB_OBJS       = $(DEBUG_OBJS) $(filter-out $(DEBUG_ORIG_OBJS),$(BOBJS))
 
1091
 
 
1092
# Print out all derived information for a given target.
 
1093
#
 
1094
$(BIN)/%.info :
 
1095
        @$(ECHO) 'Elements             : $(TGT_ELEMENTS)'
 
1096
        @$(ECHO) 'Prefix               : $(TGT_PREFIX)'
 
1097
        @$(ECHO) 'Drivers              : $(TGT_DRIVERS)'
 
1098
        @$(ECHO) 'ROM name             : $(TGT_ROM_NAME)'
 
1099
        @$(ECHO)
 
1100
        @$(ECHO) 'PCI vendor           : $(TGT_PCI_VENDOR)'
 
1101
        @$(ECHO) 'PCI device           : $(TGT_PCI_DEVICE)'
 
1102
        @$(ECHO)
 
1103
        @$(ECHO) 'LD driver symbols    : $(TGT_LD_DRIVERS)'
 
1104
        @$(ECHO) 'LD ID symbols        : $(TGT_LD_IDS)'
 
1105
        @$(ECHO) 'LD devlist symbols   : $(TGT_LD_DEVLIST)'
 
1106
        @$(ECHO) 'LD entry point       : $(TGT_LD_ENTRY)'
 
1107
        @$(ECHO)
 
1108
        @$(ECHO) 'LD target flags      : $(TGT_LD_FLAGS)'
 
1109
        @$(ECHO)
 
1110
        @$(ECHO) 'Debugging objects    : $(DEBUG_OBJS)'
 
1111
        @$(ECHO) 'Replaced objects     : $(DEBUG_ORIG_OBJS)'
 
1112
 
 
1113
# List of objects included in the last build of blib.  This is needed
 
1114
# in order to correctly rebuild blib whenever the list of objects
 
1115
# changes.
 
1116
#
 
1117
BLIB_LIST       := $(BIN)/.blib.list
 
1118
ifeq ($(wildcard $(BLIB_LIST)),)
 
1119
BLIB_OBJS_OLD   := <invalid>
 
1120
else
 
1121
BLIB_OBJS_OLD   := $(shell cat $(BLIB_LIST))
 
1122
endif
 
1123
ifneq ($(BLIB_OBJS_OLD),$(BLIB_OBJS))
 
1124
$(shell $(ECHO) "$(BLIB_OBJS)" > $(BLIB_LIST))
 
1125
endif
 
1126
 
 
1127
$(BLIB_LIST) : $(MAKEDEPS)
 
1128
 
 
1129
VERYCLEANUP     += $(BLIB_LIST)
 
1130
 
 
1131
# Library of all objects
 
1132
#
 
1133
BLIB            = $(BIN)/blib.a
 
1134
$(BLIB) : $(BLIB_OBJS) $(BLIB_LIST) $(MAKEDEPS)
 
1135
        $(Q)$(RM) $(BLIB)
 
1136
        $(QM)$(ECHO) "  [AR] $@"
 
1137
        $(Q)$(AR) r $@ $(sort $(BLIB_OBJS))
 
1138
        $(Q)$(RANLIB) $@
 
1139
blib : $(BLIB)
 
1140
 
 
1141
# Command to generate build ID.  Must be unique for each $(BIN)/%.tmp,
 
1142
# even within the same build run.
 
1143
#
 
1144
BUILD_ID_CMD    := perl -e 'printf "0x%08x", int ( rand ( 0xffffffff ) );'
 
1145
 
 
1146
# Build timestamp
 
1147
#
 
1148
BUILD_TIMESTAMP := $(shell date +%s)
 
1149
 
 
1150
# Build version
 
1151
#
 
1152
GIT_INDEX := $(if $(GITVERSION),$(if $(wildcard ../.git/index),../.git/index))
 
1153
$(BIN)/version.%.o : core/version.c $(MAKEDEPS) $(GIT_INDEX)
 
1154
        $(QM)$(ECHO) "  [VERSION] $@"
 
1155
        $(Q)$(COMPILE_c) -DBUILD_NAME="\"$*\"" \
 
1156
                -DVERSION_MAJOR=$(VERSION_MAJOR) \
 
1157
                -DVERSION_MINOR=$(VERSION_MINOR) \
 
1158
                -DVERSION_PATCH=$(VERSION_PATCH) \
 
1159
                -DVERSION="\"$(VERSION)\"" \
 
1160
                -c $< -o $@
 
1161
 
 
1162
# Build an intermediate object file from the objects required for the
 
1163
# specified target.
 
1164
#
 
1165
$(BIN)/%.tmp : $(BIN)/version.%.o $(BLIB) $(MAKEDEPS) $(LDSCRIPT)
 
1166
        $(QM)$(ECHO) "  [LD] $@"
 
1167
        $(Q)$(LD) $(LDFLAGS) -T $(LDSCRIPT) $(TGT_LD_FLAGS) $< $(BLIB) -o $@ \
 
1168
                --defsym _build_id=`$(BUILD_ID_CMD)` \
 
1169
                --defsym _build_timestamp=$(BUILD_TIMESTAMP) \
 
1170
                -Map $(BIN)/$*.tmp.map
 
1171
        $(Q)$(OBJDUMP) -ht $@ | $(PERL) $(SORTOBJDUMP) >> $(BIN)/$*.tmp.map
 
1172
 
 
1173
# Keep intermediate object file (useful for debugging)
 
1174
.PRECIOUS : $(BIN)/%.tmp
 
1175
 
 
1176
# Show a linker map for the specified target
 
1177
#
 
1178
$(BIN)/%.map : $(BIN)/%.tmp
 
1179
        @less $(BIN)/$*.tmp.map
 
1180
 
 
1181
# Get objects list for the specified target
 
1182
#
 
1183
define objs_list
 
1184
        $(sort $(foreach OBJ_SYMBOL,\
 
1185
                 $(filter obj_%,$(shell $(NM) $(1) | cut -d" " -f3)),\
 
1186
                 $(patsubst obj_%,%,$(OBJ_SYMBOL))))
 
1187
endef
 
1188
$(BIN)/%.objs : $(BIN)/%.tmp
 
1189
        $(Q)$(ECHO) $(call objs_list,$<)
 
1190
$(BIN)/%.sizes : $(BIN)/%.tmp
 
1191
        $(Q)$(SIZE) -t $(foreach OBJ,$(call objs_list,$<),$(wildcard $(BIN)/$(subst _,?,$(OBJ)).o)) | \
 
1192
                sort -g
 
1193
 
 
1194
# Get dependency list for the specified target
 
1195
#
 
1196
define deps_list
 
1197
        $(sort $(foreach OBJ,$(call objs_list,$(1)),$($(OBJ)_DEPS)))
 
1198
endef
 
1199
$(BIN)/%.deps : $(BIN)/%.tmp
 
1200
        $(Q)$(ECHO) $(call deps_list,$<)
 
1201
 
 
1202
# Get unneeded source files for the specified target
 
1203
#
 
1204
define nodeps_list
 
1205
        $(sort $(filter-out $(call deps_list,$(1)),\
 
1206
                 $(foreach BOBJ,$(BOBJS),\
 
1207
                   $($(basename $(notdir $(BOBJ)))_DEPS))))
 
1208
endef
 
1209
$(BIN)/%.nodeps : $(BIN)/%.tmp
 
1210
        $(Q)$(ECHO) $(call nodeps_list,$<)
 
1211
 
 
1212
# Get licensing verdict for the specified target
 
1213
#
 
1214
define licensable_deps_list
 
1215
        $(filter-out config/local/%.h,\
 
1216
          $(filter-out $(BIN)/.%.list,\
 
1217
            $(call deps_list,$(1))))
 
1218
endef
 
1219
define unlicensed_deps_list
 
1220
        $(shell grep -L FILE_LICENCE $(call licensable_deps_list,$(1)))
 
1221
endef
 
1222
define licence_list
 
1223
        $(sort $(foreach LICENCE,\
 
1224
                 $(filter __licence__%,$(shell $(NM) $(1) | cut -d" " -f3)),\
 
1225
                 $(word 2,$(subst __, ,$(LICENCE)))))
 
1226
endef
 
1227
$(BIN)/%.licence_list : $(BIN)/%.tmp
 
1228
        $(Q)$(ECHO) $(call licence_list,$<)
 
1229
$(BIN)/%.licence : $(BIN)/%.tmp
 
1230
        $(QM)$(ECHO) "  [LICENCE] $@"
 
1231
        $(Q)$(if $(strip $(call unlicensed_deps_list,$<)),\
 
1232
                echo -n "Unable to determine licence because the following " ;\
 
1233
                echo "files are missing a licence declaration:" ;\
 
1234
                echo $(call unlicensed_deps_list,$<);\
 
1235
                exit 1,\
 
1236
                $(PERL) $(LICENCE) $(call licence_list,$<))
 
1237
 
 
1238
# Extract compression information from intermediate object file
 
1239
#
 
1240
$(BIN)/%.zinfo : $(BIN)/%.tmp
 
1241
        $(QM)$(ECHO) "  [ZINFO] $@"
 
1242
        $(Q)$(OBJCOPY) -O binary -j .zinfo $< $@
 
1243
 
 
1244
# Build raw binary file from intermediate object file
 
1245
#
 
1246
$(BIN)/%.bin : $(BIN)/%.tmp
 
1247
        $(QM)$(ECHO) "  [BIN] $@"
 
1248
        $(Q)$(OBJCOPY) -O binary -R .zinfo $< $@
 
1249
 
 
1250
# Compress raw binary file
 
1251
#
 
1252
$(BIN)/%.zbin : $(BIN)/%.bin $(BIN)/%.zinfo $(ZBIN)
 
1253
        $(QM)$(ECHO) "  [ZBIN] $@"
 
1254
        $(Q)$(ZBIN) $(BIN)/$*.bin $(BIN)/$*.zinfo > $@
 
1255
 
 
1256
# Rules for each media format.  These are generated and placed in an
 
1257
# external Makefile fragment.  We could do this via $(eval ...), but
 
1258
# that would require make >= 3.80.
 
1259
 
1260
# Note that there's an alternative way to generate most .rom images:
 
1261
# they can be copied from their 'master' ROM image using cp and
 
1262
# reprocessed with makerom to add the PCI IDs and ident string.  The
 
1263
# relevant rule would look something like:
 
1264
#
 
1265
#   $(BIN)/dfe538%rom : $(BIN)/rtl8139%rom
 
1266
#       cat $< $@
 
1267
#       $(FINALISE_rom)
 
1268
 
1269
# You can derive the ROM/driver relationships using the variables
 
1270
# DRIVER_<rom> and/or ROMS_<driver>.
 
1271
 
1272
# We don't currently do this, because (a) it would require generating
 
1273
# yet more Makefile fragments (since you need a rule for each ROM in
 
1274
# ROMS), and (b) the linker is so fast that it probably wouldn't make
 
1275
# much difference to the overall build time.
 
1276
 
 
1277
# Add NON_AUTO_MEDIA to the media list, so that they show up in the
 
1278
# output of "make"
 
1279
#
 
1280
MEDIA           += $(NON_AUTO_MEDIA)
 
1281
 
 
1282
media :
 
1283
        @$(ECHO) $(MEDIA)
 
1284
 
 
1285
AUTO_MEDIA      = $(filter-out $(NON_AUTO_MEDIA),$(MEDIA))
 
1286
automedia :
 
1287
        @$(ECHO) $(AUTO_MEDIA)
 
1288
 
 
1289
# media_template : create media rules
 
1290
#
 
1291
# $(1) is the media name (e.g. "rom")
 
1292
#
 
1293
define media_template
 
1294
$(if $(filter $(1),$(AUTO_MEDIA)),$(call auto_media_template,$(1)))
 
1295
LIST_$(1) := $$(if $$(LIST_NAME_$(1)),$$($$(LIST_NAME_$(1))),$$(DRIVERS))
 
1296
ALL_$(1) = $$(foreach ITEM,$$(LIST_$(1)),$$(BIN)/$$(ITEM).$(1))
 
1297
$$(BIN)/all$(1)s : $$(ALL_$(1))
 
1298
$$(BIN)/allall : $$(BIN)/all$(1)s
 
1299
all$(1)s : $$(BIN)/all$(1)s
 
1300
allall : $$(BIN)/allall
 
1301
endef
 
1302
#
 
1303
# $(1) is the media name (e.g. "rom")
 
1304
#
 
1305
define auto_media_template
 
1306
$$(BIN)/%.$(1) : $$(BIN)/%.$(1).zbin
 
1307
        $$(QM)echo "  [FINISH] $$@"
 
1308
        $$(Q)$$(CP) $$< $$@
 
1309
        $$(Q)$$(if $$(PAD_$(1)),$$(PAD_$(1)) $$@)
 
1310
        $$(Q)$$(if $$(FINALISE_$(1)),$$(FINALISE_$(1)) $$@)
 
1311
endef
 
1312
#
 
1313
# $(1) is the media name (e.g. "rom")
 
1314
#
 
1315
define media_template_file
 
1316
        @$(ECHO) "  [MEDIARULES] $(1)"
 
1317
        @$(MKDIR) -p $(BIN)/rules/$(dir $(1))
 
1318
        @$(ECHO_E) '$(subst $(NEWLINE),\n,$(call media_template,$(1)))' \
 
1319
                > $(BIN)/rules/$(1).media.r
 
1320
endef
 
1321
 
 
1322
# Generate media rules files
 
1323
#
 
1324
$(BIN)/rules/%.media.r : $(MAKEDEPS)
 
1325
        $(call media_template_file,$*)
 
1326
 
 
1327
# Calculate list of media rules files
 
1328
#
 
1329
MEDIA_RULES             = $(patsubst %,$(BIN)/rules/%.media.r,$(MEDIA))
 
1330
mediarules :
 
1331
        @$(ECHO) $(MEDIA_RULES)
 
1332
 
 
1333
# Evaluate media rules (or include media rules files)
 
1334
#
 
1335
ifdef NEED_DEPS
 
1336
ifneq ($(MEDIA_RULES),)
 
1337
ifneq ($(HAVE_EVAL),)
 
1338
$(foreach MEDIUM,$(MEDIA),$(eval $(call media_template,$(MEDIUM))))
 
1339
else
 
1340
-include $(MEDIA_RULES)
 
1341
endif
 
1342
endif
 
1343
endif
 
1344
 
 
1345
# Alias for ipxe.%
 
1346
#
 
1347
$(BIN)/etherboot.% : $(BIN)/ipxe.%
 
1348
        ln -sf $(notdir $<) $@
 
1349
 
 
1350
endif # defined(BIN)
 
1351
 
 
1352
###############################################################################
 
1353
#
 
1354
# The compression utilities
 
1355
#
 
1356
 
 
1357
ZBIN_LDFLAGS := -llzma
 
1358
 
 
1359
$(ZBIN) : util/zbin.c $(MAKEDEPS)
 
1360
        $(QM)$(ECHO) "  [HOSTCC] $@"
 
1361
        $(Q)$(HOST_CC) $(HOST_CFLAGS) $< $(ZBIN_LDFLAGS) -o $@
 
1362
CLEANUP += $(ZBIN)
 
1363
 
 
1364
###############################################################################
 
1365
#
 
1366
# The EFI image converter
 
1367
#
 
1368
 
 
1369
$(ELF2EFI32) : util/elf2efi.c $(MAKEDEPS)
 
1370
        $(QM)$(ECHO) "  [HOSTCC] $@"
 
1371
        $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -DEFI_TARGET32 $< -o $@
 
1372
CLEANUP += $(ELF2EFI32)
 
1373
 
 
1374
$(ELF2EFI64) : util/elf2efi.c $(MAKEDEPS)
 
1375
        $(QM)$(ECHO) "  [HOSTCC] $@"
 
1376
        $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -DEFI_TARGET64 $< -o $@
 
1377
CLEANUP += $(ELF2EFI64)
 
1378
 
 
1379
$(EFIROM) : util/efirom.c $(MAKEDEPS)
 
1380
        $(QM)$(ECHO) "  [HOSTCC] $@"
 
1381
        $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
 
1382
CLEANUP += $(EFIROM)
 
1383
 
 
1384
$(EFIFATBIN) : util/efifatbin.c $(MAKEDEPS)
 
1385
        $(QM)$(ECHO) "  [HOSTCC] $@"
 
1386
        $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
 
1387
CLEANUP += $(EFIFATBIN)
 
1388
 
 
1389
###############################################################################
 
1390
#
 
1391
# The ICC fixup utility
 
1392
#
 
1393
$(ICCFIX) : util/iccfix.c $(MAKEDEPS)
 
1394
        $(QM)$(ECHO) "  [HOSTCC] $@"
 
1395
        $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
 
1396
CLEANUP += $(ICCFIX)
 
1397
 
 
1398
###############################################################################
 
1399
#
 
1400
# The error usage information utility
 
1401
#
 
1402
$(EINFO) : util/einfo.c $(MAKEDEPS)
 
1403
        $(QM)$(ECHO) "  [HOSTCC] $@"
 
1404
        $(Q)$(HOST_CC) $(HOST_CFLAGS) -idirafter include -o $@ $<
 
1405
CLEANUP += $(EINFO)
 
1406
 
 
1407
###############################################################################
 
1408
#
 
1409
# Local configs
 
1410
#
 
1411
CONFIG_HEADERS := $(patsubst config/%,%,$(wildcard config/*.h))
 
1412
CONFIG_LOCAL_HEADERS := $(foreach HEADER,$(CONFIG_HEADERS),\
 
1413
                                  config/local/$(HEADER))
 
1414
 
 
1415
$(CONFIG_LOCAL_HEADERS) :
 
1416
        $(Q)$(TOUCH) $@
 
1417
 
 
1418
.PRECIOUS : $(CONFIG_LOCAL_HEADERS)
 
1419
 
 
1420
ifneq ($(CONFIG),)
 
1421
 
 
1422
CONFIG_LOCAL_NAMED_HEADERS := $(foreach HEADER,$(CONFIG_HEADERS),\
 
1423
                                        config/local/$(CONFIG)/$(HEADER))
 
1424
 
 
1425
$(CONFIG_LOCAL_NAMED_HEADERS) :
 
1426
        $(Q)$(MKDIR) -p $(dir $@)
 
1427
        $(Q)$(TOUCH) $@
 
1428
 
 
1429
.PRECIOUS : $(CONFIG_LOCAL_NAMED_HEADERS)
 
1430
 
 
1431
endif
 
1432
 
 
1433
###############################################################################
 
1434
#
 
1435
# Build the TAGS file(s) for emacs
 
1436
#
 
1437
TAGS :
 
1438
        ctags -e -R -f $@ --exclude=bin
 
1439
 
 
1440
CLEANUP += TAGS
 
1441
 
 
1442
###############################################################################
 
1443
#
 
1444
# Force rebuild for any given target
 
1445
#
 
1446
%.rebuild :
 
1447
        rm -f $*
 
1448
        $(Q)$(MAKE) $*
 
1449
 
 
1450
###############################################################################
 
1451
#
 
1452
# Symbol table checks
 
1453
#
 
1454
 
 
1455
ifdef BIN
 
1456
 
 
1457
SYMTAB  = $(BIN)/symtab
 
1458
$(SYMTAB) : $(BLIB)
 
1459
        $(OBJDUMP) -w -t $< > $@
 
1460
 
 
1461
CLEANUP += $(BIN)/symtab
 
1462
 
 
1463
symcheck : $(SYMTAB)
 
1464
        $(PERL) $(SYMCHECK) $<
 
1465
 
 
1466
endif # defined(BIN)
 
1467
 
 
1468
###############################################################################
 
1469
#
 
1470
# Build bochs symbol table
 
1471
#
 
1472
 
 
1473
ifdef BIN
 
1474
 
 
1475
$(BIN)/%.bxs : $(BIN)/%.tmp
 
1476
        $(NM) $< | cut -d" " -f1,3 > $@
 
1477
 
 
1478
endif # defined(BIN)
 
1479
 
 
1480
###############################################################################
 
1481
#
 
1482
# Documentation
 
1483
#
 
1484
 
 
1485
ifdef BIN
 
1486
 
 
1487
$(BIN)/doxygen.cfg : doxygen.cfg $(MAKEDEPS)
 
1488
        $(Q)$(PERL) -pe 's{\@SRCDIRS\@}{$(SRCDIRS)}; ' \
 
1489
                -e  's{\@INCDIRS\@}{$(filter-out .,$(INCDIRS))}; ' \
 
1490
                -e  's{\@BIN\@}{$(BIN)}; ' \
 
1491
                -e  's{\@ARCH\@}{$(ARCH)}; ' \
 
1492
                $< > $@
 
1493
 
 
1494
$(BIN)/doc : $(BIN)/doxygen.cfg
 
1495
        $(Q)$(DOXYGEN) $<
 
1496
 
 
1497
.PHONY : $(BIN)/doc
 
1498
 
 
1499
doc : $(BIN)/doc
 
1500
 
 
1501
doc-clean :
 
1502
        $(Q)$(RM) -r $(BIN)/doc
 
1503
 
 
1504
VERYCLEANUP     += $(BIN)/doc
 
1505
 
 
1506
docview :
 
1507
        @[ -f $(BIN)/doc/html/index.html ] || $(MAKE) $(BIN)/doc
 
1508
        @if [ -n "$$BROWSER" ] ; then \
 
1509
                ( $$BROWSER $(BIN)/doc/html/index.html & ) ; \
 
1510
        else \
 
1511
                $(ECHO) "Documentation index in $(BIN)/doc/html/index.html" ; \
 
1512
        fi
 
1513
 
 
1514
endif # defined(BIN)
 
1515
 
 
1516
###############################################################################
 
1517
#
 
1518
# Keyboard maps
 
1519
#
 
1520
 
 
1521
hci/keymap/keymap_%.c :
 
1522
        $(Q)$(PERL) $(GENKEYMAP) $* > $@
 
1523
 
 
1524
###############################################################################
 
1525
#
 
1526
# Force deletion of incomplete targets
 
1527
#
 
1528
 
 
1529
.DELETE_ON_ERROR :
 
1530
 
 
1531
###############################################################################
 
1532
#
 
1533
# Clean-up
 
1534
#
 
1535
 
 
1536
ifeq ($(NUM_BINS),0)
 
1537
ALLBINS         := bin{,-*}
 
1538
CLEANUP         := $(patsubst $(BIN)/%,$(ALLBINS)/%,$(CLEANUP))
 
1539
VERYCLEANUP     := $(patsubst $(BIN)/%,$(ALLBINS)/%,$(VERYCLEANUP))
 
1540
endif
 
1541
 
 
1542
clean :
 
1543
        $(RM) $(CLEANUP)
 
1544
 
 
1545
veryclean : clean
 
1546
        $(RM) -r $(VERYCLEANUP)