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 |
| 22 | export KERNELVERSION := 4.0 |
| 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 | |
| 52 | ramstage-S-ccopts:=-DASSEMBLY |
| 53 | romstage-c-ccopts:=-D__PRE_RAM__ |
| 54 | romstage-S-ccopts:=-DASSEMBLY -D__PRE_RAM__ |
| 55 | driver-S-ccopts:=-DASSEMBLY |
| 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 |
| 63 | $(obj)/$(1).ramstage.o: src/$(1).asl |
| 64 | @printf " IASL $$(subst $(top)/,,$$(@))\n" |
| 65 | $(CPP) -D__ACPI__ -P -include $(abspath $(obj)/config.h) -I$(src) -I$(src)/mainboard/$(MAINBOARDDIR) $$< -o $$(basename $$@).asl |
| 66 | iasl -p $$(obj)/$(1) -tc $$(basename $$@).asl |
| 67 | mv $$(obj)/$(1).hex $$(basename $$@).c |
| 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 |
| 87 | CBFS_COMPRESS_FLAG:=l |
| 88 | CBFS_PAYLOAD_COMPRESS_FLAG:= |
| 89 | CBFS_PAYLOAD_COMPRESS_NAME:=none |
| 90 | ifeq ($(CONFIG_COMPRESSED_PAYLOAD_LZMA),y) |
| 91 | CBFS_PAYLOAD_COMPRESS_FLAG:=l |
| 92 | CBFS_PAYLOAD_COMPRESS_NAME:=LZMA |
| 93 | endif |
| 94 | |
| 95 | ifneq ($(CONFIG_LOCALVERSION),"") |
| 96 | COREBOOT_EXTRA_VERSION := -$(call strip_quotes,$(CONFIG_LOCALVERSION)) |
| 97 | endif |
| 98 | |
| 99 | INCLUDES := -Isrc -Isrc/include -I$(obj) -Isrc/arch/$(ARCHDIR-y)/include |
| 100 | INCLUDES += -Isrc/devices/oprom/include |
| 101 | # abspath is a workaround for romcc |
| 102 | INCLUDES += -include $(abspath $(obj)/config.h) |
| 103 | |
| 104 | CFLAGS = $(INCLUDES) -Os -pipe -g |
| 105 | CFLAGS += -nostdlib -Wall -Wundef -Wstrict-prototypes -Wmissing-prototypes |
| 106 | CFLAGS += -Wwrite-strings -Wredundant-decls -Wno-trigraphs |
| 107 | CFLAGS += -Wstrict-aliasing -Wshadow |
| 108 | ifeq ($(CONFIG_WARNINGS_ARE_ERRORS),y) |
| 109 | CFLAGS += -Werror |
| 110 | endif |
| 111 | ifneq ($(CONFIG_AMD_AGESA),y) |
| 112 | CFLAGS += -nostdinc |
| 113 | endif |
| 114 | CFLAGS += -fno-common -ffreestanding -fno-builtin -fomit-frame-pointer |
| 115 | |
| 116 | additional-dirs := $(objutil)/cbfstool $(objutil)/romcc $(objutil)/options |
| 117 | |
| 118 | ####################################################################### |
| 119 | # generate build support files |
| 120 | $(obj)/build.h: .xcompile |
| 121 | @printf " GEN build.h\n" |
| 122 | rm -f $(obj)/build.h |
| 123 | printf "/* build system definitions (autogenerated) */\n" > $(obj)/build.ht |
| 124 | printf "#ifndef __BUILD_H\n" >> $(obj)/build.ht |
| 125 | printf "#define __BUILD_H\n\n" >> $(obj)/build.ht |
| 126 | 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 |
| 127 | printf "#define COREBOOT_EXTRA_VERSION \"$(COREBOOT_EXTRA_VERSION)\"\n" >> $(obj)/build.ht |
| 128 | printf "#define COREBOOT_BUILD \"`LANG= date`\"\n" >> $(obj)/build.ht |
| 129 | printf "\n" >> $(obj)/build.ht |
| 130 | printf "#define COREBOOT_COMPILER \"$(shell LANG= $(CC) --version | head -n1)\"\n" >> $(obj)/build.ht |
| 131 | printf "#define COREBOOT_ASSEMBLER \"$(shell LANG= $(AS) --version | head -n1)\"\n" >> $(obj)/build.ht |
| 132 | printf "#define COREBOOT_LINKER \"$(shell LANG= $(LD) --version | head -n1)\"\n" >> $(obj)/build.ht |
| 133 | printf "#define COREBOOT_COMPILE_TIME \"`LANG= date +%T`\"\n" >> $(obj)/build.ht |
| 134 | printf "#define COREBOOT_COMPILE_BY \"$(subst \,@,$(shell PATH=$$PATH:/usr/ucb whoami))\"\n" >> $(obj)/build.ht |
| 135 | printf "#define COREBOOT_COMPILE_HOST \"$(shell hostname -s 2>/dev/null)\"\n" >> $(obj)/build.ht |
| 136 | printf "#define COREBOOT_COMPILE_DOMAIN \"$(shell test `uname -s` = "Linux" && dnsdomainname || domainname 2>/dev/null)\"\n" >> $(obj)/build.ht |
| 137 | printf "#endif\n" >> $(obj)/build.ht |
| 138 | mv $(obj)/build.ht $(obj)/build.h |
| 139 | |
| 140 | $(obj)/ldoptions: $(obj)/config.h |
| 141 | awk '/^#define ([^"])* ([^"])*$$/ {gsub("\\r","",$$3); print $$2 " = " $$3 ";";}' $< > $@ |
| 142 | |
| 143 | ####################################################################### |
| 144 | # Build the tools |
| 145 | CBFSTOOL:=$(obj)/cbfstool |
| 146 | |
| 147 | $(CBFSTOOL): $(objutil)/cbfstool/cbfstool |
| 148 | cp $< $@ |
| 149 | |
| 150 | _WINCHECK=$(shell uname -o 2> /dev/null) |
| 151 | STACK= |
| 152 | ifeq ($(_WINCHECK),Msys) |
| 153 | STACK=-Wl,--stack,16384000 |
| 154 | endif |
| 155 | ifeq ($(_WINCHECK),Cygwin) |
| 156 | STACK=-Wl,--stack,16384000 |
| 157 | endif |
| 158 | |
| 159 | ROMCC:= $(objutil)/romcc/romcc |
| 160 | $(ROMCC): $(top)/util/romcc/romcc.c |
| 161 | @printf " HOSTCC $(subst $(obj)/,,$(@)) (this may take a while)\n" |
| 162 | @# Note: Adding -O2 here might cause problems. For details see: |
| 163 | @# http://www.coreboot.org/pipermail/coreboot/2010-February/055825.html |
| 164 | $(HOSTCC) -g $(STACK) -Wall -o $@ $< |
| 165 | |
| 166 | ####################################################################### |
| 167 | # needed objects that every mainboard uses |
| 168 | # Creation of these is architecture and mainboard independent |
| 169 | $(obj)/mainboard/$(MAINBOARDDIR)/static.c: $(src)/mainboard/$(MAINBOARDDIR)/devicetree.cb $(objutil)/sconfig/sconfig |
| 170 | @printf " SCONFIG $(subst $(src)/,,$(<))\n" |
| 171 | mkdir -p $(obj)/mainboard/$(MAINBOARDDIR) |
| 172 | $(objutil)/sconfig/sconfig $(MAINBOARDDIR) $(obj)/mainboard/$(MAINBOARDDIR) |
| 173 | |
| 174 | ramstage-y+=$(obj)/mainboard/$(MAINBOARDDIR)/static.c |
| 175 | |
| 176 | $(objutil)/%.o: $(objutil)/%.c |
| 177 | @printf " HOSTCC $(subst $(objutil)/,,$(@))\n" |
| 178 | $(HOSTCC) -MMD -I$(subst $(objutil)/,util/,$(dir $<)) -I$(dir $<) $(HOSTCFLAGS) -c -o $@ $< |
| 179 | |
Patrick Georgi | 57205c7 | 2011-03-08 20:49:18 +0000 | [diff] [blame] | 180 | $(obj)/%.ramstage.o: $(obj)/%.c $(obj)/config.h $(OPTION_TABLE_H) |
Patrick Georgi | 71b8480 | 2011-02-22 14:35:05 +0000 | [diff] [blame] | 181 | @printf " CC $(subst $(obj)/,,$(@))\n" |
| 182 | $(CC) -MMD $(CFLAGS) -c -o $@ $< |
| 183 | |
| 184 | ####################################################################### |
| 185 | # Clean up rules |
| 186 | clean-abuild: |
| 187 | rm -rf coreboot-builds |
| 188 | |
| 189 | clean-for-update-target: |
| 190 | rm -f $(obj)/coreboot_ram* $(obj)/coreboot.romstage $(obj)/coreboot.pre* $(obj)/coreboot.bootblock $(obj)/coreboot.a |
| 191 | rm -rf $(obj)/bootblock* $(obj)/romstage* $(obj)/location.* |
| 192 | rm -f $(obj)/option_table.* $(obj)/crt0.S $(obj)/ldscript |
| 193 | rm -f $(obj)/mainboard/$(MAINBOARDDIR)/static.c $(obj)/mainboard/$(MAINBOARDDIR)/config.py $(obj)/mainboard/$(MAINBOARDDIR)/static.dot |
| 194 | rm -f $(obj)/mainboard/$(MAINBOARDDIR)/crt0.s $(obj)/mainboard/$(MAINBOARDDIR)/crt0.disasm |
| 195 | rm -f $(obj)/mainboard/$(MAINBOARDDIR)/romstage.inc |
| 196 | rm -f $(obj)/mainboard/$(MAINBOARDDIR)/bootblock.* $(obj)/mainboard/$(MAINBOARDDIR)/dsdt.* |
| 197 | rm -f $(obj)/cpu/x86/smm/smm_bin.c $(obj)/cpu/x86/smm/smm.* $(obj)/cpu/x86/smm/smm |
| 198 | $(MAKE) -C payloads/external/SeaBIOS -f Makefile.inc clean |
| 199 | |
| 200 | clean-target: |
| 201 | rm -f $(obj)/coreboot* |
| 202 | |
| 203 | ####################################################################### |
| 204 | # Development utilities |
| 205 | printcrt0s: |
| 206 | @echo crt0s=$(crt0s) |
| 207 | @echo ldscripts=$(ldscripts) |
| 208 | |
| 209 | update: |
| 210 | dongle.py -c /dev/term/1 $(obj)/coreboot.rom EOF |
| 211 | |
| 212 | lint: |
| 213 | FAILED=0; LINTLOG=`mktemp`; \ |
| 214 | for script in util/lint/lint-*; do \ |
| 215 | echo; echo `basename $$script`; \ |
| 216 | grep "^# DESCR:" $$script | sed "s,.*DESCR: *,," ; \ |
| 217 | echo ========; \ |
| 218 | $$script > $$LINTLOG; \ |
| 219 | if [ `wc -l $$LINTLOG | cut -d' ' -f1` -eq 0 ]; then \ |
| 220 | printf "success\n\n"; \ |
| 221 | else \ |
| 222 | echo test failed: ; \ |
| 223 | cat $$LINTLOG; \ |
| 224 | rm -f $$LINTLOG; \ |
| 225 | FAILED=$$(( $$FAILED + 1 )); \ |
| 226 | fi; \ |
| 227 | echo ========; \ |
| 228 | done; \ |
| 229 | test $$FAILED -eq 0 || { echo "ERROR: $$FAILED test(s) failed." && exit 1; }; \ |
| 230 | rm -f $$LINTLOG |