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,5 +1,5 @@
PROJ_NAME = hello_world PROJ_NAME = hello_world
DEBUG=no DEBUG = yes
BENCH = no BENCH = no
MULDIV = no MULDIV = no
@ -29,11 +29,11 @@ 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)
@ -52,16 +52,19 @@ 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) \
-DNDEBUG \
-fno-pic \
-ffreestanding \
-MD \
-fstrict-volatile-bitfields \
-fno-strict-aliasing
CXXFLAGS += -march=$(MARCH) \
-mabi=$(MABI) \ -mabi=$(MABI) \
-DNDEBUG \ -DNDEBUG \
-fno-pic \ -fno-pic \
@ -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);
} }