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