blob: 0754b15cedc89be75cf323b007b7d59b667deebe [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
Patrick Georgi020f51f2010-03-14 21:25:03 +000022ifeq ($(INNER_SCANBUILD),y)
23CC_real:=$(CC)
24endif
Patrick Georgi23d89cc2010-03-16 01:17:19 +000025
Patrick Georgi0588d192009-08-12 15:00:51 +000026$(if $(wildcard .xcompile),,$(eval $(shell bash util/xcompile/xcompile > .xcompile)))
27include .xcompile
Patrick Georgi23d89cc2010-03-16 01:17:19 +000028
Patrick Georgi020f51f2010-03-14 21:25:03 +000029ifeq ($(INNER_SCANBUILD),y)
30CC:=$(CC_real)
31HOSTCC:=$(CC_real) --hostcc
32HOSTCXX:=$(CC_real) --hostcxx
33endif
Patrick Georgi0588d192009-08-12 15:00:51 +000034
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +000035export top := $(CURDIR)
Patrick Georgi51e142f2010-03-27 17:18:39 +000036export src := src
Patrick Georgi0588d192009-08-12 15:00:51 +000037export srck := $(top)/util/kconfig
Patrick Georgi51e142f2010-03-27 17:18:39 +000038export obj ?= build
Patrick Georgia2acbc72010-04-16 22:48:57 +000039export objutil ?= $(obj)/util
40export objk := $(objutil)/kconfig
Patrick Georgi0588d192009-08-12 15:00:51 +000041
42
Stefan Reinauer37d8c212010-02-08 18:30:41 +000043export KERNELVERSION := 4.0
Patrick Georgi0588d192009-08-12 15:00:51 +000044export KCONFIG_AUTOHEADER := $(obj)/config.h
45export KCONFIG_AUTOCONFIG := $(obj)/auto.conf
Patrick Georgi0588d192009-08-12 15:00:51 +000046
47CONFIG_SHELL := sh
48KBUILD_DEFCONFIG := configs/defconfig
49UNAME_RELEASE := $(shell uname -r)
Patrick Georgi89ec3762010-12-08 19:58:30 +000050DOTCONFIG ?= .config
51KCONFIG_CONFIG = $(DOTCONFIG)
52export KCONFIG_CONFIG
53HAVE_DOTCONFIG := $(wildcard $(DOTCONFIG))
Patrick Georgi0588d192009-08-12 15:00:51 +000054MAKEFLAGS += -rR --no-print-directory
55
56# Make is silent per default, but 'make V=1' will show all compiler calls.
Patrick Georgi2b7418e2009-08-25 19:38:46 +000057Q:=@
Patrick Georgi0588d192009-08-12 15:00:51 +000058ifneq ($(V),1)
Patrick Georgi2b7418e2009-08-25 19:38:46 +000059ifneq ($(Q),)
60.SILENT:
61endif
Patrick Georgi0588d192009-08-12 15:00:51 +000062endif
63
64CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
Patrick Georgia2acbc72010-04-16 22:48:57 +000065ROMCC:= $(objutil)/romcc/romcc
Patrick Georgi0588d192009-08-12 15:00:51 +000066HOSTCC = gcc
67HOSTCXX = g++
68HOSTCFLAGS := -I$(srck) -I$(objk) -g
69HOSTCXXFLAGS := -I$(srck) -I$(objk)
Stefan Reinauer68a564f2010-03-16 01:02:18 +000070LIBGCC_FILE_NAME := $(shell test -r `$(CC) -print-libgcc-file-name` && $(CC) -print-libgcc-file-name)
Patrick Georgi0588d192009-08-12 15:00:51 +000071
72DOXYGEN := doxygen
73DOXYGEN_OUTPUT_DIR := doxygen
74
Patrick Georgicf036d12010-04-21 06:36:20 +000075# Three cases where we don't need fully populated $(obj) lists:
76# 1. when no .config exists
77# 2. when make config (in any flavour) is run
78# 3. when make distclean is run
79# Don't waste time on reading all Makefile.incs in these cases
Patrick Georgi0588d192009-08-12 15:00:51 +000080ifeq ($(strip $(HAVE_DOTCONFIG)),)
Patrick Georgicf036d12010-04-21 06:36:20 +000081NOCOMPILE:=1
82endif
83ifneq ($(MAKECMDGOALS),)
84ifneq ($(filter %config distclean,$(MAKECMDGOALS)),)
85NOCOMPILE:=1
86endif
87endif
Patrick Georgi0588d192009-08-12 15:00:51 +000088
Patrick Georgicf036d12010-04-21 06:36:20 +000089ifeq ($(NOCOMPILE),1)
Patrick Georgi0588d192009-08-12 15:00:51 +000090all: config
91
92else
93
Patrick Georgi977b9852010-09-24 22:15:54 +000094include $(HAVE_DOTCONFIG)
Patrick Georgi0588d192009-08-12 15:00:51 +000095
Patrick Georgi23d89cc2010-03-16 01:17:19 +000096ifneq ($(INNER_SCANBUILD),y)
97ifeq ($(CONFIG_COMPILER_LLVM_CLANG),y)
98CC:=clang -m32
99HOSTCC:=clang
100endif
101endif
102
Patrick Georgi516a2a72010-03-25 21:45:25 +0000103ifeq ($(CONFIG_CCACHE),y)
Patrick Georgi977b9852010-09-24 22:15:54 +0000104CCACHE:=$(wildcard $(addsuffix /ccache,$(subst :, ,$(PATH))))
Patrick Georgi516a2a72010-03-25 21:45:25 +0000105ifeq ($(CCACHE),)
106$(error ccache selected, but not found in PATH)
107endif
Patrick Georgi977b9852010-09-24 22:15:54 +0000108CCACHE:=CCACHE_COMPILERCHECK=content CCACHE_BASEDIR=$(top) $(CCACHE)
Patrick Georgi516a2a72010-03-25 21:45:25 +0000109CC := $(CCACHE) $(CC)
110HOSTCC := $(CCACHE) $(HOSTCC)
111HOSTCXX := $(CCACHE) $(HOSTCXX)
112ROMCC := $(CCACHE) $(ROMCC)
113endif
114
Patrick Georgia84e98b2010-03-16 19:01:32 +0000115strip_quotes = $(subst ",,$(subst \",,$(1)))
116
Stefan Reinauer8677a232010-12-11 20:33:41 +0000117ARCHDIR-$(CONFIG_ARCH_X86) := x86
Patrick Georgi0588d192009-08-12 15:00:51 +0000118ARCHDIR-$(CONFIG_ARCH_POWERPC) := ppc
119
Patrick Georgia84e98b2010-03-16 19:01:32 +0000120MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR))
Patrick Georgi0588d192009-08-12 15:00:51 +0000121export MAINBOARDDIR
122
123PLATFORM-y += src/arch/$(ARCHDIR-y) src/cpu src/mainboard/$(MAINBOARDDIR)
124TARGETS-y :=
125
Sven Schnelle7592e8b2011-01-27 11:43:03 +0000126BUILD-y := src/lib src/boot src/console src/devices src/ec src/southbridge src/northbridge src/superio src/drivers
Patrick Georgi7e8c9aa2010-04-08 11:37:43 +0000127BUILD-y += util/cbfstool util/sconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000128BUILD-$(CONFIG_ARCH_X86) += src/pc80
129
Uwe Hermannc04be932009-10-05 13:55:28 +0000130ifneq ($(CONFIG_LOCALVERSION),"")
Patrick Georgia84e98b2010-03-16 19:01:32 +0000131COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION))
Uwe Hermannc04be932009-10-05 13:55:28 +0000132endif
133
Patrick Georgi0588d192009-08-12 15:00:51 +0000134# The primary target needs to be here before we include the
135# other files
136
Patrick Georgi020f51f2010-03-14 21:25:03 +0000137ifeq ($(INNER_SCANBUILD),y)
138CONFIG_SCANBUILD_ENABLE:=
139endif
140
141ifeq ($(CONFIG_SCANBUILD_ENABLE),y)
142ifneq ($(CONFIG_SCANBUILD_REPORT_LOCATION),)
143CONFIG_SCANBUILD_REPORT_LOCATION:=-o $(CONFIG_SCANBUILD_REPORT_LOCATION)
144endif
145all:
146 echo '#!/bin/sh' > .ccwrap
147 echo 'CC="$(CC)"' >> .ccwrap
148 echo 'if [ "$$1" = "--hostcc" ]; then shift; CC="$(HOSTCC)"; fi' >> .ccwrap
149 echo 'if [ "$$1" = "--hostcxx" ]; then shift; CC="$(HOSTCXX)"; fi' >> .ccwrap
150 echo 'eval $$CC $$*' >> .ccwrap
151 chmod +x .ccwrap
152 scan-build $(CONFIG_SCANBUILD_REPORT_LOCATION) -analyze-headers --use-cc=$(top)/.ccwrap --use-c++=$(top)/.ccwrap $(MAKE) INNER_SCANBUILD=y
153else
Stefan Reinauere9f32582010-03-29 13:04:13 +0000154all: $(obj)/config.h coreboot
Patrick Georgi020f51f2010-03-14 21:25:03 +0000155endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000156
Patrick Georgi51e142f2010-03-27 17:18:39 +0000157# must come rather early
158.SECONDEXPANSION:
159
Stefan Reinauer1425add2010-03-21 22:35:58 +0000160$(obj)/config.h:
161 $(MAKE) oldconfig
Patrick Georgi0588d192009-08-12 15:00:51 +0000162
163#######################################################################
164# Build the tools
165
Kevin O'Connoraaafec32011-01-30 07:40:32 +0000166CBFSTOOL:=$(obj)/cbfstool
167
168$(CBFSTOOL): $(objutil)/cbfstool/cbfstool
169 cp $< $@
Patrick Georgi0588d192009-08-12 15:00:51 +0000170
Stefan Reinauer14e22772010-04-27 06:56:47 +0000171# needed objects that every mainboard uses
Patrick Georgi0588d192009-08-12 15:00:51 +0000172# Creation of these is architecture and mainboard independent
Patrick Georgia2acbc72010-04-16 22:48:57 +0000173$(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(objutil)/sconfig/sconfig
Stefan Reinauere705f9c2010-04-08 13:16:32 +0000174 @printf " SCONFIG $(subst $(src)/,,$(<))\n"
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000175 mkdir -p $(obj)/mainboard/$(MAINBOARDDIR)
Patrick Georgia2acbc72010-04-16 22:48:57 +0000176 $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000177
Stefan Reinauer961a7b02010-04-19 20:47:29 +0000178$(objutil)/%.o: $(objutil)/%.c
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000179 @printf " HOSTCC $(subst $(objutil)/,,$(@))\n"
Patrick Georgi114e7b22010-05-05 11:19:50 +0000180 $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $<
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000181
Patrick Georgi8463dd92010-09-30 16:55:02 +0000182$(obj)/%.ramstage.o: $(obj)/%.c $(obj)/config.h
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000183 @printf " CC $(subst $(obj)/,,$(@))\n"
184 $(CC) -MMD $(CFLAGS) -c -o $@ $<
185
Patrick Georgi58262652011-02-17 20:47:49 +0000186# Add a new class of source/object files to the build system
187add-class= \
188 $(eval $(1)-srcs:=) \
189 $(eval $(1)-objs:=) \
190 $(eval classes+=$(1))
Patrick Georgi8463dd92010-09-30 16:55:02 +0000191
Patrick Georgi58262652011-02-17 20:47:49 +0000192# Special classes are managed types with special behaviour
193# On parse time, for each entry in variable $(1)-y
194# a handler $(1)-handler is executed with the arguments:
195# * $(1): directory the parser is in
196# * $(2): current entry
197add-special-class= \
198 $(eval $(1):=) \
199 $(eval special-classes+=$(1))
200
201$(call add-class,ramstage)
202$(call add-class,romstage)
203$(call add-class,driver)
204$(call add-class,smm)
205
206$(call add-special-class,cbfs-files)
207cbfs-files-handler= \
208 $(if $(wildcard $(1)$($(2)-file)), \
209 $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \
210 $(eval tmp-cbfs-file:= $($(2)-file))) \
211 $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-position)) \
212 $(eval $(2)-name:=) \
213 $(eval $(2)-type:=) \
214 $(eval $(2)-position:=)
215
216ramstage-srcs+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c
Patrick Georgi47d68d82010-03-06 21:18:43 +0000217
218# Clean -y variables, include Makefile.inc
Patrick Georgi8463dd92010-09-30 16:55:02 +0000219# Add paths to files in X-y to X-srcs
Patrick Georgi47d68d82010-03-06 21:18:43 +0000220# Add subdirs-y to subdirs
221includemakefiles= \
Patrick Georgi58262652011-02-17 20:47:49 +0000222 $(foreach class,classes subdirs $(classes) $(special-classes), $(eval $(class)-y:=)) \
Patrick Georgi47d68d82010-03-06 21:18:43 +0000223 $(eval -include $(1)) \
Patrick Georgi58262652011-02-17 20:47:49 +0000224 $(foreach class,$(classes-y), $(call add-class,$(class))) \
225 $(foreach class,$(classes), \
226 $(eval $(class)-srcs+= \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000227 $$(subst $(top)/,, \
Patrick Georgi58262652011-02-17 20:47:49 +0000228 $$(abspath $$(addprefix $(dir $(1)),$$($(class)-y)))))) \
229 $(foreach special,$(special-classes), \
230 $(foreach item,$($(special)-y), $(call $(special)-handler,$(dir $(1)),$(item)))) \
Jonathan Kollasch7ff5b442010-09-28 21:11:48 +0000231 $(eval subdirs+=$$(subst $(CURDIR)/,,$$(abspath $$(addprefix $(dir $(1)),$$(subdirs-y)))))
Patrick Georgi47d68d82010-03-06 21:18:43 +0000232
Patrick Georgi8463dd92010-09-30 16:55:02 +0000233# For each path in $(subdirs) call includemakefiles
Patrick Georgi47d68d82010-03-06 21:18:43 +0000234# Repeat until subdirs is empty
235evaluate_subdirs= \
236 $(eval cursubdirs:=$(subdirs)) \
237 $(eval subdirs:=) \
238 $(foreach dir,$(cursubdirs), \
Patrick Georgi58262652011-02-17 20:47:49 +0000239 $(eval $(call includemakefiles,$(dir)/Makefile.inc))) \
Patrick Georgi51e142f2010-03-27 17:18:39 +0000240 $(if $(subdirs),$(eval $(call evaluate_subdirs)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000241
242# collect all object files eligible for building
243subdirs:=$(PLATFORM-y) $(BUILD-y)
Patrick Georgi51e142f2010-03-27 17:18:39 +0000244$(eval $(call evaluate_subdirs))
Patrick Georgi0588d192009-08-12 15:00:51 +0000245
Patrick Georgi8463dd92010-09-30 16:55:02 +0000246src-to-obj=$(addsuffix .$(1).o, $(basename $(patsubst src/%, $(obj)/%, $($(1)-srcs))))
Patrick Georgi58262652011-02-17 20:47:49 +0000247$(foreach class,$(classes),$(eval $(class)-objs:=$(call src-to-obj,$(class))))
Patrick Georgid3428b02010-02-24 13:18:01 +0000248
Patrick Georgi58262652011-02-17 20:47:49 +0000249allsrcs:=$(foreach var, $(addsuffix -srcs,$(classes)), $($(var)))
250allobjs:=$(foreach var, $(addsuffix -objs,$(classes)), $($(var)))
Patrick Georgi0588d192009-08-12 15:00:51 +0000251alldirs:=$(sort $(abspath $(dir $(allobjs))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000252
Patrick Georgi8463dd92010-09-30 16:55:02 +0000253define ramstage-objs_asl_template
254$(obj)/$(1).ramstage.o: src/$(1).asl
Patrick Georgi1a47b5e2010-02-10 18:53:40 +0000255 @printf " IASL $$(subst $(top)/,,$$(@))\n"
Patrick Georgi51e142f2010-03-27 17:18:39 +0000256 $(CPP) -D__ACPI__ -P -include $(abspath $(obj)/config.h) -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl
Stefan Reinauer20c3d772010-11-15 21:09:57 +0000257 iasl -p $$(obj)/$(1) -tc $$(basename $$@).asl
Patrick Georgi8463dd92010-09-30 16:55:02 +0000258 mv $$(obj)/$(1).hex $$(basename $$@).c
259 $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $(1)))), -DAmlCode=AmlCode_$$(basename $$(notdir $(1)))) -c -o $$@ $$(basename $$@).c
Zheng Bao12fa1592010-04-26 12:27:18 +0000260 # keep %.o: %.c rule from catching the temporary .c file after a make clean
261 mv $$(basename $$@).c $$(basename $$@).hex
Patrick Georgi88f55b22009-09-25 18:43:02 +0000262endef
263
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000264# macro to define template macros that are used by use_template macro
265define create_cc_template
Patrick Georgi8463dd92010-09-30 16:55:02 +0000266# $1 obj class (ramstage, romstage, driver, smm)
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000267# $2 source suffix (c, S)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000268# $3 additional compiler flags
269de$(EMPTY)fine $(1)-objs_$(2)_template
270$(obj)/$$(1).$(1).o: src/$$(1).$(2) $(obj)/config.h
Patrick Georgi1cd76e72010-04-19 20:39:22 +0000271 @printf " CC $$$$(subst $$$$(obj)/,,$$$$(@))\n"
Patrick Georgi8463dd92010-09-30 16:55:02 +0000272 $(CC) $(3) -MMD $$$$(CFLAGS) -c -o $$$$@ $$$$<
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000273en$(EMPTY)def
Patrick Georgi0588d192009-08-12 15:00:51 +0000274endef
275
Patrick Georgi8463dd92010-09-30 16:55:02 +0000276$(eval $(call create_cc_template,ramstage,c))
277$(eval $(call create_cc_template,ramstage,S,-DASSEMBLY))
278$(eval $(call create_cc_template,romstage,c,-D__PRE_RAM__))
279$(eval $(call create_cc_template,romstage,S,-DASSEMBLY -D__PRE_RAM__))
280$(eval $(call create_cc_template,driver,c))
281$(eval $(call create_cc_template,driver,S,-DASSEMBLY))
282$(eval $(call create_cc_template,smm,c))
283$(eval $(call create_cc_template,smm,S))
Patrick Georgi0588d192009-08-12 15:00:51 +0000284
Patrick Georgi8463dd92010-09-30 16:55:02 +0000285foreach-src=$(foreach file,$($(1)-srcs),$(eval $(call $(1)-objs_$(subst .,,$(suffix $(file)))_template,$(subst src/,,$(basename $(file))))))
Patrick Georgi58262652011-02-17 20:47:49 +0000286$(eval $(foreach class,$(classes),$(call foreach-src,$(class))))
Patrick Georgi0588d192009-08-12 15:00:51 +0000287
Patrick Georgi8463dd92010-09-30 16:55:02 +0000288DEPENDENCIES = $(ramstage-objs:.o=.d) $(romstage-objs:.o=.d) $(driver-objs:.o=.d) $(smm-objs:.o=.d)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000289-include $(DEPENDENCIES)
290
Patrick Georgi0588d192009-08-12 15:00:51 +0000291printall:
Patrick Georgi8463dd92010-09-30 16:55:02 +0000292 @echo ramstage-objs:=$(ramstage-objs)
293 @echo romstage-objs:=$(romstage-objs)
294 @echo driver-objs:=$(driver-objs)
295 @echo smm-objs:=$(smm-objs)
Patrick Georgi0588d192009-08-12 15:00:51 +0000296 @echo alldirs:=$(alldirs)
Patrick Georgi8463dd92010-09-30 16:55:02 +0000297 @echo allsrcs=$(allsrcs)
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000298 @echo DEPENDENCIES=$(DEPENDENCIES)
Stefan Reinauer68a564f2010-03-16 01:02:18 +0000299 @echo LIBGCC_FILE_NAME=$(LIBGCC_FILE_NAME)
Patrick Georgic2c23dc2010-12-16 07:36:28 +0000300 @echo cbfs-files:='$(cbfs-files)'
Patrick Georgi0588d192009-08-12 15:00:51 +0000301
Patrick Georgieb49f9d2010-02-25 17:03:17 +0000302printcrt0s:
Stefan Reinaueracdd52f2010-03-30 20:32:01 +0000303 @echo crt0s=$(crt0s)
304 @echo ldscripts=$(ldscripts)
Patrick Georgieb49f9d2010-02-25 17:03:17 +0000305
Patrick Georgi0588d192009-08-12 15:00:51 +0000306OBJS := $(patsubst %,$(obj)/%,$(TARGETS-y))
Stefan Reinauer14e22772010-04-27 06:56:47 +0000307INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include
Patrick Georgi51e142f2010-03-27 17:18:39 +0000308INCLUDES += -Isrc/devices/oprom/include
309# abspath is a workaround for romcc
Stefan Reinauere9f32582010-03-29 13:04:13 +0000310INCLUDES += -include $(abspath $(obj)/config.h)
Patrick Georgi0588d192009-08-12 15:00:51 +0000311
Frank Vibrans0822ad82011-02-14 18:47:37 +0000312CFLAGS = $(INCLUDES) -Os -pipe -g
Patrick Georgi0588d192009-08-12 15:00:51 +0000313CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes
Stefan Reinauer14e22772010-04-27 06:56:47 +0000314CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs
Stefan Reinauer68a564f2010-03-16 01:02:18 +0000315CFLAGS += -Wstrict-aliasing -Wshadow
Myles Watson2e672732009-11-12 16:38:03 +0000316ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y)
317CFLAGS += -Werror
318endif
Frank Vibrans0822ad82011-02-14 18:47:37 +0000319ifneq ($(CONFIG_AMD_AGESA),y)
320CFLAGS += -nostdinc
321endif
Patrick Georgi0588d192009-08-12 15:00:51 +0000322CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer
323
Patrick Georgi0588d192009-08-12 15:00:51 +0000324CBFS_COMPRESS_FLAG:=l
Myles Watson422d0cb2009-09-23 17:48:28 +0000325CBFS_PAYLOAD_COMPRESS_FLAG:=
Stefan Reinauer314e5512010-04-09 20:36:29 +0000326CBFS_PAYLOAD_COMPRESS_NAME:=none
Myles Watson422d0cb2009-09-23 17:48:28 +0000327ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y)
328CBFS_PAYLOAD_COMPRESS_FLAG:=l
Stefan Reinauer314e5512010-04-09 20:36:29 +0000329CBFS_PAYLOAD_COMPRESS_NAME:=LZMA
Patrick Georgi0588d192009-08-12 15:00:51 +0000330endif
331
Patrick Georgi25fc5ff2010-04-27 09:19:47 +0000332coreboot: $(obj)/coreboot.rom
Patrick Georgi0588d192009-08-12 15:00:51 +0000333
334endif
335
Patrick Georgi25fc5ff2010-04-27 09:19:47 +0000336$(shell mkdir -p $(obj) $(objutil)/kconfig/lxdialog $(objutil)/cbfstool $(objutil)/romcc $(objutil)/options $(alldirs))
Patrick Georgi0588d192009-08-12 15:00:51 +0000337
Stefan Reinauere9f32582010-03-29 13:04:13 +0000338$(obj)/build.h: .xcompile
Uwe Hermann6c73b4412009-10-28 17:10:51 +0000339 @printf " GEN build.h\n"
Patrick Georgicccbb892010-01-29 17:38:57 +0000340 rm -f $(obj)/build.h
Stefan Reinauerb4d3af82010-02-11 03:21:29 +0000341 printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht
342 printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht
343 printf "#define __BUILD_H\n\n" >> $(obj)/build.ht
Patrick Georgi6630ce12010-04-14 20:47:45 +0000344 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
Patrick Georgicccbb892010-01-29 17:38:57 +0000345 printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht
346 printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht
347 printf "\n" >> $(obj)/build.ht
348 printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht
349 printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht
350 printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht
351 printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht
352 printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht
Patrick Georgi patrick.georgic5f773d2010-03-16 12:01:13 +0000353 printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null)\"\n" >> $(obj)/build.ht
354 printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht
Stefan Reinauerb4d3af82010-02-11 03:21:29 +0000355 printf "#endif\n" >> $(obj)/build.ht
Patrick Georgicccbb892010-01-29 17:38:57 +0000356 mv $(obj)/build.ht $(obj)/build.h
Patrick Georgi0588d192009-08-12 15:00:51 +0000357
Warren Turkala9fc3302010-09-03 08:57:32 +0000358cscope:
359 cscope -bR
360
Patrick Georgi0588d192009-08-12 15:00:51 +0000361doxy: doxygen
362doxygen:
Stefan Reinauer1bbad5c2010-02-10 15:36:53 +0000363 $(DOXYGEN) documentation/Doxyfile.coreboot
Patrick Georgi0588d192009-08-12 15:00:51 +0000364
365doxyclean: doxygen-clean
366doxygen-clean:
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000367 rm -rf $(DOXYGEN_OUTPUT_DIR)
Patrick Georgi0588d192009-08-12 15:00:51 +0000368
Patrick Georgi967952a2010-02-09 19:41:11 +0000369clean-for-update: doxygen-clean
Patrick Georgi8463dd92010-09-30 16:55:02 +0000370 rm -f $(ramstage-objs) $(romstage-objs) $(driver-objs) $(smm-objs) .xcompile
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000371 rm -f $(DEPENDENCIES)
Patrick Georgi967952a2010-02-09 19:41:11 +0000372 rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a
Patrick Georgi9341acd2009-12-23 12:52:56 +0000373 rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.*
Patrick Georgie64b6372010-04-08 21:04:45 +0000374 rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000375 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot
Stefan Reinauerf9035dd2010-03-17 01:18:14 +0000376 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm
Stefan Reinauer6bee9512010-03-24 15:51:48 +0000377 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc
Stefan Reinauer37e78172010-03-17 01:50:15 +0000378 rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.*
379 rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm
Patrick Georgi2b7418e2009-08-25 19:38:46 +0000380 rmdir -p $(alldirs) 2>/dev/null >/dev/null || true
Stefan Reinauer6c285222011-01-05 01:37:48 +0000381 $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean
Patrick Georgi0588d192009-08-12 15:00:51 +0000382
Patrick Georgi967952a2010-02-09 19:41:11 +0000383clean: clean-for-update
Patrick Georgi020f51f2010-03-14 21:25:03 +0000384 rm -f $(obj)/coreboot* .ccwrap
Patrick Georgi967952a2010-02-09 19:41:11 +0000385
Warren Turkal0e8f2042010-09-27 21:14:19 +0000386clean-abuild:
Warren Turkal1f98ee72010-09-28 21:02:03 +0000387 rm -rf coreboot-builds
Warren Turkal0e8f2042010-09-27 21:14:19 +0000388
Warren Turkala9fc3302010-09-03 08:57:32 +0000389clean-cscope:
390 rm -f cscope.out
391
Patrick Georgiafbf0722010-09-29 20:28:59 +0000392distclean: clean-cscope
Myles Watson1af297c2010-01-06 16:59:18 +0000393 rm -rf $(obj)
Patrick Georgicf036d12010-04-21 06:36:20 +0000394 rm -f .config .config.old ..config.tmp .kconfig.d .tmpconfig* .ccwrap .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000395
396update:
Myles Watsond4e5c0a2009-10-28 15:30:11 +0000397 dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF
Patrick Georgi0588d192009-08-12 15:00:51 +0000398
Patrick Georgic6ef20f2010-11-18 15:05:06 +0000399lint:
Patrick Georgie8826302010-11-19 10:16:43 +0000400 FAILED=0; LINTLOG=`mktemp`; \
Patrick Georgic6ef20f2010-11-18 15:05:06 +0000401 for script in util/lint/lint-*; do \
Patrick Georgie8826302010-11-19 10:16:43 +0000402 echo; echo `basename $$script`; \
Patrick Georgic6ef20f2010-11-18 15:05:06 +0000403 grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \
404 echo ========; \
405 $$script > $$LINTLOG; \
406 if [ `wc -l $$LINTLOG | cut -d' ' -f1` -eq 0 ]; then \
407 printf "success\n\n"; \
408 else \
409 echo test failed: ; \
410 cat $$LINTLOG; \
411 rm -f $$LINTLOG; \
Patrick Georgie8826302010-11-19 10:16:43 +0000412 FAILED=$$(( $$FAILED + 1 )); \
413 fi; \
414 echo ========; \
Patrick Georgic6ef20f2010-11-18 15:05:06 +0000415 done; \
Patrick Georgie8826302010-11-19 10:16:43 +0000416 test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed." && exit 1; }; \
Patrick Georgic6ef20f2010-11-18 15:05:06 +0000417 rm -f $$LINTLOG
418
Patrick Georgi0588d192009-08-12 15:00:51 +0000419# This include must come _before_ the pattern rules below!
420# Order _does_ matter for pattern rules.
421include util/kconfig/Makefile
422
423$(obj)/ldoptions: $(obj)/config.h
Patrick Georgi26774f22009-11-21 19:54:02 +0000424 awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@
Patrick Georgi0588d192009-08-12 15:00:51 +0000425
Stefan Reinauerc53d1f32010-05-08 17:15:36 +0000426_WINCHECK=$(shell uname -o 2> /dev/null)
Patrick Georgi26774f22009-11-21 19:54:02 +0000427STACK=
Stefan Reinauerc53d1f32010-05-08 17:15:36 +0000428ifeq ($(_WINCHECK),Msys)
Patrick Georgi26774f22009-11-21 19:54:02 +0000429 STACK=-Wl,--stack,16384000
430endif
Stefan Reinauerc53d1f32010-05-08 17:15:36 +0000431ifeq ($(_WINCHECK),Cygwin)
Patrick Georgi26774f22009-11-21 19:54:02 +0000432 STACK=-Wl,--stack,16384000
433endif
Stefan Reinauerc53d1f32010-05-08 17:15:36 +0000434
Patrick Georgia2acbc72010-04-16 22:48:57 +0000435$(objutil)/romcc/romcc: $(top)/util/romcc/romcc.c
Uwe Hermann6c73b4412009-10-28 17:10:51 +0000436 @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n"
Uwe Hermann0dd63a22010-02-15 23:24:51 +0000437 @# Note: Adding -O2 here might cause problems. For details see:
438 @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html
Marc Jones516255e2010-02-13 18:06:29 +0000439 $(HOSTCC) -g $(STACK) -Wall -o $@ $<
Patrick Georgi0588d192009-08-12 15:00:51 +0000440
Warren Turkal0e8f2042010-09-27 21:14:19 +0000441.PHONY: $(PHONY) clean clean-abuild clean-cscope cscope distclean doxygen doxy coreboot .xcompile
Patrick Georgi0588d192009-08-12 15:00:51 +0000442