xref: /DragonOS/Makefile (revision d031d46fd9e9a62e8e975dba76e3bdef027f63b6)
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/
4543ef2a0dSLoGin
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 .."
94*d031d46fSLoGin
95*d031d46fSLoGin# 不编译,直接启动QEMU,不显示图像
96*d031d46fSLoGinqemu-nographic:
97*d031d46fSLoGin	sh -c "cd tools && bash run-qemu.sh --bios=legacy --display=nographic && cd .."
98*d031d46fSLoGin
997f439c5dSYJwu2023# 不编译,直接启动QEMU(UEFI)
1007f439c5dSYJwu2023qemu-uefi:
1016d345b77SHoshuChiu	sh -c "cd tools && bash run-qemu.sh --bios=uefi --display=window && cd .."
1026d345b77SHoshuChiu# 不编译,直接启动QEMU,使用VNC Display作为图像输出
1036d345b77SHoshuChiuqemu-vnc:
1046d345b77SHoshuChiu	sh -c "cd tools && bash run-qemu.sh --bios=legacy --display=vnc && cd .."
1056d345b77SHoshuChiu# 不编译,直接启动QEMU(UEFI),使用VNC Display作为图像输出
1066d345b77SHoshuChiuqemu-uefi-vnc:
1076d345b77SHoshuChiu	sh -c "cd tools && bash run-qemu.sh --bios=uefi --display=vnc && cd .."
1082813126eSlogin
1092813126eSlogin# 编译并写入磁盘镜像
1102813126eSloginbuild:
1112813126eSlogin	$(MAKE) all -j $(NPROCS)
1122813126eSlogin	$(MAKE) write_diskimage || exit 1
1132813126eSlogin
1142813126eSlogin# 在docker中编译,并写入磁盘镜像
1152813126eSlogindocker:
1162813126eSlogin	@echo "使用docker构建"
1172813126eSlogin	sudo bash tools/build_in_docker.sh || exit 1
1185ed4cd46Sguanjinquan	$(MAKE) write_diskimage || exit 1
1192813126eSlogin
1207f439c5dSYJwu2023# uefi方式启动
1217f439c5dSYJwu2023run-uefi:
1227f439c5dSYJwu2023	$(MAKE) all -j $(NPROCS)
1237f439c5dSYJwu2023	$(MAKE) write_diskimage-uefi || exit 1
1247f439c5dSYJwu2023	$(MAKE) qemu-uefi
1257f439c5dSYJwu2023
1262813126eSlogin# 编译并启动QEMU
1272813126eSloginrun:
1282813126eSlogin	$(MAKE) all -j $(NPROCS)
1292813126eSlogin	$(MAKE) write_diskimage || exit 1
1302813126eSlogin	$(MAKE) qemu
1312813126eSlogin
1326d345b77SHoshuChiu# uefi方式启动,使用VNC Display作为图像输出
1336d345b77SHoshuChiurun-uefi-vnc:
1346d345b77SHoshuChiu	$(MAKE) all -j $(NPROCS)
1356d345b77SHoshuChiu	$(MAKE) write_diskimage-uefi || exit 1
1366d345b77SHoshuChiu	$(MAKE) qemu-uefi-vnc
1376d345b77SHoshuChiu
1386d345b77SHoshuChiu# 编译并启动QEMU,使用VNC Display作为图像输出
1396d345b77SHoshuChiurun-vnc:
1406d345b77SHoshuChiu	$(MAKE) all -j $(NPROCS)
1416d345b77SHoshuChiu	$(MAKE) write_diskimage || exit 1
1426d345b77SHoshuChiu	$(MAKE) qemu-vnc
1436d345b77SHoshuChiu
1442813126eSlogin# 在docker中编译,并启动QEMU
1452813126eSloginrun-docker:
1462813126eSlogin	@echo "使用docker构建并运行"
1472813126eSlogin	sudo bash tools/build_in_docker.sh || exit 1
1485ed4cd46Sguanjinquan	$(MAKE) write_diskimage || exit 1
1492813126eSlogin	$(MAKE) qemu
1505f578343STptogiar
151e92d0228SLoGinfmt:
152e92d0228SLoGin	@echo "格式化代码"
153e92d0228SLoGin	FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C kernel
154e92d0228SLoGin	FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C user
155e26ca418SLoGin	FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C build-scripts
156e92d0228SLoGin
1577b32f508SLoGinlog-monitor:
1587b32f508SLoGin	@echo "启动日志监控"
1597b32f508SLoGin	@sh -c "cd tools/debugging/logmonitor && cargo run --release -- --log-dir $(ROOT_PATH)/logs/ --kernel $(ROOT_PATH)/bin/kernel/kernel.elf"
1607b32f508SLoGin
161af354310SLoGin.PHONY: update-submodules
162af354310SLoGinupdate-submodules:
163af354310SLoGin	@echo "更新子模块"
164703ce5a7SLoGin	@git submodule update --recursive --init
165af354310SLoGin	@git submodule foreach git pull origin master
166af354310SLoGin
167af354310SLoGin.PHONY: update-submodules-by-mirror
168af354310SLoGinupdate-submodules-by-mirror:
169af354310SLoGin	@echo "从镜像更新子模块"
170af354310SLoGin	@git config --global url."https://git.mirrors.dragonos.org.cn/DragonOS-Community/".insteadOf https://github.com/DragonOS-Community/
171e35f8aa1SEMasi	@$(MAKE) update-submodules
172af354310SLoGin	@git config --global --unset url."https://git.mirrors.dragonos.org.cn/DragonOS-Community/".insteadOf
173af354310SLoGin
1745f578343STptogiarhelp:
1755f578343STptogiar	@echo "编译:"
1765f578343STptogiar	@echo "  make all -j <n>       - 本地编译,不运行,n为要用于编译的CPU核心数"
1775f578343STptogiar	@echo "  make build            - 本地编译,并写入磁盘镜像"
1785f578343STptogiar	@echo "  make docker           - Docker编译,并写入磁盘镜像"
1795f578343STptogiar	@echo ""
1805f578343STptogiar	@echo "编译并运行:"
1815f578343STptogiar	@echo "  make run-docker       - Docker编译,写入磁盘镜像,并在QEMU中运行"
1825f578343STptogiar	@echo "  make run              - 本地编译,写入磁盘镜像,并在QEMU中运行"
1835f578343STptogiar	@echo "  make run-uefi         - 以uefi方式启动运行"
1845f578343STptogiar	@echo ""
1855f578343STptogiar	@echo "运行:"
1865f578343STptogiar	@echo "  make qemu             - 不编译,直接从已有的磁盘镜像启动运行"
1875f578343STptogiar	@echo "  make qemu-uefi        - 不编译,直接从已有的磁盘镜像以UEFI启动运行"
1885f578343STptogiar	@echo ""
1895f578343STptogiar	@echo ""
1905f578343STptogiar	@echo "注: 对于上述的run, run-uefi, qemu, qemu-uefi命令可以在命令后加上-vnc后缀,来通过vnc连接到DragonOS, 默认会在5900端口运行vnc服务器。如:make run-vnc "
191af354310SLoGin	@echo ""
192af354310SLoGin	@echo "其他:"
193af354310SLoGin	@echo "  make clean            - 清理编译产生的文件"
194af354310SLoGin	@echo "  make fmt              - 格式化代码"
195af354310SLoGin	@echo "  make log-monitor      - 启动日志监控"
196af354310SLoGin	@echo "  make docs             - 生成文档"
197af354310SLoGin	@echo "  make clean-docs       - 清理文档"
198af354310SLoGin	@echo ""
199af354310SLoGin	@echo "  make update-submodules - 更新子模块"
200af354310SLoGin	@echo "  make update-submodules-by-mirror - 从镜像更新子模块"
201af354310SLoGin
202