-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
54 lines (41 loc) · 1.88 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# Makefile for building and running the code
# QEMU path
QEMU=qemu-system-riscv32
# Compiler and flags
CC=clang
OBJCOPY=llvm-objcopy
CFLAGS=-std=c11 -O2 -g3 -Wall -Wextra --target=riscv32 -ffreestanding -nostdlib -I include
# Source folders
KERNEL_SRC=kernel
USER_SRC=user
BUILD_DIR=build
# Source files
SRC_FILES=$(shell find $(KERNEL_SRC) $(USER_SRC) -name '*.c')
SHELL_SOURCES= $(USER_SRC)/shell.c $(USER_SRC)/user.c $(KERNEL_SRC)/common.c
KERNEL_SOURCES= $(wildcard $(KERNEL_SRC)/*.c)
# Build targets
all: $(BUILD_DIR) $(BUILD_DIR)/shell.bin.o kernel.elf disk.tar
# Add this before your first target
$(BUILD_DIR):
mkdir -p $(BUILD_DIR)
# Add this as a dependency to your targets that use $(BUILD_DIR)
$(BUILD_DIR)/shell.bin.o: $(SHELL_SOURCES) | $(BUILD_DIR)
$(CC) $(CFLAGS) -Wl,-Tuser.ld -o $(BUILD_DIR)/shell.elf $(SHELL_SOURCES)
$(OBJCOPY) --set-section-flags .bss=alloc,contents -O binary $(BUILD_DIR)/shell.elf $(BUILD_DIR)/shell.bin
$(OBJCOPY) -Ibinary -Oelf32-littleriscv $(BUILD_DIR)/shell.bin $(BUILD_DIR)/shell.bin.o
kernel.elf: $(BUILD_DIR)/shell.bin.o $(SRC_FILES) | $(BUILD_DIR)
$(CC) $(CFLAGS) -Wl,-Tkernel.ld -o kernel.elf \
$(KERNEL_SOURCES) $(BUILD_DIR)/shell.bin.o
# $(BUILD_DIR)/shell.bin.o: $(SHELL_SOURCES)
# $(CC) $(CFLAGS) -Wl,-Tuser.ld -o $(BUILD_DIR)/shell.elf $(SHELL_SOURCES)
# $(OBJCOPY) --set-section-flags .bss=alloc,contents -O binary $(BUILD_DIR)/shell.elf $(BUILD_DIR)/shell.bin
# $(OBJCOPY) -Ibinary -Oelf32-littleriscv $(BUILD_DIR)/shell.bin $(BUILD_DIR)/shell.bin.o
# kernel.elf: $(BUILD_DIR)/shell.bin.o $(SRC_FILES)
# $(CC) $(CFLAGS) -Wl,-Tkernel.ld -o kernel.elf \
# $(KERNEL_SOURCES) $(BUILD_DIR)/shell.bin.o
# Use tar for file system, ./disk/* are dependencies
disk.tar: $(wildcard disk/*)
tar -cf disk.tar --format=ustar ./disk/*.txt
clean:
rm -f $(BUILD_DIR)/*.bin $(BUILD_DIR)/*.elf $(BUILD_DIR)/*.o $(BUILD_DIR)/*.map
.PHONY: all run clean