Fix small typo in root Makefile.
[coreboot.git] / Makefile
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 ##
8 ## This program is free software; you can redistribute it and/or modify
9 ## it under the terms of the GNU General Public License as published by
10 ## the Free Software Foundation; version 2 of the License.
11 ##
12 ## This program is distributed in the hope that it will be useful,
13 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ## GNU General Public License for more details.
16 ##
17 ## You should have received a copy of the GNU General Public License
18 ## along with this program; if not, write to the Free Software
19 ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20 ##
21
22 ifeq ($(INNER_SCANBUILD),y)
23 CC_real:=$(CC)
24 endif
25
26 $(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
27 include .xcompile
28
29 ifeq ($(INNER_SCANBUILD),y)
30 CC:=$(CC_real)
31 HOSTCC:=$(CC_real) --hostcc
32 HOSTCXX:=$(CC_real) --hostcxx
33 endif
34
35 export top := $(PWD)
36 export src := src
37 export srck := $(top)/util/kconfig
38 export obj ?= build
39 export objutil ?= $(obj)/util
40 export objk := $(objutil)/kconfig
41
42
43 export KERNELVERSION      := 4.0
44 export KCONFIG_AUTOHEADER := $(obj)/config.h
45 export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
46
47 CONFIG_SHELL := sh
48 KBUILD_DEFCONFIG := configs/defconfig
49 UNAME_RELEASE := $(shell uname -r)
50 HAVE_DOTCONFIG := $(wildcard .config)
51 MAKEFLAGS += -rR --no-print-directory
52
53 # Make is silent per default, but 'make V=1' will show all compiler calls.
54 Q:=@
55 ifneq ($(V),1)
56 ifneq ($(Q),)
57 .SILENT:
58 endif
59 endif
60
61 CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
62 ROMCC:= $(objutil)/romcc/romcc
63 HOSTCC = gcc
64 HOSTCXX = g++
65 HOSTCFLAGS := -I$(srck) -I$(objk) -g
66 HOSTCXXFLAGS := -I$(srck) -I$(objk)
67 LIBGCC_FILE_NAME := $(shell test -r `$(CC) -print-libgcc-file-name` && $(CC) -print-libgcc-file-name)
68
69 DOXYGEN := doxygen
70 DOXYGEN_OUTPUT_DIR := doxygen
71
72 # Three cases where we don't need fully populated $(obj) lists:
73 # 1. when no .config exists
74 # 2. when make config (in any flavour) is run
75 # 3. when make distclean is run
76 # Don't waste time on reading all Makefile.incs in these cases
77 ifeq ($(strip $(HAVE_DOTCONFIG)),)
78 NOCOMPILE:=1
79 endif
80 ifneq ($(MAKECMDGOALS),)
81 ifneq ($(filter %config distclean,$(MAKECMDGOALS)),)
82 NOCOMPILE:=1
83 endif
84 endif
85
86 ifeq ($(NOCOMPILE),1)
87 all: config
88
89 else
90
91 include $(HAVE_DOTCONFIG)
92
93 ifneq ($(INNER_SCANBUILD),y)
94 ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
95 CC:=clang -m32
96 HOSTCC:=clang
97 endif
98 endif
99
100 ifeq ($(CONFIG_CCACHE),y)
101 CCACHE:=$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH))))
102 ifeq ($(CCACHE),)
103 $(error ccache selected, but not found in PATH)
104 endif
105 CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
106 CC := $(CCACHE) $(CC)
107 HOSTCC := $(CCACHE) $(HOSTCC)
108 HOSTCXX := $(CCACHE) $(HOSTCXX)
109 ROMCC := $(CCACHE) $(ROMCC)
110 endif
111
112 strip_quotes = $(subst ",,$(subst \",,$(1)))
113
114 ARCHDIR-$(CONFIG_ARCH_X86)    := i386
115 ARCHDIR-$(CONFIG_ARCH_POWERPC) := ppc
116
117 MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
118 export MAINBOARDDIR
119
120 PLATFORM-y += src/arch/$(ARCHDIR-y) src/cpu src/mainboard/$(MAINBOARDDIR)
121 TARGETS-y :=
122
123 BUILD-y := src/lib src/boot src/console src/devices src/southbridge src/northbridge src/superio src/drivers
124 BUILD-y += util/cbfstool util/sconfig
125 BUILD-$(CONFIG_ARCH_X86) += src/pc80
126
127 ifneq ($(CONFIG_LOCALVERSION),"")
128 COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
129 endif
130
131 # The primary target needs to be here before we include the
132 # other files
133
134 ifeq ($(INNER_SCANBUILD),y)
135 CONFIG_SCANBUILD_ENABLE:=
136 endif
137
138 ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
139 ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
140 CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
141 endif
142 all:
143         echo '#!/bin/sh' > .ccwrap
144         echo 'CC="$(CC)"' >> .ccwrap
145         echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
146         echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
147         echo 'eval $$CC $$*' >> .ccwrap
148         chmod +x .ccwrap
149         scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
150 else
151 all: $(obj)/config.h coreboot
152 endif
153
154 # must come rather early
155 .SECONDEXPANSION:
156
157 $(obj)/config.h:
158         $(MAKE) oldconfig
159
160 #######################################################################
161 # Build the tools
162
163 CBFSTOOL:=$(objutil)/cbfstool/cbfstool
164
165 # needed objects that every mainboard uses
166 # Creation of these is architecture and mainboard independent
167 $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb  $(objutil)/sconfig/sconfig
168         @printf "    SCONFIG    $(subst $(src)/,,$(<))\n"
169         mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
170         $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
171
172 $(objutil)/%.o: $(objutil)/%.c
173         @printf "    HOSTCC     $(subst $(objutil)/,,$(@))\n"
174         $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
175
176 $(obj)/%.o: $(obj)/%.c $(obj)/config.h
177         @printf "    CC         $(subst $(obj)/,,$(@))\n"
178         $(CC) -MMD $(CFLAGS) -c -o $@ $<
179
180 objs:=$(obj)/mainboard/$(MAINBOARDDIR)/static.o
181 initobjs:=
182 drivers:=
183 smmobjs:=
184 types:=obj initobj driver smmobj
185
186 # Clean -y variables, include Makefile.inc
187 # If $(3) is non-empty, add paths to files in X-y, and add them to Xs
188 # Add subdirs-y to subdirs
189 includemakefiles= \
190         $(foreach type,$(2), $(eval $(type)-y:=)) \
191         $(eval subdirs-y:=) \
192         $(eval -include $(1)) \
193         $(foreach type,$(2), \
194                 $(eval $(type)s+= \
195                         $$(subst $(top)/,, \
196                         $$(abspath $$(patsubst src/%, \
197                                         $(obj)/%, \
198                                         $$(addprefix $(dir $(1)),$$($(type)-y))))))) \
199         $(eval subdirs+=$$(subst $(PWD)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
200
201 # For each path in $(subdirs) call includemakefiles, passing $(1) as $(3)
202 # Repeat until subdirs is empty
203 evaluate_subdirs= \
204         $(eval cursubdirs:=$(subdirs)) \
205         $(eval subdirs:=) \
206         $(foreach dir,$(cursubdirs), \
207                 $(eval $(call includemakefiles,$(dir)/Makefile.inc,$(types)))) \
208         $(if $(subdirs),$(eval $(call evaluate_subdirs)))
209
210 # collect all object files eligible for building
211 subdirs:=$(PLATFORM-y) $(BUILD-y)
212 $(eval $(call evaluate_subdirs))
213
214 initobjs:=$(addsuffix .initobj.o, $(basename $(initobjs)))
215 drivers:=$(addsuffix .driver.o, $(basename $(drivers)))
216 smmobjs:=$(addsuffix .smmobj.o, $(basename $(smmobjs)))
217
218 allobjs:=$(foreach var, $(addsuffix s,$(types)), $($(var)))
219 alldirs:=$(sort $(abspath $(dir $(allobjs))))
220 source_with_ext=$(patsubst $(obj)/%.o,src/%.$(1),$(allobjs))
221 allsrc=$(wildcard $(call source_with_ext,c) $(call source_with_ext,S))
222
223 define objs_asl_template
224 $(obj)/$(1)%.o: src/$(1)%.asl
225         @printf "    IASL       $$(subst $(top)/,,$$(@))\n"
226         $(CPP) -D__ACPI__ -P -include $(abspath $(obj)/config.h) -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
227         iasl -p $$(basename $$@) -tc $$(basename $$@).asl
228         mv $$(basename $$@).hex $$(basename $$@).c
229         $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $$@))), -DAmlCode=AmlCode_$$(basename $$(notdir $$@))) -c -o $$@ $$(basename $$@).c
230         # keep %.o: %.c rule from catching the temporary .c file after a make clean
231         mv $$(basename $$@).c $$(basename $$@).hex
232 endef
233
234 # macro to define template macros that are used by use_template macro
235 define create_cc_template
236 # $1 obj class (objs, initobjs, ...)
237 # $2 source suffix (c, S)
238 # $3 .o infix ("" ".initobj", ...)
239 # $4 additional compiler flags
240 de$(EMPTY)fine $(1)_$(2)_template
241 $(obj)/$$(1)%$(3).o: src/$$(1)%.$(2) $(obj)/config.h
242         @printf "    CC         $$$$(subst $$$$(obj)/,,$$$$(@))\n"
243         $(CC) $(4) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
244 en$(EMPTY)def
245 endef
246
247 $(eval $(call create_cc_template,objs,c))
248 $(eval $(call create_cc_template,objs,S,,-DASSEMBLY))
249 $(eval $(call create_cc_template,initobjs,c,.initobj,-D__PRE_RAM__))
250 $(eval $(call create_cc_template,initobjs,S,.initobj,-DASSEMBLY -D__PRE_RAM__))
251 $(eval $(call create_cc_template,drivers,c,.driver))
252 $(eval $(call create_cc_template,drivers,S,.driver,-DASSEMBLY))
253 $(eval $(call create_cc_template,smmobjs,c,.smmobj))
254 $(eval $(call create_cc_template,smmobjs,S,.smmobj))
255
256 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
257 usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
258 $(eval $(call usetemplate,objs,asl))
259 $(eval $(call usetemplate,objs,c))
260 $(eval $(call usetemplate,objs,S))
261 $(eval $(call usetemplate,initobjs,c))
262 $(eval $(call usetemplate,initobjs,S))
263 $(eval $(call usetemplate,drivers,c))
264 $(eval $(call usetemplate,drivers,S))
265 $(eval $(call usetemplate,smmobjs,c))
266 $(eval $(call usetemplate,smmobjs,S))
267
268 DEPENDENCIES = $(objs:.o=.d) $(initobjs:.o=.d) $(drivers:.o=.d) $(smmobjs:.o=.d)
269 -include $(DEPENDENCIES)
270
271 printall:
272         @echo objs:=$(objs)
273         @echo initobjs:=$(initobjs)
274         @echo drivers:=$(drivers)
275         @echo smmobjs:=$(smmobjs)
276         @echo alldirs:=$(alldirs)
277         @echo allsrc=$(allsrc)
278         @echo DEPENDENCIES=$(DEPENDENCIES)
279         @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
280
281 printcrt0s:
282         @echo crt0s=$(crt0s)
283         @echo ldscripts=$(ldscripts)
284
285 OBJS     := $(patsubst %,$(obj)/%,$(TARGETS-y))
286 INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include
287 INCLUDES += -Isrc/devices/oprom/include
288 # abspath is a workaround for romcc
289 INCLUDES += -include $(abspath $(obj)/config.h)
290
291 CFLAGS = $(INCLUDES) -Os -nostdinc -pipe -g
292 CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
293 CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
294 CFLAGS += -Wstrict-aliasing -Wshadow
295 ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
296 CFLAGS += -Werror
297 endif
298 CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
299
300 CBFS_COMPRESS_FLAG:=l
301 CBFS_PAYLOAD_COMPRESS_FLAG:=
302 CBFS_PAYLOAD_COMPRESS_NAME:=none
303 ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
304 CBFS_PAYLOAD_COMPRESS_FLAG:=l
305 CBFS_PAYLOAD_COMPRESS_NAME:=LZMA
306 endif
307
308 coreboot: $(obj)/coreboot.rom
309
310 endif
311
312 $(shell mkdir -p $(obj) $(objutil)/kconfig/lxdialog $(objutil)/cbfstool $(objutil)/romcc $(objutil)/options $(alldirs))
313
314 $(obj)/build.h: .xcompile
315         @printf "    GEN        build.h\n"
316         rm -f $(obj)/build.h
317         printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
318         printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
319         printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
320         printf "#define COREBOOT_VERSION \"$(KERNELVERSION)-r$(shell if [ -d $(top)/.svn -a -f "`which svnversion`" ]; then svnversion $(top); else if [ -d $(top)/.git -a -f "`which git`" ]; then git --git-dir=/$(top)/.git log|grep git-svn-id|cut -f 2 -d@|cut -f 1 -d' '|sort -g|tail -1; fi; fi)\"\n" >> $(obj)/build.ht
321         printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
322         printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
323         printf "\n" >> $(obj)/build.ht
324         printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
325         printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
326         printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
327         printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
328         printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
329         printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null)\"\n" >> $(obj)/build.ht
330         printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht
331         printf "#endif\n" >> $(obj)/build.ht
332         mv $(obj)/build.ht $(obj)/build.h
333
334 cscope:
335         cscope -bR
336
337 doxy: doxygen
338 doxygen:
339         $(DOXYGEN) documentation/Doxyfile.coreboot
340
341 doxyclean: doxygen-clean
342 doxygen-clean:
343         rm -rf $(DOXYGEN_OUTPUT_DIR)
344
345 clean-for-update: doxygen-clean
346         rm -f $(objs) $(initobjs) $(drivers) $(smmobjs) .xcompile
347         rm -f $(DEPENDENCIES)
348         rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
349         rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
350         rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
351         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
352         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
353         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
354         rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
355         rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
356         rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
357
358 clean: clean-for-update
359         rm -f $(obj)/coreboot* .ccwrap
360
361 clean-abuild:
362         rm -rf coreboot-builds
363
364 clean-cscope:
365         rm -f cscope.out
366
367 distclean: clean-cscope clean-abuild
368         rm -rf $(obj)
369         rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
370
371 update:
372         dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
373
374 # This include must come _before_ the pattern rules below!
375 # Order _does_ matter for pattern rules.
376 include util/kconfig/Makefile
377
378 $(obj)/ldoptions: $(obj)/config.h
379         awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
380
381 _WINCHECK=$(shell uname -o 2> /dev/null)
382 STACK=
383 ifeq ($(_WINCHECK),Msys)
384         STACK=-Wl,--stack,16384000
385 endif
386 ifeq ($(_WINCHECK),Cygwin)
387         STACK=-Wl,--stack,16384000
388 endif
389
390 $(objutil)/romcc/romcc: $(top)/util/romcc/romcc.c
391         @printf "    HOSTCC     $(subst $(obj)/,,$(@)) (this may take a while)\n"
392         @# Note: Adding -O2 here might cause problems. For details see:
393         @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
394         $(HOSTCC) -g $(STACK) -Wall -o $@ $<
395
396 .PHONY: $(PHONY) clean clean-abuild clean-cscope cscope distclean doxygen doxy coreboot .xcompile
397