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