blob: 0cf7e7c142cf0b41139f6eaca40a1624441402a9 [file] [log] [blame]
Travis Geiselbrecht78d0e6c2009-11-27 13:37:03 -08001ifeq ($(MAKECMDGOALS),spotless)
2spotless:
3 rm -rf build-*
4else
5
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07006-include local.mk
Travis Geiselbrecht5bcbd9d2009-01-24 20:15:32 -08007include make/macros.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07008
Brian Swetlandf1e5afd2009-01-24 22:09:30 -08009# If one of our goals (from the commandline) happens to have a
10# matching project/goal.mk, then we should re-invoke make with
11# that project name specified...
12
13project-name := $(firstword $(MAKECMDGOALS))
14
15ifneq ($(project-name),)
16ifneq ($(wildcard project/$(project-name).mk),)
17do-nothing := 1
18$(MAKECMDGOALS) _all: make-make
19make-make:
20 @PROJECT=$(project-name) $(MAKE) $(filter-out $(project-name), $(MAKECMDGOALS))
21endif
22endif
23
24ifeq ($(do-nothing),)
25
26ifeq ($(PROJECT),)
27$(error No project specified. Use "make projectname" or put "PROJECT := projectname" in local.mk)
28endif
29
Chandan Uddaraju40b227d2010-08-03 19:25:41 -070030DEBUG ?= 0
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070031
Chandan Uddarajua9b07bb2009-11-21 12:22:02 -080032ifndef $(BOOTLOADER_OUT)
33BOOTLOADER_OUT := .
34endif
35
Chandan Uddaraju885e4db2009-12-03 22:45:26 -080036LK_TOP_DIR:= .
Chandan Uddarajua9b07bb2009-11-21 12:22:02 -080037BUILDDIR := $(BOOTLOADER_OUT)/build-$(PROJECT)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070038OUTBIN := $(BUILDDIR)/lk.bin
39OUTELF := $(BUILDDIR)/lk
Channagoud Kadabi02072a42014-02-28 19:15:40 -080040OUTELF_STRIP := $(BUILDDIR)/lk_s.elf
41
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070042CONFIGHEADER := $(BUILDDIR)/config.h
43
Subbaraman Narayanamurthy8bcd5fd2011-01-17 17:18:44 -080044#Initialize the command-line flag ENABLE_TRUSTZONE. Value for flag passed in at command-line will take precedence
45ENABLE_TRUSTZONE := 0
46
47ifeq ($(ENABLE_TRUSTZONE),1)
48 INPUT_TZ_BIN := tzbsp/tzbsp.bin
49 OUTPUT_TZ_BIN := $(BUILDDIR)/tzbsp_bin.o
50endif
51
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070052INCLUDES := -I$(BUILDDIR) -Iinclude
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070053CFLAGS := -O2 -g -fno-builtin -finline -W -Wall -Wno-multichar -Wno-unused-parameter -Wno-unused-function -include $(CONFIGHEADER)
54#CFLAGS += -Werror
David Ng025c1d92009-12-09 23:46:00 -080055ifeq ($(EMMC_BOOT),1)
56 CFLAGS += -D_EMMC_BOOT=1
57endif
Shashank Mittalcd98d472011-08-02 14:29:24 -070058
59ifeq ($(SIGNED_KERNEL),1)
60 CFLAGS += -D_SIGNED_KERNEL=1
61endif
62
Channagoud Kadabi02072a42014-02-28 19:15:40 -080063# setup toolchain prefix
64TOOLCHAIN_PREFIX ?= arm-eabi-
Maria Yud3200512014-05-28 15:57:51 +080065CFLAGS += -fstack-protector-all
vijay kumarc2119f12014-07-22 18:30:11 +053066CFLAGS += -fno-strict-overflow
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070067CPPFLAGS := -fno-exceptions -fno-rtti -fno-threadsafe-statics
68#CPPFLAGS += -Weffc++
69ASMFLAGS := -DASSEMBLY
70LDFLAGS :=
71
72CFLAGS += -ffunction-sections -fdata-sections
73LDFLAGS += -gc-sections
74
75# top level rule
Channagoud Kadabi02072a42014-02-28 19:15:40 -080076all:: $(OUTBIN) $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym $(OUTELF).size $(OUTELF_STRIP) APPSBOOTHEADER
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070077
78# the following three object lists are identical except for the ordering
79# which is bootobjs, kobjs, objs
80BOOTOBJS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070081OBJS :=
82
83# a linker script needs to be declared in one of the project/target/platform files
84LINKER_SCRIPT :=
85
86# anything you add here will be deleted in make clean
87GENERATED := $(CONFIGHEADER)
88
89# anything added to DEFINES will be put into $(BUILDDIR)/config.h
90DEFINES := LK=1
91
92# Anything added to SRCDEPS will become a dependency of every source file in the system.
93# Useful for header files that may be included by one or more source files.
94SRCDEPS := $(CONFIGHEADER)
95
96# these need to be filled out by the project/target/platform rules.mk files
97TARGET :=
98PLATFORM :=
99ARCH :=
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700100ALLMODULES :=
101MODULES :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700102
103# any rules you put here will also be built by the system before considered being complete
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700104EXTRA_BUILDDEPS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700105
106# any rules you put here will be depended on in clean builds
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700107EXTRA_CLEANDEPS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700108
Travis Geiselbrecht577036f2009-01-24 21:37:21 -0800109include project/$(PROJECT).mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700110include target/$(TARGET)/rules.mk
Chandan Uddarajua9b07bb2009-11-21 12:22:02 -0800111include target/$(TARGET)/tools/makefile
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700112include platform/$(PLATFORM)/rules.mk
113include arch/$(ARCH)/rules.mk
114include platform/rules.mk
115include target/rules.mk
116include kernel/rules.mk
117include dev/rules.mk
Travis Geiselbrecht68372232009-01-24 21:21:08 -0800118include app/rules.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700119
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700120# recursively include any modules in the MODULE variable, leaving a trail of included
121# modules in the ALLMODULES list
Travis Geiselbrecht5bcbd9d2009-01-24 20:15:32 -0800122include make/module.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700123
124# any extra top level build dependencies that someone declared
125all:: $(EXTRA_BUILDDEPS)
126
127ALLOBJS := \
128 $(BOOTOBJS) \
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700129 $(OBJS)
130
131# add some automatic configuration defines
132DEFINES += \
Subbaraman Narayanamurthyeb92bcc2010-07-20 14:32:46 -0700133 BOARD=$(PROJECT) \
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700134 PROJECT_$(PROJECT)=1 \
135 TARGET_$(TARGET)=1 \
136 PLATFORM_$(PLATFORM)=1 \
137 ARCH_$(ARCH)=1 \
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700138 $(addsuffix =1,$(addprefix WITH_,$(ALLMODULES)))
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700139
140# debug build?
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700141ifneq ($(DEBUG),)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700142DEFINES += \
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700143 DEBUG=$(DEBUG)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700144endif
145
146ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS))
147
148DEPS := $(ALLOBJS:%o=%d)
149
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700150# default to no ccache
151CCACHE ?=
152CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
Channagoud Kadabi02072a42014-02-28 19:15:40 -0800153ifeq ($(LD),ld)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700154LD := $(TOOLCHAIN_PREFIX)ld
Channagoud Kadabi02072a42014-02-28 19:15:40 -0800155endif
156STRIP := $(TOOLCHAIN_PREFIX)strip
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700157OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
158OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
159CPPFILT := $(TOOLCHAIN_PREFIX)c++filt
160SIZE := $(TOOLCHAIN_PREFIX)size
161NM := $(TOOLCHAIN_PREFIX)nm
162
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700163# comment out or override if you want to see the full output of each command
164NOECHO ?= @
165
166# the logic to compile and link stuff is in here
Travis Geiselbrecht5bcbd9d2009-01-24 20:15:32 -0800167include make/build.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700168
169clean: $(EXTRA_CLEANDEPS)
Channagoud Kadabi02072a42014-02-28 19:15:40 -0800170 rm -f $(ALLOBJS) $(DEPS) $(GENERATED) $(OUTBIN) $(OUTELF) $(OUTELF).lst $(OUTELF_STRIP)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700171
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700172install: all
173 scp $(OUTBIN) 192.168.0.4:/tftproot
174
175# generate a config.h file with all of the DEFINES laid out in #define format
176configheader:
177
178$(CONFIGHEADER): configheader
179 @$(MKDIR)
180 @echo generating $@
181 @rm -f $(CONFIGHEADER).tmp; \
182 echo \#ifndef __CONFIG_H > $(CONFIGHEADER).tmp; \
183 echo \#define __CONFIG_H >> $(CONFIGHEADER).tmp; \
184 for d in `echo $(DEFINES) | tr [:lower:] [:upper:]`; do \
185 echo "#define $$d" | sed "s/=/\ /g;s/-/_/g;s/\//_/g" >> $(CONFIGHEADER).tmp; \
186 done; \
187 echo \#endif >> $(CONFIGHEADER).tmp; \
188 if [ -f "$(CONFIGHEADER)" ]; then \
189 if cmp "$(CONFIGHEADER).tmp" "$(CONFIGHEADER)"; then \
190 rm -f $(CONFIGHEADER).tmp; \
191 else \
192 mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \
193 fi \
194 else \
195 mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \
196 fi
197
198# Empty rule for the .d files. The above rules will build .d files as a side
199# effect. Only works on gcc 3.x and above, however.
200%.d:
201
202ifeq ($(filter $(MAKECMDGOALS), clean), )
203-include $(DEPS)
204endif
205
206.PHONY: configheader
Brian Swetlandf1e5afd2009-01-24 22:09:30 -0800207endif
Travis Geiselbrecht78d0e6c2009-11-27 13:37:03 -0800208
209endif # make spotless