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