Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 1 | ## |
| 2 | ## This file is part of the coreboot project. |
| 3 | ## |
| 4 | ## Copyright (C) 2011 secunet Security Networks AG |
| 5 | ## |
| 6 | ## This program is free software; you can redistribute it and/or modify |
| 7 | ## it under the terms of the GNU General Public License as published by |
| 8 | ## the Free Software Foundation; version 2 of the License. |
| 9 | ## |
| 10 | ## This program is distributed in the hope that it will be useful, |
| 11 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | ## GNU General Public License for more details. |
| 14 | ## |
| 15 | ## You should have received a copy of the GNU General Public License |
| 16 | ## along with this program; if not, write to the Free Software |
| 17 | ## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | ## |
| 19 | |
| 20 | ####################################################################### |
| 21 | # misleadingly named, this is the coreboot version |
Sven Schnelle | 054849d | 2011-08-26 21:57:53 +0200 | [diff] [blame] | 22 | export KERNELVERSION := $(shell if [ -d "$(top)/.git" -a -f "`which git`" ]; then git describe --dirty; else echo unknown; fi) |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 23 | |
| 24 | ####################################################################### |
| 25 | # Basic component discovery |
| 26 | ARCHDIR-$(CONFIG_ARCH_X86) := x86 |
| 27 | MAINBOARDDIR=$(call strip_quotes,$(CONFIG_MAINBOARD_DIR)) |
| 28 | export MAINBOARDDIR |
| 29 | |
| 30 | ####################################################################### |
| 31 | # root rule to resolve if in build mode (ie. configuration exists) |
| 32 | real-target: $(obj)/config.h coreboot |
| 33 | coreboot: $(obj)/coreboot.rom |
| 34 | |
| 35 | ####################################################################### |
| 36 | # our phony targets |
Patrick Georgi | cb02cb7 | 2012-02-25 19:42:59 +0100 | [diff] [blame] | 37 | PHONY+= clean-abuild coreboot lint lint-stable |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 38 | |
| 39 | ####################################################################### |
| 40 | # root source directories of coreboot |
Kyösti Mälkki | 2a830d0 | 2011-12-01 17:49:43 +0200 | [diff] [blame] | 41 | subdirs-y := src/lib src/boot src/console src/devices src/ec src/southbridge |
| 42 | subdirs-y += src/northbridge src/superio src/drivers src/cpu src/vendorcode |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 43 | subdirs-y += util/cbfstool util/sconfig |
| 44 | subdirs-y += src/arch/$(ARCHDIR-y) |
| 45 | subdirs-y += src/mainboard/$(MAINBOARDDIR) |
Stefan Reinauer | 9aea04a | 2012-03-30 12:01:06 -0700 | [diff] [blame] | 46 | subdirs-y += src/vendorcode |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 47 | |
| 48 | subdirs-$(CONFIG_ARCH_X86) += src/pc80 |
| 49 | |
Patrick Georgi | a25828d | 2011-09-02 09:57:01 +0200 | [diff] [blame] | 50 | subdirs-y += site-local |
| 51 | |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 52 | ####################################################################### |
| 53 | # Add source classes and their build options |
| 54 | classes-y := ramstage romstage driver smm |
| 55 | |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 56 | romstage-c-ccopts:=-D__PRE_RAM__ |
Stefan Reinauer | 61aee5f | 2011-04-10 04:15:23 +0000 | [diff] [blame] | 57 | romstage-S-ccopts:=-D__PRE_RAM__ |
Rudolf Marek | 7f0e930 | 2011-09-02 23:23:41 +0200 | [diff] [blame] | 58 | ifeq ($(CONFIG_TRACE),y) |
| 59 | ramstage-c-ccopts:= -finstrument-functions |
| 60 | endif |
| 61 | |
Stefan Reinauer | 24ef134 | 2011-04-14 22:28:00 +0000 | [diff] [blame] | 62 | smm-c-ccopts:=-D__SMM__ |
| 63 | smm-S-ccopts:=-D__SMM__ |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 64 | |
Patrick Georgi | 57205c7 | 2011-03-08 20:49:18 +0000 | [diff] [blame] | 65 | ramstage-c-deps:=$$(OPTION_TABLE_H) |
| 66 | romstage-c-deps:=$$(OPTION_TABLE_H) |
| 67 | |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 68 | ####################################################################### |
| 69 | # Add handler to compile ACPI's ASL |
| 70 | define ramstage-objs_asl_template |
Sven Schnelle | d69438e | 2011-03-29 09:01:10 +0000 | [diff] [blame] | 71 | $(obj)/$(1).ramstage.o: src/$(1).asl $(obj)/config.h |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 72 | @printf " IASL $$(subst $(top)/,,$$(@))\n" |
Patrick Georgi | c8feedd | 2012-02-16 18:43:25 +0100 | [diff] [blame] | 73 | $(CC) -x assembler-with-cpp -E -MMD -MT $$(@) -D__ACPI__ -P -include $(abspath $(obj)/config.h) -I$(src) -I$(src)/include -I$(src)/arch/$(ARCHDIR-y)/include -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl |
Marc Jones | 2aac3f6 | 2011-08-08 16:07:50 -0600 | [diff] [blame] | 74 | cd $$(dir $$@); $(IASL) -p $$(notdir $$@) -tc $$(notdir $$(basename $$@)).asl |
Patrick Georgi | b2a4264 | 2011-06-01 19:54:16 +0000 | [diff] [blame] | 75 | mv $$(basename $$@).hex $$(basename $$@).c |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 76 | $(CC) $$(CFLAGS) $$(if $$(subst dsdt,,$$(basename $$(notdir $(1)))), -DAmlCode=AmlCode_$$(basename $$(notdir $(1)))) -c -o $$@ $$(basename $$@).c |
| 77 | # keep %.o: %.c rule from catching the temporary .c file after a make clean |
| 78 | mv $$(basename $$@).c $$(basename $$@).hex |
| 79 | endef |
| 80 | |
| 81 | ####################################################################### |
| 82 | # Add handler for arbitrary files in CBFS |
| 83 | $(call add-special-class,cbfs-files) |
| 84 | cbfs-files-handler= \ |
| 85 | $(if $(wildcard $(1)$($(2)-file)), \ |
| 86 | $(eval tmp-cbfs-file:= $(wildcard $(1)$($(2)-file))), \ |
| 87 | $(eval tmp-cbfs-file:= $($(2)-file))) \ |
| 88 | $(eval cbfs-files += $(tmp-cbfs-file)|$(2)|$($(2)-type)|$($(2)-position)) \ |
| 89 | $(eval $(2)-name:=) \ |
| 90 | $(eval $(2)-type:=) \ |
| 91 | $(eval $(2)-position:=) |
| 92 | |
| 93 | ####################################################################### |
| 94 | # a variety of flags for our build |
Sven Schnelle | 8eee19d | 2011-05-02 19:53:04 +0000 | [diff] [blame] | 95 | CBFS_COMPRESS_FLAG:= |
| 96 | ifeq ($(CONFIG_COMPRESS_RAMSTAGE),y) |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 97 | CBFS_COMPRESS_FLAG:=l |
Sven Schnelle | 8eee19d | 2011-05-02 19:53:04 +0000 | [diff] [blame] | 98 | endif |
| 99 | |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 100 | CBFS_PAYLOAD_COMPRESS_FLAG:= |
| 101 | CBFS_PAYLOAD_COMPRESS_NAME:=none |
| 102 | ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y) |
| 103 | CBFS_PAYLOAD_COMPRESS_FLAG:=l |
| 104 | CBFS_PAYLOAD_COMPRESS_NAME:=LZMA |
| 105 | endif |
| 106 | |
| 107 | ifneq ($(CONFIG_LOCALVERSION),"") |
| 108 | COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION)) |
| 109 | endif |
| 110 | |
| 111 | INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include |
| 112 | INCLUDES += -Isrc/devices/oprom/include |
| 113 | # abspath is a workaround for romcc |
| 114 | INCLUDES += -include $(abspath $(obj)/config.h) |
| 115 | |
Frank Vibrans | ec40260 | 2011-05-05 16:45:36 +0000 | [diff] [blame] | 116 | CFLAGS = $(INCLUDES) -Os -pipe -g -nostdinc |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 117 | CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes |
| 118 | CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs |
| 119 | CFLAGS += -Wstrict-aliasing -Wshadow |
| 120 | ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y) |
| 121 | CFLAGS += -Werror |
| 122 | endif |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 123 | CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer |
| 124 | |
| 125 | additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/options |
| 126 | |
| 127 | ####################################################################### |
| 128 | # generate build support files |
| 129 | $(obj)/build.h: .xcompile |
| 130 | @printf " GEN build.h\n" |
| 131 | rm -f $(obj)/build.h |
| 132 | printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht |
| 133 | printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht |
| 134 | printf "#define __BUILD_H\n\n" >> $(obj)/build.ht |
Patrick Georgi | b8e9ba9 | 2011-03-17 07:47:49 +0000 | [diff] [blame] | 135 | printf "#define COREBOOT_VERSION \"$(KERNELVERSION)\"\n" >> $(obj)/build.ht |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 136 | printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht |
| 137 | printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht |
Sven Schnelle | 164bcfd | 2011-08-14 20:56:34 +0200 | [diff] [blame] | 138 | printf "#define COREBOOT_DMI_DATE \"`LANG= date +"%m/%d/%Y"`\"\n" >> $(obj)/build.ht |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 139 | printf "\n" >> $(obj)/build.ht |
| 140 | printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht |
| 141 | printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht |
| 142 | printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht |
| 143 | printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht |
| 144 | printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht |
| 145 | printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null)\"\n" >> $(obj)/build.ht |
| 146 | printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht |
| 147 | printf "#endif\n" >> $(obj)/build.ht |
| 148 | mv $(obj)/build.ht $(obj)/build.h |
| 149 | |
| 150 | $(obj)/ldoptions: $(obj)/config.h |
| 151 | awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@ |
| 152 | |
| 153 | ####################################################################### |
| 154 | # Build the tools |
| 155 | CBFSTOOL:=$(obj)/cbfstool |
| 156 | |
| 157 | $(CBFSTOOL): $(objutil)/cbfstool/cbfstool |
| 158 | cp $< $@ |
| 159 | |
| 160 | _WINCHECK=$(shell uname -o 2> /dev/null) |
| 161 | STACK= |
| 162 | ifeq ($(_WINCHECK),Msys) |
| 163 | STACK=-Wl,--stack,16384000 |
| 164 | endif |
| 165 | ifeq ($(_WINCHECK),Cygwin) |
| 166 | STACK=-Wl,--stack,16384000 |
| 167 | endif |
| 168 | |
| 169 | ROMCC:= $(objutil)/romcc/romcc |
| 170 | $(ROMCC): $(top)/util/romcc/romcc.c |
| 171 | @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n" |
| 172 | @# Note: Adding -O2 here might cause problems. For details see: |
| 173 | @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html |
| 174 | $(HOSTCC) -g $(STACK) -Wall -o $@ $< |
| 175 | |
| 176 | ####################################################################### |
| 177 | # needed objects that every mainboard uses |
| 178 | # Creation of these is architecture and mainboard independent |
| 179 | $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(objutil)/sconfig/sconfig |
| 180 | @printf " SCONFIG $(subst $(src)/,,$(<))\n" |
| 181 | mkdir -p $(obj)/mainboard/$(MAINBOARDDIR) |
| 182 | $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR) |
| 183 | |
| 184 | ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c |
| 185 | |
| 186 | $(objutil)/%.o: $(objutil)/%.c |
| 187 | @printf " HOSTCC $(subst $(objutil)/,,$(@))\n" |
| 188 | $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $< |
| 189 | |
Patrick Georgi | 64ccc3b8 | 2011-05-20 23:08:12 +0000 | [diff] [blame] | 190 | $(obj)/%.ramstage.o $(abspath $(obj))/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H) |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 191 | @printf " CC $(subst $(obj)/,,$(@))\n" |
| 192 | $(CC) -MMD $(CFLAGS) -c -o $@ $< |
| 193 | |
| 194 | ####################################################################### |
| 195 | # Clean up rules |
| 196 | clean-abuild: |
| 197 | rm -rf coreboot-builds |
| 198 | |
| 199 | clean-for-update-target: |
| 200 | rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a |
| 201 | rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.* |
| 202 | rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript |
| 203 | rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot |
| 204 | rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm |
| 205 | rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc |
| 206 | rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.* |
| 207 | rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm |
Marc Jones | 1dd0dda | 2012-03-19 17:32:33 -0600 | [diff] [blame] | 208 | $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean OUT=$(abspath $(obj)) HOSTCC="$(HOSTCC)" CC="$(CC)" LD="$(LD)" |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 209 | |
| 210 | clean-target: |
| 211 | rm -f $(obj)/coreboot* |
| 212 | |
| 213 | ####################################################################### |
| 214 | # Development utilities |
| 215 | printcrt0s: |
| 216 | @echo crt0s=$(crt0s) |
| 217 | @echo ldscripts=$(ldscripts) |
| 218 | |
| 219 | update: |
| 220 | dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF |
| 221 | |
Patrick Georgi | cb02cb7 | 2012-02-25 19:42:59 +0100 | [diff] [blame] | 222 | lint lint-stable: |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 223 | FAILED=0; LINTLOG=`mktemp`; \ |
Patrick Georgi | cb02cb7 | 2012-02-25 19:42:59 +0100 | [diff] [blame] | 224 | for script in util/lint/$@-*; do \ |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 225 | echo; echo `basename $$script`; \ |
| 226 | grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \ |
| 227 | echo ========; \ |
| 228 | $$script > $$LINTLOG; \ |
Patrick Georgi | c040e476 | 2012-03-09 23:02:09 +0100 | [diff] [blame] | 229 | if [ `cat $$LINTLOG | wc -l` -eq 0 ]; then \ |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 230 | printf "success\n\n"; \ |
| 231 | else \ |
| 232 | echo test failed: ; \ |
| 233 | cat $$LINTLOG; \ |
| 234 | rm -f $$LINTLOG; \ |
| 235 | FAILED=$$(( $$FAILED + 1 )); \ |
| 236 | fi; \ |
| 237 | echo ========; \ |
| 238 | done; \ |
| 239 | test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed." && exit 1; }; \ |
| 240 | rm -f $$LINTLOG |
Patrick Georgi | 6c44550 | 2011-05-16 15:32:28 +0000 | [diff] [blame] | 241 | |
Patrick Georgi | bb60528 | 2011-06-05 15:15:49 +0200 | [diff] [blame] | 242 | gitconfig: |
Patrick Georgi | 07408e6 | 2012-02-25 19:52:45 +0100 | [diff] [blame] | 243 | for hook in commit-msg pre-commit; do if ! [ -x .git/hooks/$$hook ]; then cp util/gitconfig/$$hook .git/hooks/$$hook; chmod +x .git/hooks/$$hook; fi; done |
Patrick Georgi | bb60528 | 2011-06-05 15:15:49 +0200 | [diff] [blame] | 244 | (git config --global user.name >/dev/null && git config --global user.email >/dev/null) || (printf 'Please configure your name and email in git:\n\n git config --global user.name "Your Name Comes Here"\n git config --global user.email your.email@example.com\n'; exit 1) |
| 245 | |
Patrick Georgi | 6c44550 | 2011-05-16 15:32:28 +0000 | [diff] [blame] | 246 | crossgcc: clean-for-update |
Peter Stuge | 0b6b4d6 | 2011-06-09 05:06:25 +0200 | [diff] [blame] | 247 | $(MAKE) -C util/crossgcc build-without-gdb |
| 248 | |
| 249 | crosstools: clean-for-update |
Patrick Georgi | 6c44550 | 2011-05-16 15:32:28 +0000 | [diff] [blame] | 250 | $(MAKE) -C util/crossgcc build |
| 251 | |
| 252 | crossgcc-clean: clean-for-update |
| 253 | $(MAKE) -C util/crossgcc clean |
| 254 | |