blob: d3fe248aedf55653c0f428653d22c3ca64b37c68 [file] [log] [blame]
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07001-include local.mk
Travis Geiselbrecht5bcbd9d2009-01-24 20:15:32 -08002include make/macros.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -07003
Brian Swetlandf1e5afd2009-01-24 22:09:30 -08004# 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
8project-name := $(firstword $(MAKECMDGOALS))
9
10ifneq ($(project-name),)
11ifneq ($(wildcard project/$(project-name).mk),)
12do-nothing := 1
13$(MAKECMDGOALS) _all: make-make
14make-make:
15 @PROJECT=$(project-name) $(MAKE) $(filter-out $(project-name), $(MAKECMDGOALS))
16endif
17endif
18
19ifeq ($(do-nothing),)
20
21ifeq ($(PROJECT),)
22$(error No project specified. Use "make projectname" or put "PROJECT := projectname" in local.mk)
23endif
24
Travis Geiselbrechteb946052008-09-07 22:32:49 -070025DEBUG ?= 2
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070026
27BUILDDIR := build-$(PROJECT)
28OUTBIN := $(BUILDDIR)/lk.bin
29OUTELF := $(BUILDDIR)/lk
30CONFIGHEADER := $(BUILDDIR)/config.h
31
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070032INCLUDES := -I$(BUILDDIR) -Iinclude
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070033CFLAGS := -O2 -g -fno-builtin -finline -W -Wall -Wno-multichar -Wno-unused-parameter -Wno-unused-function -include $(CONFIGHEADER)
34#CFLAGS += -Werror
35CPPFLAGS := -fno-exceptions -fno-rtti -fno-threadsafe-statics
36#CPPFLAGS += -Weffc++
37ASMFLAGS := -DASSEMBLY
38LDFLAGS :=
39
40CFLAGS += -ffunction-sections -fdata-sections
41LDFLAGS += -gc-sections
42
43# top level rule
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070044all:: $(OUTBIN) $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym $(OUTELF).size
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070045
46# the following three object lists are identical except for the ordering
47# which is bootobjs, kobjs, objs
48BOOTOBJS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070049OBJS :=
50
51# a linker script needs to be declared in one of the project/target/platform files
52LINKER_SCRIPT :=
53
54# anything you add here will be deleted in make clean
55GENERATED := $(CONFIGHEADER)
56
57# anything added to DEFINES will be put into $(BUILDDIR)/config.h
58DEFINES := 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.
62SRCDEPS := $(CONFIGHEADER)
63
64# these need to be filled out by the project/target/platform rules.mk files
65TARGET :=
66PLATFORM :=
67ARCH :=
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070068ALLMODULES :=
69MODULES :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070070
71# any rules you put here will also be built by the system before considered being complete
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070072EXTRA_BUILDDEPS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070073
74# any rules you put here will be depended on in clean builds
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070075EXTRA_CLEANDEPS :=
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070076
Travis Geiselbrecht577036f2009-01-24 21:37:21 -080077include project/$(PROJECT).mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070078include target/$(TARGET)/rules.mk
79include platform/$(PLATFORM)/rules.mk
80include arch/$(ARCH)/rules.mk
81include platform/rules.mk
82include target/rules.mk
83include kernel/rules.mk
84include dev/rules.mk
Travis Geiselbrecht68372232009-01-24 21:21:08 -080085include app/rules.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070086
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -070087# recursively include any modules in the MODULE variable, leaving a trail of included
88# modules in the ALLMODULES list
Travis Geiselbrecht5bcbd9d2009-01-24 20:15:32 -080089include make/module.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070090
91# any extra top level build dependencies that someone declared
92all:: $(EXTRA_BUILDDEPS)
93
94ALLOBJS := \
95 $(BOOTOBJS) \
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -070096 $(OBJS)
97
98# add some automatic configuration defines
99DEFINES += \
100 PROJECT_$(PROJECT)=1 \
101 TARGET_$(TARGET)=1 \
102 PLATFORM_$(PLATFORM)=1 \
103 ARCH_$(ARCH)=1 \
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700104 $(addsuffix =1,$(addprefix WITH_,$(ALLMODULES)))
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700105
106# debug build?
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700107ifneq ($(DEBUG),)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700108DEFINES += \
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700109 DEBUG=$(DEBUG)
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700110endif
111
112ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS))
113
114DEPS := $(ALLOBJS:%o=%d)
115
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700116# default to no ccache
117CCACHE ?=
118CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700119LD := $(TOOLCHAIN_PREFIX)ld
120OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
121OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy
122CPPFILT := $(TOOLCHAIN_PREFIX)c++filt
123SIZE := $(TOOLCHAIN_PREFIX)size
124NM := $(TOOLCHAIN_PREFIX)nm
125
Travis Geiselbrechtf54ab822008-09-05 04:14:40 -0700126# comment out or override if you want to see the full output of each command
127NOECHO ?= @
128
129# the logic to compile and link stuff is in here
Travis Geiselbrecht5bcbd9d2009-01-24 20:15:32 -0800130include make/build.mk
Travis Geiselbrecht1d0df692008-09-01 02:26:09 -0700131
132clean: $(EXTRA_CLEANDEPS)
133 rm -f $(ALLOBJS) $(DEPS) $(GENERATED) $(OUTBIN) $(OUTELF) $(OUTELF).lst
134
135spotless:
136 rm -rf build-*
137
138install: 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
142configheader:
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
168ifeq ($(filter $(MAKECMDGOALS), clean), )
169-include $(DEPS)
170endif
171
172.PHONY: configheader
Brian Swetlandf1e5afd2009-01-24 22:09:30 -0800173endif