Subversion Repositories freemyipod

Rev

Rev 457 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

NAME := ftlstub

ifeq ($(shell uname),WindowsNT)
CCACHE :=
else
CCACHE := $(shell which ccache)
endif

CROSS   ?= arm-elf-eabi-
CC      := $(CCACHE) $(CROSS)gcc
AS      := $(CROSS)as
LD      := $(CROSS)ld
OBJCOPY := $(CROSS)objcopy
UCLPACK := ucl2e10singleblk

CFLAGS  += -Os -mthumb -fno-pie -fno-stack-protector -fomit-frame-pointer -I. -ffunction-sections
LDFLAGS += --gc-sections

preprocess = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#")
preprocesspaths = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#" | sed -e "s:^..*:$(dir $(1))&:")

SRC := $(call preprocesspaths,SOURCES,)
OBJ := $(SRC:%.c=build/%.o)
OBJ := $(OBJ:%.S=build/%.o)

all: $(NAME)

$(NAME): build/$(NAME).ucl

build/$(NAME).ucl: build/$(NAME).bin
        @echo [UCL]    $<
        @$(UCLPACK) $^ $@

build/$(NAME).bin: build/$(NAME).elf
        @echo [OC]     $<
        @$(OBJCOPY) -O binary $^ $@

build/$(NAME).elf: ls.x $(OBJ) build/main.o
        @echo [LD]     $@
        @$(LD) $(LDFLAGS) -o $@ -T ls.x $(OBJ)

build/%.o: %.c
        @echo [CC]     $<
ifeq ($(shell uname),WindowsNT)
        @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
else
        @-mkdir -p $(dir $@)
endif
        @$(CC) -c $(CFLAGS) -o $@ $<
        @$(CC) -MM $(CFLAGS) $< > $@.dep.tmp
        @sed -e "s|.*:|$@:|" < $@.dep.tmp > $@.dep
ifeq ($(shell uname),WindowsNT)
        @sed -e "s/.*://" -e "s/\\$$//" < $@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$/:/" >> $@.dep
else
        @sed -e 's/.*://' -e 's/\\$$//' < $@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $@.dep
endif
        @rm -f $@.dep.tmp

build/%.o: %.S
        @echo [CC]     $<
ifeq ($(shell uname),WindowsNT)
        @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
else
        @-mkdir -p $(dir $@)
endif
        @$(CC) -c $(CFLAGS) -o $@ $<
        @$(CC) -MM $(CFLAGS) $< > $@.dep.tmp
        @sed -e "s|.*:|$@:|" < $@.dep.tmp > $@.dep
ifeq ($(shell uname),WindowsNT)
        @sed -e "s/.*://" -e "s/\\$$//" < $@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$/:/" >> $@.dep
else
        @sed -e 's/.*://' -e 's/\\$$//' < $@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $@.dep
endif
        @rm -f $@.dep.tmp

-include $(OBJ:%=%.dep)

clean:
        rm -rf build

.PHONY: all clean $(NAME)