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