Subversion Repositories freemyipod

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
870 theseven 1
NAME := emcore
2
 
3
ifeq ($(shell uname),WindowsNT)
4
CCACHE :=
5
else
6
CCACHE := $(shell which ccache)
7
endif
8
 
9
CROSS   ?= arm-elf-eabi-
10
CC      := $(CCACHE) $(CROSS)gcc
11
AS      := $(CROSS)as
12
LD      := $(CROSS)ld
13
OBJCOPY := $(CROSS)objcopy
14
UCLPACK := ucl2e10singleblk
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
 
19
preprocess = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#")
20
preprocesspaths = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#" | sed -e "s:^..*:$(dir $(1))&:" | sed -e "s:^\\./::")
21
 
22
REVISION := $(shell svnversion .)
23
REVISIONINT := $(shell echo $(REVISION) | sed -e "s/[^0-9].*$$//")
24
 
25
TARGETS := $(call preprocess,TARGETS,-I.)
26
 
27
define TARGET_template
28
-include target/$(1)/target.mk
29
 
30
SRC_$(1) := $$(call preprocesspaths,SOURCES,-DTARGET_$(1) -Itarget/$(1) -I.)
31
OBJ_$(1) := $$(SRC_$(1):%.c=build/$(1)/%.o)
32
OBJ_$(1) := $$(OBJ_$(1):%.S=build/$(1)/%.o)
33
 
34
-include $$(OBJ_$(1):%=%.dep)
35
 
36
$(1): build/$(1)/$(NAME)-$(1).ucl
37
 
38
build/$(1)/$(NAME)-$(1).ucl: build/$(1)/$(NAME).bin
39
	@echo [UCL]    $$<
40
	@$(UCLPACK) $$^ $$@
41
 
42
build/$(1)/$(NAME).bin: build/$(1)/$(NAME).elf
43
	@echo [OC]     $$<
44
	@$(OBJCOPY) -O binary $$^ $$@
45
 
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))
49
 
50
build/$(1)/%.o: %.c build/version.h
51
	@echo [CC]     $$<
52
ifeq ($(shell uname),WindowsNT)
53
	@-if not exist $$(subst /,\,$$(dir $$@)) md $$(subst /,\,$$(dir $$@))
54
else
55
	@-mkdir -p $$(dir $$@)
56
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
60
ifeq ($(shell uname),WindowsNT)
61
	@sed -e "s/.*://" -e "s/\\$$$$//" < $$@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$$$/:/" >> $$@.dep
62
else
63
	@sed -e 's/.*://' -e 's/\\$$$$//' < $$@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$$$/:/' >> $$@.dep
64
endif
65
	@rm -f $$@.dep.tmp
66
 
67
build/$(1)/%.o: %.S build/version.h
68
	@echo [CC]     $$<
69
ifeq ($(shell uname),WindowsNT)
70
	@-if not exist $$(subst /,\,$$(dir $$@)) md $$(subst /,\,$$(dir $$@))
71
else
72
	@-mkdir -p $$(dir $$@)
73
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
80
	@sed -e 's/.*://' -e 's/\\$$$$//' < $$@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$$$/:/' >> $$@.dep
81
endif
82
	@rm -f $$@.dep.tmp
83
endef
84
 
85
all: $(TARGETS)
86
 
87
$(foreach target,$(TARGETS),$(eval $(call TARGET_template,$(target))))
88
 
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
98
 
99
clean:
100
	@rm -rf build
101
 
102
.PHONY: all clean $(TARGETS)