blob: 80fafd7242bb8b423895cc65b451be9208b1b05f [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
Chandan Uddaraju40b227d2010-08-03 19:25:41 -070025DEBUG ?= 0
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070026
Chandan Uddarajua9b07bb2009-11-21 12:22:02 -080027ifndef $(BOOTLOADER_OUT)
28BOOTLOADER_OUT := .
29endif
30
Chandan Uddaraju885e4db2009-12-03 22:45:26 -080031LK_TOP_DIR:= .
Chandan Uddarajua9b07bb2009-11-21 12:22:02 -080032BUILDDIR := $(BOOTLOADER_OUT)/build-$(PROJECT)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070033OUTBIN := $(BUILDDIR)/lk.bin
34OUTELF := $(BUILDDIR)/lk
35CONFIGHEADER := $(BUILDDIR)/config.h
36
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070037INCLUDES := -I$(BUILDDIR) -Iinclude
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070038CFLAGS := -O2 -g -fno-builtin -finline -W -Wall -Wno-multichar -Wno-unused-parameter -Wno-unused-function -include $(CONFIGHEADER)
39#CFLAGS += -Werror
David Ng025c1d92009-12-09 23:46:00 -080040ifeq ($(EMMC_BOOT),1)
41 CFLAGS += -D_EMMC_BOOT=1
42endif
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070043CPPFLAGS := -fno-exceptions -fno-rtti -fno-threadsafe-statics
44#CPPFLAGS += -Weffc++
45ASMFLAGS := -DASSEMBLY
46LDFLAGS :=
47
48CFLAGS += -ffunction-sections -fdata-sections
49LDFLAGS += -gc-sections
50
51# top level rule
Chandan Uddarajua9b07bb2009-11-21 12:22:02 -080052all:: $(OUTBIN) $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym $(OUTELF).size APPSBOOTHEADER
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070053
54# the following three object lists are identical except for the ordering
55# which is bootobjs, kobjs, objs
56BOOTOBJS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070057OBJS :=
58
59# a linker script needs to be declared in one of the project/target/platform files
60LINKER_SCRIPT :=
61
62# anything you add here will be deleted in make clean
63GENERATED := $(CONFIGHEADER)
64
65# anything added to DEFINES will be put into $(BUILDDIR)/config.h
66DEFINES := LK=1
67
68# Anything added to SRCDEPS will become a dependency of every source file in the system.
69# Useful for header files that may be included by one or more source files.
70SRCDEPS := $(CONFIGHEADER)
71
72# these need to be filled out by the project/target/platform rules.mk files
73TARGET :=
74PLATFORM :=
75ARCH :=
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070076ALLMODULES :=
77MODULES :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070078
79# any rules you put here will also be built by the system before considered being complete
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070080EXTRA_BUILDDEPS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070081
82# any rules you put here will be depended on in clean builds
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070083EXTRA_CLEANDEPS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070084
Travis Geiselbrecht577036f2009-01-24 21:37:21 -080085include project/$(PROJECT).mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070086include target/$(TARGET)/rules.mk
Chandan Uddarajua9b07bb2009-11-21 12:22:02 -080087include target/$(TARGET)/tools/makefile
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070088include platform/$(PLATFORM)/rules.mk
89include arch/$(ARCH)/rules.mk
90include platform/rules.mk
91include target/rules.mk
92include kernel/rules.mk
93include dev/rules.mk
Travis Geiselbrecht68372232009-01-24 21:21:08 -080094include app/rules.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070095
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070096# recursively include any modules in the MODULE variable, leaving a trail of included
97# modules in the ALLMODULES list
Travis Geiselbrecht5bcbd9d2009-01-24 20:15:32 -080098include make/module.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070099
100# any extra top level build dependencies that someone declared
101all:: $(EXTRA_BUILDDEPS)
102
103ALLOBJS := \
104 $(BOOTOBJS) \
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700105 $(OBJS)
106
107# add some automatic configuration defines
108DEFINES += \
Subbaraman Narayanamurthyeb92bcc2010-07-20 14:32:46 -0700109 BOARD=$(PROJECT) \
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700110 PROJECT_$(PROJECT)=1 \
111 TARGET_$(TARGET)=1 \
112 PLATFORM_$(PLATFORM)=1 \
113 ARCH_$(ARCH)=1 \
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700114 $(addsuffix =1,$(addprefix WITH_,$(ALLMODULES)))
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700115
116# debug build?
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700117ifneq ($(DEBUG),)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700118DEFINES += \
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700119 DEBUG=$(DEBUG)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700120endif
121
122ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS))
123
124DEPS := $(ALLOBJS:%o=%d)
125
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700126# default to no ccache
127CCACHE ?=
128CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700129LD := $(TOOLCHAIN_PREFIX)ld
130OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
131OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
132CPPFILT := $(TOOLCHAIN_PREFIX)c++filt
133SIZE := $(TOOLCHAIN_PREFIX)size
134NM := $(TOOLCHAIN_PREFIX)nm
135
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700136# comment out or override if you want to see the full output of each command
137NOECHO ?= @
138
139# the logic to compile and link stuff is in here
Travis Geiselbrecht5bcbd9d2009-01-24 20:15:32 -0800140include make/build.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700141
142clean: $(EXTRA_CLEANDEPS)
143 rm -f $(ALLOBJS) $(DEPS) $(GENERATED) $(OUTBIN) $(OUTELF) $(OUTELF).lst
144
145spotless:
146 rm -rf build-*
147
148install: all
149 scp $(OUTBIN) 192.168.0.4:/tftproot
150
151# generate a config.h file with all of the DEFINES laid out in #define format
152configheader:
153
154$(CONFIGHEADER): configheader
155 @$(MKDIR)
156 @echo generating $@
157 @rm -f $(CONFIGHEADER).tmp; \
158 echo \#ifndef __CONFIG_H > $(CONFIGHEADER).tmp; \
159 echo \#define __CONFIG_H >> $(CONFIGHEADER).tmp; \
160 for d in `echo $(DEFINES) | tr [:lower:] [:upper:]`; do \
161 echo "#define $$d" | sed "s/=/\ /g;s/-/_/g;s/\//_/g" >> $(CONFIGHEADER).tmp; \
162 done; \
163 echo \#endif >> $(CONFIGHEADER).tmp; \
164 if [ -f "$(CONFIGHEADER)" ]; then \
165 if cmp "$(CONFIGHEADER).tmp" "$(CONFIGHEADER)"; then \
166 rm -f $(CONFIGHEADER).tmp; \
167 else \
168 mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \
169 fi \
170 else \
171 mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \
172 fi
173
174# Empty rule for the .d files. The above rules will build .d files as a side
175# effect. Only works on gcc 3.x and above, however.
176%.d:
177
178ifeq ($(filter $(MAKECMDGOALS), clean), )
179-include $(DEPS)
180endif
181
182.PHONY: configheader
Brian Swetlandf1e5afd2009-01-24 22:09:30 -0800183endif