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