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