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