freertos/Demo/Common/Makefile

173 lines
4.6 KiB
Makefile
Raw Normal View History

# File to be included in all makefiles
PROJ_NAME = freeRTOS_demo
RISCV_XLEN ?= 32
RISCV_LIB ?= elf
ARCH ?= rv32i_zicsr
OPT ?= O0
PRINT_ENABLE ?= yes
TARGET=riscv32-unknown-${RISCV_LIB}
GCC_PACK ?= yes
2024-07-13 16:33:13 +00:00
RISCV_NAME ?= riscv64-unknown-elf
ifeq ($(GCC_PACK),yes)
2024-07-13 16:33:13 +00:00
RISCV_PATH ?= /home/user/riscv/opt/rv32i_zicsr/
endif
MABI = ilp32
MARCH := rv32i_zicsr
WARNINGS= -Wall -Wextra -Wshadow -Wpointer-arith -Wbad-function-cast -Wcast-align -Wsign-compare \
-Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wunused
FREERTOS_SOURCE_DIR = ../../Source
CUNIT = ../../../cunit
INCLUDES = \
-I. \
-I../arch \
-I.. \
-I./conf \
-I./include \
-I$(FREERTOS_SOURCE_DIR)/include \
-I../Common/include \
2024-07-13 16:33:13 +00:00
-I../Common/include/FreeRTOS \
-I$(FREERTOS_SOURCE_DIR)/portable/GCC/RISCV
CFLAGS = \
$(WARNINGS) $(INCLUDES) \
-fomit-frame-pointer -fno-strict-aliasing -fno-builtin \
-D__gracefulExit -mcmodel=medany \
2024-07-13 16:33:13 +00:00
-march=$(ARCH) -mabi=$(MABI) -ggdb3 -gdwarf-3 -${OPT}
CXXFLAGS += -march=$(ARCH) \
-mabi=$(MABI) \
-DNDEBUG \
-fno-pic \
-MD \
-fstrict-volatile-bitfields \
-fno-strict-aliasing \
2024-07-13 16:33:13 +00:00
-fno-exceptions \
-std=c++17 \
-ggdb3 -gdwarf-3 \
$(INCLUDES)
ifeq ($(PRINT_ENABLE),yes)
CFLAGS += -DPRINT_ENABLE
CXXFLAGS += -DPRINT_ENABLE
endif
2024-07-13 16:33:13 +00:00
LDFLAGS = -g -T ../arch/link.ld \
-nostartfiles \
-static \
-fno-exceptions \
-march=$(ARCH) -mabi=$(MABI) -ggdb3 -gdwarf-3
LIBS = -L$(RISCV_PATH)/lib/gcc/$(TARGET)/$(GCCVER) \
-L$(RISCV_PATH)/$(TARGET)/lib \
2024-07-13 16:33:13 +00:00
-fno-exceptions \
-lc -lgcc -lstdc++
RISCV_OBJCOPY = $(RISCV_PATH)/bin/$(RISCV_NAME)-objcopy
RISCV_OBJDUMP = $(RISCV_PATH)/bin/$(RISCV_NAME)-objdump
RISCV_CC = $(RISCV_PATH)/bin/$(RISCV_NAME)-gcc
CXX = $(RISCV_PATH)/bin/$(RISCV_NAME)-g++
SRCS = $(wildcard ../arch/*.c) \
$(wildcard ../arch/*.cpp) \
$(wildcard ../arch/*.S) \
$(wildcard ../Common/*.c) \
$(wildcard ../Common/*.cpp) \
$(wildcard ../Common/*.S) \
2024-07-13 16:33:13 +00:00
$(wildcard ../Common/lib/*.c) \
$(FREERTOS_SOURCE_DIR)/croutine.c \
$(FREERTOS_SOURCE_DIR)/list.c \
$(FREERTOS_SOURCE_DIR)/queue.c \
$(FREERTOS_SOURCE_DIR)/tasks.c \
$(FREERTOS_SOURCE_DIR)/timers.c \
$(FREERTOS_SOURCE_DIR)/event_groups.c \
2024-07-13 16:33:13 +00:00
$(FREERTOS_SOURCE_DIR)/portable/MemMang/heap_3.c \
$(FREERTOS_SOURCE_DIR)/string.c \
$(FREERTOS_SOURCE_DIR)/portable/GCC/RISCV/port.c \
$(FREERTOS_SOURCE_DIR)/portable/GCC/RISCV/portasm.S \
../arch/boot.S
OBJDIR = bin
OBJS := $(SRCS)
OBJS := $(OBJS:../arch/%.c=bin/arch/%.o)
OBJS := $(OBJS:../arch/%.cpp=bin/arch/%.o)
OBJS := $(OBJS:../arch/%.S=bin/arch/%.o)
OBJS := $(OBJS:../Common/%.c=bin/Common/%.o)
OBJS := $(OBJS:../Common/%.cpp=bin/Common/%.o)
OBJS := $(OBJS:../Common/%.S=bin/Common/%.o)
OBJS := $(OBJS:$(FREERTOS_SOURCE_DIR)/%.c=bin/freertos/%.o)
OBJS := $(OBJS:$(FREERTOS_SOURCE_DIR)/%.cpp=bin/freertos/%.o)
OBJS := $(OBJS:$(FREERTOS_SOURCE_DIR)/%.S=bin/freertos/%.o)
all: $(OBJDIR)/$(PROJ_NAME).elf $(OBJDIR)/$(PROJ_NAME).hex $(OBJDIR)/$(PROJ_NAME).asm
$(OBJDIR)/%.elf: $(OBJS) | $(OBJDIR)
$(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBS)
$(OBJDIR)/%.hex: $(OBJDIR)/%.elf
$(RISCV_OBJCOPY) -O ihex $^ $@
$(OBJDIR)/%.bin: $(OBJDIR)/%.elf
$(RISCV_OBJCOPY) -O binary $^ $@
$(OBJDIR)/%.v: $(OBJDIR)/%.elf
$(RISCV_OBJCOPY) -O verilog $^ $@
$(OBJDIR)/%.asm: $(OBJDIR)/%.elf
$(RISCV_OBJDUMP) -S -d $^ > $@
$(OBJDIR)/arch/%.o: ../arch/%.c
mkdir -p $(dir $@)
$(RISCV_CC) -c $(CFLAGS) $(INC) -o $@ $^
$(OBJDIR)/arch/%.o: ../arch/%.cpp
mkdir -p $(dir $@)
$(CXX) -c $(CXXFLAGS) $(INC) -o $@ $^
$(OBJDIR)/arch/%.o: ../arch/%.S
mkdir -p $(dir $@)
$(RISCV_CC) -c $(CFLAGS) -o $@ $^ -D__ASSEMBLY__=1
$(OBJDIR)/Common/%.o: ../Common/%.c
mkdir -p $(dir $@)
$(RISCV_CC) -c $(CFLAGS) $(INC) -o $@ $^
$(OBJDIR)/Common/%.o: ../Common/%.cpp
mkdir -p $(dir $@)
$(CXX) -c $(CXXFLAGS) $(INC) -o $@ $^
$(OBJDIR)/Common/%.o: ../Common/%.S
mkdir -p $(dir $@)
$(RISCV_CC) -c $(CFLAGS) -o $@ $^ -D__ASSEMBLY__=1
$(OBJDIR)/freertos/%.o: $(FREERTOS_SOURCE_DIR)/%.c
mkdir -p $(dir $@)
$(RISCV_CC) -c $(CFLAGS) $(INC) -o $@ $^
$(OBJDIR)/freertos/%.o: $(FREERTOS_SOURCE_DIR)/%.cpp
mkdir -p $(dir $@)
$(CXX) -c $(CXXFLAGS) $(INC) -o $@ $^
$(OBJDIR)/freertos/%.o: $(FREERTOS_SOURCE_DIR)/%.S
mkdir -p $(dir $@)
$(RISCV_CC) -c $(CFLAGS) -o $@ $^ -D__ASSEMBLY__=1
$(OBJDIR):
mkdir -p $@
.PHONY: clean
clean:
rm -rf $(OBJDIR)/*
clean-all: clean
.SECONDARY: $(OBJS)