BINARY=test OBJS=test.o util-debug.o ds18b20.o OPENCM3_DIR=/home/mj/stm/libopencm3 DEVICE=stm32f103x8 all: $(BINARY).elf $(BINARY).bin flash: all ../bin/st-flash write $(BINARY).bin 0x8000000 reset: all ../bin/st-flash reset ifneq ($(V),1) Q := @ NULL := 2>/dev/null endif include $(OPENCM3_DIR)/mk/genlink-config.mk PREFIX ?= arm-none-eabi CC := $(PREFIX)-gcc CXX := $(PREFIX)-g++ LD := $(PREFIX)-gcc AR := $(PREFIX)-ar AS := $(PREFIX)-as OBJCOPY := $(PREFIX)-objcopy OBJDUMP := $(PREFIX)-objdump GDB := $(PREFIX)-gdb OPT := -Os DEBUG := -ggdb3 CSTD ?= -std=c99 TGT_CFLAGS += $(OPT) $(CSTD) $(DEBUG) TGT_CFLAGS += $(ARCH_FLAGS) TGT_CFLAGS += -Wall -Wextra -Wshadow -Wimplicit-function-declaration TGT_CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes TGT_CFLAGS += -fno-common -ffunction-sections -fdata-sections TGT_CPPFLAGS += -MD TGT_LDFLAGS += --static -nostartfiles TGT_LDFLAGS += -T$(LDSCRIPT) TGT_LDFLAGS += $(ARCH_FLAGS) $(DEBUG) TGT_LDFLAGS += -Wl,-Map=$(*).map -Wl,--cref TGT_LDFLAGS += -Wl,--gc-sections ifeq ($(V),99) TGT_LDFLAGS += -Wl,--print-gc-sections endif LDLIBS += -Wl,--start-group -lc -lgcc -lnosys -Wl,--end-group include $(OPENCM3_DIR)/mk/genlink-rules.mk %.bin: %.elf @printf " OBJCOPY $(*).bin\n" $(Q)$(OBJCOPY) -Obinary $(*).elf $(*).bin %.elf: $(OBJS) $(LDSCRIPT) @printf " LD $(*).elf\n" $(Q)$(LD) $(TGT_LDFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS) -o $*.elf %.o: %.c @printf " CC $(*).c\n" $(Q)$(CC) $(TGT_CFLAGS) $(CFLAGS) $(TGT_CPPFLAGS) $(CPPFLAGS) -o $*.o -c $*.c .PHONY: clean clean: @printf " CLEAN\n" $(Q)rm -f *.elf *.bin *.o *.d *.map $(LDSCRIPT) %.stlink-flash: %.bin @printf " FLASH $<\n" $(STFLASH) write $(*).bin 0x8000000 .SECONDEXPANSION: .SECONDARY: -include $(OBJS:.o=.d)