Revert "[WIP] console/Kconfig: Calculate COM port base addresses only on x86"
[coreboot.git] / Makefile
blob440128876004d6aef5186c444685ec4dc0d49f7a
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 # in addition to the dependency below, create the file if it doesn't exist
34 # to silence stupid warnings about a file that would be generated anyway.
35 $(if $(wildcard .xcompile),,$(eval $(shell util/xcompile/xcompile $(XGCCPATH) > .xcompile || rm -f .xcompile)))
37 .xcompile: util/xcompile/xcompile
38 rm -f $@
39 $< $(XGCCPATH) > $@.tmp
40 \mv -f $@.tmp $@ 2> /dev/null
41 rm -f $@.tmp
43 export top := $(CURDIR)
44 export src := src
45 export srck := $(top)/util/kconfig
46 obj ?= build
47 override obj := $(subst $(top)/,,$(abspath $(obj)))
48 export obj
49 export objutil ?= $(obj)/util
50 export objk := $(objutil)/kconfig
51 absobj := $(abspath $(obj))
54 export KCONFIG_AUTOHEADER := $(obj)/config.h
55 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
56 export KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
57 export KCONFIG_SPLITCONFIG := $(obj)/config
58 export KCONFIG_TRISTATE := $(obj)/tristate.conf
59 export KCONFIG_NEGATIVES := 1
60 export KCONFIG_STRICT := 1
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 DOTCONFIG ?= $(top)/.config
69 KCONFIG_CONFIG = $(DOTCONFIG)
70 export KCONFIG_CONFIG
71 HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
72 MAKEFLAGS += -rR --no-print-directory
74 # Make is silent per default, but 'make V=1' will show all compiler calls.
75 Q:=@
76 ifneq ($(V),1)
77 ifneq ($(Q),)
78 .SILENT:
79 endif
80 endif
82 # Disable implicit/built-in rules to make Makefile errors fail fast.
83 .SUFFIXES:
85 HOSTCC := $(if $(shell type gcc 2>/dev/null),gcc,cc)
86 HOSTCXX = g++
87 HOSTCFLAGS := -g
88 HOSTCXXFLAGS := -g
90 PREPROCESS_ONLY := -E -P -x assembler-with-cpp -undef -I .
92 DOXYGEN := doxygen
93 DOXYGEN_OUTPUT_DIR := doxygen
95 all: real-all
97 help_coreboot help::
98 @echo '*** coreboot platform targets ***'
99 @echo ' Use "make [target] V=1" for extra build debug information'
100 @echo ' all - Build coreboot'
101 @echo ' clean - Remove coreboot build artifacts'
102 @echo ' distclean - Remove build artifacts and config files'
103 @echo ' doxygen - Build doxygen documentation for coreboot'
104 @echo ' what-jenkins-does - Run platform build tests (Use CPUS=# for more cores)'
105 @echo ' printall - print makefile info for debugging'
106 @echo ' lint / lint-stable - run coreboot lint tools (all / minimal)'
107 @echo ' gitconfig - set up git to submit patches to coreboot'
108 @echo ' ctags / ctags-project - make ctags file for all of coreboot or current board'
109 @echo ' cscope / cscope-project - make cscope.out file for coreboot or current board'
110 @echo
112 # This include must come _before_ the pattern rules below!
113 # Order _does_ matter for pattern rules.
114 include $(srck)/Makefile
116 # Three cases where we don't need fully populated $(obj) lists:
117 # 1. when no .config exists
118 # 2. when make config (in any flavour) is run
119 # 3. when make distclean is run
120 # Don't waste time on reading all Makefile.incs in these cases
121 ifeq ($(strip $(HAVE_DOTCONFIG)),)
122 NOCOMPILE:=1
123 endif
124 ifneq ($(MAKECMDGOALS),)
125 ifneq ($(filter %config %clean cross% clang iasl gnumake lint% help% what-jenkins-does,$(MAKECMDGOALS)),)
126 NOCOMPILE:=1
127 endif
128 ifeq ($(MAKECMDGOALS), %clean)
129 NOMKDIR:=1
130 endif
131 endif
133 ifeq ($(NOCOMPILE),1)
134 include $(TOPLEVEL)/Makefile.inc
135 include $(TOPLEVEL)/payloads/Makefile.inc
136 real-all: config
138 else
140 include $(DOTCONFIG)
142 -include .xcompile
144 ifneq ($(XCOMPILE_COMPLETE),1)
145 $(shell rm -f .xcompile)
146 $(error .xcompile deleted because it's invalid. \
147 Restarting the build should fix that, or explain the problem)
148 endif
150 ifneq ($(CONFIG_MMX),y)
151 CFLAGS_x86_32 += -mno-mmx
152 endif
154 include toolchain.inc
156 strip_quotes = $(strip $(subst ",,$(subst \",,$(1))))
157 # fix makefile syntax highlighting after strip macro \" "))
159 # The primary target needs to be here before we include the
160 # other files
162 real-all: real-target
164 # must come rather early
165 .SECONDEXPANSION:
167 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG)
168 $(MAKE) oldconfig
170 # Add a new class of source/object files to the build system
171 add-class= \
172 $(eval $(1)-srcs:=) \
173 $(eval $(1)-objs:=) \
174 $(eval classes+=$(1))
176 # Special classes are managed types with special behaviour
177 # On parse time, for each entry in variable $(1)-y
178 # a handler $(1)-handler is executed with the arguments:
179 # * $(1): directory the parser is in
180 # * $(2): current entry
181 add-special-class= \
182 $(eval $(1):=) \
183 $(eval special-classes+=$(1))
185 # Converts one or more source file paths to their corresponding build/ paths.
186 # Only .ads, adb, .c and .S get converted to .o, other files (like .ld) keep
187 # their name.
188 # $1 stage name
189 # $2 file path (list)
190 src-to-obj=\
191 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
192 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
193 $(patsubst src/%,$(obj)/%,\
194 $(patsubst %.ads,%.o,\
195 $(patsubst %.adb,%.o,\
196 $(patsubst %.c,%.o,\
197 $(patsubst %.S,%.o,\
198 $(subst .$(1),,$(2)))))))))
200 # Converts one or more source file paths to the corresponding build/ paths
201 # of their Ada library information (.ali) files.
202 # $1 stage name
203 # $2 file path (list)
204 src-to-ali=\
205 $(patsubst $(obj)/%,$(obj)/$(1)/%,\
206 $(patsubst $(obj)/$(1)/%,$(obj)/%,\
207 $(patsubst src/%,$(obj)/%,\
208 $(patsubst %.ads,%.ali,\
209 $(patsubst %.adb,%.ali,\
210 $(subst .$(1),,\
211 $(filter %.ads %.adb,$(2))))))))
213 # Clean -y variables, include Makefile.inc
214 # Add paths to files in X-y to X-srcs
215 # Add subdirs-y to subdirs
216 includemakefiles= \
217 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
218 $(eval -include $(1)) \
219 $(foreach class,$(classes-y), $(call add-class,$(class))) \
220 $(foreach class,$(classes), \
221 $(eval $(class)-srcs+= \
222 $$(subst $(absobj)/,$(obj)/, \
223 $$(subst $(top)/,, \
224 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
225 $(foreach special,$(special-classes), \
226 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
227 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
229 # For each path in $(subdirs) call includemakefiles
230 # Repeat until subdirs is empty
231 evaluate_subdirs= \
232 $(eval cursubdirs:=$(subdirs)) \
233 $(eval subdirs:=) \
234 $(foreach dir,$(cursubdirs), \
235 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
236 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
238 # collect all object files eligible for building
239 subdirs:=$(TOPLEVEL)
240 $(eval $(call evaluate_subdirs))
241 ifeq ($(FAILBUILD),1)
242 $(error cannot continue build)
243 endif
245 # Eliminate duplicate mentions of source files in a class
246 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
248 # To track dependencies, we need all Ada specification (.ads) files in
249 # *-srcs. Extract / filter all specification files that have a matching
250 # body (.adb) file here (specifications without a body are valid sources
251 # in Ada).
252 $(foreach class,$(classes),$(eval $(class)-extra-specs := \
253 $(filter \
254 $(addprefix %/,$(patsubst %.adb,%.ads,$(notdir $(filter %.adb,$($(class)-srcs))))), \
255 $(filter %.ads,$($(class)-srcs)))))
256 $(foreach class,$(classes),$(eval $(class)-srcs := \
257 $(filter-out $($(class)-extra-specs),$($(class)-srcs))))
259 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
260 $(foreach class,$(classes),$(eval $(class)-alis:=$(call src-to-ali,$(class),$($(class)-srcs))))
262 # For Ada includes
263 $(foreach class,$(classes),$(eval $(class)-ada-dirs:=$(sort $(dir $(filter %.ads %.adb,$($(class)-srcs)) $($(class)-extra-specs)))))
265 # Save all objs before processing them (for dependency inclusion)
266 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
268 # Call post-processors if they're defined
269 $(foreach class,$(classes),\
270 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
272 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
273 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
274 alldirs:=$(sort $(abspath $(dir $(allobjs))))
276 # Reads dependencies from an Ada library information (.ali) file
277 # Only basenames (with suffix) are preserved so we have to look the
278 # paths up in $($(stage)-srcs).
279 # $1 stage name
280 # $2 ali file
281 create_ada_deps=$$(if $(2),\
282 gnat.adc \
283 $$(filter \
284 $$(addprefix %/,$$(shell sed -ne's/^D \([^\t]\+\).*$$$$/\1/p' $(2) 2>/dev/null)), \
285 $$($(1)-srcs) $$($(1)-extra-specs)))
287 # macro to define template macros that are used by use_template macro
288 define create_cc_template
289 # $1 obj class
290 # $2 source suffix (c, S, ld, ...)
291 # $3 additional compiler flags
292 # $4 additional dependencies
293 ifn$(EMPTY)def $(1)-objs_$(2)_template
294 de$(EMPTY)fine $(1)-objs_$(2)_template
295 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $$(call create_ada_deps,$1,$$(call src-to-ali,$1,$$(1).$2)) $(KCONFIG_AUTOHEADER) $(4)
296 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
297 $(CC_$(1)) \
298 $$(if $$(filter-out ads adb,$(2)), \
299 -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@), \
300 $$$$(ADAFLAGS_$(1)) $$$$(addprefix -I,$$$$($(1)-ada-dirs))) \
301 $(3) -c -o $$$$@ $$$$<
302 en$(EMPTY)def
303 end$(EMPTY)if
304 endef
306 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
307 $(foreach class,$(classes), \
308 $(foreach type,$(call filetypes-of-class,$(class)), \
309 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
310 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
311 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
313 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
314 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
316 # To supported complex package initializations, we need to call the
317 # emitted code explicitly. gnatbind gathers all the calls for us
318 # and exports them as a procedure $(stage)_adainit(). Every stage that
319 # uses Ada code has to call it!
320 define gnatbind_template
321 # $1 class
322 $$(obj)/$(1)/b__$(1).adb: $$$$(filter-out $$(obj)/$(1)/b__$(1).ali,$$$$($(1)-alis))
323 @printf " BIND $$(subst $$(obj)/,,$$@)\n"
324 # We have to give gnatbind a simple filename (without leading
325 # path components) so just cd there.
326 cd $$(dir $$@) && \
327 $$(GNATBIND_$(1)) -a -n \
328 --RTS=$$(absobj)/libgnat-$$(ARCH-$(1)-y)/ \
329 -L$(1)_ada -o $$(notdir $$@) \
330 $$(subst $$(dir $$@),,$$^)
331 $$(obj)/$(1)/b__$(1).o: $$(obj)/$(1)/b__$(1).adb
332 @printf " CC $$(subst $$(obj)/,,$$@)\n"
333 $(CC_$(1)) $$(ADAFLAGS_$(1)) -c -o $$@ $$<
334 $(1)-objs += $$(obj)/$(1)/b__$(1).o
335 $($(1)-alis): %.ali: %.o ;
336 endef
338 $(eval $(foreach class,$(filter-out libgnat-%,$(classes)), \
339 $(if $($(class)-alis),$(call gnatbind_template,$(class)))))
341 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
342 -include $(DEPENDENCIES)
344 printall:
345 @$(foreach class,$(classes), echo $(class)-objs: $($(class)-objs) | tr ' ' '\n'; echo; )
346 @echo alldirs: $(alldirs) | tr ' ' '\n'; echo
347 @echo allsrcs: $(allsrcs) | tr ' ' '\n'; echo
348 @echo DEPENDENCIES: $(DEPENDENCIES) | tr ' ' '\n'; echo
349 @$(foreach class,$(special-classes),echo $(class):'$($(class))' | tr ' ' '\n'; echo; )
350 endif
352 ifndef NOMKDIR
353 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
354 endif
356 $(obj)/project_filelist.txt: all
357 find $(obj) -name "*.d" -exec cat {} \; | \
358 sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
359 grep -v '\.o$$' > $(obj)/project_filelist.txt
361 #works with either exuberant ctags or ctags.emacs
362 ctags-project: clean-ctags $(obj)/project_filelist.txt
363 cat $(obj)/project_filelist.txt | \
364 xargs ctags -o tags
366 cscope-project: clean-cscope $(obj)/project_filelist.txt
367 cat $(obj)/project_filelist.txt | xargs cscope -b
369 cscope:
370 cscope -bR
372 doxy: doxygen
373 doxygen:
374 $(DOXYGEN) Documentation/Doxyfile.coreboot
376 doxygen_simple:
377 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
379 doxyclean: doxygen-clean
380 doxygen-clean:
381 rm -rf $(DOXYGEN_OUTPUT_DIR)
383 clean-for-update: doxygen-clean clean-for-update-target
384 rm -rf $(obj) .xcompile
386 clean: clean-for-update clean-target
387 rm -f .ccwrap
389 clean-cscope:
390 rm -f cscope.out
392 clean-ctags:
393 rm -f tags
395 distclean: clean clean-ctags clean-cscope distclean-payloads
396 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
398 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
399 .PHONY: ctags-project cscope-project clean-ctags