Subversion Repositories freemyipod

Rev

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

Rev Author Line No. Line
2 theseven 1
NAME := embios
2
 
42 theseven 3
CROSS   ?= arm-none-eabi-
4
CC      := $(CROSS)gcc
5
AS      := $(CROSS)as
6
LD      := $(CROSS)ld
7
OBJCOPY := $(CROSS)objcopy
2 theseven 8
UCLPACK := ucl2e10singleblk
9
 
110 theseven 10
CFLAGS  += -Os -fno-pie -fno-stack-protector -fomit-frame-pointer -I. -Ilibc/include -Iexport -ffunction-sections -fdata-sections
33 theseven 11
LDFLAGS += "$(shell $(CC) -print-libgcc-file-name)" --gc-sections
2 theseven 12
 
21 theseven 13
preprocess = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#")
14
preprocesspaths = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#" | sed -e "s:^..*:$(dir $(1))&:")
2 theseven 15
 
28 theseven 16
REVISION := $(shell svnversion .)
17
REVISIONINT := $(shell echo $(REVISION) | sed -e "s/[^0-9].*$$//")
18
 
21 theseven 19
TARGETS := $(call preprocess,TARGETS,-I.)
20
 
2 theseven 21
define TARGET_template
91 theseven 22
-include target/$(1)/target.mk
23
 
21 theseven 24
SRC_$(1) := $$(call preprocesspaths,SOURCES,-DTARGET_$(1) -Itarget/$(1) -I.)
2 theseven 25
OBJ_$(1) := $$(SRC_$(1):%.c=build/$(1)/%.o)
26
OBJ_$(1) := $$(OBJ_$(1):%.S=build/$(1)/%.o)
27
 
28
-include $$(OBJ_$(1):%=%.dep)
29
 
30
$(1): build/$(1)/$(NAME)-$(1).ucl
31
 
32
build/$(1)/$(NAME)-$(1).ucl: build/$(1)/$(NAME).bin
33
	$(UCLPACK) $$^ $$@
34
 
35
build/$(1)/$(NAME).bin: build/$(1)/$(NAME).elf
36
	$(OBJCOPY) -O binary $$^ $$@
37
 
38
build/$(1)/$(NAME).elf: target/$(1)/ls.x build/$(1)/target/$(1)/crt0.o $$(OBJ_$(1))
91 theseven 39
	$(LD) $(LDFLAGS) $$(LDFLAGS_$(1)) -o $$@ -T target/$(1)/ls.x $$(OBJ_$(1))
2 theseven 40
 
28 theseven 41
build/$(1)/%.o: %.c build/version.h
2 theseven 42
ifeq ($(shell uname),WindowsNT)
43
	@-if not exist $$(subst /,\,$$(dir $$@)) md $$(subst /,\,$$(dir $$@))
44
else
45
	@-mkdir -p $$(dir $$@)
46
endif
91 theseven 47
	$(CC) -c $(CFLAGS) $$(CFLAGS_$(1)) -Itarget/$(1) -DTARGET_$(1) -o $$@ $$<
48
	@$(CC) -MM $(CFLAGS) $$(CFLAGS_$(1)) -Itarget/$(1) -DTARGET_$(1) $$< > $$@.dep.tmp
2 theseven 49
	@sed -e "s|.*:|$$@:|" < $$@.dep.tmp > $$@.dep
32 theseven 50
ifeq ($(shell uname),WindowsNT)
11 theseven 51
	@sed -e "s/.*://" -e "s/\\$$$$//" < $$@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$$$/:/" >> $$@.dep
32 theseven 52
else
33 theseven 53
	@sed -e 's/.*://' -e 's/\\$$$$//' < $$@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$$$/:/' >> $$@.dep
32 theseven 54
endif
2 theseven 55
	@rm -f $$@.dep.tmp
56
 
28 theseven 57
build/$(1)/%.o: %.S build/version.h
2 theseven 58
ifeq ($(shell uname),WindowsNT)
59
	@-if not exist $$(subst /,\,$$(dir $$@)) md $$(subst /,\,$$(dir $$@))
60
else
61
	@-mkdir -p $$(dir $$@)
62
endif
91 theseven 63
	$(CC) -c $(CFLAGS) $$(CFLAGS_$(1)) -Itarget/$(1) -DTARGET_$(1) -o $$@ $$<
64
	@$(CC) -MM $(CFLAGS) $$(CFLAGS_$(1)) -Itarget/$(1) -DTARGET_$(1) $$< > $$@.dep.tmp
2 theseven 65
	@sed -e "s|.*:|$$@:|" < $$@.dep.tmp > $$@.dep
32 theseven 66
ifeq ($(shell uname),WindowsNT)
11 theseven 67
	@sed -e "s/.*://" -e "s/\\$$$$//" < $$@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$$$/:/" >> $$@.dep
32 theseven 68
else
33 theseven 69
	@sed -e 's/.*://' -e 's/\\$$$$//' < $$@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$$$/:/' >> $$@.dep
32 theseven 70
endif
2 theseven 71
	@rm -f $$@.dep.tmp
72
endef
73
 
74
all: $(TARGETS)
75
 
76
$(foreach target,$(TARGETS),$(eval $(call TARGET_template,$(target))))
77
 
28 theseven 78
build/version.h: version.h .svn/entries build
32 theseven 79
ifeq ($(shell uname),WindowsNT)
28 theseven 80
	@sed -e "s/\$$REVISION\$$/$(REVISION)/" -e "s/\$$REVISIONINT\$$/$(REVISIONINT)/" < $< > $@
32 theseven 81
else
33 theseven 82
	@sed -e 's/\$$REVISION\$$/$(REVISION)/' -e 's/\$$REVISIONINT\$$/$(REVISIONINT)/' < $< > $@
32 theseven 83
endif
28 theseven 84
 
85
build:
33 theseven 86
	@mkdir $@
28 theseven 87
 
2 theseven 88
clean:
89
	rm -rf build
90
 
91
.PHONY: all clean $(TARGETS)