85f1632b938132e8705837eb41e9585ce002a012
[coreboot.git] / src / config / Config.lb
1 ## This is Architecture independant part of the makefile
2
3 uses HAVE_OPTION_TABLE
4 uses CONFIG_AP_CODE_IN_CAR
5 uses ASSEMBLER_DEBUG
6
7 makedefine CPP:= $(CC) -x assembler-with-cpp -DASSEMBLY -E
8 makedefine LIBGCC_FILE_NAME := $(shell $(CC) -print-libgcc-file-name)
9 makedefine GCC_INC_DIR := $(shell LC_ALL=C $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp")
10
11 makedefine CPPFLAGS := -I$(TOP)/src/include -I$(TOP)/src/arch/$(ARCH)/include -I$(GCC_INC_DIR) $(CPUFLAGS)
12 makedefine CFLAGS := $(CPU_OPT) $(DISTRO_CFLAGS) $(CPPFLAGS) -Os -nostdinc -nostdlib -fno-builtin  -Wall
13
14 if ASSEMBLER_DEBUG
15 makedefine DEBUG_CFLAGS := -g -dA -fverbose-asm
16 end
17
18 makedefine HOSTCFLAGS:= -Os -Wall
19
20 makerule ldscript.ld   
21         depends "ldoptions $(LDSUBSCRIPTS-1)" 
22         action  "echo '/*ldoptions*/' > $@; cat ldoptions >> $@ ; for file in $(LDSUBSCRIPTS-1) ; do echo /\* $$file \*/ >> $@; cat $$file >> $@ ; done"
23 end
24
25 #makerule cpuflags   
26 #       depends "Makefile.settings" 
27 #       action  "perl -e 'print \"CPUFLAGS :=\n\"; foreach $$var (split(\" \", $$ENV{VARIABLES})) { if (exists($$ENV{$$var})) { print \"CPUFLAGS += -D$$var\" . (length($$ENV{$$var})?\"=\x27$$ENV{$$var}\x27\":\"\") .\"\n\"} else { print \"CPUFLAGS += -U$$var\n\"} }' > $@"
28 #end
29
30 #makerule ldoptions   
31 #       depends "Makefile.settings" 
32 #       action  "perl -e 'foreach $$var (split(\" \", $$ENV{VARIABLES})) { if ($$ENV{$$var} =~ m/^(0x[0-9a-fA-F]+|0[0-7]+|[0-9]+)$$/) { print \"$$var = $$ENV{$$var};\n\"; }}' > $@"
33 #end
34
35 makerule coreboot.strip  
36         depends "coreboot" 
37         action  "$(OBJCOPY) -O binary coreboot coreboot.strip"
38 end
39
40 makerule coreboot.a
41         depends "$(OBJECTS)"
42         action  "rm -f coreboot.a"
43         action  "$(CROSS_COMPILE)ar cr coreboot.a $(OBJECTS)"
44 end
45
46
47 makerule coreboot_ram.o
48         depends "$(DRIVER) coreboot.a $(LIBGCC_FILE_NAME)" 
49         action  "$(CC) $(DISTRO_LFLAGS) -nostdlib -r -o $@ c_start.o $(DRIVER) coreboot.a $(LIBGCC_FILE_NAME)"
50 end
51
52 makerule coreboot_ram
53         depends "coreboot_ram.o $(TOP)/src/config/coreboot_ram.ld ldoptions" 
54         action  "$(CC) $(DISTRO_LFLAGS) -nostdlib -nostartfiles -static -o $@ -T $(TOP)/src/config/coreboot_ram.ld coreboot_ram.o"
55         action  "$(CROSS_COMPILE)nm -n coreboot_ram | sort > coreboot_ram.map"
56 end
57
58 ##
59 ## By default compress the part of coreboot that runs from RAM
60 ##
61 makedefine COREBOOT_RAM-$(CONFIG_COMPRESS):=coreboot_ram.nrv2b
62 makedefine COREBOOT_RAM-$(CONFIG_UNCOMPRESSED):=coreboot_ram.bin
63
64 makerule coreboot_ram.bin 
65         depends "coreboot_ram" 
66         action  "$(OBJCOPY) -O binary $< $@"
67 end
68
69 makerule coreboot_ram.nrv2b 
70         depends "coreboot_ram.bin nrv2b" 
71         action  "./nrv2b e $< $@"
72 end
73
74 makerule coreboot_ram.rom
75         depends "$(COREBOOT_RAM-1)" 
76         action  "cp $(COREBOOT_RAM-1) coreboot_ram.rom"
77 end
78
79 makedefine COREBOOT_APC:=
80
81 if CONFIG_AP_CODE_IN_CAR
82         #for ap code in cache
83
84         makerule coreboot_apc.a
85                 depends "apc_auto.o"
86                 action  "rm -f coreboot_apc.a"
87                 action  "$(CROSS_COMPILE)ar cr coreboot_apc.a apc_auto.o"
88         end
89
90         makerule coreboot_apc.o
91                 depends "coreboot_apc.a c_start.o $(LIBGCC_FILE_NAME)"
92                 action  "$(CC) $(DISTRO_LFLAGS) -nostdlib -r -o $@ c_start.o coreboot_apc.a $(LIBGCC_FILE_NAME)"
93         end
94
95         makerule coreboot_apc
96                 depends "coreboot_apc.o $(TOP)/src/config/coreboot_apc.ld ldoptions"
97                 action  "$(CC) $(DISTRO_LFLAGS) -nostdlib -nostartfiles -static -o $@ -T $(TOP)/src/config/coreboot_apc.ld coreboot_apc.o"
98                 action  "$(CROSS_COMPILE)nm -n coreboot_apc | sort > coreboot_apc.map"
99         end
100
101         ##
102         ## By default compress the part of coreboot that runs from cache as ram
103         ##
104         makedefine COREBOOT_APC-$(CONFIG_COMPRESS):=coreboot_apc.nrv2b
105         makedefine COREBOOT_APC-$(CONFIG_UNCOMPRESSED):=coreboot_apc.bin
106
107         makerule coreboot_apc.bin
108                 depends "coreboot_apc"
109                 action  "$(OBJCOPY) -O binary $< $@"
110         end
111
112         makerule coreboot_apc.nrv2b
113         depends "coreboot_apc.bin nrv2b"
114         action  "./nrv2b e $< $@"
115         end
116
117         makerule coreboot_apc.rom
118                 depends "$(COREBOOT_APC-1)"
119                 action  "cp $(COREBOOT_APC-1) coreboot_apc.rom"
120         end
121
122         makedefine COREBOOT_APC:=coreboot_apc.rom
123
124 end
125
126 makedefine COREBOOT_RAM_ROM:=coreboot_ram.rom
127
128 makerule coreboot   
129         depends "crt0.o $(INIT-OBJECTS) $(COREBOOT_APC) $(COREBOOT_RAM_ROM) ldscript.ld"
130         action  "$(CC) $(DISTRO_LFLAGS) -nostdlib -nostartfiles -static -o $@ -T ldscript.ld crt0.o $(INIT-OBJECTS)"
131         action  "$(CROSS_COMPILE)nm -n coreboot | sort > coreboot.map"
132         action  "$(CROSS_COMPILE)objdump -dS coreboot > coreboot.disasm"        
133 end
134
135 # the buildrom tool
136 makerule buildrom 
137         depends "$(TOP)/util/buildrom/buildrom.c" 
138         action  "$(HOSTCC) -o $@ $<"
139 end
140
141 # Force crt0.s (which has build time version code in it to rebuild every time)
142 makedefine .PHONY : crt0.s
143 makerule crt0.s   
144         depends "crt0.S $(CRT0_INCLUDES)" 
145         action  "$(CPP) $(CPPFLAGS) -I. -I$(TOP)/src  $< > $@.new && mv $@.new $@"
146 end
147
148 # generate an assembly listing via -a switch.
149 makerule crt0.o  
150         depends "crt0.s" 
151         action  "$(CC) -Wa,-acdlns -c $(CPU_OPT) -o $@ $< >crt0.disasm"
152 end
153
154 makerule etags   
155         depends "$(SOURCES)" 
156         action  "etags $(SOURCES)"
157 end
158 makerule tags   
159         depends "$(SOURCES)" 
160         action  "ctags $(SOURCES)"
161 end
162 makerule corebootDoc.config
163         depends "$(TOP)/src/config/corebootDoc.config" 
164         action "cat $(TOP)/src/config/corebootDoc.config > corebootDoc.config"
165         action "echo 'INPUT=$(SOURCES)' >> corebootDoc.config"
166 end
167 makerule documentation   
168         depends "corebootDoc.config"
169         action  "doxygen corebootDoc.config"
170 end
171
172 # Yes, the rule doesn't seem to make sense, but multiple images could try to
173 # create a romcc binary at the same time, clobbering each other.
174 # Our makefile architecture won't allow us to easily have the romcc target
175 # in the main makefile, so keep it here and move the race condition winner
176 # in place. That way, romcc may get compiled twice, but the binary will always
177 # be in a correct and valid state if it exists because the move is atomic.
178 makerule ../romcc   
179         depends "$(TOP)/util/romcc/romcc.c" 
180         action  "$(HOSTCC) -g $(HOSTCFLAGS) $< -o romcc.tmpfile"
181         action  "mv romcc.tmpfile $@"
182 end
183
184 makerule build_opt_tbl   
185         depends "$(TOP)/util/options/build_opt_tbl.c $(TOP)/src/include/pc80/mc146818rtc.h $(TOP)/src/include/boot/coreboot_tables.h Makefile.settings Makefile"
186         action  "$(HOSTCC) $(HOSTCFLAGS) $(CPUFLAGS) $< -o $@" 
187 end
188
189 makerule option_table.h option_table.c
190         depends "build_opt_tbl $(MAINBOARD)/cmos.layout" 
191         action  "./build_opt_tbl --config $(MAINBOARD)/cmos.layout --header option_table.h --option option_table.c"
192 end
193
194 if HAVE_OPTION_TABLE
195 object ./option_table.o 
196 end
197
198 makerule clean 
199         action  "rm -f coreboot.* *~"
200         action  "rm -f coreboot"
201         action  "rm -f ldscript.ld"
202         action  "rm -f a.out *.s *.l *.o *.E *.inc"
203         action  "rm -f TAGS tags romcc*"
204         action  "rm -f docipl buildrom* chips.c *chip.c coreboot_apc* coreboot_ram* coreboot_pay*"
205         action  "rm -f build_opt_tbl* nrv2b* option_table.c crt0.S"
206 end
207
208 # do standard config files that the user need not specify
209 # for now, this is just 'lib', but it may be more later. 
210 dir /lib
211 dir /console
212 dir /stream
213 dir /devices
214 dir /pc80
215 dir /boot