blob: ef20d1a2890bbdc78874264bf530f69c955a5de1 [file] [log] [blame]
Patrick Georgi0588d192009-08-12 15:00:51 +00001##
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##
7## Redistribution and use in source and binary forms, with or without
8## modification, are permitted provided that the following conditions
9## are met:
10## 1. Redistributions of source code must retain the above copyright
11## notice, this list of conditions and the following disclaimer.
12## 2. Redistributions in binary form must reproduce the above copyright
13## notice, this list of conditions and the following disclaimer in the
14## documentation and/or other materials provided with the distribution.
15## 3. The name of the author may not be used to endorse or promote products
16## derived from this software without specific prior written permission.
17##
18## THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19## ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20## IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21## ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22## FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23## DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24## OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25## HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26## LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27## OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28## SUCH DAMAGE.
29##
30
31$(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
32include .xcompile
33
34export top := $(shell pwd)
35export src := $(top)/src
36export srck := $(top)/util/kconfig
37export obj := $(top)/build
38export objk := $(top)/build/util/kconfig
39export sconfig := $(top)/util/sconfig
40export yapps2_py := $(sconfig)/yapps2.py
41export config_g := $(sconfig)/config.g
42
43
44export KERNELVERSION := 2.3
45export KCONFIG_AUTOHEADER := $(obj)/config.h
46export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
47export COREBOOT_V2 := 1
48
49CONFIG_SHELL := sh
50KBUILD_DEFCONFIG := configs/defconfig
51UNAME_RELEASE := $(shell uname -r)
52HAVE_DOTCONFIG := $(wildcard .config)
53MAKEFLAGS += -rR --no-print-directory
54
55# Make is silent per default, but 'make V=1' will show all compiler calls.
56ifneq ($(V),1)
57Q := @
58endif
59
60CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
61HOSTCC = gcc
62HOSTCXX = g++
63HOSTCFLAGS := -I$(srck) -I$(objk) -g
64HOSTCXXFLAGS := -I$(srck) -I$(objk)
65
66DESTDIR = /opt
67
68DOXYGEN := doxygen
69DOXYGEN_OUTPUT_DIR := doxygen
70
71ifeq ($(strip $(HAVE_DOTCONFIG)),)
72
73all: config
74
75else
76
77include $(top)/.config
78
79ARCHDIR-$(CONFIG_ARCH_X86) := i386
80ARCHDIR-$(CONFIG_ARCH_POWERPC) := ppc
81
82MAINBOARDDIR=$(shell echo $(CONFIG_MAINBOARD_DIR))
83export MAINBOARDDIR
84
85PLATFORM-y += src/arch/$(ARCHDIR-y) src/cpu src/mainboard/$(MAINBOARDDIR)
86TARGETS-y :=
87
88BUILD-y := src/lib src/boot src/console src/devices src/southbridge src/northbridge src/superio src/drivers util/x86emu
89BUILD-y += util/cbfstool
90BUILD-$(CONFIG_ARCH_X86) += src/pc80
91
92# The primary target needs to be here before we include the
93# other files
94
95all: coreboot
96
97
98#######################################################################
99# Build the tools
100
101CBFSTOOL:=$(obj)/util/cbfstool/cbfstool
102
103$(obj)/mainboard/$(MAINBOARDDIR)/config.py: $(yapps2_py) $(config_g)
104 $(Q)mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
105 $(Q)python $(yapps2_py) $(config_g) $(obj)/mainboard/$(MAINBOARDDIR)/config.py
106
107
108# needed objects that every mainboard uses
109# Creation of these is architecture and mainboard independent
110$(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/Config.lb $(obj)/mainboard/$(MAINBOARDDIR)/config.py
111 $(Q)mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
112 (cd $(obj)/mainboard/$(MAINBOARDDIR) ; PYTHONPATH=$(top)/util/sconfig export PYTHONPATH; python config.py $(MAINBOARDDIR) $(top) $(obj)/mainboard/$(MAINBOARDDIR))
113
114$(obj)/mainboard/$(MAINBOARDDIR)/static.o: $(obj)/mainboard/$(MAINBOARDDIR)/static.c
115#
116
117objs:=$(obj)/mainboard/$(MAINBOARDDIR)/static.o
118initobjs:=
119drivers:=
120smmobjs:=
121crt0s:=
122ldscripts:=
123types:=obj initobj driver smmobj
124src_types:=crt0 ldscript
125includemakefiles=$(foreach type,$(2), $(eval $(type)-y:=)) $(eval subdirs-y:=) $(eval include $(1)) $(if $(strip $(3)),$(foreach type,$(2),$(eval $(type)s+=$$(patsubst src/%,$(obj)/%,$$(addprefix $(dir $(1)),$$($(type)-y)))))) $(eval subdirs+=$$(subst $(PWD)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
126evaluate_subdirs=$(eval cursubdirs:=$(subdirs)) $(eval subdirs:=) $(foreach dir,$(cursubdirs),$(eval $(call includemakefiles,$(dir)/Makefile.inc,$(types) $(src_types),$(1)))) $(if $(subdirs),$(eval $(call evaluate_subdirs, $(1))))
127
128# collect all object files eligible for building
129subdirs:=$(PLATFORM-y) $(BUILD-y)
130$(eval $(call evaluate_subdirs, modify))
131
132allobjs:=$(foreach var, $(addsuffix s,$(types)), $($(var)))
133alldirs:=$(sort $(abspath $(dir $(allobjs))))
134source_with_ext=$(patsubst $(obj)/%.o,src/%.$(1),$(allobjs))
135allsrc=$(wildcard $(call source_with_ext,c) $(call source_with_ext,S))
136
137POST_EVALUATION:=y
138
139# fetch rules (protected in POST_EVALUATION) that rely on the variables filled above
140subdirs:=$(PLATFORM-y) $(BUILD-y)
141$(eval $(call evaluate_subdirs))
142
143
144define objs_c_template
145$(obj)/$(1)%.o: src/$(1)%.c
146 $(Q)printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
147 $(Q)$(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
148endef
149
150define objs_S_template
151$(obj)/$(1)%.o: src/$(1)%.S
152 $(Q)printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
153 $(Q)$(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
154endef
155
156define initobjs_c_template
157$(obj)/$(1)%.o: src/$(1)%.c
158 $(Q)printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
159 $(Q)$(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
160endef
161
162define initobjs_S_template
163$(obj)/$(1)%.o: src/$(1)%.S
164 $(Q)printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
165 $(Q)$(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
166endef
167
168define drivers_c_template
169$(obj)/$(1)%.o: src/$(1)%.c
170 $(Q)printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
171 $(Q)$(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
172endef
173
174define drivers_S_template
175$(obj)/$(1)%.o: src/$(1)%.S
176 $(Q)printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
177 $(Q)$(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
178endef
179
180define smmobjs_c_template
181$(obj)/$(1)%.o: src/$(1)%.c
182 $(Q)printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
183 $(Q)$(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
184endef
185
186define smmobjs_S_template
187$(obj)/$(1)%.o: src/$(1)%.S
188 $(Q)printf " CC $$(subst $$(shell pwd)/,,$$(@))\n"
189 $(Q)$(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
190endef
191
192usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
193usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
194$(eval $(call usetemplate,objs,c))
195$(eval $(call usetemplate,objs,S))
196$(eval $(call usetemplate,initobjs,c))
197$(eval $(call usetemplate,initobjs,S))
198$(eval $(call usetemplate,drivers,c))
199$(eval $(call usetemplate,drivers,S))
200$(eval $(call usetemplate,smmobjs,c))
201$(eval $(call usetemplate,smmobjs,S))
202
203printall:
204 @echo objs:=$(objs)
205 @echo initobjs:=$(initobjs)
206 @echo drivers:=$(drivers)
207 @echo smmobjs:=$(smmobjs)
208 @echo alldirs:=$(alldirs)
209 @echo allsrc=$(allsrc)
210
211OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y))
212INCLUDES := -I$(top)/src -I$(top)/src/include -I$(obj) -I$(top)/src/arch/$(ARCHDIR-y)/include
213INCLUDES += -I$(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
214INCLUDES += -include $(obj)/build.h
215
216try-run= $(shell set -e; \
217TMP=".$$$$.tmp"; \
218if ($(1)) > /dev/null 2>&1; \
219then echo "$(2)"; \
220else echo "$(3)"; \
221fi; rm -rf "$$TMP")
222
223cc-option= $(call try-run,\
224$(CC) $(1) -S -xc /dev/null -o "$$TMP", $(1), $(2))
225
226STACKPROTECT += $(call cc-option, -fno-stack-protector,)
227
228CFLAGS = $(STACKPROTECT) $(INCLUDES) $(MAINBOARD_OPTIONS) -Os -nostdinc
229CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
230CFLAGS +=-Wwrite-strings -Wredundant-decls -Wno-trigraphs
231CFLAGS += -Werror-implicit-function-declaration -Wstrict-aliasing -Wshadow
232CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
233
234CBFS_COMPRESS_FLAG:=
235ifeq "$(CONFIG_COMPRESSED_PAYLOAD_LZMA)" "1"
236CBFS_COMPRESS_FLAG:=l
237endif
238
239coreboot: prepare prepare2 $(obj)/coreboot.rom
240
241endif
242
243prepare:
244 $(Q)mkdir -p $(obj)
245 $(Q)mkdir -p $(obj)/util/kconfig/lxdialog
246 $(Q)test -n "$(alldirs)" && mkdir -p $(alldirs) || true
247
248prepare2:
249 $(Q)printf " GEN $(subst $(shell pwd)/,,$(obj)/build.h)\n"
250 $(Q)printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" > $(obj)/build.h
251 $(Q)printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.h
252 $(Q)printf "#define COREBOOT_V2 \"$(COREBOOT_V2)\"\n" >> $(obj)/build.h
253 $(Q)printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.h
254 $(Q)printf "\n" >> $(obj)/build.h
255 $(Q)printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.h
256 $(Q)printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.h
257 $(Q)printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.h
258 $(Q)printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.h
259 $(Q)printf "#define COREBOOT_COMPILE_BY \"$(shell PATH=$$PATH:/usr/ucb whoami)\"\n" >> $(obj)/build.h
260 $(Q)printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname)\"\n" >> $(obj)/build.h
261 $(Q)printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname)\"\n" >> $(obj)/build.h
262 $(Q)printf "#include \"config.h\"\n" >> $(obj)/build.h
263
264doxy: doxygen
265doxygen:
266 $(Q)$(DOXYGEN) Doxyfile
267
268doxyclean: doxygen-clean
269doxygen-clean:
270 $(Q)rm -rf $(DOXYGEN_OUTPUT_DIR)
271
272clean: doxygen-clean
273 $(Q)rm -f $(allobjs) build/coreboot* .xcompile
274 $(Q)rm -f build/option_table.* build/crt0_includes.h build/ldscript
275 $(Q)rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
276 $(Q)rm -f $(obj)/mainboard/$(MAINBOARDDIR)/auto.inc $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
277 $(Q)rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
278
279distclean: clean
280 $(Q)rm -rf build
281 $(Q)rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig*
282
283update:
284 $(Q)dongle.py -c /dev/term/1 build/coreboot.rom EOF
285
286# This include must come _before_ the pattern rules below!
287# Order _does_ matter for pattern rules.
288include util/kconfig/Makefile
289
290$(obj)/ldoptions: $(obj)/config.h
291# cat $(obj)/config.h | grep -v \" |grep -v AUTOCONF_INCLUDED | grep \#define | sed s/\#define\ // | sed s/\ /\ =\ / | sed 's/$$/;/' > $(obj)/ldoptions
292 $(Q)awk '/^#define ([^"])* ([^"])*$$/ {print $$2 " = " $$3 ";";}' $< > $@
293
294$(obj)/romcc: $(top)/util/romcc/romcc.c
295 $(Q)printf " HOSTCC romcc"
296 $(HOSTCC) -g -O2 -Wall -o $@ $<
297
298.PHONY: $(PHONY) prepare prepare2 clean distclean doxygen doxy coreboot
299