blob: 7082311010a218e81963bcce15ec817d75fe6e68 [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
Sridhar Parasurame94e8152014-10-24 14:06:03 -070063ifeq ($(TARGET_BUILD_VARIANT),user)
64 CFLAGS += -DDISABLE_FASTBOOT_CMDS=1
65endif
66
anisha agarwalebc52bc2016-07-08 15:50:00 -070067ifeq ($(APPEND_CMDLINE),1)
68 CFLAGS += -D_APPEND_CMDLINE=1
69endif
70
Channagoud Kadabi02072a42014-02-28 19:15:40 -080071# setup toolchain prefix
72TOOLCHAIN_PREFIX ?= arm-eabi-
Maria Yud3200512014-05-28 15:57:51 +080073CFLAGS += -fstack-protector-all
vijay kumarc2119f12014-07-22 18:30:11 +053074CFLAGS += -fno-strict-overflow
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070075CPPFLAGS := -fno-exceptions -fno-rtti -fno-threadsafe-statics
76#CPPFLAGS += -Weffc++
77ASMFLAGS := -DASSEMBLY
78LDFLAGS :=
79
80CFLAGS += -ffunction-sections -fdata-sections
81LDFLAGS += -gc-sections
82
83# top level rule
Channagoud Kadabi02072a42014-02-28 19:15:40 -080084all:: $(OUTBIN) $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym $(OUTELF).size $(OUTELF_STRIP) APPSBOOTHEADER
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070085
86# the following three object lists are identical except for the ordering
87# which is bootobjs, kobjs, objs
88BOOTOBJS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070089OBJS :=
90
91# a linker script needs to be declared in one of the project/target/platform files
92LINKER_SCRIPT :=
93
94# anything you add here will be deleted in make clean
95GENERATED := $(CONFIGHEADER)
96
97# anything added to DEFINES will be put into $(BUILDDIR)/config.h
98DEFINES := LK=1
99
100# Anything added to SRCDEPS will become a dependency of every source file in the system.
101# Useful for header files that may be included by one or more source files.
102SRCDEPS := $(CONFIGHEADER)
103
Shashank Mittale99a8d32014-09-11 19:51:06 -0700104ifeq ($(VERIFIED_BOOT),1)
105 DEFINES += VERIFIED_BOOT=1
106 DEFINES += _SIGNED_KERNEL=1
107 ifeq ($(DEFAULT_UNLOCK),true)
108 DEFINES += DEFAULT_UNLOCK=1
109 endif
110endif
111
Vijay Kumar Pendoti2f869052016-07-15 12:04:19 +0530112ifeq ($(OSVERSION_IN_BOOTIMAGE),1)
113 DEFINES += OSVERSION_IN_BOOTIMAGE=1
114endif
115
116ifeq ($(ENABLE_VB_ATTEST),1)
117 DEFINES += ENABLE_VB_ATTEST=1
118endif
119
Channagoud Kadabi9071af32015-03-12 12:39:56 -0700120ifeq ($(USER_BUILD_VARIANT),true)
121 DEFINES += USER_BUILD_VARIANT=1
122endif
123
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700124# these need to be filled out by the project/target/platform rules.mk files
125TARGET :=
126PLATFORM :=
127ARCH :=
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700128ALLMODULES :=
129MODULES :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700130
131# any rules you put here will also be built by the system before considered being complete
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700132EXTRA_BUILDDEPS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700133
134# any rules you put here will be depended on in clean builds
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700135EXTRA_CLEANDEPS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700136
Travis Geiselbrecht577036f2009-01-24 21:37:21 -0800137include project/$(PROJECT).mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700138include target/$(TARGET)/rules.mk
Chandan Uddarajua9b07bb2009-11-21 12:22:02 -0800139include target/$(TARGET)/tools/makefile
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700140include platform/$(PLATFORM)/rules.mk
141include arch/$(ARCH)/rules.mk
142include platform/rules.mk
143include target/rules.mk
144include kernel/rules.mk
145include dev/rules.mk
Travis Geiselbrecht68372232009-01-24 21:21:08 -0800146include app/rules.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700147
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700148# recursively include any modules in the MODULE variable, leaving a trail of included
149# modules in the ALLMODULES list
Travis Geiselbrecht5bcbd9d2009-01-24 20:15:32 -0800150include make/module.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700151
152# any extra top level build dependencies that someone declared
153all:: $(EXTRA_BUILDDEPS)
154
155ALLOBJS := \
156 $(BOOTOBJS) \
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700157 $(OBJS)
158
159# add some automatic configuration defines
160DEFINES += \
lijuang42d0ec42015-12-04 17:36:51 +0800161 BOARD=$(BOARD_NAME) \
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700162 PROJECT_$(PROJECT)=1 \
163 TARGET_$(TARGET)=1 \
164 PLATFORM_$(PLATFORM)=1 \
165 ARCH_$(ARCH)=1 \
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700166 $(addsuffix =1,$(addprefix WITH_,$(ALLMODULES)))
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700167
168# debug build?
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700169ifneq ($(DEBUG),)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700170DEFINES += \
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700171 DEBUG=$(DEBUG)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700172endif
173
174ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS))
175
176DEPS := $(ALLOBJS:%o=%d)
177
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700178# default to no ccache
179CCACHE ?=
180CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
Channagoud Kadabi02072a42014-02-28 19:15:40 -0800181ifeq ($(LD),ld)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700182LD := $(TOOLCHAIN_PREFIX)ld
Channagoud Kadabi02072a42014-02-28 19:15:40 -0800183endif
184STRIP := $(TOOLCHAIN_PREFIX)strip
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700185OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
186OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
187CPPFILT := $(TOOLCHAIN_PREFIX)c++filt
188SIZE := $(TOOLCHAIN_PREFIX)size
189NM := $(TOOLCHAIN_PREFIX)nm
190
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700191# comment out or override if you want to see the full output of each command
192NOECHO ?= @
193
194# the logic to compile and link stuff is in here
Travis Geiselbrecht5bcbd9d2009-01-24 20:15:32 -0800195include make/build.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700196
197clean: $(EXTRA_CLEANDEPS)
Channagoud Kadabi02072a42014-02-28 19:15:40 -0800198 rm -f $(ALLOBJS) $(DEPS) $(GENERATED) $(OUTBIN) $(OUTELF) $(OUTELF).lst $(OUTELF_STRIP)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700199
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700200install: all
201 scp $(OUTBIN) 192.168.0.4:/tftproot
202
203# generate a config.h file with all of the DEFINES laid out in #define format
204configheader:
205
206$(CONFIGHEADER): configheader
207 @$(MKDIR)
208 @echo generating $@
209 @rm -f $(CONFIGHEADER).tmp; \
210 echo \#ifndef __CONFIG_H > $(CONFIGHEADER).tmp; \
211 echo \#define __CONFIG_H >> $(CONFIGHEADER).tmp; \
212 for d in `echo $(DEFINES) | tr [:lower:] [:upper:]`; do \
213 echo "#define $$d" | sed "s/=/\ /g;s/-/_/g;s/\//_/g" >> $(CONFIGHEADER).tmp; \
214 done; \
215 echo \#endif >> $(CONFIGHEADER).tmp; \
216 if [ -f "$(CONFIGHEADER)" ]; then \
217 if cmp "$(CONFIGHEADER).tmp" "$(CONFIGHEADER)"; then \
218 rm -f $(CONFIGHEADER).tmp; \
219 else \
220 mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \
221 fi \
222 else \
223 mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \
224 fi
225
226# Empty rule for the .d files. The above rules will build .d files as a side
227# effect. Only works on gcc 3.x and above, however.
228%.d:
229
230ifeq ($(filter $(MAKECMDGOALS), clean), )
231-include $(DEPS)
232endif
233
234.PHONY: configheader
Brian Swetlandf1e5afd2009-01-24 22:09:30 -0800235endif
Travis Geiselbrecht78d0e6c2009-11-27 13:37:03 -0800236
237endif # make spotless