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