makefile fixed, c++ stl working :)

This commit is contained in:
mpabi 2024-07-04 22:07:49 +00:00
parent 0f74c6d90f
commit 24b76da4b0
2 changed files with 44 additions and 35 deletions

View File

@ -1,12 +1,12 @@
PROJ_NAME=hello_world PROJ_NAME = hello_world
DEBUG=no DEBUG = yes
BENCH=no BENCH = no
MULDIV=no MULDIV = no
SRCS = $(wildcard src/*.c) \ SRCS = $(wildcard src/*.c) \
$(wildcard src/*.cpp) \ $(wildcard src/*.cpp) \
$(wildcard src/*.S) \ $(wildcard src/*.S) \
src/stub_stdlib.c src/stub_stdlib.c
OBJDIR = build OBJDIR = build
@ -20,46 +20,40 @@ GCC_PACK ?= yes
ifeq ($(GCC_PACK),yes) ifeq ($(GCC_PACK),yes)
RISCV_NAME ?= riscv32-unknown-elf RISCV_NAME ?= riscv32-unknown-elf
RISCV_PATH ?= /home/user/riscv/opt/rv32im/ RISCV_PATH ?= /home/user/riscv/opt/rv32im/
endif endif
MABI=ilp32 MABI = ilp32
MARCH := rv32i_zicsr MARCH := rv32i_zicsr
ifeq ($(MULDIV),yes) ifeq ($(MULDIV),yes)
MARCH := $(MARCH)m MARCH := $(MARCH)m
endif endif
#CFLAGS += -march=$(MARCH) -mabi=$(MABI) -DNDEBUG
#LDFLAGS += -march=$(MARCH) -mabi=$(MABI)
ifeq ($(DEBUG),yes) ifeq ($(DEBUG),yes)
CFLAGS += -g3 -O0 # CFLAGS += -g3 -O0
CFLAGS += -g3 -gdwarf-3 -O0 -DDEBUG
CXXFLAGS += -g3 -gdwarf-3 -O0 -DDEBUG
LDFLAGS += -g3 -gdwarf-3
endif endif
ifeq ($(DEBUG),no) ifeq ($(DEBUG),no)
CFLAGS += -g -Os CFLAGS += -g -Os
endif endif
ifeq ($(BENCH),yes) ifeq ($(BENCH),yes)
CFLAGS += -fno-inline CFLAGS += -fno-inline
endif endif
ifeq ($(SIFIVE_GCC_PACK),yes) ifeq ($(SIFIVE_GCC_PACK),yes)
RISCV_CLIB=$(RISCV_PATH)/$(RISCV_NAME)/lib/$(MARCH)/$(MABI)/ RISCV_CLIB=$(RISCV_PATH)/$(RISCV_NAME)/lib/$(MARCH)/$(MABI)/
else else
RISCV_CLIB=$(RISCV_PATH)/$(RISCV_NAME)/lib/ RISCV_CLIB=$(RISCV_PATH)/$(RISCV_NAME)/lib/
endif endif
RISCV_OBJCOPY = $(RISCV_PATH)/bin/$(RISCV_NAME)-objcopy RISCV_OBJCOPY = $(RISCV_PATH)/bin/$(RISCV_NAME)-objcopy
RISCV_OBJDUMP = $(RISCV_PATH)/bin/$(RISCV_NAME)-objdump RISCV_OBJDUMP = $(RISCV_PATH)/bin/$(RISCV_NAME)-objdump
RISCV_CC=$(RISCV_PATH)/bin/$(RISCV_NAME)-g++ RISCV_CC = $(RISCV_PATH)/bin/$(RISCV_NAME)-gcc
#RISCV_CC=$(RISCV_PATH)/bin/$(RISCV_NAME)-gcc CXX = $(RISCV_PATH)/bin/$(RISCV_NAME)-g++
#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) \ CFLAGS += -march=$(MARCH) \
-mabi=$(MABI) \ -mabi=$(MABI) \
@ -68,8 +62,17 @@ CFLAGS += -march=$(MARCH) \
-ffreestanding \ -ffreestanding \
-MD \ -MD \
-fstrict-volatile-bitfields \ -fstrict-volatile-bitfields \
-fno-strict-aliasing \ -fno-strict-aliasing
-std=c++11
CXXFLAGS += -march=$(MARCH) \
-mabi=$(MABI) \
-DNDEBUG \
-fno-pic \
-ffreestanding \
-MD \
-fstrict-volatile-bitfields \
-fno-strict-aliasing \
-std=c++11
LDFLAGS += -march=$(MARCH) \ LDFLAGS += -march=$(MARCH) \
-mabi=$(MABI) \ -mabi=$(MABI) \
@ -90,7 +93,7 @@ OBJS := $(addprefix $(OBJDIR)/,$(OBJS))
all: $(OBJDIR)/$(PROJ_NAME).elf $(OBJDIR)/$(PROJ_NAME).hex $(OBJDIR)/$(PROJ_NAME).asm $(OBJDIR)/$(PROJ_NAME).v all: $(OBJDIR)/$(PROJ_NAME).elf $(OBJDIR)/$(PROJ_NAME).hex $(OBJDIR)/$(PROJ_NAME).asm $(OBJDIR)/$(PROJ_NAME).v
$(OBJDIR)/%.elf: $(OBJS) | $(OBJDIR) $(OBJDIR)/%.elf: $(OBJS) | $(OBJDIR)
$(RISCV_CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) $(LIBSINC) $(LIBS) $(CXX) $(CXXFLAGS) -o $@ $^ $(LDFLAGS) $(LIBSINC) $(LIBS)
%.hex: %.elf %.hex: %.elf
$(RISCV_OBJCOPY) -O ihex $^ $@ $(RISCV_OBJCOPY) -O ihex $^ $@
@ -110,7 +113,7 @@ $(OBJDIR)/%.o: %.c
$(OBJDIR)/%.o: %.cpp $(OBJDIR)/%.o: %.cpp
mkdir -p $(dir $@) mkdir -p $(dir $@)
$(RISCV_CC) -c $(CFLAGS) $(INC) -o $@ $^ $(CXX) -c $(CXXFLAGS) $(INC) -o $@ $^
$(OBJDIR)/%.o: %.S $(OBJDIR)/%.o: %.S
mkdir -p $(dir $@) mkdir -p $(dir $@)

View File

@ -87,19 +87,23 @@ int myfunc(const char *s)
void test (std::initializer_list<int> vals) { void test (std::initializer_list<int> vals) {
char buffer[50]; int buffer[50];
for (auto p = vals.begin(); p != vals.end(); ++p) { for (auto p = vals.begin(); p != vals.end(); ++p) {
std::sprintf(buffer, "%d\n", *p);
int * i = buffer;
*i++ = *p;
// sprintf(buffer, "%d\n", *p);
// printf("%s", buffer); // printf("%s", buffer);
} }
} }
int main() { int main() {
char str[10] = {1,2,3}; char str[10] = {1,2,3};
myfunc(str); /// myfunc(str);
// println("hello world arty a7 v1"); // println("hello world arty a7 v1");
@ -118,7 +122,9 @@ int main() {
// Thread 0 // Thread 0
while( 1){ while( 1){
char * s = "11111111112222222222"; char * s = "11111111112222222222";
++ile;
++ile;
test({1,2,3,4,5});
// len (s); // len (s);
} }