Subversion Repositories freemyipod

Rev

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
 
21 theseven 16
TARGETS := $(call preprocess,TARGETS,-I.)
17
 
2 theseven 18
define TARGET_template
21 theseven 19
SRC_$(1) := $$(call preprocesspaths,SOURCES,-DTARGET_$(1) -Itarget/$(1) -I.)
2 theseven 20
OBJ_$(1) := $$(SRC_$(1):%.c=build/$(1)/%.o)
21
OBJ_$(1) := $$(OBJ_$(1):%.S=build/$(1)/%.o)
22
 
23
-include $$(OBJ_$(1):%=%.dep)
24
 
25
$(1): build/$(1)/$(NAME)-$(1).ucl
26
 
27
build/$(1)/$(NAME)-$(1).ucl: build/$(1)/$(NAME).bin
28
	$(UCLPACK) $$^ $$@
29
 
30
build/$(1)/$(NAME).bin: build/$(1)/$(NAME).elf
31
	$(OBJCOPY) -O binary $$^ $$@
32
 
33
build/$(1)/$(NAME).elf: target/$(1)/ls.x build/$(1)/target/$(1)/crt0.o $$(OBJ_$(1))
34
	$(LD) $(LDFLAGS) -o $$@ -T target/$(1)/ls.x $$(OBJ_$(1))
35
 
36
build/$(1)/%.o: %.c
37
ifeq ($(shell uname),WindowsNT)
38
	@-if not exist $$(subst /,\,$$(dir $$@)) md $$(subst /,\,$$(dir $$@))
39
else
40
	@-mkdir -p $$(dir $$@)
41
endif
5 theseven 42
	$(CC) -c $(CFLAGS) -Itarget/$(1) -DTARGET_$(1) -o $$@ $$<
9 theseven 43
	@$(CC) -MM $(CFLAGS) -Itarget/$(1) -DTARGET_$(1) $$< > $$@.dep.tmp
2 theseven 44
	@sed -e "s|.*:|$$@:|" < $$@.dep.tmp > $$@.dep
11 theseven 45
	@sed -e "s/.*://" -e "s/\\$$$$//" < $$@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$$$/:/" >> $$@.dep
2 theseven 46
	@rm -f $$@.dep.tmp
47
 
48
build/$(1)/%.o: %.S
49
ifeq ($(shell uname),WindowsNT)
50
	@-if not exist $$(subst /,\,$$(dir $$@)) md $$(subst /,\,$$(dir $$@))
51
else
52
	@-mkdir -p $$(dir $$@)
53
endif
5 theseven 54
	$(CC) -c $(CFLAGS) -Itarget/$(1) -DTARGET_$(1) -o $$@ $$<
9 theseven 55
	@$(CC) -MM $(CFLAGS) -Itarget/$(1) -DTARGET_$(1) $$< > $$@.dep.tmp
2 theseven 56
	@sed -e "s|.*:|$$@:|" < $$@.dep.tmp > $$@.dep
11 theseven 57
	@sed -e "s/.*://" -e "s/\\$$$$//" < $$@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$$$/:/" >> $$@.dep
2 theseven 58
	@rm -f $$@.dep.tmp
59
endef
60
 
61
all: $(TARGETS)
62
 
63
$(foreach target,$(TARGETS),$(eval $(call TARGET_template,$(target))))
64
 
65
clean:
66
	rm -rf build
67
 
68
.PHONY: all clean $(TARGETS)