Gitignore and better makefile
This commit is contained in:
parent
bd1fe4b2a8
commit
9ff42d8fbc
2 changed files with 55 additions and 12 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
*.o
|
||||||
|
*.elf
|
65
makefile
65
makefile
|
@ -1,16 +1,40 @@
|
||||||
# Compiler and assembler
|
# Compiler and assembler
|
||||||
CC = riscv64-linux-gnu-gcc
|
CROSS=riscv64-linux-gnu
|
||||||
AS = riscv64-linux-gnu-as
|
CC = ${CROSS}-gcc
|
||||||
LD = riscv64-linux-gnu-ld
|
AS = ${CROSS}-as
|
||||||
|
LD = ${CROSS}-ld
|
||||||
|
OBJDUMP = ${CROSS}-objdump
|
||||||
|
SIZE = ${CROSS}-size
|
||||||
|
|
||||||
# Flags for compiler and assembler
|
# Specify the target binary (call it whatever)
|
||||||
CFLAGS = -static -nostartfiles -nostdlib
|
TARGET = bin.elf
|
||||||
ASFLAGS =
|
|
||||||
|
|
||||||
# QEMU command and flags
|
# QEMU command and flags
|
||||||
QEMU = qemu-riscv64-static
|
QEMU = qemu-riscv64-static
|
||||||
QEMU_FLAGS =
|
QEMU_FLAGS =
|
||||||
|
|
||||||
|
# Flags for compiler and assembler
|
||||||
|
CFLAGS += -static# # Use static linking
|
||||||
|
CFLAGS += -nostartfiles# # Do not use standard startup files
|
||||||
|
CFLAGS += -nostdlib# # Do not use standard libraries
|
||||||
|
CFLAGS += -fno-builtin# # Do not use built-in functions
|
||||||
|
CFLAGS += -fno-common# # Do not use common sections
|
||||||
|
CFLAGS += -march=rv64i # Use RV64I ISA, i.e., integer only
|
||||||
|
CFLAGS += -mabi=lp64 # Use LP64 ABI, i.e., 64-bit longs and pointers, 32-bit ints
|
||||||
|
CFLAGS += -Os# # Optimize for size
|
||||||
|
|
||||||
|
# Use GC=0 to disable garbage collection
|
||||||
|
ifneq ($(GC), 0)
|
||||||
|
CFLAGS += -ffreestanding
|
||||||
|
CFLAGS += -ffunction-sections -fdata-sections
|
||||||
|
CFLAGS += -Wl,--gc-sections
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Debugging flags, passed as 'make DEBUG=1 <target>'
|
||||||
|
ifeq ($(DEBUG), 1)
|
||||||
|
CFLAGS += -g -O0
|
||||||
|
endif
|
||||||
|
|
||||||
# Assembly source files
|
# Assembly source files
|
||||||
AS_SRCS := $(wildcard *.s)
|
AS_SRCS := $(wildcard *.s)
|
||||||
|
|
||||||
|
@ -19,17 +43,34 @@ OBJS := $(AS_SRCS:.s=.o)
|
||||||
|
|
||||||
# Default target
|
# Default target
|
||||||
all: $(OBJS)
|
all: $(OBJS)
|
||||||
$(LD) -o program $(OBJS)
|
@$(CC) $(CFLAGS) -o $(TARGET) $(OBJS)
|
||||||
# $(CC) $(CFLAGS) -o program $(OBJS)
|
@echo "LD $(OBJS)"
|
||||||
|
|
||||||
# Compile assembly sources
|
# Compile assembly sources
|
||||||
%.o: %.s
|
%.o: %.s
|
||||||
$(AS) $(ASFLAGS) -o $@ $<
|
@$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
@echo "CC $<"
|
||||||
|
|
||||||
# Run the program in QEMU
|
# Run the binary in QEMU
|
||||||
run: all
|
run: all
|
||||||
$(QEMU) $(QEMU_FLAGS) ./program
|
$(QEMU) $(QEMU_FLAGS) ./$(TARGET)
|
||||||
|
|
||||||
|
# View the text section of the binary
|
||||||
|
inspect: all
|
||||||
|
$(OBJDUMP) -d $(TARGET)
|
||||||
|
|
||||||
|
# View the disassembly
|
||||||
|
raw: all
|
||||||
|
$(OBJDUMP) -D $(TARGET)
|
||||||
|
|
||||||
|
# View the data section
|
||||||
|
data: all
|
||||||
|
$(OBJDUMP) -s $(TARGET) --section=.data
|
||||||
|
|
||||||
|
# Check the size of the compiled binary
|
||||||
|
size: all
|
||||||
|
$(SIZE) $(TARGET)
|
||||||
|
|
||||||
# Clean up
|
# Clean up
|
||||||
clean:
|
clean:
|
||||||
rm -f program $(OBJS)
|
rm -f $(TARGET) $(OBJS)
|
||||||
|
|
Loading…
Reference in a new issue