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
 
3
CROSS   := arm-none-eabi-
4
CC      := $(CROSS)gcc
5
AS      := $(CROSS)as
6
LD      := $(CROSS)ld
7
OBJCOPY := $(CROSS)objcopy
8
UCLPACK := ucl2e10singleblk
9
 
18 theseven 10
CFLAGS  ?= -Os -fno-pie -fno-stack-protector -fomit-frame-pointer -I. -ffunction-sections -fdata-sections
2 theseven 11
LDFLAGS ?= "$(shell $(CC) -print-libgcc-file-name)" --gc-sections
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
21 theseven 22
SRC_$(1) := $$(call preprocesspaths,SOURCES,-DTARGET_$(1) -Itarget/$(1) -I.)
2 theseven 23
OBJ_$(1) := $$(SRC_$(1):%.c=build/$(1)/%.o)
24
OBJ_$(1) := $$(OBJ_$(1):%.S=build/$(1)/%.o)
25
 
26
-include $$(OBJ_$(1):%=%.dep)
27
 
28
$(1): build/$(1)/$(NAME)-$(1).ucl
29
 
30
build/$(1)/$(NAME)-$(1).ucl: build/$(1)/$(NAME).bin
31
	$(UCLPACK) $$^ $$@
32
 
33
build/$(1)/$(NAME).bin: build/$(1)/$(NAME).elf
34
	$(OBJCOPY) -O binary $$^ $$@
35
 
36
build/$(1)/$(NAME).elf: target/$(1)/ls.x build/$(1)/target/$(1)/crt0.o $$(OBJ_$(1))
37
	$(LD) $(LDFLAGS) -o $$@ -T target/$(1)/ls.x $$(OBJ_$(1))
38
 
28 theseven 39
build/$(1)/%.o: %.c build/version.h
2 theseven 40
ifeq ($(shell uname),WindowsNT)
41
	@-if not exist $$(subst /,\,$$(dir $$@)) md $$(subst /,\,$$(dir $$@))
42
else
43
	@-mkdir -p $$(dir $$@)
44
endif
5 theseven 45
	$(CC) -c $(CFLAGS) -Itarget/$(1) -DTARGET_$(1) -o $$@ $$<
9 theseven 46
	@$(CC) -MM $(CFLAGS) -Itarget/$(1) -DTARGET_$(1) $$< > $$@.dep.tmp
2 theseven 47
	@sed -e "s|.*:|$$@:|" < $$@.dep.tmp > $$@.dep
11 theseven 48
	@sed -e "s/.*://" -e "s/\\$$$$//" < $$@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$$$/:/" >> $$@.dep
2 theseven 49
	@rm -f $$@.dep.tmp
50
 
28 theseven 51
build/$(1)/%.o: %.S build/version.h
2 theseven 52
ifeq ($(shell uname),WindowsNT)
53
	@-if not exist $$(subst /,\,$$(dir $$@)) md $$(subst /,\,$$(dir $$@))
54
else
55
	@-mkdir -p $$(dir $$@)
56
endif
5 theseven 57
	$(CC) -c $(CFLAGS) -Itarget/$(1) -DTARGET_$(1) -o $$@ $$<
9 theseven 58
	@$(CC) -MM $(CFLAGS) -Itarget/$(1) -DTARGET_$(1) $$< > $$@.dep.tmp
2 theseven 59
	@sed -e "s|.*:|$$@:|" < $$@.dep.tmp > $$@.dep
11 theseven 60
	@sed -e "s/.*://" -e "s/\\$$$$//" < $$@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$$$/:/" >> $$@.dep
2 theseven 61
	@rm -f $$@.dep.tmp
62
endef
63
 
64
all: $(TARGETS)
65
 
66
$(foreach target,$(TARGETS),$(eval $(call TARGET_template,$(target))))
67
 
28 theseven 68
build/version.h: version.h .svn/entries build
69
	@sed -e "s/\$$REVISION\$$/$(REVISION)/" -e "s/\$$REVISIONINT\$$/$(REVISIONINT)/" < $< > $@
70
 
71
build:
72
	@mkdir build
73
 
2 theseven 74
clean:
75
	rm -rf build
76
 
77
.PHONY: all clean $(TARGETS)