freertos/Demo/Common/Makefile

165 lines
4.4 KiB
Makefile

# 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
RISCV_NAME ?= riscv32-unknown-elf
ifeq ($(GCC_PACK),yes)
RISCV_PATH ?= /home/user/riscv/opt/rv32im/
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 \
-I$(FREERTOS_SOURCE_DIR)/portable/GCC/RISCV
CFLAGS = \
$(WARNINGS) $(INCLUDES) \
-fomit-frame-pointer -fno-strict-aliasing -fno-builtin \
-D__gracefulExit -mcmodel=medany \
-march=$(ARCH) -mabi=$(MABI) -ggdb3 -${OPT}
CXXFLAGS += -march=$(ARCH) \
-mabi=$(MABI) \
-DNDEBUG \
-fno-pic \
-MD \
-fstrict-volatile-bitfields \
-fno-strict-aliasing \
-std=c++11 \
-ggdb3 -gdwarf-3 \
$(INCLUDES)
ifeq ($(PRINT_ENABLE),yes)
CFLAGS += -DPRINT_ENABLE
CXXFLAGS += -DPRINT_ENABLE
endif
LDFLAGS = -g -T ../arch/link.ld -nostartfiles -static -march=$(ARCH)
LIBS = -L$(RISCV_PATH)/lib/gcc/$(TARGET)/$(GCCVER) \
-L$(RISCV_PATH)/$(TARGET)/lib \
-lc -lgcc -lstdc++\
-I/home/user/opt/include
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) \
$(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 \
$(FREERTOS_SOURCE_DIR)/portable/MemMang/heap_2.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)