Subversion Repositories freemyipod

Rev

Rev 895 | Details | Compare with Previous | 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
 
891 theseven 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
PPCFLAGS += -DASM_FILE
870 theseven 19
 
20
preprocess = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#")
21
preprocesspaths = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#" | sed -e "s:^..*:$(dir $(1))&:" | sed -e "s:^\\./::")
22
 
23
REVISION := $(shell svnversion .)
24
REVISIONINT := $(shell echo $(REVISION) | sed -e "s/[^0-9].*$$//")
25
 
26
TARGETS := $(call preprocess,TARGETS,-I.)
27
 
28
define TARGET_template
29
-include target/$(1)/target.mk
30
 
895 theseven 31
SRC_$(1) := $$(call preprocesspaths,SOURCES,-DTARGET_$(1) -DTARGET=\"$(1)\" -DCONFIG_H=\"target/$(1)/config.h\" -DTARGET_H=\"target/$(1)/target.h\" -D_NO_VERSION_H_ -Itarget/$(1) -I.)
870 theseven 32
OBJ_$(1) := $$(SRC_$(1):%.c=build/$(1)/%.o)
33
OBJ_$(1) := $$(OBJ_$(1):%.S=build/$(1)/%.o)
34
 
35
-include $$(OBJ_$(1):%=%.dep)
36
 
37
$(1): build/$(1)/$(NAME)-$(1).ucl
38
 
39
build/$(1)/$(NAME)-$(1).ucl: build/$(1)/$(NAME).bin
40
	@echo [UCL]    $$<
41
	@$(UCLPACK) $$^ $$@
42
 
43
build/$(1)/$(NAME).bin: build/$(1)/$(NAME).elf
44
	@echo [OC]     $$<
45
	@$(OBJCOPY) -O binary $$^ $$@
46
 
47
build/$(1)/$(NAME).elf: target/$(1)/ls.x build/$(1)/target/$(1)/crt0.o $$(OBJ_$(1))
48
	@echo [LD]     $$@
49
	@$(LD) $(LDFLAGS) $$(LDFLAGS_$(1)) -o $$@ -T target/$(1)/ls.x $$(OBJ_$(1))
50
 
51
build/$(1)/%.o: %.c build/version.h
52
	@echo [CC]     $$<
53
ifeq ($(shell uname),WindowsNT)
54
	@-if not exist $$(subst /,\,$$(dir $$@)) md $$(subst /,\,$$(dir $$@))
55
else
56
	@-mkdir -p $$(dir $$@)
57
endif
58
	@$(CC) -c $(CFLAGS) $$(CFLAGS_$(1)) -DTARGET_$(1) -DTARGET=\"$(1)\" -DCONFIG_H=\"target/$(1)/config.h\" -DTARGET_H=\"target/$(1)/target.h\" -o $$@ $$<
59
	@$(CC) -MM $(CFLAGS) $$(CFLAGS_$(1)) -DTARGET_$(1) -DTARGET=\"$(1)\" -DCONFIG_H=\"target/$(1)/config.h\" -DTARGET_H=\"target/$(1)/target.h\" $$< > $$@.dep.tmp
60
	@sed -e "s|.*:|$$@:|" < $$@.dep.tmp > $$@.dep
61
ifeq ($(shell uname),WindowsNT)
62
	@sed -e "s/.*://" -e "s/\\$$$$//" < $$@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$$$/:/" >> $$@.dep
63
else
64
	@sed -e 's/.*://' -e 's/\\$$$$//' < $$@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$$$/:/' >> $$@.dep
65
endif
66
	@rm -f $$@.dep.tmp
67
 
68
build/$(1)/%.o: %.S build/version.h
69
	@echo [CC]     $$<
70
ifeq ($(shell uname),WindowsNT)
71
	@-if not exist $$(subst /,\,$$(dir $$@)) md $$(subst /,\,$$(dir $$@))
72
else
73
	@-mkdir -p $$(dir $$@)
74
endif
75
	@$(CC) -c $(CFLAGS) $$(CFLAGS_$(1)) -DTARGET_$(1) -DTARGET=\"$(1)\" -DCONFIG_H=\"target/$(1)/config.h\" -DTARGET_H=\"target/$(1)/target.h\" -o $$@ $$<
76
	@$(CC) -MM $(CFLAGS) $$(CFLAGS_$(1)) -DTARGET_$(1) -DTARGET=\"$(1)\" -DCONFIG_H=\"target/$(1)/config.h\" -DTARGET_H=\"target/$(1)/target.h\" $$< > $$@.dep.tmp
77
	@sed -e "s|.*:|$$@:|" < $$@.dep.tmp > $$@.dep
78
ifeq ($(shell uname),WindowsNT)
79
	@sed -e "s/.*://" -e "s/\\$$$$//" < $$@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$$$/:/" >> $$@.dep
80
else
81
	@sed -e 's/.*://' -e 's/\\$$$$//' < $$@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$$$/:/' >> $$@.dep
82
endif
83
	@rm -f $$@.dep.tmp
84
endef
85
 
86
all: $(TARGETS)
87
 
88
$(foreach target,$(TARGETS),$(eval $(call TARGET_template,$(target))))
89
 
90
build/version.h: version.h ../../.svn/entries
91
	@echo [PP]     $<
92
ifeq ($(shell uname),WindowsNT)
93
	@-if not exist build md build
94
	@sed -e "s/\$$REVISION\$$/$(REVISION)/" -e "s/\$$REVISIONINT\$$/$(REVISIONINT)/" < $< > $@
95
else
96
	@-mkdir -p build
97
	@sed -e 's/\$$REVISION\$$/$(REVISION)/' -e 's/\$$REVISIONINT\$$/$(REVISIONINT)/' < $< > $@
98
endif
99
 
100
clean:
101
	@rm -rf build
102
 
103
.PHONY: all clean $(TARGETS)