| Line 1... |
Line -... |
| 1 |
NAME := umsboot
|
- |
|
| 2 |
|
- |
|
| 3 |
ifeq ($(shell uname),WindowsNT)
|
- |
|
| 4 |
CCACHE :=
|
- |
|
| 5 |
else
|
- |
|
| 6 |
CCACHE := $(shell which ccache)
|
1 |
CCACHE ?= $(shell which ccache)
|
| 7 |
endif
|
- |
|
| 8 |
|
- |
|
| 9 |
CROSS ?= arm-elf-eabi-
|
2 |
CROSS ?= arm-elf-eabi-
|
| 10 |
CC := $(CCACHE) $(CROSS)gcc
|
3 |
CC := $(CCACHE) $(CROSS)gcc
|
| 11 |
AS := $(CROSS)as
|
- |
|
| 12 |
LD := $(CROSS)ld
|
4 |
LD := $(CROSS)ld
|
| 13 |
OBJCOPY := $(CROSS)objcopy
|
5 |
OBJCOPY := $(CROSS)objcopy
|
| 14 |
UCLPACK := ucl2e10singleblk
|
6 |
OBJDUMP := $(CROSS)objdump
|
| 15 |
|
- |
|
| 16 |
CFLAGS += -Os -fno-pie -fno-stack-protector -fomit-frame-pointer -I. -Iexport -ffunction-sections -fdata-sections -marm
|
- |
|
| 17 |
LDFLAGS += "$(shell $(CC) -print-libgcc-file-name)" --gc-sections
|
- |
|
| 18 |
|
7 |
|
| - |
|
8 |
CFLAGS_GENERAL := -c -ffunction-sections -fdata-sections -fmessage-length=0 -Wall $(CFLAGS_GENERAL)
|
| - |
|
9 |
CFLAGS_ASM := -x assembler-with-cpp $(CFLAGS_ASM)
|
| - |
|
10 |
CFLAGS_debug := -O0 -g3 -gdwarf-2 $(CFLAGS_DEBUG)
|
| - |
|
11 |
CFLAGS_release := -flto -flto-partition=none -Os -fno-pie -fno-stack-protector -fomit-frame-pointer $(CFLAGS_RELEASE)
|
| - |
|
12 |
LDFLAGS_GENERAL := -nostdlib --gc-sections $(LDFLAGS_GENERAL)
|
| - |
|
13 |
LDFLAGS_debug := -O0 $(LDFLAGS_DEBUG)
|
| 19 |
preprocess = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#")
|
14 |
LDFLAGS_release := -flto -flto-partition=none -Os $(LDFLAGS_RELEASE)
|
| 20 |
preprocesspaths = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#" | sed -e "s:^..*:$(dir $(1))&:" | sed -e "s:^\\./::")
|
15 |
PPFLAGS_GENERAL := -DTARGET_$(subst /,_,$(TARGET)) -DTARGET=$(TARGET) -DCONFIG_H=target/$(TARGET)/config.h -DTARGET_H=target/$(TARGET)/target.h -Isrc
|
| - |
|
16 |
PPFLAGS_debug := -DDEBUG
|
| - |
|
17 |
PPFLAGS_release := -DRELEASE
|
| - |
|
18 |
PPONLY_FLAGS := -E -P -x c -DASM_FILE
|
| - |
|
19 |
SPEC_FLAGS := -E -P -v -dD
|
| - |
|
20 |
|
| - |
|
21 |
ifeq ($(VERY_VERBOSE),)
|
| - |
|
22 |
VQ := @
|
| - |
|
23 |
else
|
| - |
|
24 |
VERBOSE := 1
|
| - |
|
25 |
endif
|
| - |
|
26 |
|
| - |
|
27 |
ifeq ($(VERBOSE),)
|
| - |
|
28 |
Q := @
|
| - |
|
29 |
endif
|
| 21 |
|
30 |
|
| 22 |
REVISION := $(shell svnversion .)
|
31 |
CWD := $(shell pwd)
|
| - |
|
32 |
relpath = $(patsubst $(CWD)/%,%,$(realpath $(1)))
|
| 23 |
REVISIONINT := $(shell echo $(REVISION) | sed -e "s/[^0-9].*$$//")
|
33 |
preprocess = $(shell $(CC) $(2) $(PPONLY_FLAGS) $(1) | grep -v "^\#")
|
| - |
|
34 |
preprocesspaths = $(shell $(CC) $(2) $(PPONLY_FLAGS) $(1) | grep -v "^\#" | sed -e "s:^..*:$(dir $(1))&:" | sed -e "s:^\\./::")
|
| 24 |
|
35 |
|
| 25 |
TARGETS := $(call preprocess,TARGETS,-I.)
|
36 |
TARGETS := $(call preprocess,TARGETS,-I.)
|
| 26 |
|
37 |
|
| - |
|
38 |
ifeq ($(TARGET),)
|
| - |
|
39 |
all: $(TARGETS)
|
| 27 |
define TARGET_template
|
40 |
define TARGET_template
|
| 28 |
-include target/$(1)/target.mk
|
- |
|
| 29 |
|
41 |
$(1):
|
| 30 |
SRC_$(1) := $$(call preprocesspaths,SOURCES,-DTARGET_$(1) -Itarget/$(1) -I.)
|
- |
|
| 31 |
OBJ_$(1) := $$(SRC_$(1):%.c=build/$(1)/%.o)
|
42 |
$(Q)+$(MAKE) TARGET=$(1)
|
| 32 |
OBJ_$(1) := $$(OBJ_$(1):%.S=build/$(1)/%.o)
|
- |
|
| 33 |
|
43 |
endef
|
| 34 |
-include $$(OBJ_$(1):%=%.dep)
|
44 |
$(foreach target,$(TARGETS),$(eval $(call TARGET_template,$(target))))
|
| 35 |
|
45 |
else
|
| 36 |
$(1): build/$(1)/$(NAME)-$(1).ucl
|
- |
|
| 37 |
|
46 |
|
| 38 |
build/$(1)/$(NAME)-$(1).ucl: build/$(1)/$(NAME).bin
|
47 |
ifneq ($(TYPE),debug)
|
| 39 |
@echo [UCL] $$<
|
48 |
ifneq ($(TYPE),release)
|
| 40 |
@$(UCLPACK) $$^ $$@
|
49 |
$(error Please define either TYPE=debug or TYPE=release)
|
| - |
|
50 |
endif
|
| - |
|
51 |
endif
|
| 41 |
|
52 |
|
| 42 |
build/$(1)/$(NAME).bin: build/$(1)/$(NAME).elf
|
53 |
ifeq ($(LISTING),)
|
| 43 |
@echo [OC] $$<
|
54 |
all: $(TARGET)
|
| - |
|
55 |
else
|
| 44 |
@$(OBJCOPY) -O binary $$^ $$@
|
56 |
all: $(TARGET) LISTINGS
|
| - |
|
57 |
endif
|
| 45 |
|
58 |
|
| 46 |
build/$(1)/$(NAME).elf: target/$(1)/ls.x build/$(1)/target/$(1)/crt0.o $$(OBJ_$(1))
|
- |
|
| 47 |
@echo [LD] $$@
|
- |
|
| 48 |
@$(LD) $(LDFLAGS) $$(LDFLAGS_$(1)) -o $$@ -T target/$(1)/ls.x $$(OBJ_$(1))
|
59 |
_PPFLAGS := $(PPFLAGS_GENERAL) $(PPFLAGS_$(TYPE)) $(PPFLAGS)
|
| 49 |
|
60 |
|
| 50 |
build/$(1)/%.o: %.c build/version.h
|
- |
|
| 51 |
@echo [CC] $$<
|
61 |
define MODULE_template
|
| 52 |
ifeq ($(shell uname),WindowsNT)
|
62 |
ifeq ($(1),)
|
| 53 |
@-if not exist $$(subst /,\,$$(dir $$@)) md $$(subst /,\,$$(dir $$@))
|
63 |
$$(shell echo Cannot resolve module $(2) 1>&2)
|
| 54 |
else
|
64 |
else
|
| - |
|
65 |
ifeq ($$(filter $(1),$$(INCLUDED_MODULES)),)
|
| 55 |
@-mkdir -p $$(dir $$@)
|
66 |
INCLUDED_MODULES += $(1)
|
| - |
|
67 |
ifneq ($(VERBOSE),)
|
| - |
|
68 |
$$(shell echo Including module $(1) 1>&2)
|
| 56 |
endif
|
69 |
endif
|
| 57 |
@$(CC) -c $(CFLAGS) $$(CFLAGS_$(1)) -DTARGET_$(1) -DTARGET=\"$(1)\" -DCONFIG_H=\"target/$(1)/config.h\" -DTARGET_H=\"target/$(1)/target.h\" -o $$@ $$<
|
- |
|
| 58 |
@$(CC) -MM $(CFLAGS) $$(CFLAGS_$(1)) -DTARGET_$(1) -DTARGET=\"$(1)\" -DCONFIG_H=\"target/$(1)/config.h\" -DTARGET_H=\"target/$(1)/target.h\" $$< > $$@.dep.tmp
|
- |
|
| 59 |
@sed -e "s|.*:|$$@:|" < $$@.dep.tmp > $$@.dep
|
70 |
-include $(1)/target.mk
|
| 60 |
ifeq ($(shell uname),WindowsNT)
|
71 |
ifneq ($(wildcard $(1)/SOURCES),)
|
| 61 |
@sed -e "s/.*://" -e "s/\\$$$$//" < $$@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$$$/:/" >> $$@.dep
|
- |
|
| 62 |
else
|
72 |
SOURCES += $(1)/SOURCES
|
| 63 |
@sed -e 's/.*://' -e 's/\\$$$$//' < $$@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$$$/:/' >> $$@.dep
|
73 |
SRC += $$(call preprocesspaths,$(1)/SOURCES,$(_PPFLAGS))
|
| 64 |
endif
|
74 |
endif
|
| 65 |
@rm -f $$@.dep.tmp
|
- |
|
| 66 |
|
- |
|
| 67 |
build/$(1)/%.o: %.S build/version.h
|
75 |
ifneq ($(wildcard $(1)/DEPS),)
|
| 68 |
@echo [CC] $$<
|
76 |
DEPS += $(1)/DEPS
|
| 69 |
ifeq ($(shell uname),WindowsNT)
|
- |
|
| 70 |
@-if not exist $$(subst /,\,$$(dir $$@)) md $$(subst /,\,$$(dir $$@))
|
77 |
$$(foreach module,$$(strip $$(call preprocesspaths,$(1)/DEPS,$(_PPFLAGS))),$$(eval $$(call MODULE_template,$$(call relpath,$$(module)),$$(module))))
|
| 71 |
else
|
- |
|
| 72 |
@-mkdir -p $$(dir $$@)
|
- |
|
| 73 |
endif
|
78 |
endif
|
| 74 |
@$(CC) -c $(CFLAGS) $$(CFLAGS_$(1)) -DTARGET_$(1) -DTARGET=\"$(1)\" -DCONFIG_H=\"target/$(1)/config.h\" -DTARGET_H=\"target/$(1)/target.h\" -o $$@ $$<
|
- |
|
| 75 |
@$(CC) -MM $(CFLAGS) $$(CFLAGS_$(1)) -DTARGET_$(1) -DTARGET=\"$(1)\" -DCONFIG_H=\"target/$(1)/config.h\" -DTARGET_H=\"target/$(1)/target.h\" $$< > $$@.dep.tmp
|
- |
|
| 76 |
@sed -e "s|.*:|$$@:|" < $$@.dep.tmp > $$@.dep
|
- |
|
| 77 |
ifeq ($(shell uname),WindowsNT)
|
- |
|
| 78 |
@sed -e "s/.*://" -e "s/\\$$$$//" < $$@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$$$/:/" >> $$@.dep
|
- |
|
| 79 |
else
|
79 |
else
|
| - |
|
80 |
ifneq ($(VERY_VERBOSE),)
|
| 80 |
@sed -e 's/.*://' -e 's/\\$$$$//' < $$@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$$$/:/' >> $$@.dep
|
81 |
$$(shell echo Module $(1) is already included 1>&2)
|
| - |
|
82 |
endif
|
| - |
|
83 |
endif
|
| 81 |
endif
|
84 |
endif
|
| 82 |
@rm -f $$@.dep.tmp
|
- |
|
| 83 |
endef
|
85 |
endef
|
| 84 |
|
86 |
|
| 85 |
all: $(TARGETS)
|
87 |
$(eval $(call MODULE_template,src,src))
|
| 86 |
|
88 |
|
| 87 |
$(foreach target,$(TARGETS),$(eval $(call TARGET_template,$(target))))
|
89 |
SRC := $(foreach file,$(SRC),$(call relpath,$(file)))
|
| - |
|
90 |
OBJ := $(SRC:src/%.c=build/$(TARGET)/$(TYPE)/%.o)
|
| - |
|
91 |
OBJ := $(OBJ:src/%.S=build/$(TARGET)/$(TYPE)/%.o)
|
| - |
|
92 |
_LDSCRIPT = $(LDSCRIPT:src/%.lds=build/$(TARGET)/$(TYPE)/%.lds)
|
| - |
|
93 |
|
| - |
|
94 |
_ASMFLAGS := $(CFLAGS_GENERAL) $(CFLAGS_ASM) $(CFLAGS_$(TYPE)) $(_CFLAGS) $(_PPFLAGS) $(CFLAGS) $(ASMFLAGS)
|
| - |
|
95 |
_CFLAGS := $(CFLAGS_GENERAL) $(CFLAGS_$(TYPE)) $(_CFLAGS) $(_PPFLAGS) $(CFLAGS)
|
| - |
|
96 |
_LDFLAGS := $(LDFLAGS_GENERAL) $(LDFLAGS_$(TYPE)) $(_LDFLAGS) $(LDFLAGS)
|
| - |
|
97 |
|
| - |
|
98 |
define CCRULE_template
|
| - |
|
99 |
build/$(TARGET)/$(TYPE)/%.$(1): src/%.$(2)
|
| - |
|
100 |
$(VQ)echo $(3) $$<
|
| - |
|
101 |
$(VQ)-mkdir -p $$(dir $$@)
|
| - |
|
102 |
$(Q)$(CC) -Wa,-adhlns="build/$(TARGET)/$(TYPE)/$$*.lst" $(4) -o $$@ $$<
|
| - |
|
103 |
$(VQ)$(CC) -MM $(4) $$< > $$@.dep.tmp
|
| - |
|
104 |
$(VQ)sed -e "s|.*:|$$@:|" < $$@.dep.tmp > $$@.dep
|
| - |
|
105 |
$(VQ)sed -e 's/.*://' -e 's/\\$$$$//' < $$@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$$$/:/' >> $$@.dep
|
| - |
|
106 |
$(VQ)rm -f $$@.dep.tmp
|
| - |
|
107 |
endef
|
| - |
|
108 |
|
| - |
|
109 |
-include $(OBJ:%=%.dep)
|
| - |
|
110 |
|
| - |
|
111 |
build/$(TARGET)/$(TYPE)/%.bin: build/$(TARGET)/$(TYPE)/%.elf
|
| - |
|
112 |
$(VQ)echo "[OC] " $<
|
| - |
|
113 |
$(Q)$(OBJCOPY) -O binary $^ $@
|
| - |
|
114 |
|
| - |
|
115 |
build/$(TARGET)/$(TYPE)/$(NAME).elf: $(_LDSCRIPT) $(OBJ) $(SOURCES) $(DEPS)
|
| - |
|
116 |
$(VQ)echo "[LD] " $@
|
| - |
|
117 |
$(Q)$(LD) -Map "$@.map" $(_LDFLAGS) -o $@ -T $(_LDSCRIPT) $(OBJ)
|
| - |
|
118 |
|
| - |
|
119 |
%.lst: %
|
| - |
|
120 |
$(VQ)echo "[OD] " $<
|
| - |
|
121 |
$(Q)$(OBJDUMP) -S $< > $@
|
| - |
|
122 |
|
| - |
|
123 |
LISTINGS: $(OBJ:%=%.lst)
|
| - |
|
124 |
|
| - |
|
125 |
$(eval $(call CCRULE_template,lds,lds,"[PP] ",$(_PPFLAGS) $(PPONLY_FLAGS)))
|
| - |
|
126 |
|
| - |
|
127 |
$(eval $(call CCRULE_template,o,c,"[CC] ",$(_CFLAGS)))
|
| - |
|
128 |
|
| - |
|
129 |
$(eval $(call CCRULE_template,o,S,"[CC] ",$(_CFLAGS)))
|
| 88 |
|
130 |
|
| 89 |
build/version.h: version.h ../.svn/entries
|
- |
|
| 90 |
@echo [PP] $<
|
- |
|
| 91 |
ifeq ($(shell uname),WindowsNT)
|
- |
|
| 92 |
@-if not exist build md build
|
- |
|
| 93 |
@sed -e "s/\$$REVISION\$$/$(REVISION)/" -e "s/\$$REVISIONINT\$$/$(REVISIONINT)/" < $< > $@
|
- |
|
| 94 |
else
|
- |
|
| 95 |
@-mkdir -p build
|
- |
|
| 96 |
@sed -e 's/\$$REVISION\$$/$(REVISION)/' -e 's/\$$REVISIONINT\$$/$(REVISIONINT)/' < $< > $@
|
- |
|
| 97 |
endif
|
131 |
endif
|
| 98 |
|
132 |
|
| - |
|
133 |
spec:
|
| - |
|
134 |
$(Q)$(CC) $(_CFLAGS) $(SPEC_FLAGS) src/spec.c
|
| - |
|
135 |
|
| 99 |
clean:
|
136 |
clean:
|
| 100 |
@rm -rf build
|
137 |
$(Q)rm -rf build
|
| 101 |
|
138 |
|
| 102 |
.PHONY: all clean $(TARGETS)
|
139 |
.PHONY: all spec clean $(TARGETS) SOURCES DEPS LISTINGS
|