southbridge/amd/sb700: Fix SATA port 4/5 drive detection
[coreboot.git] / Makefile
blob421e91932602173fd746415c6d69dbd0f8be4854
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)))
37 .xcompile: util/xcompile/xcompile
38 $< $(XGCCPATH) > $@.tmp
39 \mv -f $@.tmp $@ 2> /dev/null
41 export top := $(CURDIR)
42 export src := src
43 export srck := $(top)/util/kconfig
44 obj ?= build
45 override obj := $(subst $(top)/,,$(abspath $(obj)))
46 export obj
47 export objutil ?= $(obj)/util
48 export objk := $(objutil)/kconfig
49 absobj := $(abspath $(obj))
52 export KCONFIG_AUTOHEADER := $(obj)/config.h
53 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
54 export KCONFIG_DEPENDENCIES := $(obj)/auto.conf.cmd
55 export KCONFIG_SPLITCONFIG := $(obj)/config
56 export KCONFIG_TRISTATE := $(obj)/tristate.conf
57 export KCONFIG_NEGATIVES := 1
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 DOTCONFIG ?= .config
66 KCONFIG_CONFIG = $(DOTCONFIG)
67 export KCONFIG_CONFIG
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 := gcc
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 all: real-all
94 # This include must come _before_ the pattern rules below!
95 # Order _does_ matter for pattern rules.
96 include $(srck)/Makefile
98 # Three cases where we don't need fully populated $(obj) lists:
99 # 1. when no .config exists
100 # 2. when make config (in any flavour) is run
101 # 3. when make distclean is run
102 # Don't waste time on reading all Makefile.incs in these cases
103 ifeq ($(strip $(HAVE_DOTCONFIG)),)
104 NOCOMPILE:=1
105 endif
106 ifneq ($(MAKECMDGOALS),)
107 ifneq ($(filter %config %clean cross% lint% what-jenkins-does,$(MAKECMDGOALS)),)
108 NOCOMPILE:=1
109 endif
110 ifeq ($(MAKECMDGOALS), %clean)
111 NOMKDIR:=1
112 endif
113 endif
115 ifeq ($(NOCOMPILE),1)
116 include $(TOPLEVEL)/Makefile.inc
117 real-all: config
119 else
121 include $(HAVE_DOTCONFIG)
123 include .xcompile
125 ifneq ($(CONFIG_MMX),y)
126 CFLAGS_x86_32 += -mno-mmx
127 endif
129 include toolchain.inc
131 strip_quotes = $(subst ",,$(subst \",,$(1)))
133 # The primary target needs to be here before we include the
134 # other files
136 real-all: real-target
138 # must come rather early
139 .SECONDEXPANSION:
141 $(KCONFIG_AUTOHEADER): $(KCONFIG_CONFIG)
142 $(MAKE) oldconfig
144 # Add a new class of source/object files to the build system
145 add-class= \
146 $(eval $(1)-srcs:=) \
147 $(eval $(1)-objs:=) \
148 $(eval classes+=$(1))
150 # Special classes are managed types with special behaviour
151 # On parse time, for each entry in variable $(1)-y
152 # a handler $(1)-handler is executed with the arguments:
153 # * $(1): directory the parser is in
154 # * $(2): current entry
155 add-special-class= \
156 $(eval $(1):=) \
157 $(eval special-classes+=$(1))
159 # Clean -y variables, include Makefile.inc
160 # Add paths to files in X-y to X-srcs
161 # Add subdirs-y to subdirs
162 includemakefiles= \
163 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
164 $(eval -include $(1)) \
165 $(foreach class,$(classes-y), $(call add-class,$(class))) \
166 $(foreach class,$(classes), \
167 $(eval $(class)-srcs+= \
168 $$(subst $(absobj)/,$(obj)/, \
169 $$(subst $(top)/,, \
170 $$(abspath $$(subst $(dir $(1))/,/,$$(addprefix $(dir $(1)),$$($(class)-y)))))))) \
171 $(foreach special,$(special-classes), \
172 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
173 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
175 # For each path in $(subdirs) call includemakefiles
176 # Repeat until subdirs is empty
177 evaluate_subdirs= \
178 $(eval cursubdirs:=$(subdirs)) \
179 $(eval subdirs:=) \
180 $(foreach dir,$(cursubdirs), \
181 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
182 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
184 # collect all object files eligible for building
185 subdirs:=$(TOPLEVEL)
186 $(eval $(call evaluate_subdirs))
187 ifeq ($(FAILBUILD),1)
188 $(error cannot continue build)
189 endif
191 # Eliminate duplicate mentions of source files in a class
192 $(foreach class,$(classes),$(eval $(class)-srcs:=$(sort $($(class)-srcs))))
194 # Converts one or more source file paths to their corresponding build/ paths.
195 # Only .c and .S get converted to .o, other files (like .ld) keep their name.
196 # $1 stage name
197 # $2 file path (list)
198 src-to-obj=$(foreach file,$(2),$(subst .$(1),,$(basename $(patsubst src/%,$(obj)/%,$(file)))).$(1)$(patsubst %.c,%.o,$(patsubst %.S,%.o,$(suffix $(file)))))
200 $(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class),$($(class)-srcs))))
202 # Save all objs before processing them (for dependency inclusion)
203 originalobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
205 # Call post-processors if they're defined
206 $(foreach class,$(classes),\
207 $(if $(value $(class)-postprocess),$(eval $(call $(class)-postprocess,$($(class)-objs)))))
209 allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
210 allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
211 alldirs:=$(sort $(abspath $(dir $(allobjs))))
213 # macro to define template macros that are used by use_template macro
214 define create_cc_template
215 # $1 obj class
216 # $2 source suffix (c, S, ld, ...)
217 # $3 additional compiler flags
218 # $4 additional dependencies
219 ifn$(EMPTY)def $(1)-objs_$(2)_template
220 de$(EMPTY)fine $(1)-objs_$(2)_template
221 $$(call src-to-obj,$1,$$(1).$2): $$(1).$2 $(KCONFIG_AUTOHEADER) $(4)
222 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
223 $(CC_$(1)) -MMD $$$$(CPPFLAGS_$(1)) $$$$(CFLAGS_$(1)) -MT $$$$(@) $(3) -c -o $$$$@ $$$$<
224 en$(EMPTY)def
225 end$(EMPTY)if
226 endef
228 filetypes-of-class=$(subst .,,$(sort $(suffix $($(1)-srcs))))
229 $(foreach class,$(classes), \
230 $(foreach type,$(call filetypes-of-class,$(class)), \
231 $(eval $(class)-$(type)-ccopts += $(generic-$(type)-ccopts) $($(class)-generic-ccopts)) \
232 $(if $(generic-objs_$(type)_template_gen),$(eval $(call generic-objs_$(type)_template_gen,$(class))),\
233 $(eval $(call create_cc_template,$(class),$(type),$($(class)-$(type)-ccopts),$($(class)-$(type)-deps))))))
235 foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(basename $(file)))))
236 $(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
238 DEPENDENCIES += $(addsuffix .d,$(basename $(allobjs)))
239 -include $(DEPENDENCIES)
241 printall:
242 @$(foreach class,$(classes),echo $(class)-objs:=$($(class)-objs); )
243 @echo alldirs:=$(alldirs)
244 @echo allsrcs=$(allsrcs)
245 @echo DEPENDENCIES=$(DEPENDENCIES)
246 @$(foreach class,$(special-classes),echo $(class):='$($(class))'; )
248 endif
250 ifndef NOMKDIR
251 $(shell mkdir -p $(KCONFIG_SPLITCONFIG) $(objk)/lxdialog $(additional-dirs) $(alldirs))
252 endif
254 $(obj)/project_filelist.txt: all
255 find $(obj) -name "*.d" -exec cat {} \; | \
256 sed 's/[:\\]/ /g' | sed 's/ /\n/g' | sort | uniq | \
257 grep -v '\.o$$' > $(obj)/project_filelist.txt
259 #works with either exuberant ctags or ctags.emacs
260 ctags-project: clean-ctags $(obj)/project_filelist.txt
261 cat $(obj)/project_filelist.txt | \
262 xargs ctags -o tags
264 cscope-project: clean-cscope $(obj)/project_filelist.txt
265 cat $(obj)/project_filelist.txt | xargs cscope -b
267 cscope:
268 cscope -bR
270 doxy: doxygen
271 doxygen:
272 $(DOXYGEN) Documentation/Doxyfile.coreboot
274 doxygen_simple:
275 $(DOXYGEN) Documentation/Doxyfile.coreboot_simple
277 doxyclean: doxygen-clean
278 doxygen-clean:
279 rm -rf $(DOXYGEN_OUTPUT_DIR)
281 clean-for-update: doxygen-clean clean-for-update-target
282 rm -rf $(obj) .xcompile
284 clean: clean-for-update clean-target
285 rm -f .ccwrap
287 clean-cscope:
288 rm -f cscope.out
290 clean-ctags:
291 rm -f tags
293 distclean: clean clean-ctags clean-cscope
294 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
296 .PHONY: $(PHONY) clean clean-for-update clean-cscope cscope distclean doxygen doxy doxygen_simple
297 .PHONY: ctags-project cscope-project clean-ctags