handle own libraries
This commit is contained in:
parent
e50c9a1c49
commit
ebd0bc03b2
21
Makefile
21
Makefile
|
@ -21,10 +21,13 @@ Q := @
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# the final binary name (without extension)
|
# the final binary name (without extension)
|
||||||
BINARY = main
|
BINARY = firmware
|
||||||
|
|
||||||
# source files
|
# source files
|
||||||
OBJS += $(BINARY).o
|
LIBS = lib
|
||||||
|
CSRC = $(wildcard *.c)
|
||||||
|
CSRC += $(foreach LIB,$(LIBS),$(wildcard $(LIB)/*.c))
|
||||||
|
OBJ = $(patsubst %.c,%.o,$(CSRC))
|
||||||
|
|
||||||
# executables
|
# executables
|
||||||
PREFIX ?= arm-none-eabi
|
PREFIX ?= arm-none-eabi
|
||||||
|
@ -55,11 +58,12 @@ DEFS += -DSTM32F1
|
||||||
|
|
||||||
# C flags
|
# C flags
|
||||||
CFLAGS += -Os -g
|
CFLAGS += -Os -g
|
||||||
CFLAGS += -Wall -Wundef -Wextra -Wshadow -Wimplicit-function-declaration
|
CFLAGS += -Wall -Werror -Wundef -Wextra -Wshadow -Wimplicit-function-declaration
|
||||||
CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes
|
CFLAGS += -Wredundant-decls -Wmissing-prototypes -Wstrict-prototypes
|
||||||
CFLAGS += -fno-common -ffunction-sections -fdata-sections
|
CFLAGS += -fno-common -ffunction-sections -fdata-sections
|
||||||
CFLAGS += -MD
|
CFLAGS += -MD
|
||||||
CFLAGS += -I$(INCLUDE_DIR) $(DEFS)
|
CFLAGS += -I. -I$(INCLUDE_DIR) $(patsubst %,-I%,$(LIBS))
|
||||||
|
CFLAGS += $(DEFS)
|
||||||
|
|
||||||
# linker script
|
# linker script
|
||||||
LDSCRIPT = stm32f103x8-dfu.ld
|
LDSCRIPT = stm32f103x8-dfu.ld
|
||||||
|
@ -67,6 +71,7 @@ LDSCRIPT = stm32f103x8-dfu.ld
|
||||||
# linker flags
|
# linker flags
|
||||||
LDFLAGS += --static -nostartfiles
|
LDFLAGS += --static -nostartfiles
|
||||||
LDFLAGS += -L$(LIB_DIR)
|
LDFLAGS += -L$(LIB_DIR)
|
||||||
|
LDFLAGS += -I. $(patsubst %,-I%,$(LIBS))
|
||||||
LDFLAGS += -T$(LDSCRIPT)
|
LDFLAGS += -T$(LDSCRIPT)
|
||||||
LDFLAGS += -Wl,-Map=$(*).map
|
LDFLAGS += -Wl,-Map=$(*).map
|
||||||
LDFLAGS += -Wl,--gc-sections
|
LDFLAGS += -Wl,--gc-sections
|
||||||
|
@ -123,9 +128,9 @@ list: $(BINARY).list
|
||||||
%.map: %.elf
|
%.map: %.elf
|
||||||
@# it's generated along with the elf
|
@# it's generated along with the elf
|
||||||
|
|
||||||
%.elf: $(OBJS) $(LDSCRIPT) $(LIB_DIR)/lib$(LIBNAME).a
|
%.elf: $(OBJ) $(LDSCRIPT) $(LIB_DIR)/lib$(LIBNAME).a
|
||||||
$(info compiling $(@))
|
$(info compiling $(@))
|
||||||
$(Q)$(LD) $(LDFLAGS) $(ARCH_FLAGS) $(OBJS) $(LDLIBS) -o $(@)
|
$(Q)$(LD) $(LDFLAGS) $(ARCH_FLAGS) $(OBJ) $(LDLIBS) -o $(@)
|
||||||
|
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
@#printf " CC $(*).c\n"
|
@#printf " CC $(*).c\n"
|
||||||
|
@ -154,5 +159,5 @@ flash-dfu: $(BINARY).bin
|
||||||
$(Q)dfu-util --device 1eaf:0003 --cfg 1 --intf 0 --alt 2 --reset --download $(<)
|
$(Q)dfu-util --device 1eaf:0003 --cfg 1 --intf 0 --alt 2 --reset --download $(<)
|
||||||
|
|
||||||
.PHONY: clean elf bin hex srec list bootloader flash flash-swd flash-dfu
|
.PHONY: clean elf bin hex srec list bootloader flash flash-swd flash-dfu
|
||||||
|
.SECONDARY:
|
||||||
-include $(OBJS:.o=.d)
|
-include $(OBJ:.o=.d)
|
||||||
|
|
Loading…
Reference in New Issue