soc/amd/stoneyridge: Replace magic registers
[coreboot.git] / Makefile
blobdedf6885b645aca2b99a8ee0a5c9a5f21cd40ac7
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_AUTOHEADER := $(obj)/config.h
48 KCONFIG_AUTOCONFIG := $(obj)/auto.conf
49 KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
50 KCONFIG_SPLITCONFIG := $(obj)/config
51 KCONFIG_TRISTATE := $(obj)/tristate.conf
52 KCONFIG_NEGATIVES := 1
53 KCONFIG_STRICT := 1
55 COREBOOT_EXPORTS += KCONFIG_CONFIG KCONFIG_AUTOHEADER KCONFIG_AUTOCONFIG
56 COREBOOT_EXPORTS += KCONFIG_DEPENDENCIES KCONFIG_SPLITCONFIG KCONFIG_TRISTATE
57 COREBOOT_EXPORTS += KCONFIG_NEGATIVES KCONFIG_STRICT
59 # directory containing the toplevel Makefile.inc
60 TOPLEVEL := .
62 CONFIG_SHELL := sh
63 KBUILD_DEFCONFIG := configs/defconfig
64 UNAME_RELEASE := $(shell uname -r)
65 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
66 MAKEFLAGS += -rR --no-print-directory
68 # Make is silent per default, but 'make V=1' will show all compiler calls.
69 Q:=@
70 ifneq ($(V),1)
71 ifneq ($(Q),)
72 .SILENT:
73 endif
74 endif
76 # Disable implicit/built-in rules to make Makefile errors fail fast.
77 .SUFFIXES:
79 HOSTCC := $(if $(shell type gcc 2>/dev/null),gcc,cc)
80 HOSTCXX = g++
81 HOSTCFLAGS := -g
82 HOSTCXXFLAGS := -g
84 PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
86 DOXYGEN := doxygen
87 DOXYGEN_OUTPUT_DIR := doxygen
89 export $(COREBOOT_EXPORTS)
91 all: real-all
93 help_coreboot help::
94 @echo '*** coreboot platform targets ***'
95 @echo ' Use "make [target] V=1" for extra build debug information'
96 @echo ' all - Build coreboot'
97 @echo ' clean - Remove coreboot build artifacts'
98 @echo ' distclean - Remove build artifacts and config files'
99 @echo ' doxygen - Build doxygen documentation for coreboot'
100 @echo ' doxyplatform - Build doxygen documentation for the current platform'
101 @echo ' printall - print makefile info for debugging'
102 @echo ' gitconfig - set up git to submit patches to coreboot'
103 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
104 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
105 @echo
107 # This include must come _before_ the pattern rules below!
108 # Order _does_ matter for pattern rules.
109 include $(srck)/Makefile
111 # Three cases where we don't need fully populated $(obj) lists:
112 # 1. when no .config exists
113 # 2. when make config (in any flavour) is run
114 # 3. when make distclean is run
115 # Don't waste time on reading all Makefile.incs in these cases
116 ifeq ($(strip $(HAVE_DOTCONFIG)),)
117 NOCOMPILE:=1
118 endif
119 ifneq ($(MAKECMDGOALS),)
120 ifneq ($(filter %config %clean cross% clang iasl gnumake lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
121 NOCOMPILE:=1
122 endif
123 ifeq ($(MAKECMDGOALS), %clean)
124 NOMKDIR:=1
125 endif
126 endif
128 ifeq ($(NOCOMPILE),1)
129 include $(TOPLEVEL)/Makefile.inc
130 include $(TOPLEVEL)/payloads/Makefile.inc
131 include $(TOPLEVEL)/util/testing/Makefile.inc
132 -include $(TOPLEVEL)/site-local/Makefile.inc
133 real-all:
134 @echo "Error: Expected config file ($(DOTCONFIG)) not present." >&2
135 @echo "Please specify a config file or run 'make menuconfig' to" >&2
136 @echo "generate a new config file." >&2
137 @exit 1
138 else
140 include $(DOTCONFIG)
142 # in addition to the dependency below, create the file if it doesn't exist
143 # to silence stupid warnings about a file that would be generated anyway.
144 $(if $(wildcard .xcompile)$(NOCOMPILE),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
146 .xcompile: util/xcompile/xcompile
147 rm -f $@
148 $< $(XGCCPATH) > $@.tmp
149 \mv -f $@.tmp $@ 2> /dev/null
150 rm -f $@.tmp
152 -include .xcompile
154 ifneq ($(XCOMPILE_COMPLETE),1)
155 $(shell rm -f .xcompile)
156 $(error .xcompile deleted because it's invalid. \
157 Restarting the build should fix that, or explain the problem)
158 endif
160 ifneq ($(CONFIG_MMX),y)
161 CFLAGS_x86_32 += -mno-mmx
162 endif
164 include toolchain.inc
166 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
167 # fix makefile syntax highlighting after strip macro \" "))
169 # The primary target needs to be here before we include the
170 # other files
172 real-all: real-target
174 # must come rather early
175 .SECONDEXPANSION:
177 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG)
178 +$(MAKE) oldconfig
180 # Add a new class of source/object files to the build system
181 add-class= \
182 $(eval $(1)-srcs:=) \
183 $(eval $(1)-objs:=) \
184 $(eval classes+=$(1))
186 # Special classes are managed types with special behaviour
187 # On parse time, for each entry in variable $(1)-y
188 # a handler $(1)-handler is executed with the arguments:
189 # * $(1): directory the parser is in
190 # * $(2): current entry
191 add-special-class= \
192 $(eval $(1):=) \
193 $(eval special-classes+=$(1))
195 # Converts one or more source file paths to their corresponding build/ paths.
196 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
197 # their name.
198 # $1 stage name
199 # $2 file path (list)
200 src-to-obj=\
201 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
202 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
203 $(patsubst 3rdparty/%,$(obj)/%,\
204 $(patsubst src/%,$(obj)/%,\
205 $(patsubst %.ads,%.o,\
206 $(patsubst %.adb,%.o,\
207 $(patsubst %.c,%.o,\
208 $(patsubst %.S,%.o,\
209 $(subst .$(1),,$(2))))))))))
211 # Converts one or more source file paths to the corresponding build/ paths
212 # of their Ada library information (.ali) files.
213 # $1 stage name
214 # $2 file path (list)
215 src-to-ali=\
216 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
217 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
218 $(patsubst 3rdparty/%,$(obj)/%,\
219 $(patsubst src/%,$(obj)/%,\
220 $(patsubst %.ads,%.ali,\
221 $(patsubst %.adb,%.ali,\
222 $(subst .$(1),,\
223 $(filter %.ads %.adb,$(2)))))))))
225 # Clean -y variables, include Makefile.inc
226 # Add paths to files in X-y to X-srcs
227 # Add subdirs-y to subdirs
228 includemakefiles= \
229 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
230 $(eval -include $(1)) \
231 $(foreach class,$(classes-y), $(call add-class,$(class))) \
232 $(foreach class,$(classes), \
233 $(eval $(class)-srcs+= \
234 $$(subst $(absobj)/,$(obj)/, \
235 $$(subst $(top)/,, \
236 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
237 $(foreach special,$(special-classes), \
238 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
239 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
241 # For each path in $(subdirs) call includemakefiles
242 # Repeat until subdirs is empty
243 evaluate_subdirs= \
244 $(eval cursubdirs:=$(subdirs)) \
245 $(eval subdirs:=) \
246 $(foreach dir,$(cursubdirs), \
247 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
248 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
250 # collect all object files eligible for building
251 subdirs:=$(TOPLEVEL)
252 postinclude-hooks :=
253 $(eval $(call evaluate_subdirs))
254 ifeq ($(FAILBUILD),1)
255 $(error cannot continue build)
256 endif
258 # Run hooks registered by subdirectories that need to be evaluated after all files have been parsed
259 $(eval $(postinclude-hooks))
261 # Eliminate duplicate mentions of source files in a class
262 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
264 # To track dependencies, we need all Ada specification (.ads) files in
265 # *-srcs. Extract / filter all specification files that have a matching
266 # body (.adb) file here (specifications without a body are valid sources
267 # in Ada).
268 $(foreach class,$(classes),$(eval $(class)-extra-specs := \
269 $(filter \
270 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
271 $(filter %.ads,$($(class)-srcs)))))
272 $(foreach class,$(classes),$(eval $(class)-srcs := \
273 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
275 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
276 $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
278 # For Ada includes
279 $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
281 # Save all objs before processing them (for dependency inclusion)
282 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
284 # Call post-processors if they're defined
285 $(foreach class,$(classes),\
286 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
288 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
289 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
290 alldirs:=$(sort $(abspath $(dir $(allobjs))))
292 # Reads dependencies from an Ada library information (.ali) file
293 # Only basenames (with suffix) are preserved so we have to look the
294 # paths up in $($(stage)-srcs).
295 # $1 stage name
296 # $2 ali file
297 create_ada_deps=$$(if $(2),\
298 gnat.adc \
299 $$(filter \
300 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
301 $$($(1)-srcs) $$($(1)-extra-specs)))
303 # macro to define template macros that are used by use_template macro
304 define create_cc_template
305 # $1 obj class
306 # $2 source suffix (c, S, ld, ...)
307 # $3 additional compiler flags
308 # $4 additional dependencies
309 ifn$(EMPTY)def $(1)-objs_$(2)_template
310 de$(EMPTY)fine $(1)-objs_$(2)_template
311 ifn$(EMPTY)eq ($(filter ads adb,$(2)),)
312 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(KCONFIG_AUTOHEADER) $(4)
313 @printf " GCC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
314 $(GCC_$(1)) \
315 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs)) \
316 $(3) -c -o $$$$@ $$$$<
317 el$(EMPTY)se
318 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
319 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
320 $(CC_$(1)) \
321 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) \
322 $(3) -c -o $$$$@ $$$$<
323 end$(EMPTY)if
324 en$(EMPTY)def
325 end$(EMPTY)if
326 endef
328 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
329 $(foreach class,$(classes), \
330 $(foreach type,$(call filetypes-of-class,$(class)), \
331 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
332 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
333 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
335 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
336 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
338 # To supported complex package initializations, we need to call the
339 # emitted code explicitly. gnatbind gathers all the calls for us
340 # and exports them as a procedure $(stage)_adainit(). Every stage that
341 # uses Ada code has to call it!
342 define gnatbind_template
343 # $1 class
344 $$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
345 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
346 # We have to give gnatbind a simple filename (without leading
347 # path components) so just cd there.
348 cd $$(dir $$@) && \
349 $$(GNATBIND_$(1)) -a -n \
350 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
351 -L$(1)_ada -o $$(notdir $$@) \
352 $$(subst $$(dir $$@),,$$^)
353 $$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
354 @printf " GCC $$(subst $$(obj)/,,$$@)\n"
355 $(GCC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
356 $(1)-objs += $$(obj)/$(1)/b__$(1).o
357 $($(1)-alis): %.ali: %.o ;
358 endef
360 $(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
361 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
363 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
364 -include $(DEPENDENCIES)
366 printall:
367 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
368 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
369 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
370 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
371 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
372 endif
374 ifndef NOMKDIR
375 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
376 endif
378 $(obj)/project_filelist.txt:
379 if [ -z "$(wildcard $(obj)/coreboot.rom)" ]; then \
380 echo "*** Error: Project must be built before generating file list ***"; \
381 exit 1; \
383 find $(obj) -path "$(obj)/util" -prune -o -name "*.d" -exec cat {} \; | \
384 sed "s|$(top)/||" | sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
385 grep -v '\.o$$' > $(obj)/project_filelist.txt
387 filelist: $(obj)/project_filelist.txt
388 printf "\nFiles used in build:\n"
389 cat $(obj)/project_filelist.txt
391 #works with either exuberant ctags or ctags.emacs
392 ctags-project: clean-ctags $(obj)/project_filelist.txt
393 cat $(obj)/project_filelist.txt | \
394 xargs ctags -o tags
396 cscope-project: clean-cscope $(obj)/project_filelist.txt
397 cat $(obj)/project_filelist.txt | xargs cscope -b
399 cscope:
400 cscope -bR
402 doxy: doxygen
403 doxygen:
404 $(DOXYGEN) Documentation/Doxyfile.coreboot
406 doxygen_simple:
407 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
409 doxyplatform doxygen_platform: $(obj)/project_filelist.txt
410 echo
411 echo "Building doxygen documentation for $(CONFIG_MAINBOARD_PART_NUMBER)"
412 export DOXYGEN_OUTPUT_DIR="$(DOXYGEN_OUTPUT_DIR)/$(CONFIG_MAINBOARD_VENDOR)/$(CONFIG_MAINBOARD_PART_NUMBER)"; \
413 mkdir -p "$$DOXYGEN_OUTPUT_DIR"; \
414 export DOXYFILES="$$(cat $(obj)/project_filelist.txt | grep -v '\.ld$$' | sed 's/\.aml/\.dsl/' | tr '\n' ' ')"; \
415 export DOXYGEN_PLATFORM="$(CONFIG_MAINBOARD_DIR) ($(CONFIG_MAINBOARD_PART_NUMBER)) version $(KERNELVERSION)"; \
416 $(DOXYGEN) Documentation/doxygen/Doxyfile.coreboot_platform
418 doxyclean: doxygen-clean
419 doxygen-clean:
420 rm -rf $(DOXYGEN_OUTPUT_DIR)
422 clean-for-update: doxygen-clean clean-for-update-target
423 rm -rf $(obj) .xcompile
425 clean: clean-for-update clean-target clean-utils
426 rm -f .ccwrap
428 clean-cscope:
429 rm -f cscope.out
431 clean-ctags:
432 rm -f tags
434 clean-utils:
435 $(foreach tool, $(TOOLLIST), \
436 $(MAKE) -C util/$(tool) clean MFLAGS= MAKEFLAGS= ;)
438 distclean-utils:
439 $(foreach tool, $(TOOLLIST), \
440 $(MAKE) -C util/$(tool) distclean MFLAGS= MAKEFLAGS= ; \
441 rm -f /util/$(tool)/junit.xml;)
443 distclean: clean clean-ctags clean-cscope distclean-payloads distclean-utils
444 rm -f .config .config.old ..config.tmp* .kconfig.d .tmpconfig* .ccwrap .xcompile
445 rm -rf coreboot-builds coreboot-builds-chromeos
446 rm -f abuild*.xml junit.xml* util/lint/junit.xml
448 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
449 .PHONY: ctags-project cscope-project clean-ctags