123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119 |
- TOOL_PREFIX = riscv32-unknown-elf-
- #arm-none-eabi-
- CC = $(TOOL_PREFIX)gcc
- OBJCOPY = $(TOOL_PREFIX)objcopy
- LD = $(TOOL_PREFIX)ld
- PYTHON = python3
- ZIP = zip -r
- UNZIP = unzip
- ifneq ($(VERBOSE),1)
- TOOL_PREFIX := @$(TOOL_PREFIX)
- endif
- FLAGS = -g -Os -nostdlib -std=gnu99 -iquote $(ROOT)/inc
- FLAGS += -Wall -Werror -Wno-format -Wdeclaration-after-statement
- FLAGS += -Wstrict-prototypes -Wredundant-decls -Wnested-externs
- FLAGS += -fno-common -fno-exceptions -fno-strict-aliasing
- FLAGS += -mlittle-endian
- #-mthumb -mfloat-abi=soft
- FLAGS += -Wno-unused-value -ffunction-sections
- ifeq ($(mcu),stm32f1)
- FLAGS += -mcpu=cortex-m3 -DSTM32F1=1 -DMCU=1
- stm32f1=y
- arch=arm
- else ifeq ($(mcu),stm32f7)
- FLAGS += -mcpu=cortex-m7 -DSTM32F7=7 -DMCU=7
- stm32f7=y
- arch=arm
- else ifeq ($(mcu),at32f4)
- FLAGS += -mcpu=cortex-m4 -DAT32F4=4 -DMCU=4
- at32f4=y
- arch=arm
- else ifeq ($(mcu),gd32vf1)
- FLAGS += -march=rv32imac -DGD32VF1=2 -DMCU=2
- gd32vf1=y
- arch=rv32
- endif
- ifneq ($(debug),y)
- FLAGS += -DNDEBUG
- endif
- ifeq ($(bootloader),y)
- FLAGS += -DBOOTLOADER=1
- endif
- FLAGS += -MMD -MF .$(@F).d
- DEPS = .*.d
- FLAGS += $(FLAGS-y)
- CFLAGS += $(CFLAGS-y) $(FLAGS) -include decls.h
- AFLAGS += $(AFLAGS-y) $(FLAGS) -D__ASSEMBLY__
- LDFLAGS += $(LDFLAGS-y) $(FLAGS) -Wl,--gc-sections
- RULES_MK := y
- include Makefile
- SUBDIRS += $(SUBDIRS-y)
- OBJS += $(OBJS-y) $(patsubst %,%/build.o,$(SUBDIRS))
- # Force execution of pattern rules (for which PHONY cannot be directly used).
- .PHONY: FORCE
- FORCE:
- .PHONY: clean
- .SECONDARY:
- build.o: $(OBJS)
- $(LD) -r -o $@ $^
- %/build.o: FORCE
- $(MAKE) -f $(ROOT)/Rules.mk -C $* build.o
- %.o: %.c Makefile
- @echo CC $@
- $(CC) $(CFLAGS) -c $< -o $@
- %.o: %.S Makefile
- @echo AS $@
- $(CC) $(AFLAGS) -c $< -o $@
- %.ld: %.ld.S Makefile
- @echo CPP $@
- $(CC) -P -E $(AFLAGS) $< -o $@
- %.elf: $(OBJS) %.ld Makefile
- @echo LD $@
- $(CC) $(LDFLAGS) -T$(*F).ld $(OBJS) -o $@
- chmod a-x $@
- %.hex: %.elf
- @echo OBJCOPY $@
- $(OBJCOPY) -O ihex $< $@
- chmod a-x $@
- %.bin: %.elf
- @echo OBJCOPY $@
- $(OBJCOPY) -O binary $< $@
- chmod a-x $@
- %.o: $(RPATH)/%.c Makefile
- @echo CC $@
- $(CC) $(CFLAGS) -c $< -o $@
- %.o: $(RPATH)/%.S Makefile
- @echo AS $@
- $(CC) $(AFLAGS) -c $< -o $@
- clean:: $(addprefix _clean_,$(SUBDIRS) $(SUBDIRS-n) $(SUBDIRS-))
- rm -f *.orig *.rej *~ *.o *.elf *.hex *.bin *.ld $(DEPS)
- _clean_%: FORCE
- $(MAKE) -f $(ROOT)/Rules.mk -C $* clean
- -include $(DEPS)
|