summaryrefslogtreecommitdiffstats
path: root/config.mk
blob: 878618f8410e31a10e1d9b2c3e5effb1dc8f2972 (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
#  IBM_PROLOG_BEGIN_TAG
#  This is an automatically generated prolog.
#
#  $Source: config.mk $
#
#  IBM CONFIDENTIAL
#
#  COPYRIGHT International Business Machines Corp. 2010 - 2011
#
#  p1
#
#  Object Code Only (OCO) source materials
#  Licensed Internal Code Source Materials
#  IBM HostBoot Licensed Internal Code
#
#  The source code for this program is not published or other-
#  wise divested of its trade secrets, irrespective of what has
#  been deposited with the U.S. Copyright Office.
#
#  Origin: 30
#
#  IBM_PROLOG_END

all:
	${MAKE} gen_pass
	${MAKE} code_pass

## output libs, objs for userdetails parsers
UD_DIR = ${ROOTPATH}/obj/modules/userdetails
UD_OBJS = ${UD_DIR}*.o ${UD_DIR}/*.so ${UD_DIR}/*.a

ifdef MODULE
OBJDIR = ${ROOTPATH}/obj/modules/${MODULE}
BEAMDIR = ${ROOTPATH}/obj/beam/${MODULE}
GENDIR = ${ROOTPATH}/obj/genfiles
IMGDIR = ${ROOTPATH}/img
GCOVNAME = ${MODULE}.lcov
EXTRACOMMONFLAGS += -fPIC -Bsymbolic -Bsymbolic-functions 
ifdef STRICT
        EXTRACOMMONFLAGS += -Weffc++
endif
CUSTOMFLAGS += -D__HOSTBOOT_MODULE=${MODULE}
ifdef HOSTBOOT_PROFILE
vpath %.C ${ROOTPATH}/src/sys/prof
OBJS += gcov.o
endif
LIBS += $(addsuffix .so, $(addprefix lib, ${MODULE}))
MODULE_INIT = ${ROOTPATH}/obj/core/module_init.o
EXTRAINCDIR += ${ROOTPATH}/src/include/usr ${GENDIR}
else
OBJDIR = ${ROOTPATH}/obj/core
BEAMDIR = ${ROOTPATH}/obj/beam/core
GENDIR = ${ROOTPATH}/obj/genfiles
IMGDIR = ${ROOTPATH}/img
EXTRAINCDIR += ${GENDIR}
GCOVNAME = $(notdir $(shell pwd)).lcov
endif
GCOVDIR = ${ROOTPATH}/obj/gcov

__internal__comma= ,
__internal__empty=
__internal__space=$(__internal__empty) $(__internal__empty)
MAKE_SPACE_LIST = $(subst $(__internal__comma),$(__internal__space),$(1))

ifdef HOSTBOOT_DEBUG
ifeq ($(HOSTBOOT_DEBUG),1)
    CUSTOMFLAGS += -DHOSTBOOT_DEBUG=1
else
ifndef MODULE
ifneq (,$(filter kernel,$(call MAKE_SPACE_LIST, $(HOSTBOOT_DEBUG))))
    CUSTOMFLAGS += -DHOSTBOOT_DEBUG=kernel
endif
else
ifneq (,$(filter $(MODULE), $(call MAKE_SPACE_LIST, $(HOSTBOOT_DEBUG))))
    CUSTOMFLAGS += -DHOSTBOOT_DEBUG=$(MODULE)
endif
endif
endif
endif

ifdef HOSTBOOT_PROFILE
CUSTOMFLAGS += --coverage
endif

TRACEPP = ${ROOTPATH}/src/build/trace/tracepp
CUSTOM_LINKER_EXE = ${ROOTPATH}/src/build/linker/linker
CUSTOM_LINKER = i686-mcp6-jail ${CUSTOM_LINKER_EXE}

CC_RAW = ppc64-mcp6-gcc -std=c99
CXX_RAW = ppc64-mcp6-g++
CC = ${TRACEPP} ${CC_RAW}
CXX = ${TRACEPP} ${CXX_RAW}

LD = ppc64-mcp6-ld
OBJDUMP = ppc64-mcp6-objdump
GCOV = ppc64-mcp6-gcov
APYFIPSHDR = apyfipshdr
APYRUHHDR = apyruhhdr

BINFILE_CACHE_LOCALDIR = ${ROOTPATH}/.git/hb_cache/data/
BINFILE_CACHE_REMOTEDIR = /gsa/ausgsa/projects/h/hostboot/.binary_cache/data/

BEAMVER = beam-3.5.2
BEAMPATH = /afs/rch/projects/esw/beam/${BEAMVER}
BEAMCMD = i686-mcp6-jail ${BEAMPATH}/bin/beam_compile
BEAMFLAGS = \
    --beam::source=${BEAMPATH}/tcl/beam_default_parms.tcl \
    --beam::source=${ROOTPATH}/src/build/beam/compiler_c_config.tcl \
    --beam::source=${ROOTPATH}/src/build/beam/compiler_cpp_config.tcl \
    --beam::exit0 \
    -o /dev/null

COMMONFLAGS = -O3 -nostdlib ${EXTRACOMMONFLAGS}
CFLAGS = ${COMMONFLAGS} -mcpu=power7 -nostdinc -g -mno-vsx -mno-altivec\
	 -Wall -Werror -fshort-enums ${CUSTOMFLAGS}
ASMFLAGS = ${COMMONFLAGS} -mcpu=power7
CXXFLAGS = ${CFLAGS} -nostdinc++ -fno-rtti -fno-exceptions -Wall
LDFLAGS = --nostdlib --sort-common ${COMMONFLAGS}

ifdef HOSTBOOT_PROFILE
    PROFILE_FLAGS_FILTER = $(if $(findstring gcov,$(2)),\
				$(filter-out --coverage,$(1)),\
				$(1))
else
    PROFILE_FLAGS_FILTER = $(1)
endif

FLAGS_FILTER = $(call PROFILE_FLAGS_FILTER, $(1), $(2))

ifdef USE_PYTHON
    TESTGEN = ${ROOTPATH}/src/usr/cxxtest/cxxtestgen.py
else
    TESTGEN = ${ROOTPATH}/src/usr/cxxtest/cxxtestgen.pl
endif

ifdef TESTS
ifdef MODULE
OBJS += ${MODULE}.o
EXTRA_OBJS += ${OBJDIR}/${MODULE}.C
vpath %.C ${OBJDIR} $(shell mkdir -p ${OBJDIR})
else
$(error MODULE must be defined for a testcase.)
endif
endif


INCDIR = ${ROOTPATH}/src/include/
_INCDIRS = ${INCDIR} ${EXTRAINCDIR}
INCFLAGS = $(addprefix -I, ${_INCDIRS} )
ASMINCFLAGS = $(addprefix $(lastword -Wa,-I), ${_INCDIRS})

OBJECTS = $(addprefix ${OBJDIR}/, ${OBJS})
LIBRARIES = $(addprefix ${IMGDIR}/, ${LIBS})

ifdef IMGS
IMGS_ = $(addprefix ${IMGDIR}/, ${IMGS})
LIDS = $(foreach lid,$(addsuffix _LIDNUMBER, $(IMGS)),$(addprefix ${IMGDIR}/,$(addsuffix .ruhx, $($(lid)))))
IMAGES = $(addsuffix .bin, ${IMGS_}) $(addsuffix .elf, ${IMGS_}) ${LIDS}
#$(addsuffix .ruhx, ${IMGS_})
IMAGE_EXTRAS = $(addprefix ${IMGDIR}/, hbotStringFile)
endif

ifdef EXTRA_LIDS
EXTRA_LIDS_ = $(foreach lid,$(addsuffix _LIDNUMBER, $(EXTRA_LIDS)),$(addprefix ${IMGDIR}/,$(addsuffix .lidhdr, $($(lid)))))
endif

${OBJDIR}/%.o ${OBJDIR}/%.list : %.C
	mkdir -p ${OBJDIR}
	${CXX} -c $(call FLAGS_FILTER, ${CXXFLAGS}, $<) $< \
	       -o $@ ${INCFLAGS} -iquote .
	${OBJDUMP} -rdlCS $@ > $(basename $@).list	

# Compiling *.cc files
${OBJDIR}/%.o ${OBJDIR}/%.list : %.cc
	mkdir -p ${OBJDIR}
	${CXX} -c ${CXXFLAGS} $< -o $@ ${INCFLAGS} -iquote .
	${OBJDUMP} -rdlCS $@ > $(basename $@).list	

${OBJDIR}/%.o ${OBJDIR}/%.list : %.c
	mkdir -p ${OBJDIR}
    # Override to use C++ compiler in place of C compiler
    # CC_OVERRIDE is set in the makefile of the component
ifndef CC_OVERRIDE
	${CC} -c $(call FLAGS_FILTER, ${CFLAGS}, $<) $< \
	      -o $@ ${INCFLAGS} -iquote .
else
	${CXX} -c $(call FLAGS_FILTER, ${CXXFLAGS}, $<) $< \
	      -o $@ ${INCFLAGS} -iquote .
endif
	${OBJDUMP} -rdlCS $@ > $(basename $@).list

${OBJDIR}/%.o : %.S
	mkdir -p ${OBJDIR}
	${CC} -c ${ASMFLAGS} $< -o $@ ${ASMINCFLAGS} ${INCFLAGS} -iquote .

${OBJDIR}/%.dep : %.C
	mkdir -p ${OBJDIR}; \
	rm -f $@; \
	${CXX_RAW} -M $(call FLAGS_FILTER, ${CXXFLAGS}, $<) $< \
	           -o $@.$$$$ ${INCFLAGS} -iquote .; \
	sed 's,\($*\)\.o[ :]*,${OBJDIR}/\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

${OBJDIR}/%.dep : %.cc
	mkdir -p ${OBJDIR}; \
	rm -f $@; \
	${CXX_RAW} -M ${CXXFLAGS} $< -o $@.$$$$ ${INCFLAGS} -iquote .; \
	sed 's,\($*\)\.o[ :]*,${OBJDIR}/\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

${OBJDIR}/%.dep : %.c
	mkdir -p ${OBJDIR}; \
	rm -f $@; \
	${CC_RAW} -M $(call FLAGS_FILTER, ${CFLAGS}, $<) $< \
		  -o $@.$$$$ ${INCFLAGS} -iquote .; \
	sed 's,\($*\)\.o[ :]*,${OBJDIR}/\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

${OBJDIR}/%.dep : %.S
	mkdir -p ${OBJDIR}; \
	rm -f $@; \
	${CC_RAW} -M ${ASMFLAGS} $< -o $@.$$$$ ${ASMINCFLAGS} ${INCFLAGS} -iquote .; \
	sed 's,\($*\)\.o[ :]*,${OBJDIR}/\1.o $@ : ,g' < $@.$$$$ > $@; \
	rm -f $@.$$$$

ifdef MODULE
${IMGDIR}/%.so : ${OBJECTS} ${ROOTPATH}/src/module.ld ${MODULE_INIT}
	${LD} -shared -z now ${LDFLAGS} \
	      $(filter-out ${ROOTPATH}/src/module.ld,$^) \
	      -T ${ROOTPATH}/src/module.ld -o $@
endif

ifdef TESTS
${OBJDIR}/${MODULE}.C: ${TESTS}
	mkdir -p ${OBJDIR}
	${TESTGEN} --hostboot -o $@ ${TESTS}
endif

# Rules for BINARY_FILES directive.
#
#    The BINARY_FILES directives are used to include files out of the binary
#    files cache (see 'hb cacheadd' command).  This cache exists to keep
#    binary files outside of git, because they take a larger space in the git
#    database, especially if they change frequently.
#
#    The BINARY_FILES variable is a set of <destination>:<hash_value> pairs.
#    The destination is where the make system should put the file.  The hash
#    value tells which version of a file to use and it comes from the 
#    'hb cacheadd' tool when a version of the file is added to the binary
#    files cache.
#
define __BINARY_CACHE_FILE
_BINARYFILES += $(1)

ifneq "$(wildcard $(addprefix ${BINFILE_CACHE_LOCALDIR},$(2)))" ""
$(1) : $(addprefix $${BINFILE_CACHE_LOCALDIR},$(2))
	echo "$(2) $$<" | sha1sum --check
	cp $$< $$@
else
$(1) : $(addprefix $${BINFILE_CACHE_REMOTEDIR},$(2))
	echo "$(2) $$<" | sha1sum --check
	cp $$< $$@
endif
endef
ifdef BINARY_FILES
$(foreach file,$(BINARY_FILES), \
	  $(eval $(call __BINARY_CACHE_FILE, \
			    $(firstword $(subst :, ,$(file))), \
			    $(lastword $(subst :, ,$(file))) \
	  )) \
)
endif
# end BINARY_FILES rules.

define ELF_template
$${IMGDIR}/$(1).elf: $$(addprefix $${OBJDIR}/, $$($(1)_OBJECTS)) \
		    $${ROOTPATH}/src/kernel.ld
	$${LD} -static $${LDFLAGS} \
	      $$(addprefix $${OBJDIR}/,	$$($(1)_OBJECTS)) \
	      $$($(1)_LDFLAGS) -T $${ROOTPATH}/src/kernel.ld -o $$@
endef
$(foreach img,$(IMGS),$(eval $(call ELF_template,$(img))))

${IMGDIR}/%.bin ${IMGDIR}/%.list ${IMGDIR}/%.syms: ${IMGDIR}/%.elf \
    $(wildcard ${IMGDIR}/*.so) $(addprefix ${IMGDIR}/, $($*_DATA_MODULES)) \
    ${CUSTOM_LINKER_EXE}
	${CUSTOM_LINKER} $@ $< \
	      $(addprefix ${IMGDIR}/lib, $(addsuffix .so, $($*_MODULES))) \
		--extended=0x40000 ${IMGDIR}/$*_extended.bin \
	      $(addprefix ${IMGDIR}/lib, $(addsuffix .so, $($*_EXTENDED_MODULES))) \
	      $(addprefix ${IMGDIR}/, $($*_DATA_MODULES)) \
	      > ${IMGDIR}/.$*.lnkout
	${ROOTPATH}/src/build/tools/addimgid $@ $<
	(cd ${ROOTPATH}; \
	    src/build/tools/gensyms $*.bin $*_extended.bin 0x40000000 > ./img/$*.syms ; \
	    src/build/tools/genlist $*.bin > ./img/$*.list)


define RUHX_template
${IMGDIR}/$$($(1)_LIDNUMBER).ruhx: $${ROOTPATH}/src/build/lids/$(1).lidhdr \
				   $${IMGDIR}/$(1).bin
	$${APYFIPSHDR} -r $$< -l $${IMGDIR}/$(1).bin -o $${IMGDIR}/$(1).fips
	$${APYRUHHDR} -r $$< -l ${IMGDIR}/$(1).fips -o $${IMGDIR}/$$($(1)_LIDNUMBER).ruhx
	(rm -f $${IMGDIR}/$(1).fips)
	ln -sf $${IMGDIR}/$(1).bin $${IMGDIR}/$$($(1)_LIDNUMBER).lid
	ln -sf $${ROOTPATH}/src/build/lids/$(1).lidhdr $${IMGDIR}/$$($(1)_LIDNUMBER).lidhdr
endef
$(foreach img,$(IMGS),$(eval $(call RUHX_template,$(img))))

define LIDHDR_template
${IMGDIR}/$$($(1)_LIDNUMBER).lidhdr: $${ROOTPATH}/src/build/lids/$(1).lidhdr
	ln -sf $$^ $$@
endef
$(foreach lid,$(EXTRA_LIDS),$(eval $(call LIDHDR_template,$(lid))))

${IMGDIR}/hbotStringFile : ${IMAGES}
	${ROOTPATH}/src/build/trace/tracehash_hb.pl -c -d ${ROOTPATH}/obj -s $@

%.d: ${OBJECTS}
	cd ${basename $@} && ${MAKE} code_pass

%.gen_pass:
	cd ${basename $@} && ${MAKE} gen_pass

%.gcov_pass:
	cd ${basename $@} && ${MAKE} gcov_pass -ik

%.clean:
	cd ${basename $@} && ${MAKE} clean

%.beamdir:
	cd ${basename $@} && ${MAKE} beam

code_pass: ${OBJECTS} ${SUBDIRS} ${LIBRARIES} ${EXTRA_LIDS_} ${EXTRA_PARTS}
ifdef IMAGES
	${MAKE} ${IMAGES} ${IMAGE_EXTRAS} ${IMAGE_EXTRA_TARGETS}
endif

gen_pass:
	mkdir -p ${GENDIR}
	${MAKE} GEN_PASS

_GENFILES = $(addprefix ${GENDIR}/, $(GENFILES))
GEN_PASS: $(_GENFILES) $(_BINARYFILES) ${SUBDIRS:.d=.gen_pass}

GENTARGET = $(addprefix %/, $(1))

${BEAMDIR}/%.beam : %.C
	mkdir -p ${BEAMDIR}
	${BEAMCMD} -I ${INCDIR} ${CXXFLAGS} ${BEAMFLAGS} $< \
	    --beam::complaint_file=$@ --beam::parser_file=/dev/null

${BEAMDIR}/%.beam : %.cc
	mkdir -p ${BEAMDIR}
	${BEAMCMD} -I ${INCDIR} ${CXXFLAGS} ${BEAMFLAGS} $< \
	    --beam::complaint_file=$@ --beam::parser_file=/dev/null

${BEAMDIR}/%.beam : %.c
	mkdir -p ${BEAMDIR}
	${BEAMCMD} -I ${INCDIR} ${CFLAGS} ${BEAMFLAGS} $< \
	    --beam::complaint_file=$@ --beam::parser_file=/dev/null

${BEAMDIR}/%.beam : %.S
	echo Skipping ASM file.

BEAMOBJS = $(addprefix ${BEAMDIR}/, ${OBJS:.o=.beam})
beam: ${SUBDIRS:.d=.beamdir} ${BEAMOBJS}

gcov_pass:
	mkdir -p ${GCOVDIR}
	${MAKE} GCOV_PASS

GCOV_PASS: ${SUBDIRS:.d=.gcov_pass}
ifdef OBJS
	cp ${OBJECTS:.o=.gcno} ${OBJECTS:.o=.gcda} .
	lcov --directory . -c -o ${GCOVDIR}/${GCOVNAME} \
	     --gcov-tool ${GCOV} --ignore-errors source
	rm ${OBJS:.o=.gcno} ${OBJS:.o=.gcda} -f
endif

cleanud :
	rm -f ${UD_OBJS}

clean: cleanud ${SUBDIRS:.d=.clean}
	(rm -f ${OBJECTS} ${OBJECTS:.o=.dep} ${OBJECTS:.o=.list} \
	       ${OBJECTS:.o=.o.hash} ${OBJECTS:.o=.gcno} ${OBJECTS:.o=.gcda} \
	       ${BEAMOBJS} ${LIBRARIES} \
	       ${IMAGES} ${IMAGES:.bin=.list} ${IMAGES:.bin=.syms} \
	       ${IMAGES:.bin=.bin.modinfo} ${IMAGES:.ruhx=.lid} \
	       ${IMAGES:.ruhx=.lidhdr} ${IMAGES:.bin=_extended.bin} \
	       ${IMAGE_EXTRAS} ${EXTRA_LIDS_} \
	       ${EXTRA_OBJS} ${_GENFILES} ${_BINARYFILES} ${EXTRA_PARTS} ${EXTRA_CLEAN} )

cscope: ${SUBDIRS}
	mkdir -p ${ROOTPATH}/obj/cscope
	(cd ${ROOTPATH}/obj/cscope ; rm -f cscope.* ; \
	    find ../../ -name '*.[CHchS]' -type f -fprint cscope.files; \
	    cscope -bqk)

ctags: ${SUBDIRS}
	mkdir -p ${ROOTPATH}/obj/cscope
	(cd ${ROOTPATH}/obj/cscope ; rm -f tags ; \
	    ctags --recurse=yes --fields=+S ../../src)

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(MAKECMDGOALS),gen_pass)
ifneq ($(MAKECMDGOALS),GEN_PASS)
    -include $(OBJECTS:.o=.dep)
endif
endif
endif
OpenPOWER on IntegriCloud