xref: /DragonOS/Makefile (revision 43ef2a0d2b6ec427f6775cd4593c56897dd5bf6d)
14fda81ceSLoGin# 导入环境变量
24fda81ceSLoGininclude env.mk
34fda81ceSLoGin
44fda81ceSLoGin
54fda81ceSLoGinexport ROOT_PATH=$(shell pwd)
64fda81ceSLoGin
7e26ca418SLoGinSUBDIRS = kernel user tools build-scripts
80aec6827Sfslongjin
94fda81ceSLoGin
104fda81ceSLoGin
112813126eSlogin# todo: 增加参数,判断是否在QEMU中仿真,若是,则启用该环境变量
122813126eSlogin# export EMULATOR=__QEMU_EMULATION__
130aec6827Sfslongjin
14d328bfceSlogin# 计算cpu核心数
15d328bfceSloginNPROCS:=1
16d328bfceSloginOS:=$(shell uname -s)
17d328bfceSlogin
18d328bfceSloginifeq ($(OS),Linux)
19d328bfceSlogin  NPROCS:=$(shell grep -c ^processor /proc/cpuinfo)
20d328bfceSloginendif
21d328bfceSloginifeq ($(OS),Darwin) # Assume Mac OS X
22d328bfceSlogin  NPROCS:=$(shell system_profiler | awk '/Number Of CPUs/{print $4}{next;}')
23d328bfceSloginendif
240aec6827Sfslongjin
25c7508928SLoGin
265ed4cd46Sguanjinquan
27e92d0228SLoGin# 检查是否需要进行fmt --check
28e92d0228SLoGin# 解析命令行参数
29e92d0228SLoGinFMT_CHECK?=0
30e92d0228SLoGin
31e92d0228SLoGinifeq ($(FMT_CHECK), 1)
32e92d0228SLoGin	FMT_CHECK=--check
33e92d0228SLoGinelse
34e92d0228SLoGin	FMT_CHECK=
35e92d0228SLoGinendif
36e92d0228SLoGin
37416a802bSfslongjin
38f479f321Sfslongjin.PHONY: all
391ab51cb3Sfslongjinall: kernel user
401ab51cb3Sfslongjin
411ab51cb3Sfslongjin
421ab51cb3Sfslongjin.PHONY: kernel
431ab51cb3Sfslongjinkernel:
440b0cce93Sfslongjin	mkdir -p bin/kernel/
45*43ef2a0dSLoGin
464fda81ceSLoGin	$(MAKE) -C ./kernel all ARCH=$(ARCH) || (sh -c "echo 内核编译失败" && exit 1)
47f479f321Sfslongjin
48e2a59dbdSfslongjin.PHONY: user
49e2a59dbdSfslongjinuser:
504fda81ceSLoGin	$(MAKE) -C ./user all ARCH=$(ARCH) || (sh -c "echo 用户程序编译失败" && exit 1)
51e2a59dbdSfslongjin
52f479f321Sfslongjin.PHONY: clean
53f479f321Sfslongjinclean:
54f479f321Sfslongjin	@list='$(SUBDIRS)'; for subdir in $$list; do \
55f479f321Sfslongjin		echo "Clean in dir: $$subdir";\
5605dc7ac7Sfslongjin		cd $$subdir && $(MAKE) clean;\
57f479f321Sfslongjin		cd .. ;\
58f479f321Sfslongjin	done
59e667fff2Sfslongjin
6040fe15e0SLoGin.PHONY: ECHO
6140fe15e0SLoGinECHO:
6240fe15e0SLoGin	@echo "$@"
6340fe15e0SLoGin
64d328bfceSlogincppcheck-xml:
65d328bfceSlogin	cppcheck kernel user --platform=unix64 --std=c11 -I user/libs/ -I=kernel/ --force -j $(NPROCS) --xml 2> cppcheck.xml
66d328bfceSlogin
67d328bfceSlogincppcheck:
68d328bfceSlogin	cppcheck kernel user --platform=unix64 --std=c11 -I user/libs/ -I=kernel/ --force -j $(NPROCS)
69d328bfceSlogin
7040fe15e0SLoGindocs: ECHO
7140fe15e0SLoGin	bash -c "cd docs && make html && cd .."
7240fe15e0SLoGin
7340fe15e0SLoGinclean-docs:
7440fe15e0SLoGin	bash -c "cd docs && make clean && cd .."
7540fe15e0SLoGin
76e667fff2Sfslongjingdb:
771a72a751SLoGinifeq ($(ARCH), x86_64)
7840fe15e0SLoGin	rust-gdb -n -x tools/.gdbinit
791a72a751SLoGinelse
801a72a751SLoGin	gdb-multiarch -n -x tools/.gdbinit
811a72a751SLoGinendif
822813126eSlogin
832813126eSlogin# 写入磁盘镜像
842813126eSloginwrite_diskimage:
85c7508928SLoGin	@echo "write_diskimage arch=$(ARCH)"
86c7508928SLoGin	bash -c "export ARCH=$(ARCH); cd tools && bash grub_auto_install.sh && sudo ARCH=$(ARCH) bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=legacy && cd .."
872813126eSlogin
887f439c5dSYJwu2023# 写入磁盘镜像(uefi)
897f439c5dSYJwu2023write_diskimage-uefi:
90c7508928SLoGin	bash -c "export ARCH=$(ARCH); cd tools && bash grub_auto_install.sh && sudo ARCH=$(ARCH) bash $(ROOT_PATH)/tools/write_disk_image.sh --bios=uefi && cd .."
912813126eSlogin# 不编译,直接启动QEMU
922813126eSloginqemu:
936d345b77SHoshuChiu	sh -c "cd tools && bash run-qemu.sh --bios=legacy --display=window && cd .."
947f439c5dSYJwu2023# 不编译,直接启动QEMU(UEFI)
957f439c5dSYJwu2023qemu-uefi:
966d345b77SHoshuChiu	sh -c "cd tools && bash run-qemu.sh --bios=uefi --display=window && cd .."
976d345b77SHoshuChiu# 不编译,直接启动QEMU,使用VNC Display作为图像输出
986d345b77SHoshuChiuqemu-vnc:
996d345b77SHoshuChiu	sh -c "cd tools && bash run-qemu.sh --bios=legacy --display=vnc && cd .."
1006d345b77SHoshuChiu# 不编译,直接启动QEMU(UEFI),使用VNC Display作为图像输出
1016d345b77SHoshuChiuqemu-uefi-vnc:
1026d345b77SHoshuChiu	sh -c "cd tools && bash run-qemu.sh --bios=uefi --display=vnc && cd .."
1032813126eSlogin
1042813126eSlogin# 编译并写入磁盘镜像
1052813126eSloginbuild:
1062813126eSlogin	$(MAKE) all -j $(NPROCS)
1072813126eSlogin	$(MAKE) write_diskimage || exit 1
1082813126eSlogin
1092813126eSlogin# 在docker中编译,并写入磁盘镜像
1102813126eSlogindocker:
1112813126eSlogin	@echo "使用docker构建"
1122813126eSlogin	sudo bash tools/build_in_docker.sh || exit 1
1135ed4cd46Sguanjinquan	$(MAKE) write_diskimage || exit 1
1142813126eSlogin
1157f439c5dSYJwu2023# uefi方式启动
1167f439c5dSYJwu2023run-uefi:
1177f439c5dSYJwu2023	$(MAKE) all -j $(NPROCS)
1187f439c5dSYJwu2023	$(MAKE) write_diskimage-uefi || exit 1
1197f439c5dSYJwu2023	$(MAKE) qemu-uefi
1207f439c5dSYJwu2023
1212813126eSlogin# 编译并启动QEMU
1222813126eSloginrun:
1232813126eSlogin	$(MAKE) all -j $(NPROCS)
1242813126eSlogin	$(MAKE) write_diskimage || exit 1
1252813126eSlogin	$(MAKE) qemu
1262813126eSlogin
1276d345b77SHoshuChiu# uefi方式启动,使用VNC Display作为图像输出
1286d345b77SHoshuChiurun-uefi-vnc:
1296d345b77SHoshuChiu	$(MAKE) all -j $(NPROCS)
1306d345b77SHoshuChiu	$(MAKE) write_diskimage-uefi || exit 1
1316d345b77SHoshuChiu	$(MAKE) qemu-uefi-vnc
1326d345b77SHoshuChiu
1336d345b77SHoshuChiu# 编译并启动QEMU,使用VNC Display作为图像输出
1346d345b77SHoshuChiurun-vnc:
1356d345b77SHoshuChiu	$(MAKE) all -j $(NPROCS)
1366d345b77SHoshuChiu	$(MAKE) write_diskimage || exit 1
1376d345b77SHoshuChiu	$(MAKE) qemu-vnc
1386d345b77SHoshuChiu
1392813126eSlogin# 在docker中编译,并启动QEMU
1402813126eSloginrun-docker:
1412813126eSlogin	@echo "使用docker构建并运行"
1422813126eSlogin	sudo bash tools/build_in_docker.sh || exit 1
1435ed4cd46Sguanjinquan	$(MAKE) write_diskimage || exit 1
1442813126eSlogin	$(MAKE) qemu
1455f578343STptogiar
146e92d0228SLoGinfmt:
147e92d0228SLoGin	@echo "格式化代码"
148e92d0228SLoGin	FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C kernel
149e92d0228SLoGin	FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C user
150e26ca418SLoGin	FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C build-scripts
151e92d0228SLoGin
1527b32f508SLoGinlog-monitor:
1537b32f508SLoGin	@echo "启动日志监控"
1547b32f508SLoGin	@sh -c "cd tools/debugging/logmonitor && cargo run --release -- --log-dir $(ROOT_PATH)/logs/ --kernel $(ROOT_PATH)/bin/kernel/kernel.elf"
1557b32f508SLoGin
156af354310SLoGin.PHONY: update-submodules
157af354310SLoGinupdate-submodules:
158af354310SLoGin	@echo "更新子模块"
15909d2bf52SLoGin	@git submodule update --recursive
160af354310SLoGin	@git submodule foreach git pull origin master
161af354310SLoGin
162af354310SLoGin.PHONY: update-submodules-by-mirror
163af354310SLoGinupdate-submodules-by-mirror:
164af354310SLoGin	@echo "从镜像更新子模块"
165af354310SLoGin	@git config --global url."https://git.mirrors.dragonos.org.cn/DragonOS-Community/".insteadOf https://github.com/DragonOS-Community/
166af354310SLoGin	@$(MAKE) update-submodules
167af354310SLoGin	@git config --global --unset url."https://git.mirrors.dragonos.org.cn/DragonOS-Community/".insteadOf
168af354310SLoGin
1695f578343STptogiarhelp:
1705f578343STptogiar	@echo "编译:"
1715f578343STptogiar	@echo "  make all -j <n>       - 本地编译,不运行,n为要用于编译的CPU核心数"
1725f578343STptogiar	@echo "  make build            - 本地编译,并写入磁盘镜像"
1735f578343STptogiar	@echo "  make docker           - Docker编译,并写入磁盘镜像"
1745f578343STptogiar	@echo ""
1755f578343STptogiar	@echo "编译并运行:"
1765f578343STptogiar	@echo "  make run-docker       - Docker编译,写入磁盘镜像,并在QEMU中运行"
1775f578343STptogiar	@echo "  make run              - 本地编译,写入磁盘镜像,并在QEMU中运行"
1785f578343STptogiar	@echo "  make run-uefi         - 以uefi方式启动运行"
1795f578343STptogiar	@echo ""
1805f578343STptogiar	@echo "运行:"
1815f578343STptogiar	@echo "  make qemu             - 不编译,直接从已有的磁盘镜像启动运行"
1825f578343STptogiar	@echo "  make qemu-uefi        - 不编译,直接从已有的磁盘镜像以UEFI启动运行"
1835f578343STptogiar	@echo ""
1845f578343STptogiar	@echo ""
1855f578343STptogiar	@echo "注: 对于上述的run, run-uefi, qemu, qemu-uefi命令可以在命令后加上-vnc后缀,来通过vnc连接到DragonOS, 默认会在5900端口运行vnc服务器。如:make run-vnc "
186af354310SLoGin	@echo ""
187af354310SLoGin	@echo "其他:"
188af354310SLoGin	@echo "  make clean            - 清理编译产生的文件"
189af354310SLoGin	@echo "  make fmt              - 格式化代码"
190af354310SLoGin	@echo "  make log-monitor      - 启动日志监控"
191af354310SLoGin	@echo "  make docs             - 生成文档"
192af354310SLoGin	@echo "  make clean-docs       - 清理文档"
193af354310SLoGin	@echo ""
194af354310SLoGin	@echo "  make update-submodules - 更新子模块"
195af354310SLoGin	@echo "  make update-submodules-by-mirror - 从镜像更新子模块"
196af354310SLoGin
197