blob: acf71567055efb1307cf235e4edee85350f6658a [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>
Stefan Reinauer8ed1b6d2010-01-19 21:13:44 +00006## Copyright (C) 2009-2010 coresystems GmbH
Patrick Georgi0588d192009-08-12 15:00:51 +00007##
Stefan Reinauer16f515a2010-01-20 18:44:30 +00008## 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.
Patrick Georgi0588d192009-08-12 15:00:51 +000011##
Stefan Reinauer16f515a2010-01-20 18:44:30 +000012## 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
Patrick Georgi0588d192009-08-12 15:00:51 +000020##
21
22$(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
23include .xcompile
24
25export top := $(shell pwd)
26export src := $(top)/src
27export srck := $(top)/util/kconfig
Stefan Reinauere3778572010-01-30 09:47:18 +000028export obj ?= $(top)/build
Myles Watsond4e5c0a2009-10-28 15:30:11 +000029export objk := $(obj)/util/kconfig
Patrick Georgi0588d192009-08-12 15:00:51 +000030export sconfig := $(top)/util/sconfig
31export yapps2_py := $(sconfig)/yapps2.py
32export config_g := $(sconfig)/config.g
33
34
Stefan Reinauer37d8c212010-02-08 18:30:41 +000035export KERNELVERSION := 4.0
Patrick Georgi0588d192009-08-12 15:00:51 +000036export KCONFIG_AUTOHEADER := $(obj)/config.h
37export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
Patrick Georgi0588d192009-08-12 15:00:51 +000038
39CONFIG_SHELL := sh
40KBUILD_DEFCONFIG := configs/defconfig
41UNAME_RELEASE := $(shell uname -r)
42HAVE_DOTCONFIG := $(wildcard .config)
43MAKEFLAGS += -rR --no-print-directory
44
45# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000046Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000047ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000048ifneq ($(Q),)
49.SILENT:
50endif
Patrick Georgi0588d192009-08-12 15:00:51 +000051endif
52
53CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
54HOSTCC = gcc
55HOSTCXX = g++
56HOSTCFLAGS := -I$(srck) -I$(objk) -g
57HOSTCXXFLAGS := -I$(srck) -I$(objk)
Harald Gutmanndc4bb0d2009-08-26 15:35:36 +000058LIBGCC_FILE_NAME := $(shell $(CC) -print-libgcc-file-name)
Patrick Georgi0588d192009-08-12 15:00:51 +000059
60DESTDIR = /opt
61
62DOXYGEN := doxygen
63DOXYGEN_OUTPUT_DIR := doxygen
64
65ifeq ($(strip $(HAVE_DOTCONFIG)),)
66
67all: config
68
69else
70
71include $(top)/.config
72
73ARCHDIR-$(CONFIG_ARCH_X86) := i386
74ARCHDIR-$(CONFIG_ARCH_POWERPC) := ppc
75
76MAINBOARDDIR=$(shell echo $(CONFIG_MAINBOARD_DIR))
77export MAINBOARDDIR
78
79PLATFORM-y += src/arch/$(ARCHDIR-y) src/cpu src/mainboard/$(MAINBOARDDIR)
80TARGETS-y :=
81
82BUILD-y := src/lib src/boot src/console src/devices src/southbridge src/northbridge src/superio src/drivers util/x86emu
83BUILD-y += util/cbfstool
84BUILD-$(CONFIG_ARCH_X86) += src/pc80
85
Uwe Hermannc04be932009-10-05 13:55:28 +000086ifneq ($(CONFIG_LOCALVERSION),"")
87COREBOOT_EXTRA_VERSION := -$(shell echo $(CONFIG_LOCALVERSION))
88endif
89
Patrick Georgi0588d192009-08-12 15:00:51 +000090# The primary target needs to be here before we include the
91# other files
92
93all: coreboot
94
95
96#######################################################################
97# Build the tools
98
99CBFSTOOL:=$(obj)/util/cbfstool/cbfstool
100
101$(obj)/mainboard/$(MAINBOARDDIR)/config.py: $(yapps2_py) $(config_g)
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000102 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
103 python $(yapps2_py) $(config_g) $(obj)/mainboard/$(MAINBOARDDIR)/config.py
Patrick Georgi0588d192009-08-12 15:00:51 +0000104
105
106# needed objects that every mainboard uses
107# Creation of these is architecture and mainboard independent
Myles Watsoned035562009-09-22 21:29:32 +0000108$(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(obj)/mainboard/$(MAINBOARDDIR)/config.py
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000109 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000110 (cd $(obj)/mainboard/$(MAINBOARDDIR) ; PYTHONPATH=$(top)/util/sconfig export PYTHONPATH; python config.py $(MAINBOARDDIR) $(top) $(obj)/mainboard/$(MAINBOARDDIR))
111
112$(obj)/mainboard/$(MAINBOARDDIR)/static.o: $(obj)/mainboard/$(MAINBOARDDIR)/static.c
113#
114
115objs:=$(obj)/mainboard/$(MAINBOARDDIR)/static.o
116initobjs:=
117drivers:=
118smmobjs:=
119crt0s:=
120ldscripts:=
121types:=obj initobj driver smmobj
Patrick Georgi0588d192009-08-12 15:00:51 +0000122includemakefiles=$(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)))))
Stefan Reinauere3778572010-01-30 09:47:18 +0000123evaluate_subdirs=$(eval cursubdirs:=$(subdirs)) $(eval subdirs:=) $(foreach dir,$(cursubdirs),$(eval $(call includemakefiles,$(dir)/Makefile.inc,$(types),$(1)))) $(if $(subdirs),$(eval $(call evaluate_subdirs, $(1))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000124
125# collect all object files eligible for building
126subdirs:=$(PLATFORM-y) $(BUILD-y)
127$(eval $(call evaluate_subdirs, modify))
128
129allobjs:=$(foreach var, $(addsuffix s,$(types)), $($(var)))
130alldirs:=$(sort $(abspath $(dir $(allobjs))))
131source_with_ext=$(patsubst $(obj)/%.o,src/%.$(1),$(allobjs))
132allsrc=$(wildcard $(call source_with_ext,c) $(call source_with_ext,S))
133
134POST_EVALUATION:=y
135
136# fetch rules (protected in POST_EVALUATION) that rely on the variables filled above
137subdirs:=$(PLATFORM-y) $(BUILD-y)
138$(eval $(call evaluate_subdirs))
139
140
Patrick Georgiaf97d332010-02-08 15:46:37 +0000141define objs_dsl_template
142$(obj)/$(1)%.o: src/$(1)%.asl
Patrick Georgi88f55b22009-09-25 18:43:02 +0000143 @printf " IASL $$(subst $$(shell pwd)/,,$$(@))\n"
Patrick Georgiaf97d332010-02-08 15:46:37 +0000144 $(CPP) -D__ACPI__ -P $(CPPFLAGS) -include $(obj)/config.h -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
145 iasl -p $$(basename $$@) -tc $$(basename $$@).asl
146 mv $$(basename $$@).hex $$(basename $$@).c
147 $(CC) -m32 $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $$@))), -DAmlCode=AmlCode_$$(basename $$(notdir $$@))) -c -o $$@ $$(basename $$@).c
Patrick Georgi88f55b22009-09-25 18:43:02 +0000148endef
149
Patrick Georgi0588d192009-08-12 15:00:51 +0000150define objs_c_template
Patrick Georgicccbb892010-01-29 17:38:57 +0000151$(obj)/$(1)%.o: src/$(1)%.c $(obj)/build.h
Uwe Hermann6c73b4412009-10-28 17:10:51 +0000152 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000153 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
Patrick Georgi0588d192009-08-12 15:00:51 +0000154endef
155
156define objs_S_template
Patrick Georgicccbb892010-01-29 17:38:57 +0000157$(obj)/$(1)%.o: src/$(1)%.S $(obj)/build.h
Uwe Hermann6c73b4412009-10-28 17:10:51 +0000158 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000159 $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
Patrick Georgi0588d192009-08-12 15:00:51 +0000160endef
161
162define initobjs_c_template
Patrick Georgicccbb892010-01-29 17:38:57 +0000163$(obj)/$(1)%.o: src/$(1)%.c $(obj)/build.h
Uwe Hermann6c73b4412009-10-28 17:10:51 +0000164 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000165 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
Patrick Georgi0588d192009-08-12 15:00:51 +0000166endef
167
168define initobjs_S_template
Patrick Georgicccbb892010-01-29 17:38:57 +0000169$(obj)/$(1)%.o: src/$(1)%.S $(obj)/build.h
Uwe Hermann6c73b4412009-10-28 17:10:51 +0000170 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000171 $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
Patrick Georgi0588d192009-08-12 15:00:51 +0000172endef
173
174define drivers_c_template
Patrick Georgicccbb892010-01-29 17:38:57 +0000175$(obj)/$(1)%.o: src/$(1)%.c $(obj)/build.h
Uwe Hermann6c73b4412009-10-28 17:10:51 +0000176 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000177 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
Patrick Georgi0588d192009-08-12 15:00:51 +0000178endef
179
180define drivers_S_template
181$(obj)/$(1)%.o: src/$(1)%.S
Uwe Hermann6c73b4412009-10-28 17:10:51 +0000182 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000183 $(CC) -m32 -DASSEMBLY $$(CFLAGS) -c -o $$@ $$<
Patrick Georgi0588d192009-08-12 15:00:51 +0000184endef
185
186define smmobjs_c_template
187$(obj)/$(1)%.o: src/$(1)%.c
Uwe Hermann6c73b4412009-10-28 17:10:51 +0000188 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000189 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
Patrick Georgi0588d192009-08-12 15:00:51 +0000190endef
191
192define smmobjs_S_template
193$(obj)/$(1)%.o: src/$(1)%.S
Uwe Hermann6c73b4412009-10-28 17:10:51 +0000194 @printf " CC $$(subst $$(obj)/,,$$(@))\n"
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000195 $(CC) -m32 $$(CFLAGS) -c -o $$@ $$<
Patrick Georgi0588d192009-08-12 15:00:51 +0000196endef
197
198usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
199usetemplate=$(foreach d,$(sort $(dir $($(1)))),$(eval $(call $(1)_$(2)_template,$(subst $(obj)/,,$(d)))))
Patrick Georgiaf97d332010-02-08 15:46:37 +0000200$(eval $(call usetemplate,objs,dsl))
Patrick Georgi0588d192009-08-12 15:00:51 +0000201$(eval $(call usetemplate,objs,c))
202$(eval $(call usetemplate,objs,S))
203$(eval $(call usetemplate,initobjs,c))
204$(eval $(call usetemplate,initobjs,S))
205$(eval $(call usetemplate,drivers,c))
206$(eval $(call usetemplate,drivers,S))
207$(eval $(call usetemplate,smmobjs,c))
208$(eval $(call usetemplate,smmobjs,S))
209
210printall:
211 @echo objs:=$(objs)
212 @echo initobjs:=$(initobjs)
213 @echo drivers:=$(drivers)
214 @echo smmobjs:=$(smmobjs)
215 @echo alldirs:=$(alldirs)
216 @echo allsrc=$(allsrc)
217
218OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y))
219INCLUDES := -I$(top)/src -I$(top)/src/include -I$(obj) -I$(top)/src/arch/$(ARCHDIR-y)/include
220INCLUDES += -I$(shell $(CC) -print-search-dirs | head -n 1 | cut -d' ' -f2)include
Myles Watsone6804952009-08-28 14:36:12 +0000221INCLUDES += -I$(top)/util/x86emu/include
Patrick Georgi0588d192009-08-12 15:00:51 +0000222INCLUDES += -include $(obj)/build.h
223
224try-run= $(shell set -e; \
225TMP=".$$$$.tmp"; \
226if ($(1)) > /dev/null 2>&1; \
227then echo "$(2)"; \
228else echo "$(3)"; \
229fi; rm -rf "$$TMP")
230
231cc-option= $(call try-run,\
232$(CC) $(1) -S -xc /dev/null -o "$$TMP", $(1), $(2))
233
234STACKPROTECT += $(call cc-option, -fno-stack-protector,)
235
Patrick Georgi6842c022009-09-29 17:28:13 +0000236CFLAGS = $(STACKPROTECT) $(INCLUDES) -Os -nostdinc
Patrick Georgi0588d192009-08-12 15:00:51 +0000237CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
Uwe Hermannc04be932009-10-05 13:55:28 +0000238CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
Patrick Georgi88f55b22009-09-25 18:43:02 +0000239CFLAGS += -Wstrict-aliasing -Wshadow
Myles Watson2e672732009-11-12 16:38:03 +0000240ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
241CFLAGS += -Werror
242endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000243CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
244
Patrick Georgi0588d192009-08-12 15:00:51 +0000245CBFS_COMPRESS_FLAG:=l
Myles Watson422d0cb2009-09-23 17:48:28 +0000246CBFS_PAYLOAD_COMPRESS_FLAG:=
247ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
248CBFS_PAYLOAD_COMPRESS_FLAG:=l
Patrick Georgi0588d192009-08-12 15:00:51 +0000249endif
250
251coreboot: prepare prepare2 $(obj)/coreboot.rom
252
253endif
254
255prepare:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000256 mkdir -p $(obj)
257 mkdir -p $(obj)/util/kconfig/lxdialog
258 test -n "$(alldirs)" && mkdir -p $(alldirs) || true
Patrick Georgi0588d192009-08-12 15:00:51 +0000259
Patrick Georgicccbb892010-01-29 17:38:57 +0000260prepare2: $(obj)/build.h
261
262$(obj)/build.h:
Uwe Hermann6c73b4412009-10-28 17:10:51 +0000263 @printf " GEN build.h\n"
Patrick Georgicccbb892010-01-29 17:38:57 +0000264 rm -f $(obj)/build.h
265 printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" > $(obj)/build.ht
266 printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
267 printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
268 printf "\n" >> $(obj)/build.ht
269 printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
270 printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
271 printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
272 printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
273 printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
Stefan Reinauere3778572010-01-30 09:47:18 +0000274 printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s)\"\n" >> $(obj)/build.ht
Patrick Georgicccbb892010-01-29 17:38:57 +0000275 printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname)\"\n" >> $(obj)/build.ht
276 printf "#include \"config.h\"\n" >> $(obj)/build.ht
277 mv $(obj)/build.ht $(obj)/build.h
Patrick Georgi0588d192009-08-12 15:00:51 +0000278
279doxy: doxygen
280doxygen:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000281 $(DOXYGEN) Doxyfile
Patrick Georgi0588d192009-08-12 15:00:51 +0000282
283doxyclean: doxygen-clean
284doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000285 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000286
Patrick Georgi967952a2010-02-09 19:41:11 +0000287clean-for-update: doxygen-clean
288 rm -f $(objs) $(initobjs) $(drivers) $(smmobjs) .xcompile
289 rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
Patrick Georgi9341acd2009-12-23 12:52:56 +0000290 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
Patrick Georgi967952a2010-02-09 19:41:11 +0000291 rm -f $(obj)/option_table.* $(obj)/crt0_includes.h $(obj)/ldscript $(obj)/config.h
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000292 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
293 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/auto.inc $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
294 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
Uwe Hermann6c73b4412009-10-28 17:10:51 +0000295 $(MAKE) -C util/sconfig clean
Patrick Georgi0588d192009-08-12 15:00:51 +0000296
Patrick Georgi967952a2010-02-09 19:41:11 +0000297clean: clean-for-update
298 rm -f $(obj)/coreboot*
299
Patrick Georgi0588d192009-08-12 15:00:51 +0000300distclean: clean
Myles Watson1af297c2010-01-06 16:59:18 +0000301 rm -rf $(obj)
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000302 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig*
Patrick Georgi0588d192009-08-12 15:00:51 +0000303
304update:
Myles Watsond4e5c0a2009-10-28 15:30:11 +0000305 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
Patrick Georgi0588d192009-08-12 15:00:51 +0000306
307# This include must come _before_ the pattern rules below!
308# Order _does_ matter for pattern rules.
309include util/kconfig/Makefile
310
311$(obj)/ldoptions: $(obj)/config.h
Patrick Georgi26774f22009-11-21 19:54:02 +0000312 awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
Patrick Georgi0588d192009-08-12 15:00:51 +0000313
Patrick Georgi26774f22009-11-21 19:54:02 +0000314_OS=$(shell uname -s |cut -c-7)
315STACK=
316ifeq ($(_OS),MINGW32)
317 STACK=-Wl,--stack,16384000
318endif
319ifeq ($(_OS),CYGWIN_)
320 STACK=-Wl,--stack,16384000
321endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000322$(obj)/romcc: $(top)/util/romcc/romcc.c
Uwe Hermann6c73b4412009-10-28 17:10:51 +0000323 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
Patrick Georgi26774f22009-11-21 19:54:02 +0000324 $(HOSTCC) -g -O2 $(STACK) -Wall -o $@ $<
Patrick Georgi0588d192009-08-12 15:00:51 +0000325
326.PHONY: $(PHONY) prepare prepare2 clean distclean doxygen doxy coreboot
327