create common.mk for os projects

Makefiles of rvos projects contains too many duplicated contents.
Cleanup and move it into a new common.mk file for os only, this will
not touch asm samples.

Finally the common..mk which was used for both asm & os is removed.

Signed-off-by: Wang Chen <wangchen20@iscas.ac.cn>
This commit is contained in:
Wang Chen
2024-03-26 09:00:39 +08:00
committed by Chen Wang
parent 992b0ba91c
commit a2617cffa6
16 changed files with 82 additions and 489 deletions

View File

@@ -1,3 +1,6 @@
# Note: The Makefile for each project is just a symbol-link to the build.mk
# under the "asm" folder.
EXEC = test
SRC = ${EXEC}.s

View File

@@ -1,4 +1,15 @@
include ../../common.mk
# This file will be included by the build.mk.
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -march=rv32g -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none
GDB = gdb-multiarch
CC = ${CROSS_COMPILE}gcc
OBJCOPY = ${CROSS_COMPILE}objcopy
OBJDUMP = ${CROSS_COMPILE}objdump
.DEFAULT_GOAL := all
all:

View File

@@ -1,10 +0,0 @@
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS = -nostdlib -fno-builtin -march=rv32g -mabi=ilp32 -g -Wall
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none
GDB = gdb-multiarch
CC = ${CROSS_COMPILE}gcc
OBJCOPY = ${CROSS_COMPILE}objcopy
OBJDUMP = ${CROSS_COMPILE}objdump

View File

@@ -1,4 +1,4 @@
include ../../common.mk
LDFLAGS = -Ttext=0x80000000
SRCS_ASM = \
start.S \
@@ -6,41 +6,4 @@ SRCS_ASM = \
SRCS_C = \
kernel.c \
OBJS = $(SRCS_ASM:.S=.o)
OBJS += $(SRCS_C:.c=.o)
.DEFAULT_GOAL := all
all: os.elf
# start.o must be the first in dependency!
os.elf: ${OBJS}
${CC} ${CFLAGS} -Ttext=0x80000000 -o os.elf $^
${OBJCOPY} -O binary os.elf os.bin
%.o : %.c
${CC} ${CFLAGS} -c -o $@ $<
%.o : %.S
${CC} ${CFLAGS} -c -o $@ $<
run: all
@${QEMU} -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf -s -S &
@${GDB} os.elf -q -x ../gdbinit
.PHONY : code
code: all
@${OBJDUMP} -S os.elf | less
.PHONY : clean
clean:
rm -rf *.o *.bin *.elf
include ../common.mk

View File

@@ -1,4 +1,4 @@
include ../../common.mk
LDFLAGS = -Ttext=0x80000000
SRCS_ASM = \
start.S \
@@ -7,41 +7,4 @@ SRCS_C = \
kernel.c \
uart.c \
OBJS = $(SRCS_ASM:.S=.o)
OBJS += $(SRCS_C:.c=.o)
.DEFAULT_GOAL := all
all: os.elf
# start.o must be the first in dependency!
os.elf: ${OBJS}
${CC} ${CFLAGS} -Ttext=0x80000000 -o os.elf $^
${OBJCOPY} -O binary os.elf os.bin
%.o : %.c
${CC} ${CFLAGS} -c -o $@ $<
%.o : %.S
${CC} ${CFLAGS} -c -o $@ $<
run: all
@${QEMU} -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf -s -S &
@${GDB} os.elf -q -x ../gdbinit
.PHONY : code
code: all
@${OBJDUMP} -S os.elf | less
.PHONY : clean
clean:
rm -rf *.o *.bin *.elf
include ../common.mk

View File

@@ -1,5 +1,3 @@
include ../../common.mk
SRCS_ASM = \
start.S \
mem.S \
@@ -10,41 +8,4 @@ SRCS_C = \
printf.c \
page.c \
OBJS = $(SRCS_ASM:.S=.o)
OBJS += $(SRCS_C:.c=.o)
.DEFAULT_GOAL := all
all: os.elf
# start.o must be the first in dependency!
os.elf: ${OBJS}
${CC} ${CFLAGS} -T os.ld -o os.elf $^
${OBJCOPY} -O binary os.elf os.bin
%.o : %.c
${CC} ${CFLAGS} -c -o $@ $<
%.o : %.S
${CC} ${CFLAGS} -c -o $@ $<
run: all
@${QEMU} -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf -s -S &
@${GDB} os.elf -q -x ../gdbinit
.PHONY : code
code: all
@${OBJDUMP} -S os.elf | less
.PHONY : clean
clean:
rm -rf *.o *.bin *.elf
include ../common.mk

View File

@@ -1,5 +1,3 @@
include ../../common.mk
SRCS_ASM = \
start.S \
mem.S \
@@ -12,41 +10,4 @@ SRCS_C = \
page.c \
sched.c \
OBJS = $(SRCS_ASM:.S=.o)
OBJS += $(SRCS_C:.c=.o)
.DEFAULT_GOAL := all
all: os.elf
# start.o must be the first in dependency!
os.elf: ${OBJS}
${CC} ${CFLAGS} -T os.ld -o os.elf $^
${OBJCOPY} -O binary os.elf os.bin
%.o : %.c
${CC} ${CFLAGS} -c -o $@ $<
%.o : %.S
${CC} ${CFLAGS} -c -o $@ $<
run: all
@${QEMU} -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf -s -S &
@${GDB} os.elf -q -x ../gdbinit
.PHONY : code
code: all
@${OBJDUMP} -S os.elf | less
.PHONY : clean
clean:
rm -rf *.o *.bin *.elf
include ../common.mk

View File

@@ -1,5 +1,3 @@
include ../../common.mk
SRCS_ASM = \
start.S \
mem.S \
@@ -13,41 +11,4 @@ SRCS_C = \
sched.c \
user.c \
OBJS = $(SRCS_ASM:.S=.o)
OBJS += $(SRCS_C:.c=.o)
.DEFAULT_GOAL := all
all: os.elf
# start.o must be the first in dependency!
os.elf: ${OBJS}
${CC} ${CFLAGS} -T os.ld -o os.elf $^
${OBJCOPY} -O binary os.elf os.bin
%.o : %.c
${CC} ${CFLAGS} -c -o $@ $<
%.o : %.S
${CC} ${CFLAGS} -c -o $@ $<
run: all
@${QEMU} -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf -s -S &
@${GDB} os.elf -q -x ../gdbinit
.PHONY : code
code: all
@${OBJDUMP} -S os.elf | less
.PHONY : clean
clean:
rm -rf *.o *.bin *.elf
include ../common.mk

View File

@@ -1,5 +1,3 @@
include ../../common.mk
SRCS_ASM = \
start.S \
mem.S \
@@ -14,41 +12,4 @@ SRCS_C = \
user.c \
trap.c \
OBJS = $(SRCS_ASM:.S=.o)
OBJS += $(SRCS_C:.c=.o)
.DEFAULT_GOAL := all
all: os.elf
# start.o must be the first in dependency!
os.elf: ${OBJS}
${CC} ${CFLAGS} -T os.ld -o os.elf $^
${OBJCOPY} -O binary os.elf os.bin
%.o : %.c
${CC} ${CFLAGS} -c -o $@ $<
%.o : %.S
${CC} ${CFLAGS} -c -o $@ $<
run: all
@${QEMU} -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf -s -S &
@${GDB} os.elf -q -x ../gdbinit
.PHONY : code
code: all
@${OBJDUMP} -S os.elf | less
.PHONY : clean
clean:
rm -rf *.o *.bin *.elf
include ../common.mk

View File

@@ -1,5 +1,3 @@
include ../../common.mk
SRCS_ASM = \
start.S \
mem.S \
@@ -15,41 +13,4 @@ SRCS_C = \
trap.c \
plic.c \
OBJS = $(SRCS_ASM:.S=.o)
OBJS += $(SRCS_C:.c=.o)
.DEFAULT_GOAL := all
all: os.elf
# start.o must be the first in dependency!
os.elf: ${OBJS}
${CC} ${CFLAGS} -T os.ld -o os.elf $^
${OBJCOPY} -O binary os.elf os.bin
%.o : %.c
${CC} ${CFLAGS} -c -o $@ $<
%.o : %.S
${CC} ${CFLAGS} -c -o $@ $<
run: all
@${QEMU} -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf -s -S &
@${GDB} os.elf -q -x ../gdbinit
.PHONY : code
code: all
@${OBJDUMP} -S os.elf | less
.PHONY : clean
clean:
rm -rf *.o *.bin *.elf
include ../common.mk

View File

@@ -1,5 +1,3 @@
include ../../common.mk
SRCS_ASM = \
start.S \
mem.S \
@@ -16,41 +14,4 @@ SRCS_C = \
plic.c \
timer.c \
OBJS = $(SRCS_ASM:.S=.o)
OBJS += $(SRCS_C:.c=.o)
.DEFAULT_GOAL := all
all: os.elf
# start.o must be the first in dependency!
os.elf: ${OBJS}
${CC} ${CFLAGS} -T os.ld -o os.elf $^
${OBJCOPY} -O binary os.elf os.bin
%.o : %.c
${CC} ${CFLAGS} -c -o $@ $<
%.o : %.S
${CC} ${CFLAGS} -c -o $@ $<
run: all
@${QEMU} -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf -s -S &
@${GDB} os.elf -q -x ../gdbinit
.PHONY : code
code: all
@${OBJDUMP} -S os.elf | less
.PHONY : clean
clean:
rm -rf *.o *.bin *.elf
include ../common.mk

View File

@@ -1,5 +1,3 @@
include ../../common.mk
SRCS_ASM = \
start.S \
mem.S \
@@ -16,41 +14,4 @@ SRCS_C = \
plic.c \
timer.c \
OBJS = $(SRCS_ASM:.S=.o)
OBJS += $(SRCS_C:.c=.o)
.DEFAULT_GOAL := all
all: os.elf
# start.o must be the first in dependency!
os.elf: ${OBJS}
${CC} ${CFLAGS} -T os.ld -o os.elf $^
${OBJCOPY} -O binary os.elf os.bin
%.o : %.c
${CC} ${CFLAGS} -c -o $@ $<
%.o : %.S
${CC} ${CFLAGS} -c -o $@ $<
run: all
@${QEMU} -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf -s -S &
@${GDB} os.elf -q -x ../gdbinit
.PHONY : code
code: all
@${OBJDUMP} -S os.elf | less
.PHONY : clean
clean:
rm -rf *.o *.bin *.elf
include ../common.mk

View File

@@ -1,5 +1,3 @@
include ../../common.mk
SRCS_ASM = \
start.S \
mem.S \
@@ -17,41 +15,4 @@ SRCS_C = \
timer.c \
lock.c \
OBJS = $(SRCS_ASM:.S=.o)
OBJS += $(SRCS_C:.c=.o)
.DEFAULT_GOAL := all
all: os.elf
# start.o must be the first in dependency!
os.elf: ${OBJS}
${CC} ${CFLAGS} -T os.ld -o os.elf $^
${OBJCOPY} -O binary os.elf os.bin
%.o : %.c
${CC} ${CFLAGS} -c -o $@ $<
%.o : %.S
${CC} ${CFLAGS} -c -o $@ $<
run: all
@${QEMU} -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf -s -S &
@${GDB} os.elf -q -x ../gdbinit
.PHONY : code
code: all
@${OBJDUMP} -S os.elf | less
.PHONY : clean
clean:
rm -rf *.o *.bin *.elf
include ../common.mk

View File

@@ -1,5 +1,3 @@
include ../../common.mk
SRCS_ASM = \
start.S \
mem.S \
@@ -17,41 +15,4 @@ SRCS_C = \
timer.c \
lock.c \
OBJS = $(SRCS_ASM:.S=.o)
OBJS += $(SRCS_C:.c=.o)
.DEFAULT_GOAL := all
all: os.elf
# start.o must be the first in dependency!
os.elf: ${OBJS}
${CC} ${CFLAGS} -T os.ld -o os.elf $^
${OBJCOPY} -O binary os.elf os.bin
%.o : %.c
${CC} ${CFLAGS} -c -o $@ $<
%.o : %.S
${CC} ${CFLAGS} -c -o $@ $<
run: all
@${QEMU} -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf -s -S &
@${GDB} os.elf -q -x ../gdbinit
.PHONY : code
code: all
@${OBJDUMP} -S os.elf | less
.PHONY : clean
clean:
rm -rf *.o *.bin *.elf
include ../common.mk

View File

@@ -1,5 +1,3 @@
include ../../common.mk
SYSCALL = y
ifeq (${SYSCALL}, y)
@@ -25,41 +23,4 @@ SRCS_C = \
lock.c \
syscall.c
OBJS = $(SRCS_ASM:.S=.o)
OBJS += $(SRCS_C:.c=.o)
.DEFAULT_GOAL := all
all: os.elf
# start.o must be the first in dependency!
os.elf: ${OBJS}
${CC} ${CFLAGS} -T os.ld -o os.elf $^
${OBJCOPY} -O binary os.elf os.bin
%.o : %.c
${CC} ${CFLAGS} -c -o $@ $<
%.o : %.S
${CC} ${CFLAGS} -c -o $@ $<
run: all
@${QEMU} -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf -s -S &
@${GDB} os.elf -q -x ../gdbinit
.PHONY : code
code: all
@${OBJDUMP} -S os.elf | less
.PHONY : clean
clean:
rm -rf *.o *.bin *.elf
include ../common.mk

53
code/os/common.mk Normal file
View File

@@ -0,0 +1,53 @@
# This file will be included by the Makefile of each project.
CROSS_COMPILE = riscv64-unknown-elf-
CFLAGS += -nostdlib -fno-builtin -march=rv32g -mabi=ilp32 -g -Wall
LDFLAGS ?= -T os.ld
QEMU = qemu-system-riscv32
QFLAGS = -nographic -smp 1 -machine virt -bios none
GDB = gdb-multiarch
CC = ${CROSS_COMPILE}gcc
OBJCOPY = ${CROSS_COMPILE}objcopy
OBJDUMP = ${CROSS_COMPILE}objdump
# SRCS_ASM & SRCS_C are defined in the Makefile of each project.
OBJS = $(SRCS_ASM:.S=.o)
OBJS += $(SRCS_C:.c=.o)
.DEFAULT_GOAL := all
all: os.elf
# start.o must be the first in dependency!
os.elf: ${OBJS}
${CC} ${CFLAGS} ${LDFLAGS} -o os.elf $^
${OBJCOPY} -O binary os.elf os.bin
%.o : %.c
${CC} ${CFLAGS} -c -o $@ $<
%.o : %.S
${CC} ${CFLAGS} -c -o $@ $<
run: all
@${QEMU} -M ? | grep virt >/dev/null || exit
@echo "Press Ctrl-A and then X to exit QEMU"
@echo "------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf
.PHONY : debug
debug: all
@echo "Press Ctrl-C and then input 'quit' to exit GDB and QEMU"
@echo "-------------------------------------------------------"
@${QEMU} ${QFLAGS} -kernel os.elf -s -S &
@${GDB} os.elf -q -x ../gdbinit
.PHONY : code
code: all
@${OBJDUMP} -S os.elf | less
.PHONY : clean
clean:
rm -rf *.o *.bin *.elf