76 lines
2.1 KiB
Makefile
76 lines
2.1 KiB
Makefile
|
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)/.dep/$(*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
|
||
|
#CFLAGS += -Wstrict-prototypes -Wmissing-declarations
|
||
|
|
||
|
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)
|
||
|
@$(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)
|
||
|
|
||
|
-include $(shell mkdir -p $(BUILD)/.dep 2> /dev/null) $(wildcard $(BUILD)/.dep/*.d)
|