xref: /DragonOS/Makefile (revision 78bf93f02f84bf5e024ddfb559f040e68ce39ccf)
1SUBDIRS = kernel user
2
3# ifndef $(EMULATOR)
4ifeq ($(EMULATOR), )
5export EMULATOR=__NO_EMULATION__
6endif
7# todo: 增加参数,判断是否在QEMU中仿真,若是,则启用该环境变量
8# export EMULATOR=__QEMU_EMULATION__
9
10# 计算cpu核心数
11NPROCS:=1
12OS:=$(shell uname -s)
13
14ifeq ($(OS),Linux)
15  NPROCS:=$(shell grep -c ^processor /proc/cpuinfo)
16endif
17ifeq ($(OS),Darwin) # Assume Mac OS X
18  NPROCS:=$(shell system_profiler | awk '/Number Of CPUs/{print $4}{next;}')
19endif
20
21export ARCH=__x86_64__
22export ROOT_PATH=$(shell pwd)
23
24export DEBUG=DEBUG
25export GLOBAL_CFLAGS := -mcmodel=large -fno-builtin -m64  -fno-stack-protector -D $(ARCH) -D $(EMULATOR) -O1
26
27ifeq ($(DEBUG), DEBUG)
28GLOBAL_CFLAGS += -g
29endif
30
31
32export CC=$(DragonOS_GCC)/x86_64-elf-gcc
33export LD=ld
34export AS=$(DragonOS_GCC)/x86_64-elf-as
35export NM=$(DragonOS_GCC)/x86_64-elf-nm
36export AR=$(DragonOS_GCC)/x86_64-elf-ar
37export OBJCOPY=$(DragonOS_GCC)/x86_64-elf-objcopy
38
39
40.PHONY: all
41all: kernel user
42
43
44.PHONY: kernel
45kernel:
46	mkdir -p bin/kernel/
47	@if [ -z $$DragonOS_GCC ]; then echo "\033[31m  [错误]尚未安装DragonOS交叉编译器, 请使用tools文件夹下的build_gcc_toolchain.sh脚本安装  \033[0m"; exit 1; fi
48	$(MAKE) -C ./kernel all || (sh -c "echo 内核编译失败" && exit 1)
49
50.PHONY: user
51user:
52
53	@if [ -z $$DragonOS_GCC ]; then echo "\033[31m  [错误]尚未安装DragonOS交叉编译器, 请使用tools文件夹下的build_gcc_toolchain.sh脚本安装  \033[0m"; exit 1; fi
54	$(MAKE) -C ./user all || (sh -c "echo 用户程序编译失败" && exit 1)
55
56.PHONY: clean
57clean:
58	@list='$(SUBDIRS)'; for subdir in $$list; do \
59		echo "Clean in dir: $$subdir";\
60		cd $$subdir && $(MAKE) clean;\
61		cd .. ;\
62	done
63
64cppcheck-xml:
65	cppcheck kernel user --platform=unix64 --std=c11 -I user/libs/ -I=kernel/ --force -j $(NPROCS) --xml 2> cppcheck.xml
66
67cppcheck:
68	cppcheck kernel user --platform=unix64 --std=c11 -I user/libs/ -I=kernel/ --force -j $(NPROCS)
69
70gdb:
71	gdb -n -x tools/.gdbinit
72
73# 写入磁盘镜像
74write_diskimage:
75	bash -c "cd tools && bash grub_auto_install.sh && sudo bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=legacy && cd .."
76
77# 写入磁盘镜像(uefi)
78write_diskimage-uefi:
79	bash -c "cd tools && bash grub_auto_install.sh && sudo bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=uefi && cd .."
80# 不编译,直接启动QEMU
81qemu:
82	sh -c "cd tools && bash run-qemu.sh --bios=legacy --display=window && cd .."
83# 不编译,直接启动QEMU(UEFI)
84qemu-uefi:
85	sh -c "cd tools && bash run-qemu.sh --bios=uefi --display=window && cd .."
86# 不编译,直接启动QEMU,使用VNC Display作为图像输出
87qemu-vnc:
88	sh -c "cd tools && bash run-qemu.sh --bios=legacy --display=vnc && cd .."
89# 不编译,直接启动QEMU(UEFI),使用VNC Display作为图像输出
90qemu-uefi-vnc:
91	sh -c "cd tools && bash run-qemu.sh --bios=uefi --display=vnc && cd .."
92
93# 编译并写入磁盘镜像
94build:
95	$(MAKE) all -j $(NPROCS)
96	$(MAKE) write_diskimage || exit 1
97
98# 在docker中编译,并写入磁盘镜像
99docker:
100	@echo "使用docker构建"
101	sudo bash tools/build_in_docker.sh || exit 1
102	$(MAKE) write_diskimage || exit 1
103
104# uefi方式启动
105run-uefi:
106	$(MAKE) all -j $(NPROCS)
107	$(MAKE) write_diskimage-uefi || exit 1
108	$(MAKE) qemu-uefi
109
110# 编译并启动QEMU
111run:
112	$(MAKE) all -j $(NPROCS)
113	$(MAKE) write_diskimage || exit 1
114	$(MAKE) qemu
115
116# uefi方式启动,使用VNC Display作为图像输出
117run-uefi-vnc:
118	$(MAKE) all -j $(NPROCS)
119	$(MAKE) write_diskimage-uefi || exit 1
120	$(MAKE) qemu-uefi-vnc
121
122# 编译并启动QEMU,使用VNC Display作为图像输出
123run-vnc:
124	$(MAKE) all -j $(NPROCS)
125	$(MAKE) write_diskimage || exit 1
126	$(MAKE) qemu-vnc
127
128# 在docker中编译,并启动QEMU
129run-docker:
130	@echo "使用docker构建并运行"
131	sudo bash tools/build_in_docker.sh || exit 1
132	$(MAKE) write_diskimage || exit 1
133	$(MAKE) qemu
134