util/amdfwtool: Add generic image copy function
[coreboot.git] / Makefile
blob45b0bc5f8c2fa75fdca4c25196235b7cb01434eb
1 ##
2 ## This file is part of the coreboot project.
3 ##
4 ## Copyright (C) 2008 Advanced Micro Devices, Inc.
5 ## Copyright (C) 2008 Uwe Hermann <uwe@hermann-uwe.de>
6 ## Copyright (C) 2009-2010 coresystems GmbH
7 ## Copyright (C) 2011 secunet Security Networks AG
8 ##
9 ## Redistribution and use in source and binary forms, with or without
10 ## modification, are permitted provided that the following conditions
11 ## are met:
12 ## 1. Redistributions of source code must retain the above copyright
13 ## notice, this list of conditions and the following disclaimer.
14 ## 2. Redistributions in binary form must reproduce the above copyright
15 ## notice, this list of conditions and the following disclaimer in the
16 ## documentation and/or other materials provided with the distribution.
17 ## 3. The name of the author may not be used to endorse or promote products
18 ## derived from this software without specific prior written permission.
20 ## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 ## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 ## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 ## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 ## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 ## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 ## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 ## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 ## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 ## SUCH DAMAGE.
33 top := $(CURDIR)
34 src := src
35 srck := $(top)/util/kconfig
36 obj ?= build
37 override obj := $(subst $(top)/,,$(abspath $(obj)))
38 objutil ?= $(obj)/util
39 objk := $(objutil)/kconfig
40 absobj := $(abspath $(obj))
42 COREBOOT_EXPORTS := COREBOOT_EXPORTS
43 COREBOOT_EXPORTS += top src srck obj objutil objk
45 DOTCONFIG ?= $(top)/.config
46 KCONFIG_CONFIG = $(DOTCONFIG)
47 KCONFIG_AUTOADS := $(obj)/cb-config.ads
48 KCONFIG_AUTOHEADER := $(obj)/config.h
49 KCONFIG_AUTOCONFIG := $(obj)/auto.conf
50 KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
51 KCONFIG_SPLITCONFIG := $(obj)/config
52 KCONFIG_TRISTATE := $(obj)/tristate.conf
53 KCONFIG_NEGATIVES := 1
54 KCONFIG_STRICT := 1
55 KCONFIG_PACKAGE := CB.Config
57 COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
58 COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
59 COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
60 COREBOOT_EXPORTS += KCONFIG_AUTOADS KCONFIG_PACKAGE
62 # directory containing the toplevel Makefile.inc
63 TOPLEVEL := .
65 CONFIG_SHELL := sh
66 KBUILD_DEFCONFIG := configs/defconfig
67 UNAME_RELEASE := $(shell uname -r)
68 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
69 MAKEFLAGS += -rR --no-print-directory
71 # Make is silent per default, but 'make V=1' will show all compiler calls.
72 Q:=@
73 ifneq ($(V),1)
74 ifneq ($(Q),)
75 .SILENT:
76 endif
77 endif
79 # Disable implicit/built-in rules to make Makefile errors fail fast.
80 .SUFFIXES:
82 HOSTCC := $(if $(shell type gcc 2>/dev/null),gcc,cc)
83 HOSTCXX = g++
84 HOSTCFLAGS := -g
85 HOSTCXXFLAGS := -g
87 PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
89 DOXYGEN := doxygen
90 DOXYGEN_OUTPUT_DIR := doxygen
92 export $(COREBOOT_EXPORTS)
94 all: real-all
96 help_coreboot help::
97 @echo '*** coreboot platform targets ***'
98 @echo ' Use "make [target] V=1" for extra build debug information'
99 @echo ' all - Build coreboot'
100 @echo ' clean - Remove coreboot build artifacts'
101 @echo ' distclean - Remove build artifacts and config files'
102 @echo ' doxygen - Build doxygen documentation for coreboot'
103 @echo ' doxyplatform - Build doxygen documentation for the current platform'
104 @echo ' filelist - Show files used in current build'
105 @echo ' printall - print makefile info for debugging'
106 @echo ' gitconfig - set up git to submit patches to coreboot'
107 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
108 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
109 @echo
111 # This include must come _before_ the pattern rules below!
112 # Order _does_ matter for pattern rules.
113 include $(srck)/Makefile
115 # Three cases where we don't need fully populated $(obj) lists:
116 # 1. when no .config exists
117 # 2. when make config (in any flavour) is run
118 # 3. when make distclean is run
119 # Don't waste time on reading all Makefile.incs in these cases
120 ifeq ($(strip $(HAVE_DOTCONFIG)),)
121 NOCOMPILE:=1
122 endif
123 ifneq ($(MAKECMDGOALS),)
124 ifneq ($(filter %config %clean cross% clang iasl gnumake lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
125 NOCOMPILE:=1
126 endif
127 ifeq ($(MAKECMDGOALS), %clean)
128 NOMKDIR:=1
129 endif
130 endif
132 ifeq ($(NOCOMPILE),1)
133 include $(TOPLEVEL)/Makefile.inc
134 include $(TOPLEVEL)/payloads/Makefile.inc
135 include $(TOPLEVEL)/util/testing/Makefile.inc
136 -include $(TOPLEVEL)/site-local/Makefile.inc
137 real-all:
138 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
139 @echo "Please specify a config file or run 'make menuconfig' to" >&2
140 @echo "generate a new config file." >&2
141 @exit 1
142 else
144 include $(DOTCONFIG)
146 # in addition to the dependency below, create the file if it doesn't exist
147 # to silence stupid warnings about a file that would be generated anyway.
148 $(if $(wildcard .xcompile)$(NOCOMPILE),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
150 .xcompile: util/xcompile/xcompile
151 rm -f $@
152 $< $(XGCCPATH) > $@.tmp
153 \mv -f $@.tmp $@ 2> /dev/null
154 rm -f $@.tmp
156 -include .xcompile
158 ifneq ($(XCOMPILE_COMPLETE),1)
159 $(shell rm -f .xcompile)
160 $(error .xcompile deleted because it's invalid. \
161 Restarting the build should fix that, or explain the problem)
162 endif
164 ifneq ($(CONFIG_MMX),y)
165 CFLAGS_x86_32 += -mno-mmx
166 endif
168 include toolchain.inc
170 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
171 # fix makefile syntax highlighting after strip macro \" "))
173 # The primary target needs to be here before we include the
174 # other files
176 real-all: real-target
178 # must come rather early
179 .SECONDEXPANSION:
180 .DELETE_ON_ERROR:
182 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG) $(objutil)/kconfig/conf
183 +$(MAKE) oldconfig
185 $(KCONFIG_AUTOCONFIG): $(KCONFIG_AUTOHEADER)
186 true
188 $(KCONFIG_AUTOADS): $(KCONFIG_AUTOCONFIG) $(objutil)/kconfig/toada
189 $(objutil)/kconfig/toada CB.Config <$< >$@
191 $(obj)/%/$(notdir $(KCONFIG_AUTOADS)): $(KCONFIG_AUTOADS)
192 cp $< $@
194 # Add a new class of source/object files to the build system
195 add-class= \
196 $(eval $(1)-srcs:=) \
197 $(eval $(1)-objs:=) \
198 $(eval classes+=$(1))
200 # Special classes are managed types with special behaviour
201 # On parse time, for each entry in variable $(1)-y
202 # a handler $(1)-handler is executed with the arguments:
203 # * $(1): directory the parser is in
204 # * $(2): current entry
205 add-special-class= \
206 $(eval $(1):=) \
207 $(eval special-classes+=$(1))
209 # Converts one or more source file paths to their corresponding build/ paths.
210 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
211 # their name.
212 # $1 stage name
213 # $2 file path (list)
214 src-to-obj=\
215 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
216 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
217 $(patsubst 3rdparty/%,$(obj)/%,\
218 $(patsubst src/%,$(obj)/%,\
219 $(patsubst %.ads,%.o,\
220 $(patsubst %.adb,%.o,\
221 $(patsubst %.c,%.o,\
222 $(patsubst %.S,%.o,\
223 $(subst .$(1),,$(2))))))))))
225 # Converts one or more source file paths to the corresponding build/ paths
226 # of their Ada library information (.ali) files.
227 # $1 stage name
228 # $2 file path (list)
229 src-to-ali=\
230 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
231 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
232 $(patsubst 3rdparty/%,$(obj)/%,\
233 $(patsubst src/%,$(obj)/%,\
234 $(patsubst %.ads,%.ali,\
235 $(patsubst %.adb,%.ali,\
236 $(subst .$(1),,\
237 $(filter %.ads %.adb,$(2)))))))))
239 # Clean -y variables, include Makefile.inc
240 # Add paths to files in X-y to X-srcs
241 # Add subdirs-y to subdirs
242 includemakefiles= \
243 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
244 $(eval -include $(1)) \
245 $(foreach class,$(classes-y), $(call add-class,$(class))) \
246 $(foreach class,$(classes), \
247 $(eval $(class)-srcs+= \
248 $$(subst $(absobj)/,$(obj)/, \
249 $$(subst $(top)/,, \
250 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
251 $(foreach special,$(special-classes), \
252 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
253 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(wildcard $$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y))))))
255 # For each path in $(subdirs) call includemakefiles
256 # Repeat until subdirs is empty
257 evaluate_subdirs= \
258 $(eval cursubdirs:=$(subdirs)) \
259 $(eval subdirs:=) \
260 $(foreach dir,$(cursubdirs), \
261 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
262 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
264 # collect all object files eligible for building
265 subdirs:=$(TOPLEVEL)
266 postinclude-hooks :=
267 $(eval $(call evaluate_subdirs))
268 ifeq ($(FAILBUILD),1)
269 $(error cannot continue build)
270 endif
272 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
273 $(eval $(postinclude-hooks))
275 # Eliminate duplicate mentions of source files in a class
276 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
278 # Build Kconfig .ads if necessary
279 ifeq ($(CONFIG_RAMSTAGE_ADA),y)
280 ramstage-srcs += $(obj)/ramstage/$(notdir $(KCONFIG_AUTOADS))
281 endif
283 # To track dependencies, we need all Ada specification (.ads) files in
284 # *-srcs. Extract / filter all specification files that have a matching
285 # body (.adb) file here (specifications without a body are valid sources
286 # in Ada).
287 $(foreach class,$(classes),$(eval $(class)-extra-specs := \
288 $(filter \
289 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
290 $(filter %.ads,$($(class)-srcs)))))
291 $(foreach class,$(classes),$(eval $(class)-srcs := \
292 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
294 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
295 $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
297 # For Ada includes
298 $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
300 # Save all objs before processing them (for dependency inclusion)
301 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
303 # Call post-processors if they're defined
304 $(foreach class,$(classes),\
305 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
307 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
308 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
309 alldirs:=$(sort $(abspath $(dir $(allobjs))))
311 # Reads dependencies from an Ada library information (.ali) file
312 # Only basenames (with suffix) are preserved so we have to look the
313 # paths up in $($(stage)-srcs).
314 # $1 stage name
315 # $2 ali file
316 create_ada_deps=$$(if $(2),\
317 gnat.adc \
318 $$(filter \
319 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
320 $$($(1)-srcs) $$($(1)-extra-specs)))
322 # macro to define template macros that are used by use_template macro
323 define create_cc_template
324 # $1 obj class
325 # $2 source suffix (c, S, ld, ...)
326 # $3 additional compiler flags
327 # $4 additional dependencies
328 ifn$(EMPTY)def $(1)-objs_$(2)_template
329 de$(EMPTY)fine $(1)-objs_$(2)_template
330 ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
331 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(4)
332 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
333 $(GCC_$(1)) \
334 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
335 $(3) -c -o $$$$@ $$$$<
336 el$(EMPTY)se
337 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
338 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
339 $(CC_$(1)) \
340 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
341 $(3) -c -o $$$$@ $$$$<
342 end$(EMPTY)if
343 en$(EMPTY)def
344 end$(EMPTY)if
345 endef
347 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
348 $(foreach class,$(classes), \
349 $(foreach type,$(call filetypes-of-class,$(class)), \
350 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
351 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
352 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
354 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
355 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
357 # To supported complex package initializations, we need to call the
358 # emitted code explicitly. gnatbind gathers all the calls for us
359 # and exports them as a procedure $(stage)_adainit(). Every stage that
360 # uses Ada code has to call it!
361 define gnatbind_template
362 # $1 class
363 $$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
364 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
365 # We have to give gnatbind a simple filename (without leading
366 # path components) so just cd there.
367 cd $$(dir $$@) && \
368 $$(GNATBIND_$(1)) -a -n \
369 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
370 -L$(1)_ada -o $$(notdir $$@) \
371 $$(subst $$(dir $$@),,$$^)
372 $$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
373 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
374 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
375 $(1)-objs += $$(obj)/$(1)/b__$(1).o
376 $($(1)-alis): %.ali: %.o ;
377 endef
379 $(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
380 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
382 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
383 -include $(DEPENDENCIES)
385 printall:
386 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
387 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
388 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
389 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
390 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
391 endif
393 ifndef NOMKDIR
394 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
395 endif
397 $(obj)/project_filelist.txt:
398 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
399 echo "*** Error: Project must be built before generating file list ***"; \
400 exit 1; \
402 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
403 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
404 grep -v '\.o$$' > $(obj)/project_filelist.txt
406 filelist: $(obj)/project_filelist.txt
407 printf "\nFiles used in build:\n"
408 cat $(obj)/project_filelist.txt
410 #works with either exuberant ctags or ctags.emacs
411 ctags-project: clean-ctags $(obj)/project_filelist.txt
412 cat $(obj)/project_filelist.txt | \
413 xargs ctags -o tags
415 cscope-project: clean-cscope $(obj)/project_filelist.txt
416 cat $(obj)/project_filelist.txt | xargs cscope -b
418 cscope:
419 cscope -bR
421 doxy: doxygen
422 doxygen:
423 $(DOXYGEN) Documentation/Doxyfile.coreboot
425 doxygen_simple:
426 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
428 doxyplatform doxygen_platform: $(obj)/project_filelist.txt
429 echo
430 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
431 export DOXYGEN_OUTPUT_DIR="$(DOXYGEN_OUTPUT_DIR)/$(CONFIG_MAINBOARD_VENDOR)/$(CONFIG_MAINBOARD_PART_NUMBER)"; \
432 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
433 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
434 export DOXYGEN_PLATFORM="$(CONFIG_MAINBOARD_DIR) ($(CONFIG_MAINBOARD_PART_NUMBER)) version $(KERNELVERSION)"; \
435 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
437 doxyclean: doxygen-clean
438 doxygen-clean:
439 rm -rf $(DOXYGEN_OUTPUT_DIR)
441 clean-for-update: doxygen-clean clean-for-update-target
442 rm -rf $(obj) .xcompile
444 clean: clean-for-update clean-target clean-utils
445 rm -f .ccwrap
447 clean-cscope:
448 rm -f cscope.out
450 clean-ctags:
451 rm -f tags
453 clean-utils:
454 $(foreach tool, $(TOOLLIST), \
455 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
457 distclean-utils:
458 $(foreach tool, $(TOOLLIST), \
459 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
460 rm -f /util/$(tool)/junit.xml;)
462 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
463 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
464 rm -rf coreboot-builds coreboot-builds-chromeos
465 rm -f abuild*.xml junit.xml* util/lint/junit.xml
467 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
468 .PHONY: ctags-project cscope-project clean-ctags