blob: a40bda08252301d57595a9b0bf7f52069a0962ab [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001-include local.mk
2include macros.mk
3
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -07004PROJECT ?= beagle-test
5DEBUG ?= 1
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07006
7BUILDDIR := build-$(PROJECT)
8OUTBIN := $(BUILDDIR)/lk.bin
9OUTELF := $(BUILDDIR)/lk
10CONFIGHEADER := $(BUILDDIR)/config.h
11
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070012INCLUDES := -I$(BUILDDIR) -Iinclude
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070013CFLAGS := -O2 -g -fno-builtin -finline -W -Wall -Wno-multichar -Wno-unused-parameter -Wno-unused-function -include $(CONFIGHEADER)
14#CFLAGS += -Werror
15CPPFLAGS := -fno-exceptions -fno-rtti -fno-threadsafe-statics
16#CPPFLAGS += -Weffc++
17ASMFLAGS := -DASSEMBLY
18LDFLAGS :=
19
20CFLAGS += -ffunction-sections -fdata-sections
21LDFLAGS += -gc-sections
22
23# top level rule
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070024all:: $(OUTBIN) $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym $(OUTELF).size
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070025
26# the following three object lists are identical except for the ordering
27# which is bootobjs, kobjs, objs
28BOOTOBJS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070029OBJS :=
30
31# a linker script needs to be declared in one of the project/target/platform files
32LINKER_SCRIPT :=
33
34# anything you add here will be deleted in make clean
35GENERATED := $(CONFIGHEADER)
36
37# anything added to DEFINES will be put into $(BUILDDIR)/config.h
38DEFINES := LK=1
39
40# Anything added to SRCDEPS will become a dependency of every source file in the system.
41# Useful for header files that may be included by one or more source files.
42SRCDEPS := $(CONFIGHEADER)
43
44# these need to be filled out by the project/target/platform rules.mk files
45TARGET :=
46PLATFORM :=
47ARCH :=
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070048ALLMODULES :=
49MODULES :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070050
51# any rules you put here will also be built by the system before considered being complete
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070052EXTRA_BUILDDEPS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070053
54# any rules you put here will be depended on in clean builds
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070055EXTRA_CLEANDEPS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070056
57include project/$(PROJECT)/rules.mk
58include target/$(TARGET)/rules.mk
59include platform/$(PLATFORM)/rules.mk
60include arch/$(ARCH)/rules.mk
61include platform/rules.mk
62include target/rules.mk
63include kernel/rules.mk
64include dev/rules.mk
65
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070066# recursively include any modules in the MODULE variable, leaving a trail of included
67# modules in the ALLMODULES list
68include module.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070069
70# any extra top level build dependencies that someone declared
71all:: $(EXTRA_BUILDDEPS)
72
73ALLOBJS := \
74 $(BOOTOBJS) \
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070075 $(OBJS)
76
77# add some automatic configuration defines
78DEFINES += \
79 PROJECT_$(PROJECT)=1 \
80 TARGET_$(TARGET)=1 \
81 PLATFORM_$(PLATFORM)=1 \
82 ARCH_$(ARCH)=1 \
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070083 $(addsuffix =1,$(addprefix WITH_,$(ALLMODULES)))
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070084
85# debug build?
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070086ifneq ($(DEBUG),)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070087DEFINES += \
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070088 DEBUG=$(DEBUG)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070089endif
90
91ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS))
92
93DEPS := $(ALLOBJS:%o=%d)
94
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070095# default to no ccache
96CCACHE ?=
97CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070098LD := $(TOOLCHAIN_PREFIX)ld
99OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
100OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
101CPPFILT := $(TOOLCHAIN_PREFIX)c++filt
102SIZE := $(TOOLCHAIN_PREFIX)size
103NM := $(TOOLCHAIN_PREFIX)nm
104
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700105# comment out or override if you want to see the full output of each command
106NOECHO ?= @
107
108# the logic to compile and link stuff is in here
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700109include build.mk
110
111clean: $(EXTRA_CLEANDEPS)
112 rm -f $(ALLOBJS) $(DEPS) $(GENERATED) $(OUTBIN) $(OUTELF) $(OUTELF).lst
113
114spotless:
115 rm -rf build-*
116
117install: all
118 scp $(OUTBIN) 192.168.0.4:/tftproot
119
120# generate a config.h file with all of the DEFINES laid out in #define format
121configheader:
122
123$(CONFIGHEADER): configheader
124 @$(MKDIR)
125 @echo generating $@
126 @rm -f $(CONFIGHEADER).tmp; \
127 echo \#ifndef __CONFIG_H > $(CONFIGHEADER).tmp; \
128 echo \#define __CONFIG_H >> $(CONFIGHEADER).tmp; \
129 for d in `echo $(DEFINES) | tr [:lower:] [:upper:]`; do \
130 echo "#define $$d" | sed "s/=/\ /g;s/-/_/g;s/\//_/g" >> $(CONFIGHEADER).tmp; \
131 done; \
132 echo \#endif >> $(CONFIGHEADER).tmp; \
133 if [ -f "$(CONFIGHEADER)" ]; then \
134 if cmp "$(CONFIGHEADER).tmp" "$(CONFIGHEADER)"; then \
135 rm -f $(CONFIGHEADER).tmp; \
136 else \
137 mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \
138 fi \
139 else \
140 mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \
141 fi
142
143# Empty rule for the .d files. The above rules will build .d files as a side
144# effect. Only works on gcc 3.x and above, however.
145%.d:
146
147ifeq ($(filter $(MAKECMDGOALS), clean), )
148-include $(DEPS)
149endif
150
151.PHONY: configheader