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