Travis Geiselbrecht | 78d0e6c | 2009-11-27 13:37:03 -0800 | [diff] [blame] | 1 | ifeq ($(MAKECMDGOALS),spotless) |
| 2 | spotless: |
| 3 | rm -rf build-* |
| 4 | else |
| 5 | |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 6 | -include local.mk |
Travis Geiselbrecht | 5bcbd9d | 2009-01-24 20:15:32 -0800 | [diff] [blame] | 7 | include make/macros.mk |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 8 | |
Brian Swetland | f1e5afd | 2009-01-24 22:09:30 -0800 | [diff] [blame] | 9 | # 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 | |
| 13 | project-name := $(firstword $(MAKECMDGOALS)) |
| 14 | |
| 15 | ifneq ($(project-name),) |
| 16 | ifneq ($(wildcard project/$(project-name).mk),) |
| 17 | do-nothing := 1 |
| 18 | $(MAKECMDGOALS) _all: make-make |
| 19 | make-make: |
| 20 | @PROJECT=$(project-name) $(MAKE) $(filter-out $(project-name), $(MAKECMDGOALS)) |
| 21 | endif |
| 22 | endif |
| 23 | |
| 24 | ifeq ($(do-nothing),) |
| 25 | |
| 26 | ifeq ($(PROJECT),) |
| 27 | $(error No project specified. Use "make projectname" or put "PROJECT := projectname" in local.mk) |
| 28 | endif |
| 29 | |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 30 | DEBUG ?= 0 |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 31 | |
Chandan Uddaraju | a9b07bb | 2009-11-21 12:22:02 -0800 | [diff] [blame] | 32 | ifndef $(BOOTLOADER_OUT) |
| 33 | BOOTLOADER_OUT := . |
| 34 | endif |
| 35 | |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 36 | LK_TOP_DIR:= . |
Chandan Uddaraju | a9b07bb | 2009-11-21 12:22:02 -0800 | [diff] [blame] | 37 | BUILDDIR := $(BOOTLOADER_OUT)/build-$(PROJECT) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 38 | OUTBIN := $(BUILDDIR)/lk.bin |
| 39 | OUTELF := $(BUILDDIR)/lk |
Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 40 | OUTELF_STRIP := $(BUILDDIR)/lk_s.elf |
| 41 | |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 42 | CONFIGHEADER := $(BUILDDIR)/config.h |
| 43 | |
Subbaraman Narayanamurthy | 8bcd5fd | 2011-01-17 17:18:44 -0800 | [diff] [blame] | 44 | #Initialize the command-line flag ENABLE_TRUSTZONE. Value for flag passed in at command-line will take precedence |
| 45 | ENABLE_TRUSTZONE := 0 |
| 46 | |
| 47 | ifeq ($(ENABLE_TRUSTZONE),1) |
| 48 | INPUT_TZ_BIN := tzbsp/tzbsp.bin |
| 49 | OUTPUT_TZ_BIN := $(BUILDDIR)/tzbsp_bin.o |
| 50 | endif |
| 51 | |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 52 | INCLUDES := -I$(BUILDDIR) -Iinclude |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 53 | CFLAGS := -O2 -g -fno-builtin -finline -W -Wall -Wno-multichar -Wno-unused-parameter -Wno-unused-function -include $(CONFIGHEADER) |
| 54 | #CFLAGS += -Werror |
David Ng | 025c1d9 | 2009-12-09 23:46:00 -0800 | [diff] [blame] | 55 | ifeq ($(EMMC_BOOT),1) |
| 56 | CFLAGS += -D_EMMC_BOOT=1 |
| 57 | endif |
Shashank Mittal | cd98d47 | 2011-08-02 14:29:24 -0700 | [diff] [blame] | 58 | |
| 59 | ifeq ($(SIGNED_KERNEL),1) |
| 60 | CFLAGS += -D_SIGNED_KERNEL=1 |
| 61 | endif |
| 62 | |
Sridhar Parasuram | e94e815 | 2014-10-24 14:06:03 -0700 | [diff] [blame] | 63 | ifeq ($(TARGET_BUILD_VARIANT),user) |
| 64 | CFLAGS += -DDISABLE_FASTBOOT_CMDS=1 |
| 65 | endif |
| 66 | |
anisha agarwal | ebc52bc | 2016-07-08 15:50:00 -0700 | [diff] [blame] | 67 | ifeq ($(APPEND_CMDLINE),1) |
| 68 | CFLAGS += -D_APPEND_CMDLINE=1 |
| 69 | endif |
| 70 | |
Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 71 | # setup toolchain prefix |
| 72 | TOOLCHAIN_PREFIX ?= arm-eabi- |
Maria Yu | d320051 | 2014-05-28 15:57:51 +0800 | [diff] [blame] | 73 | CFLAGS += -fstack-protector-all |
vijay kumar | c2119f1 | 2014-07-22 18:30:11 +0530 | [diff] [blame] | 74 | CFLAGS += -fno-strict-overflow |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 75 | CPPFLAGS := -fno-exceptions -fno-rtti -fno-threadsafe-statics |
| 76 | #CPPFLAGS += -Weffc++ |
| 77 | ASMFLAGS := -DASSEMBLY |
| 78 | LDFLAGS := |
| 79 | |
| 80 | CFLAGS += -ffunction-sections -fdata-sections |
| 81 | LDFLAGS += -gc-sections |
| 82 | |
| 83 | # top level rule |
Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 84 | all:: $(OUTBIN) $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym $(OUTELF).size $(OUTELF_STRIP) APPSBOOTHEADER |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 85 | |
| 86 | # the following three object lists are identical except for the ordering |
| 87 | # which is bootobjs, kobjs, objs |
| 88 | BOOTOBJS := |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 89 | OBJS := |
| 90 | |
| 91 | # a linker script needs to be declared in one of the project/target/platform files |
| 92 | LINKER_SCRIPT := |
| 93 | |
| 94 | # anything you add here will be deleted in make clean |
| 95 | GENERATED := $(CONFIGHEADER) |
| 96 | |
| 97 | # anything added to DEFINES will be put into $(BUILDDIR)/config.h |
| 98 | DEFINES := 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. |
| 102 | SRCDEPS := $(CONFIGHEADER) |
| 103 | |
Shashank Mittal | e99a8d3 | 2014-09-11 19:51:06 -0700 | [diff] [blame] | 104 | ifeq ($(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 |
| 110 | endif |
| 111 | |
Vijay Kumar Pendoti | 2f86905 | 2016-07-15 12:04:19 +0530 | [diff] [blame] | 112 | ifeq ($(OSVERSION_IN_BOOTIMAGE),1) |
| 113 | DEFINES += OSVERSION_IN_BOOTIMAGE=1 |
| 114 | endif |
| 115 | |
| 116 | ifeq ($(ENABLE_VB_ATTEST),1) |
| 117 | DEFINES += ENABLE_VB_ATTEST=1 |
| 118 | endif |
| 119 | |
Channagoud Kadabi | 9071af3 | 2015-03-12 12:39:56 -0700 | [diff] [blame] | 120 | ifeq ($(USER_BUILD_VARIANT),true) |
| 121 | DEFINES += USER_BUILD_VARIANT=1 |
| 122 | endif |
| 123 | |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 124 | # these need to be filled out by the project/target/platform rules.mk files |
| 125 | TARGET := |
| 126 | PLATFORM := |
| 127 | ARCH := |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 128 | ALLMODULES := |
| 129 | MODULES := |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 130 | |
| 131 | # any rules you put here will also be built by the system before considered being complete |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 132 | EXTRA_BUILDDEPS := |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 133 | |
| 134 | # any rules you put here will be depended on in clean builds |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 135 | EXTRA_CLEANDEPS := |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 136 | |
Travis Geiselbrecht | 577036f | 2009-01-24 21:37:21 -0800 | [diff] [blame] | 137 | include project/$(PROJECT).mk |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 138 | include target/$(TARGET)/rules.mk |
Chandan Uddaraju | a9b07bb | 2009-11-21 12:22:02 -0800 | [diff] [blame] | 139 | include target/$(TARGET)/tools/makefile |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 140 | include platform/$(PLATFORM)/rules.mk |
| 141 | include arch/$(ARCH)/rules.mk |
| 142 | include platform/rules.mk |
| 143 | include target/rules.mk |
| 144 | include kernel/rules.mk |
| 145 | include dev/rules.mk |
Travis Geiselbrecht | 6837223 | 2009-01-24 21:21:08 -0800 | [diff] [blame] | 146 | include app/rules.mk |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 147 | |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 148 | # recursively include any modules in the MODULE variable, leaving a trail of included |
| 149 | # modules in the ALLMODULES list |
Travis Geiselbrecht | 5bcbd9d | 2009-01-24 20:15:32 -0800 | [diff] [blame] | 150 | include make/module.mk |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 151 | |
| 152 | # any extra top level build dependencies that someone declared |
| 153 | all:: $(EXTRA_BUILDDEPS) |
| 154 | |
| 155 | ALLOBJS := \ |
| 156 | $(BOOTOBJS) \ |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 157 | $(OBJS) |
| 158 | |
| 159 | # add some automatic configuration defines |
| 160 | DEFINES += \ |
lijuang | 42d0ec4 | 2015-12-04 17:36:51 +0800 | [diff] [blame] | 161 | BOARD=$(BOARD_NAME) \ |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 162 | PROJECT_$(PROJECT)=1 \ |
| 163 | TARGET_$(TARGET)=1 \ |
| 164 | PLATFORM_$(PLATFORM)=1 \ |
| 165 | ARCH_$(ARCH)=1 \ |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 166 | $(addsuffix =1,$(addprefix WITH_,$(ALLMODULES))) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 167 | |
| 168 | # debug build? |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 169 | ifneq ($(DEBUG),) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 170 | DEFINES += \ |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 171 | DEBUG=$(DEBUG) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 172 | endif |
| 173 | |
| 174 | ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS)) |
| 175 | |
| 176 | DEPS := $(ALLOBJS:%o=%d) |
| 177 | |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 178 | # default to no ccache |
| 179 | CCACHE ?= |
| 180 | CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc |
Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 181 | ifeq ($(LD),ld) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 182 | LD := $(TOOLCHAIN_PREFIX)ld |
Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 183 | endif |
| 184 | STRIP := $(TOOLCHAIN_PREFIX)strip |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 185 | OBJDUMP := $(TOOLCHAIN_PREFIX)objdump |
| 186 | OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy |
| 187 | CPPFILT := $(TOOLCHAIN_PREFIX)c++filt |
| 188 | SIZE := $(TOOLCHAIN_PREFIX)size |
| 189 | NM := $(TOOLCHAIN_PREFIX)nm |
| 190 | |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 191 | # comment out or override if you want to see the full output of each command |
| 192 | NOECHO ?= @ |
| 193 | |
| 194 | # the logic to compile and link stuff is in here |
Travis Geiselbrecht | 5bcbd9d | 2009-01-24 20:15:32 -0800 | [diff] [blame] | 195 | include make/build.mk |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 196 | |
| 197 | clean: $(EXTRA_CLEANDEPS) |
Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 198 | rm -f $(ALLOBJS) $(DEPS) $(GENERATED) $(OUTBIN) $(OUTELF) $(OUTELF).lst $(OUTELF_STRIP) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 199 | |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 200 | install: 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 |
| 204 | configheader: |
| 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 | |
| 230 | ifeq ($(filter $(MAKECMDGOALS), clean), ) |
| 231 | -include $(DEPS) |
| 232 | endif |
| 233 | |
| 234 | .PHONY: configheader |
Brian Swetland | f1e5afd | 2009-01-24 22:09:30 -0800 | [diff] [blame] | 235 | endif |
Travis Geiselbrecht | 78d0e6c | 2009-11-27 13:37:03 -0800 | [diff] [blame] | 236 | |
| 237 | endif # make spotless |