TOOLCHAIN = /opt/arm-toolchain OPENOCD = /opt/arm-toolchain/openocd AS = $(TOOLCHAIN)/bin/arm-elf-as CC = $(TOOLCHAIN)/bin/arm-elf-gcc LD = $(TOOLCHAIN)/bin/arm-elf-ld NM = $(TOOLCHAIN)/bin/arm-elf-nm SIZE = $(TOOLCHAIN)/bin/arm-elf-size OBJCOPY = $(TOOLCHAIN)/bin/arm-elf-objcopy OBJDUMP = $(TOOLCHAIN)/bin/arm-elf-objdump INCDIRS = include $(TOOLCHAIN)/lib/gcc/arm-elf/4.1.1/include $(TOOLCHAIN)/arm-elf/include LIBDIRS = $(TOOLCHAIN)/arm-elf/lib $(TOOLCHAIN)/lib/gcc/arm-elf/4.1.1 # ------ BUILD = build TARGET = sam7fc ASFLAGS = -mcpu=arm7tdmi -Wa,-adhlns=$(BUILD)/$(*D)/$(*F).lst,--gdwarf-2 -Iinclude CFLAGS = -gdwarf-2 -mcpu=arm7tdmi -Os -std=gnu99 CFLAGS += -Wa,-adhlns=$(BUILD)/$(*D)/$(*F).lst CFLAGS += -nostdinc $(patsubst %,-I%,$(INCDIRS)) CFLAGS += -MD -MP -MF $(BUILD)/$(*D)/$(*F).d CFLAGS += -Wall #CFLAGS += -Wextra #CFLAGS += -Wcast-align -Wimplicit -Wunused CFLAGS += -Wpointer-arith -Wswitch CFLAGS += -Wredundant-decls -Wreturn-type -Wshadow CFLAGS += -Wbad-function-cast -Wsign-compare -Waggregate-return #CFLAGS += -Wcast-qual -Wnested-externs #CFLAGS += -Wmissing-prototypes -Wmissing-declarations CFLAGS += -Wstrict-prototypes LDFLAGS = -nostartfiles -t ldscript.ld -Wl,-Map=$@.map,--cref LDFLAGS += $(patsubst %,-L%,$(LIBDIRS)) LDFLAGS += -lc -lgcc # ------ SRC := $(wildcard *.c) $(wildcard src/*.c) $(wildcard src/*/*.c) AS_SRC := $(wildcard *.s) $(wildcard src/*.s) all: $(BUILD)/$(TARGET).elf @$(SIZE) -x $< $(BUILD)/$(TARGET).elf: $(patsubst %,$(BUILD)/%,$(AS_SRC:.s=.o) $(SRC:.c=.o)) @echo " Linking file: $@" @$(shell mkdir -p $(BUILD)/$(*D)) @$(CC) $(CFLAGS) $^ -o $@ $(LDFLAGS) > /dev/null @$(OBJCOPY) -O binary $@ $@.bin @$(OBJCOPY) -O ihex $@ $@.hex @$(OBJDUMP) -h -S -C $@ > $@.lss @$(NM) -n $@ > $@.sym $(BUILD)/%.o: %.c @echo " Building file: $<" @$(shell mkdir -p $(BUILD)/$(*D)) @$(CC) -c $(CFLAGS) $< -o $@ $(BUILD)/%.o: %.s @echo " Building file: $<" @$(shell mkdir -p $(BUILD)/$(*D)) @$(CC) -c $(ASFLAGS) $< -o $@ clean: rm -rf $(BUILD) openocd: $(shell $(OPENOCD) -f scripts/openocd.cfg) install: all # ./scripts/download.sh $(TOOLCHAIN)/dfu-util -i 0 -D $(BUILD)/$(TARGET).elf.bin -include $(shell find $(BUILD) -name *.d 2> /dev/null)