Travis Geiselbrecht | 1d0df69 | 2008-09-01 02:26:09 -0700 | [diff] [blame] | 1 | -include local.mk |
| 2 | include macros.mk |
| 3 | |
| 4 | PROJECT ?= armemu-test |
| 5 | DEBUG ?= false |
| 6 | |
| 7 | BUILDDIR := build-$(PROJECT) |
| 8 | OUTBIN := $(BUILDDIR)/lk.bin |
| 9 | OUTELF := $(BUILDDIR)/lk |
| 10 | CONFIGHEADER := $(BUILDDIR)/config.h |
| 11 | |
| 12 | INCLUDES := -Iinclude |
| 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 |
| 24 | all:: $(OUTBIN) $(OUTELF).lst $(OUTELF).debug.lst $(OUTELF).sym |
| 25 | |
| 26 | # the following three object lists are identical except for the ordering |
| 27 | # which is bootobjs, kobjs, objs |
| 28 | BOOTOBJS := |
| 29 | KOBJS := |
| 30 | OBJS := |
| 31 | |
| 32 | # a linker script needs to be declared in one of the project/target/platform files |
| 33 | LINKER_SCRIPT := |
| 34 | |
| 35 | # anything you add here will be deleted in make clean |
| 36 | GENERATED := $(CONFIGHEADER) |
| 37 | |
| 38 | # anything added to DEFINES will be put into $(BUILDDIR)/config.h |
| 39 | DEFINES := LK=1 |
| 40 | |
| 41 | # Anything added to SRCDEPS will become a dependency of every source file in the system. |
| 42 | # Useful for header files that may be included by one or more source files. |
| 43 | SRCDEPS := $(CONFIGHEADER) |
| 44 | |
| 45 | # these need to be filled out by the project/target/platform rules.mk files |
| 46 | TARGET := |
| 47 | PLATFORM := |
| 48 | ARCH := |
| 49 | LIBS := libc |
| 50 | APPS := |
| 51 | DEVS := |
| 52 | |
| 53 | # any rules you put here will also be built by the system before considered being complete |
| 54 | EXTRA_BUILDDEPS := |
| 55 | |
| 56 | # any rules you put here will be depended on in clean builds |
| 57 | EXTRA_CLEANDEPS := |
| 58 | |
| 59 | include project/$(PROJECT)/rules.mk |
| 60 | include target/$(TARGET)/rules.mk |
| 61 | include platform/$(PLATFORM)/rules.mk |
| 62 | include arch/$(ARCH)/rules.mk |
| 63 | include platform/rules.mk |
| 64 | include target/rules.mk |
| 65 | include kernel/rules.mk |
| 66 | include dev/rules.mk |
| 67 | |
| 68 | DEVS := $(sort $(DEVS)) |
| 69 | LIBS := $(sort $(LIBS)) |
| 70 | APPS := $(sort $(APPS)) |
| 71 | |
| 72 | include $(addsuffix /rules.mk,$(addprefix dev/,$(DEVS))) |
| 73 | include $(addsuffix /rules.mk,$(addprefix lib/,$(LIBS))) |
| 74 | include $(addsuffix /rules.mk,$(addprefix app/,$(APPS))) |
| 75 | |
| 76 | # any extra top level build dependencies that someone declared |
| 77 | all:: $(EXTRA_BUILDDEPS) |
| 78 | |
| 79 | ALLOBJS := \ |
| 80 | $(BOOTOBJS) \ |
| 81 | $(KOBJS) \ |
| 82 | $(OBJS) |
| 83 | |
| 84 | # add some automatic configuration defines |
| 85 | DEFINES += \ |
| 86 | PROJECT_$(PROJECT)=1 \ |
| 87 | TARGET_$(TARGET)=1 \ |
| 88 | PLATFORM_$(PLATFORM)=1 \ |
| 89 | ARCH_$(ARCH)=1 \ |
| 90 | $(addsuffix =1,$(addprefix WITH_DEV_,$(DEVS))) \ |
| 91 | $(addsuffix =1,$(addprefix WITH_LIB_,$(LIBS))) \ |
| 92 | $(addsuffix =1,$(addprefix WITH_APP_,$(APPS))) |
| 93 | |
| 94 | # debug build? |
| 95 | ifeq ($(DEBUG),true) |
| 96 | DEFINES += \ |
| 97 | DEBUG=1 |
| 98 | endif |
| 99 | |
| 100 | ALLOBJS := $(addprefix $(BUILDDIR)/,$(ALLOBJS)) |
| 101 | |
| 102 | DEPS := $(ALLOBJS:%o=%d) |
| 103 | |
| 104 | CC := $(TOOLCHAIN_PREFIX)gcc |
| 105 | LD := $(TOOLCHAIN_PREFIX)ld |
| 106 | OBJDUMP := $(TOOLCHAIN_PREFIX)objdump |
| 107 | OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy |
| 108 | CPPFILT := $(TOOLCHAIN_PREFIX)c++filt |
| 109 | SIZE := $(TOOLCHAIN_PREFIX)size |
| 110 | NM := $(TOOLCHAIN_PREFIX)nm |
| 111 | |
| 112 | include build.mk |
| 113 | |
| 114 | clean: $(EXTRA_CLEANDEPS) |
| 115 | rm -f $(ALLOBJS) $(DEPS) $(GENERATED) $(OUTBIN) $(OUTELF) $(OUTELF).lst |
| 116 | |
| 117 | spotless: |
| 118 | rm -rf build-* |
| 119 | |
| 120 | install: all |
| 121 | scp $(OUTBIN) 192.168.0.4:/tftproot |
| 122 | |
| 123 | # generate a config.h file with all of the DEFINES laid out in #define format |
| 124 | configheader: |
| 125 | |
| 126 | $(CONFIGHEADER): configheader |
| 127 | @$(MKDIR) |
| 128 | @echo generating $@ |
| 129 | @rm -f $(CONFIGHEADER).tmp; \ |
| 130 | echo \#ifndef __CONFIG_H > $(CONFIGHEADER).tmp; \ |
| 131 | echo \#define __CONFIG_H >> $(CONFIGHEADER).tmp; \ |
| 132 | for d in `echo $(DEFINES) | tr [:lower:] [:upper:]`; do \ |
| 133 | echo "#define $$d" | sed "s/=/\ /g;s/-/_/g;s/\//_/g" >> $(CONFIGHEADER).tmp; \ |
| 134 | done; \ |
| 135 | echo \#endif >> $(CONFIGHEADER).tmp; \ |
| 136 | if [ -f "$(CONFIGHEADER)" ]; then \ |
| 137 | if cmp "$(CONFIGHEADER).tmp" "$(CONFIGHEADER)"; then \ |
| 138 | rm -f $(CONFIGHEADER).tmp; \ |
| 139 | else \ |
| 140 | mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \ |
| 141 | fi \ |
| 142 | else \ |
| 143 | mv $(CONFIGHEADER).tmp $(CONFIGHEADER); \ |
| 144 | fi |
| 145 | |
| 146 | # Empty rule for the .d files. The above rules will build .d files as a side |
| 147 | # effect. Only works on gcc 3.x and above, however. |
| 148 | %.d: |
| 149 | |
| 150 | ifeq ($(filter $(MAKECMDGOALS), clean), ) |
| 151 | -include $(DEPS) |
| 152 | endif |
| 153 | |
| 154 | .PHONY: configheader |
| 155 | |