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 | |
Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 67 | # setup toolchain prefix |
| 68 | TOOLCHAIN_PREFIX ?= arm-eabi- |
Maria Yu | d320051 | 2014-05-28 15:57:51 +0800 | [diff] [blame] | 69 | CFLAGS += -fstack-protector-all |
vijay kumar | c2119f1 | 2014-07-22 18:30:11 +0530 | [diff] [blame] | 70 | CFLAGS += -fno-strict-overflow |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 71 | CPPFLAGS := -fno-exceptions -fno-rtti -fno-threadsafe-statics |
| 72 | #CPPFLAGS += -Weffc++ |
| 73 | ASMFLAGS := -DASSEMBLY |
| 74 | LDFLAGS := |
| 75 | |
| 76 | CFLAGS += -ffunction-sections -fdata-sections |
| 77 | LDFLAGS += -gc-sections |
| 78 | |
| 79 | # top level rule |
Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 80 | 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] | 81 | |
| 82 | # the following three object lists are identical except for the ordering |
| 83 | # which is bootobjs, kobjs, objs |
| 84 | BOOTOBJS := |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 85 | OBJS := |
| 86 | |
| 87 | # a linker script needs to be declared in one of the project/target/platform files |
| 88 | LINKER_SCRIPT := |
| 89 | |
| 90 | # anything you add here will be deleted in make clean |
| 91 | GENERATED := $(CONFIGHEADER) |
| 92 | |
| 93 | # anything added to DEFINES will be put into $(BUILDDIR)/config.h |
| 94 | DEFINES := LK=1 |
| 95 | |
| 96 | # Anything added to SRCDEPS will become a dependency of every source file in the system. |
| 97 | # Useful for header files that may be included by one or more source files. |
| 98 | SRCDEPS := $(CONFIGHEADER) |
| 99 | |
| 100 | # these need to be filled out by the project/target/platform rules.mk files |
| 101 | TARGET := |
| 102 | PLATFORM := |
| 103 | ARCH := |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 104 | ALLMODULES := |
| 105 | MODULES := |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 106 | |
| 107 | # 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] | 108 | EXTRA_BUILDDEPS := |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 109 | |
| 110 | # any rules you put here will be depended on in clean builds |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 111 | EXTRA_CLEANDEPS := |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 112 | |
Travis Geiselbrecht | 577036f | 2009-01-24 21:37:21 -0800 | [diff] [blame] | 113 | include project/$(PROJECT).mk |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 114 | include target/$(TARGET)/rules.mk |
Chandan Uddaraju | a9b07bb | 2009-11-21 12:22:02 -0800 | [diff] [blame] | 115 | include target/$(TARGET)/tools/makefile |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 116 | include platform/$(PLATFORM)/rules.mk |
| 117 | include arch/$(ARCH)/rules.mk |
| 118 | include platform/rules.mk |
| 119 | include target/rules.mk |
| 120 | include kernel/rules.mk |
| 121 | include dev/rules.mk |
Travis Geiselbrecht | 6837223 | 2009-01-24 21:21:08 -0800 | [diff] [blame] | 122 | include app/rules.mk |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 123 | |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 124 | # recursively include any modules in the MODULE variable, leaving a trail of included |
| 125 | # modules in the ALLMODULES list |
Travis Geiselbrecht | 5bcbd9d | 2009-01-24 20:15:32 -0800 | [diff] [blame] | 126 | include make/module.mk |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 127 | |
| 128 | # any extra top level build dependencies that someone declared |
| 129 | all:: $(EXTRA_BUILDDEPS) |
| 130 | |
| 131 | ALLOBJS := \ |
| 132 | $(BOOTOBJS) \ |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 133 | $(OBJS) |
| 134 | |
| 135 | # add some automatic configuration defines |
| 136 | DEFINES += \ |
Subbaraman Narayanamurthy | eb92bcc | 2010-07-20 14:32:46 -0700 | [diff] [blame] | 137 | BOARD=$(PROJECT) \ |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 138 | PROJECT_$(PROJECT)=1 \ |
| 139 | TARGET_$(TARGET)=1 \ |
| 140 | PLATFORM_$(PLATFORM)=1 \ |
| 141 | ARCH_$(ARCH)=1 \ |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 142 | $(addsuffix =1,$(addprefix WITH_,$(ALLMODULES))) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 143 | |
| 144 | # debug build? |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 145 | ifneq ($(DEBUG),) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 146 | DEFINES += \ |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 147 | DEBUG=$(DEBUG) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 148 | endif |
| 149 | |
| 150 | ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS)) |
| 151 | |
| 152 | DEPS := $(ALLOBJS:%o=%d) |
| 153 | |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 154 | # default to no ccache |
| 155 | CCACHE ?= |
| 156 | CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc |
Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 157 | ifeq ($(LD),ld) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 158 | LD := $(TOOLCHAIN_PREFIX)ld |
Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 159 | endif |
| 160 | STRIP := $(TOOLCHAIN_PREFIX)strip |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 161 | OBJDUMP := $(TOOLCHAIN_PREFIX)objdump |
| 162 | OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy |
| 163 | CPPFILT := $(TOOLCHAIN_PREFIX)c++filt |
| 164 | SIZE := $(TOOLCHAIN_PREFIX)size |
| 165 | NM := $(TOOLCHAIN_PREFIX)nm |
| 166 | |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 167 | # comment out or override if you want to see the full output of each command |
| 168 | NOECHO ?= @ |
| 169 | |
| 170 | # the logic to compile and link stuff is in here |
Travis Geiselbrecht | 5bcbd9d | 2009-01-24 20:15:32 -0800 | [diff] [blame] | 171 | include make/build.mk |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 172 | |
| 173 | clean: $(EXTRA_CLEANDEPS) |
Channagoud Kadabi | 02072a4 | 2014-02-28 19:15:40 -0800 | [diff] [blame] | 174 | rm -f $(ALLOBJS) $(DEPS) $(GENERATED) $(OUTBIN) $(OUTELF) $(OUTELF).lst $(OUTELF_STRIP) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 175 | |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 176 | install: all |
| 177 | scp $(OUTBIN) 192.168.0.4:/tftproot |
| 178 | |
| 179 | # generate a config.h file with all of the DEFINES laid out in #define format |
| 180 | configheader: |
| 181 | |
| 182 | $(CONFIGHEADER): configheader |
| 183 | @$(MKDIR) |
| 184 | @echo generating $@ |
| 185 | @rm -f $(CONFIGHEADER).tmp; \ |
| 186 | echo \#ifndef __CONFIG_H > $(CONFIGHEADER).tmp; \ |
| 187 | echo \#define __CONFIG_H >> $(CONFIGHEADER).tmp; \ |
| 188 | for d in `echo $(DEFINES) | tr [:lower:] [:upper:]`; do \ |
| 189 | echo "#define $$d" | sed "s/=/\ /g;s/-/_/g;s/\//_/g" >> $(CONFIGHEADER).tmp; \ |
| 190 | done; \ |
| 191 | echo \#endif >> $(CONFIGHEADER).tmp; \ |
| 192 | if [ -f "$(CONFIGHEADER)" ]; then \ |
| 193 | if cmp "$(CONFIGHEADER).tmp" "$(CONFIGHEADER)"; then \ |
| 194 | rm -f $(CONFIGHEADER).tmp; \ |
| 195 | else \ |
| 196 | mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \ |
| 197 | fi \ |
| 198 | else \ |
| 199 | mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \ |
| 200 | fi |
| 201 | |
| 202 | # Empty rule for the .d files. The above rules will build .d files as a side |
| 203 | # effect. Only works on gcc 3.x and above, however. |
| 204 | %.d: |
| 205 | |
| 206 | ifeq ($(filter $(MAKECMDGOALS), clean), ) |
| 207 | -include $(DEPS) |
| 208 | endif |
| 209 | |
| 210 | .PHONY: configheader |
Brian Swetland | f1e5afd | 2009-01-24 22:09:30 -0800 | [diff] [blame] | 211 | endif |
Travis Geiselbrecht | 78d0e6c | 2009-11-27 13:37:03 -0800 | [diff] [blame] | 212 | |
| 213 | endif # make spotless |