Makefile: Add HOSTCC
[sgabios.git] / Makefile
1 # Copyright 2010 Google Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 #
15 # $Id$
16
17 BUILD_DATE = \"$(shell date -u)\"
18 BUILD_SHORT_DATE = \"$(shell date -u +%D)\"
19 BUILD_HOST = \"$(shell hostname)\"
20 BUILD_USER = \"$(shell whoami)\"
21
22 CFLAGS := -Wall -Os -m32 -nostdlib
23
24 ASFLAGS := $(CFLAGS)
25 ASFLAGS += -DBUILD_DATE="$(BUILD_DATE)"
26 ASFLAGS += -DBUILD_SHORT_DATE="$(BUILD_SHORT_DATE)"
27 ASFLAGS += -DBUILD_HOST="$(BUILD_HOST)"
28 ASFLAGS += -DBUILD_USER="$(BUILD_USER)"
29
30 LDSCRIPT := rom16.ld
31 LDFLAGS := -T $(LDSCRIPT) -nostdlib
32 OBJCOPY := objcopy
33 HOSTCC := $(CC)
34
35 ASRCS = sgabios.S
36
37 CSRCS =
38
39 SRCS = $(CSRCS) $(ASRCS)
40
41 OBJS = ${CSRCS:.c=.o} ${ASRCS:.S=.o}
42 INCS = ${CSRCS:.c=.h} ${ASRCS:.S=.h}
43
44 PROGS = sgabios.bin csum8
45
46 .SUFFIXES: .bin .elf
47 .PHONY: buildinfo
48
49 all: $(PROGS)
50
51 sgabios.bin: sgabios.elf
52 $(OBJCOPY) -O binary $< $@
53 ./csum8 $@
54
55 sgabios.elf: .depend $(OBJS) $(LDSCRIPT) csum8
56 $(LD) $(LDFLAGS) $(OBJS) -o $@
57
58 csum8: csum8.c
59 $(HOSTCC) -Wall -O2 -o $@ $<
60
61 sgabios.o: buildinfo
62
63
64 buildinfo:
65 touch sgabios.S
66 clean:
67 $(RM) $(PROGS) $(OBJS) *.elf *.srec *.com version.h
68
69 .depend:: $(INCS) $(SRCS) Makefile
70 $(RM) .depend
71 $(CPP) -M $(CFLAGS) $(SRCS) >.tmpdepend && mv .tmpdepend .depend
72
73 ifeq (.depend, $(wildcard .depend))
74 include .depend
75 else
76 # if no .depend file existed, add a make clean to the end of building .depend
77 .depend::
78 $(MAKE) clean
79 endif