irq/makefile

137 lines
3.3 KiB
Makefile
Raw Normal View History

2024-06-01 21:14:04 +00:00
PROJ_NAME=hello_world
DEBUG=no
BENCH=no
MULDIV=no
2024-07-03 16:57:26 +00:00
SRCS = $(wildcard src/*.c) \
$(wildcard src/*.cpp) \
$(wildcard src/*.S) \
src/stub_stdlib.c
2024-06-01 21:14:04 +00:00
OBJDIR = build
INC =
LIBS =
LIBSINC = -L$(OBJDIR)
LDSCRIPT = ./src/linker.ld
# Set it to yes if you are using the sifive precompiled GCC pack
2024-07-03 16:57:26 +00:00
GCC_PACK ?= yes
2024-06-01 21:14:04 +00:00
2024-07-03 16:57:26 +00:00
ifeq ($(GCC_PACK),yes)
2024-06-01 21:14:04 +00:00
RISCV_NAME ?= riscv32-unknown-elf
2024-07-03 16:57:26 +00:00
RISCV_PATH ?= /home/user/riscv/opt/rv32im/
2024-06-01 21:14:04 +00:00
endif
MABI=ilp32
MARCH := rv32i_zicsr
ifeq ($(MULDIV),yes)
2024-07-03 16:57:26 +00:00
MARCH := $(MARCH)m
2024-06-01 21:14:04 +00:00
endif
2024-07-03 16:57:26 +00:00
#CFLAGS += -march=$(MARCH) -mabi=$(MABI) -DNDEBUG
#LDFLAGS += -march=$(MARCH) -mabi=$(MABI)
2024-06-01 21:14:04 +00:00
ifeq ($(DEBUG),yes)
2024-07-03 16:57:26 +00:00
CFLAGS += -g3 -O0
2024-06-01 21:14:04 +00:00
endif
ifeq ($(DEBUG),no)
2024-07-03 16:57:26 +00:00
CFLAGS += -g -Os
2024-06-01 21:14:04 +00:00
endif
ifeq ($(BENCH),yes)
2024-07-03 16:57:26 +00:00
CFLAGS += -fno-inline
2024-06-01 21:14:04 +00:00
endif
ifeq ($(SIFIVE_GCC_PACK),yes)
2024-07-03 16:57:26 +00:00
RISCV_CLIB=$(RISCV_PATH)/$(RISCV_NAME)/lib/$(MARCH)/$(MABI)/
2024-06-01 21:14:04 +00:00
else
2024-07-03 16:57:26 +00:00
RISCV_CLIB=$(RISCV_PATH)/$(RISCV_NAME)/lib/
2024-06-01 21:14:04 +00:00
endif
RISCV_OBJCOPY = $(RISCV_PATH)/bin/$(RISCV_NAME)-objcopy
RISCV_OBJDUMP = $(RISCV_PATH)/bin/$(RISCV_NAME)-objdump
RISCV_CC=$(RISCV_PATH)/bin/$(RISCV_NAME)-g++
2024-07-03 16:57:26 +00:00
#RISCV_CC=$(RISCV_PATH)/bin/$(RISCV_NAME)-gcc
#CFLAGS += -MD -fstrict-volatile-bitfields -fno-strict-aliasing
#LDFLAGS += -nostdlib -lgcc -mcmodel=medany -nostartfiles -ffreestanding -Wl,-Bstatic,-T,$(LDSCRIPT),-Map,$(OBJDIR)/$(PROJ_NAME).map,--print-memory-usage
#CFLAGS += -march=$(MARCH) -mabi=$(MABI) -DNDEBUG -std=c++11 -fno-pic -ffreestanding -MD -fstrict-volatile-bitfields -fno-strict-aliasing
#LDFLAGS += -march=$(MARCH) -mabi=$(MABI) -lc -lgcc -nostdlib -nostartfiles -mcmodel=medany -ffreestanding -Wl,-Bstatic,-T,$(LDSCRIPT),-Map,$(OBJDIR)/$(PROJ_NAME).map
CFLAGS += -march=$(MARCH) \
-mabi=$(MABI) \
-DNDEBUG \
-fno-pic \
-ffreestanding \
-MD \
-fstrict-volatile-bitfields \
-fno-strict-aliasing \
-std=c++11
LDFLAGS += -march=$(MARCH) \
-mabi=$(MABI) \
-lc \
-lgcc \
-nostdlib \
-nostartfiles \
-mcmodel=medany \
-ffreestanding \
-Wl,-Bstatic,-T,$(LDSCRIPT),-Map,$(OBJDIR)/$(PROJ_NAME).map
2024-06-01 21:14:04 +00:00
OBJS := $(SRCS)
OBJS := $(OBJS:.c=.o)
OBJS := $(OBJS:.cpp=.o)
OBJS := $(OBJS:.S=.o)
OBJS := $(addprefix $(OBJDIR)/,$(OBJS))
all: $(OBJDIR)/$(PROJ_NAME).elf $(OBJDIR)/$(PROJ_NAME).hex $(OBJDIR)/$(PROJ_NAME).asm $(OBJDIR)/$(PROJ_NAME).v
$(OBJDIR)/%.elf: $(OBJS) | $(OBJDIR)
$(RISCV_CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBSINC) $(LIBS)
%.hex: %.elf
$(RISCV_OBJCOPY) -O ihex $^ $@
%.bin: %.elf
$(RISCV_OBJCOPY) -O binary $^ $@
%.v: %.elf
$(RISCV_OBJCOPY) -O verilog $^ $@
%.asm: %.elf
$(RISCV_OBJDUMP) -S -d $^ > $@
$(OBJDIR)/%.o: %.c
mkdir -p $(dir $@)
2024-07-03 16:57:26 +00:00
$(RISCV_CC) -c $(CFLAGS) $(INC) -o $@ $^
2024-06-01 21:14:04 +00:00
$(OBJDIR)/%.o: %.cpp
mkdir -p $(dir $@)
2024-07-03 16:57:26 +00:00
$(RISCV_CC) -c $(CFLAGS) $(INC) -o $@ $^
2024-06-01 21:14:04 +00:00
$(OBJDIR)/%.o: %.S
mkdir -p $(dir $@)
$(RISCV_CC) -c $(CFLAGS) -o $@ $^ -D__ASSEMBLY__=1
$(OBJDIR):
mkdir -p $@
.PHONY: clean
clean:
rm -rf $(OBJDIR)/src
rm -f $(OBJDIR)/$(PROJ_NAME).elf
rm -f $(OBJDIR)/$(PROJ_NAME).hex
rm -f $(OBJDIR)/$(PROJ_NAME).map
rm -f $(OBJDIR)/$(PROJ_NAME).v
rm -f $(OBJDIR)/$(PROJ_NAME).asm
find $(OBJDIR) -type f -name '*.o' -print0 | xargs -0 -r rm
find $(OBJDIR) -type f -name '*.d' -print0 | xargs -0 -r rm
2024-07-03 16:57:26 +00:00
clean-all: clean
2024-06-01 21:14:04 +00:00
.SECONDARY: $(OBJS)
2024-07-03 16:57:26 +00:00