Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 1 | -include local.mk |
Travis Geiselbrecht | 5bcbd9d | 2009-01-24 20:15:32 -0800 | [diff] [blame] | 2 | include make/macros.mk |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 3 | |
Brian Swetland | f1e5afd | 2009-01-24 22:09:30 -0800 | [diff] [blame] | 4 | # If one of our goals (from the commandline) happens to have a |
| 5 | # matching project/goal.mk, then we should re-invoke make with |
| 6 | # that project name specified... |
| 7 | |
| 8 | project-name := $(firstword $(MAKECMDGOALS)) |
| 9 | |
| 10 | ifneq ($(project-name),) |
| 11 | ifneq ($(wildcard project/$(project-name).mk),) |
| 12 | do-nothing := 1 |
| 13 | $(MAKECMDGOALS) _all: make-make |
| 14 | make-make: |
| 15 | @PROJECT=$(project-name) $(MAKE) $(filter-out $(project-name), $(MAKECMDGOALS)) |
| 16 | endif |
| 17 | endif |
| 18 | |
| 19 | ifeq ($(do-nothing),) |
| 20 | |
| 21 | ifeq ($(PROJECT),) |
| 22 | $(error No project specified. Use "make projectname" or put "PROJECT := projectname" in local.mk) |
| 23 | endif |
| 24 | |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 25 | DEBUG ?= 0 |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 26 | |
Chandan Uddaraju | a9b07bb | 2009-11-21 12:22:02 -0800 | [diff] [blame] | 27 | ifndef $(BOOTLOADER_OUT) |
| 28 | BOOTLOADER_OUT := . |
| 29 | endif |
| 30 | |
Chandan Uddaraju | 885e4db | 2009-12-03 22:45:26 -0800 | [diff] [blame] | 31 | LK_TOP_DIR:= . |
Chandan Uddaraju | a9b07bb | 2009-11-21 12:22:02 -0800 | [diff] [blame] | 32 | BUILDDIR := $(BOOTLOADER_OUT)/build-$(PROJECT) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 33 | OUTBIN := $(BUILDDIR)/lk.bin |
| 34 | OUTELF := $(BUILDDIR)/lk |
| 35 | CONFIGHEADER := $(BUILDDIR)/config.h |
| 36 | |
Subbaraman Narayanamurthy | 8bcd5fd | 2011-01-17 17:18:44 -0800 | [diff] [blame] | 37 | #Initialize the command-line flag ENABLE_TRUSTZONE. Value for flag passed in at command-line will take precedence |
| 38 | ENABLE_TRUSTZONE := 0 |
| 39 | |
| 40 | ifeq ($(ENABLE_TRUSTZONE),1) |
| 41 | INPUT_TZ_BIN := tzbsp/tzbsp.bin |
| 42 | OUTPUT_TZ_BIN := $(BUILDDIR)/tzbsp_bin.o |
| 43 | endif |
| 44 | |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 45 | INCLUDES := -I$(BUILDDIR) -Iinclude |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 46 | CFLAGS := -O2 -g -fno-builtin -finline -W -Wall -Wno-multichar -Wno-unused-parameter -Wno-unused-function -include $(CONFIGHEADER) |
| 47 | #CFLAGS += -Werror |
David Ng | 025c1d9 | 2009-12-09 23:46:00 -0800 | [diff] [blame] | 48 | ifeq ($(EMMC_BOOT),1) |
| 49 | CFLAGS += -D_EMMC_BOOT=1 |
| 50 | endif |
Christopher Johnson | 36cd703 | 2010-11-09 14:46:30 -0700 | [diff] [blame] | 51 | # When the host arch is ARM, ensure stack protection code is not emitted since |
| 52 | # it's not supported by the bootloader's libc |
| 53 | ifneq ($(shell uname -m | grep "arm.*"),) |
| 54 | CFLAGS += -fno-stack-protector |
| 55 | endif |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 56 | CPPFLAGS := -fno-exceptions -fno-rtti -fno-threadsafe-statics |
| 57 | #CPPFLAGS += -Weffc++ |
| 58 | ASMFLAGS := -DASSEMBLY |
| 59 | LDFLAGS := |
| 60 | |
| 61 | CFLAGS += -ffunction-sections -fdata-sections |
| 62 | LDFLAGS += -gc-sections |
| 63 | |
| 64 | # top level rule |
Chandan Uddaraju | a9b07bb | 2009-11-21 12:22:02 -0800 | [diff] [blame] | 65 | all:: $(OUTBIN) $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym $(OUTELF).size APPSBOOTHEADER |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 66 | |
| 67 | # the following three object lists are identical except for the ordering |
| 68 | # which is bootobjs, kobjs, objs |
| 69 | BOOTOBJS := |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 70 | OBJS := |
| 71 | |
| 72 | # a linker script needs to be declared in one of the project/target/platform files |
| 73 | LINKER_SCRIPT := |
| 74 | |
| 75 | # anything you add here will be deleted in make clean |
| 76 | GENERATED := $(CONFIGHEADER) |
| 77 | |
| 78 | # anything added to DEFINES will be put into $(BUILDDIR)/config.h |
| 79 | DEFINES := LK=1 |
| 80 | |
| 81 | # Anything added to SRCDEPS will become a dependency of every source file in the system. |
| 82 | # Useful for header files that may be included by one or more source files. |
| 83 | SRCDEPS := $(CONFIGHEADER) |
| 84 | |
| 85 | # these need to be filled out by the project/target/platform rules.mk files |
| 86 | TARGET := |
| 87 | PLATFORM := |
| 88 | ARCH := |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 89 | ALLMODULES := |
| 90 | MODULES := |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 91 | |
| 92 | # 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] | 93 | EXTRA_BUILDDEPS := |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 94 | |
| 95 | # any rules you put here will be depended on in clean builds |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 96 | EXTRA_CLEANDEPS := |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 97 | |
Travis Geiselbrecht | 577036f | 2009-01-24 21:37:21 -0800 | [diff] [blame] | 98 | include project/$(PROJECT).mk |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 99 | include target/$(TARGET)/rules.mk |
Chandan Uddaraju | a9b07bb | 2009-11-21 12:22:02 -0800 | [diff] [blame] | 100 | include target/$(TARGET)/tools/makefile |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 101 | include platform/$(PLATFORM)/rules.mk |
| 102 | include arch/$(ARCH)/rules.mk |
| 103 | include platform/rules.mk |
| 104 | include target/rules.mk |
| 105 | include kernel/rules.mk |
| 106 | include dev/rules.mk |
Travis Geiselbrecht | 6837223 | 2009-01-24 21:21:08 -0800 | [diff] [blame] | 107 | include app/rules.mk |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 108 | |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 109 | # recursively include any modules in the MODULE variable, leaving a trail of included |
| 110 | # modules in the ALLMODULES list |
Travis Geiselbrecht | 5bcbd9d | 2009-01-24 20:15:32 -0800 | [diff] [blame] | 111 | include make/module.mk |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 112 | |
| 113 | # any extra top level build dependencies that someone declared |
| 114 | all:: $(EXTRA_BUILDDEPS) |
| 115 | |
| 116 | ALLOBJS := \ |
| 117 | $(BOOTOBJS) \ |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 118 | $(OBJS) |
| 119 | |
| 120 | # add some automatic configuration defines |
| 121 | DEFINES += \ |
Subbaraman Narayanamurthy | eb92bcc | 2010-07-20 14:32:46 -0700 | [diff] [blame] | 122 | BOARD=$(PROJECT) \ |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 123 | PROJECT_$(PROJECT)=1 \ |
| 124 | TARGET_$(TARGET)=1 \ |
| 125 | PLATFORM_$(PLATFORM)=1 \ |
| 126 | ARCH_$(ARCH)=1 \ |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 127 | $(addsuffix =1,$(addprefix WITH_,$(ALLMODULES))) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 128 | |
| 129 | # debug build? |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 130 | ifneq ($(DEBUG),) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 131 | DEFINES += \ |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 132 | DEBUG=$(DEBUG) |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 133 | endif |
| 134 | |
| 135 | ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS)) |
| 136 | |
| 137 | DEPS := $(ALLOBJS:%o=%d) |
| 138 | |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 139 | # default to no ccache |
| 140 | CCACHE ?= |
| 141 | CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 142 | LD := $(TOOLCHAIN_PREFIX)ld |
| 143 | OBJDUMP := $(TOOLCHAIN_PREFIX)objdump |
| 144 | OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy |
| 145 | CPPFILT := $(TOOLCHAIN_PREFIX)c++filt |
| 146 | SIZE := $(TOOLCHAIN_PREFIX)size |
| 147 | NM := $(TOOLCHAIN_PREFIX)nm |
| 148 | |
Travis Geiselbrecht | f54ab82 | 2008-09-05 04:14:40 -0700 | [diff] [blame] | 149 | # comment out or override if you want to see the full output of each command |
| 150 | NOECHO ?= @ |
| 151 | |
| 152 | # the logic to compile and link stuff is in here |
Travis Geiselbrecht | 5bcbd9d | 2009-01-24 20:15:32 -0800 | [diff] [blame] | 153 | include make/build.mk |
Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 154 | |
| 155 | clean: $(EXTRA_CLEANDEPS) |
| 156 | rm -f $(ALLOBJS) $(DEPS) $(GENERATED) $(OUTBIN) $(OUTELF) $(OUTELF).lst |
| 157 | |
| 158 | spotless: |
| 159 | rm -rf build-* |
| 160 | |
| 161 | install: all |
| 162 | scp $(OUTBIN) 192.168.0.4:/tftproot |
| 163 | |
| 164 | # generate a config.h file with all of the DEFINES laid out in #define format |
| 165 | configheader: |
| 166 | |
| 167 | $(CONFIGHEADER): configheader |
| 168 | @$(MKDIR) |
| 169 | @echo generating $@ |
| 170 | @rm -f $(CONFIGHEADER).tmp; \ |
| 171 | echo \#ifndef __CONFIG_H > $(CONFIGHEADER).tmp; \ |
| 172 | echo \#define __CONFIG_H >> $(CONFIGHEADER).tmp; \ |
| 173 | for d in `echo $(DEFINES) | tr [:lower:] [:upper:]`; do \ |
| 174 | echo "#define $$d" | sed "s/=/\ /g;s/-/_/g;s/\//_/g" >> $(CONFIGHEADER).tmp; \ |
| 175 | done; \ |
| 176 | echo \#endif >> $(CONFIGHEADER).tmp; \ |
| 177 | if [ -f "$(CONFIGHEADER)" ]; then \ |
| 178 | if cmp "$(CONFIGHEADER).tmp" "$(CONFIGHEADER)"; then \ |
| 179 | rm -f $(CONFIGHEADER).tmp; \ |
| 180 | else \ |
| 181 | mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \ |
| 182 | fi \ |
| 183 | else \ |
| 184 | mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \ |
| 185 | fi |
| 186 | |
| 187 | # Empty rule for the .d files. The above rules will build .d files as a side |
| 188 | # effect. Only works on gcc 3.x and above, however. |
| 189 | %.d: |
| 190 | |
| 191 | ifeq ($(filter $(MAKECMDGOALS), clean), ) |
| 192 | -include $(DEPS) |
| 193 | endif |
| 194 | |
| 195 | .PHONY: configheader |
Brian Swetland | f1e5afd | 2009-01-24 22:09:30 -0800 | [diff] [blame] | 196 | endif |