blob: 47ccb38e7b23fa48dd08e0b6792359a2e54271c7 [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001-include local.mk
Travis Geiselbrecht5bcbd9d2009-01-24 20:15:32 -08002include make/macros.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07003
Brian Swetlandf1e5afd2009-01-24 22:09:30 -08004# If one of our goals (from the commandline) happens to have a
5# matching project/goal.mk, then we should re-invoke make with
6# that project name specified...
7
8project-name := $(firstword $(MAKECMDGOALS))
9
10ifneq ($(project-name),)
11ifneq ($(wildcard project/$(project-name).mk),)
12do-nothing := 1
13$(MAKECMDGOALS) _all: make-make
14make-make:
15 @PROJECT=$(project-name) $(MAKE) $(filter-out $(project-name), $(MAKECMDGOALS))
16endif
17endif
18
19ifeq ($(do-nothing),)
20
21ifeq ($(PROJECT),)
22$(error No project specified. Use "make projectname" or put "PROJECT := projectname" in local.mk)
23endif
24
Travis Geiselbrechteb946052008-09-07 22:32:49 -070025DEBUG ?= 2
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070026
Chandan Uddarajua9b07bb2009-11-21 12:22:02 -080027ifndef $(BOOTLOADER_OUT)
28BOOTLOADER_OUT := .
29endif
30
31BUILDDIR := $(BOOTLOADER_OUT)/build-$(PROJECT)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070032OUTBIN := $(BUILDDIR)/lk.bin
33OUTELF := $(BUILDDIR)/lk
34CONFIGHEADER := $(BUILDDIR)/config.h
35
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070036INCLUDES := -I$(BUILDDIR) -Iinclude
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070037CFLAGS := -O2 -g -fno-builtin -finline -W -Wall -Wno-multichar -Wno-unused-parameter -Wno-unused-function -include $(CONFIGHEADER)
38#CFLAGS += -Werror
39CPPFLAGS := -fno-exceptions -fno-rtti -fno-threadsafe-statics
40#CPPFLAGS += -Weffc++
41ASMFLAGS := -DASSEMBLY
42LDFLAGS :=
43
44CFLAGS += -ffunction-sections -fdata-sections
45LDFLAGS += -gc-sections
46
47# top level rule
Chandan Uddarajua9b07bb2009-11-21 12:22:02 -080048all:: $(OUTBIN) $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym $(OUTELF).size APPSBOOTHEADER
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070049
50# the following three object lists are identical except for the ordering
51# which is bootobjs, kobjs, objs
52BOOTOBJS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070053OBJS :=
54
55# a linker script needs to be declared in one of the project/target/platform files
56LINKER_SCRIPT :=
57
58# anything you add here will be deleted in make clean
59GENERATED := $(CONFIGHEADER)
60
61# anything added to DEFINES will be put into $(BUILDDIR)/config.h
62DEFINES := LK=1
63
64# Anything added to SRCDEPS will become a dependency of every source file in the system.
65# Useful for header files that may be included by one or more source files.
66SRCDEPS := $(CONFIGHEADER)
67
68# these need to be filled out by the project/target/platform rules.mk files
69TARGET :=
70PLATFORM :=
71ARCH :=
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070072ALLMODULES :=
73MODULES :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070074
75# any rules you put here will also be built by the system before considered being complete
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070076EXTRA_BUILDDEPS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070077
78# any rules you put here will be depended on in clean builds
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070079EXTRA_CLEANDEPS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070080
Travis Geiselbrecht577036f2009-01-24 21:37:21 -080081include project/$(PROJECT).mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070082include target/$(TARGET)/rules.mk
Chandan Uddarajua9b07bb2009-11-21 12:22:02 -080083include target/$(TARGET)/tools/makefile
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070084include platform/$(PLATFORM)/rules.mk
85include arch/$(ARCH)/rules.mk
86include platform/rules.mk
87include target/rules.mk
88include kernel/rules.mk
89include dev/rules.mk
Travis Geiselbrecht68372232009-01-24 21:21:08 -080090include app/rules.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070091
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070092# recursively include any modules in the MODULE variable, leaving a trail of included
93# modules in the ALLMODULES list
Travis Geiselbrecht5bcbd9d2009-01-24 20:15:32 -080094include make/module.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070095
96# any extra top level build dependencies that someone declared
97all:: $(EXTRA_BUILDDEPS)
98
99ALLOBJS := \
100 $(BOOTOBJS) \
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700101 $(OBJS)
102
103# add some automatic configuration defines
104DEFINES += \
105 PROJECT_$(PROJECT)=1 \
106 TARGET_$(TARGET)=1 \
107 PLATFORM_$(PLATFORM)=1 \
108 ARCH_$(ARCH)=1 \
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700109 $(addsuffix =1,$(addprefix WITH_,$(ALLMODULES)))
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700110
111# debug build?
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700112ifneq ($(DEBUG),)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700113DEFINES += \
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700114 DEBUG=$(DEBUG)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700115endif
116
117ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS))
118
119DEPS := $(ALLOBJS:%o=%d)
120
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700121# default to no ccache
122CCACHE ?=
123CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700124LD := $(TOOLCHAIN_PREFIX)ld
125OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
126OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
127CPPFILT := $(TOOLCHAIN_PREFIX)c++filt
128SIZE := $(TOOLCHAIN_PREFIX)size
129NM := $(TOOLCHAIN_PREFIX)nm
130
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700131# comment out or override if you want to see the full output of each command
132NOECHO ?= @
133
134# the logic to compile and link stuff is in here
Travis Geiselbrecht5bcbd9d2009-01-24 20:15:32 -0800135include make/build.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700136
137clean: $(EXTRA_CLEANDEPS)
138 rm -f $(ALLOBJS) $(DEPS) $(GENERATED) $(OUTBIN) $(OUTELF) $(OUTELF).lst
139
140spotless:
141 rm -rf build-*
142
143install: all
144 scp $(OUTBIN) 192.168.0.4:/tftproot
145
146# generate a config.h file with all of the DEFINES laid out in #define format
147configheader:
148
149$(CONFIGHEADER): configheader
150 @$(MKDIR)
151 @echo generating $@
152 @rm -f $(CONFIGHEADER).tmp; \
153 echo \#ifndef __CONFIG_H > $(CONFIGHEADER).tmp; \
154 echo \#define __CONFIG_H >> $(CONFIGHEADER).tmp; \
155 for d in `echo $(DEFINES) | tr [:lower:] [:upper:]`; do \
156 echo "#define $$d" | sed "s/=/\ /g;s/-/_/g;s/\//_/g" >> $(CONFIGHEADER).tmp; \
157 done; \
158 echo \#endif >> $(CONFIGHEADER).tmp; \
159 if [ -f "$(CONFIGHEADER)" ]; then \
160 if cmp "$(CONFIGHEADER).tmp" "$(CONFIGHEADER)"; then \
161 rm -f $(CONFIGHEADER).tmp; \
162 else \
163 mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \
164 fi \
165 else \
166 mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \
167 fi
168
169# Empty rule for the .d files. The above rules will build .d files as a side
170# effect. Only works on gcc 3.x and above, however.
171%.d:
172
173ifeq ($(filter $(MAKECMDGOALS), clean), )
174-include $(DEPS)
175endif
176
177.PHONY: configheader
Brian Swetlandf1e5afd2009-01-24 22:09:30 -0800178endif