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/ 4574bde36eSguanjinquan @if [ -z $$DragonOS_GCC ]; then echo "\033[31m [错误]尚未安装DragonOS交叉编译器, 请使用tools文件夹下的build_gcc_toolchain.sh脚本安装 \033[0m"; exit 1; fi 464fda81ceSLoGin $(MAKE) -C ./kernel all ARCH=$(ARCH) || (sh -c "echo 内核编译失败" && exit 1) 47f479f321Sfslongjin 48e2a59dbdSfslongjin.PHONY: user 49e2a59dbdSfslongjinuser: 502224c93eSguanjinquan 5174bde36eSguanjinquan @if [ -z $$DragonOS_GCC ]; then echo "\033[31m [错误]尚未安装DragonOS交叉编译器, 请使用tools文件夹下的build_gcc_toolchain.sh脚本安装 \033[0m"; exit 1; fi 524fda81ceSLoGin $(MAKE) -C ./user all ARCH=$(ARCH) || (sh -c "echo 用户程序编译失败" && exit 1) 53e2a59dbdSfslongjin 54f479f321Sfslongjin.PHONY: clean 55f479f321Sfslongjinclean: 56f479f321Sfslongjin @list='$(SUBDIRS)'; for subdir in $$list; do \ 57f479f321Sfslongjin echo "Clean in dir: $$subdir";\ 5805dc7ac7Sfslongjin cd $$subdir && $(MAKE) clean;\ 59f479f321Sfslongjin cd .. ;\ 60f479f321Sfslongjin done 61e667fff2Sfslongjin 6240fe15e0SLoGin.PHONY: ECHO 6340fe15e0SLoGinECHO: 6440fe15e0SLoGin @echo "$@" 6540fe15e0SLoGin 66d328bfceSlogincppcheck-xml: 67d328bfceSlogin cppcheck kernel user --platform=unix64 --std=c11 -I user/libs/ -I=kernel/ --force -j $(NPROCS) --xml 2> cppcheck.xml 68d328bfceSlogin 69d328bfceSlogincppcheck: 70d328bfceSlogin cppcheck kernel user --platform=unix64 --std=c11 -I user/libs/ -I=kernel/ --force -j $(NPROCS) 71d328bfceSlogin 7240fe15e0SLoGindocs: ECHO 7340fe15e0SLoGin bash -c "cd docs && make html && cd .." 7440fe15e0SLoGin 7540fe15e0SLoGinclean-docs: 7640fe15e0SLoGin bash -c "cd docs && make clean && cd .." 7740fe15e0SLoGin 78e667fff2Sfslongjingdb: 7940fe15e0SLoGin rust-gdb -n -x tools/.gdbinit 802813126eSlogin 812813126eSlogin# 写入磁盘镜像 822813126eSloginwrite_diskimage: 83c7508928SLoGin @echo "write_diskimage arch=$(ARCH)" 84c7508928SLoGin 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 .." 852813126eSlogin 867f439c5dSYJwu2023# 写入磁盘镜像(uefi) 877f439c5dSYJwu2023write_diskimage-uefi: 88c7508928SLoGin 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 .." 892813126eSlogin# 不编译,直接启动QEMU 902813126eSloginqemu: 916d345b77SHoshuChiu sh -c "cd tools && bash run-qemu.sh --bios=legacy --display=window && cd .." 927f439c5dSYJwu2023# 不编译,直接启动QEMU(UEFI) 937f439c5dSYJwu2023qemu-uefi: 946d345b77SHoshuChiu sh -c "cd tools && bash run-qemu.sh --bios=uefi --display=window && cd .." 956d345b77SHoshuChiu# 不编译,直接启动QEMU,使用VNC Display作为图像输出 966d345b77SHoshuChiuqemu-vnc: 976d345b77SHoshuChiu sh -c "cd tools && bash run-qemu.sh --bios=legacy --display=vnc && cd .." 986d345b77SHoshuChiu# 不编译,直接启动QEMU(UEFI),使用VNC Display作为图像输出 996d345b77SHoshuChiuqemu-uefi-vnc: 1006d345b77SHoshuChiu sh -c "cd tools && bash run-qemu.sh --bios=uefi --display=vnc && cd .." 1012813126eSlogin 1022813126eSlogin# 编译并写入磁盘镜像 1032813126eSloginbuild: 1042813126eSlogin $(MAKE) all -j $(NPROCS) 1052813126eSlogin $(MAKE) write_diskimage || exit 1 1062813126eSlogin 1072813126eSlogin# 在docker中编译,并写入磁盘镜像 1082813126eSlogindocker: 1092813126eSlogin @echo "使用docker构建" 1102813126eSlogin sudo bash tools/build_in_docker.sh || exit 1 1115ed4cd46Sguanjinquan $(MAKE) write_diskimage || exit 1 1122813126eSlogin 1137f439c5dSYJwu2023# uefi方式启动 1147f439c5dSYJwu2023run-uefi: 1157f439c5dSYJwu2023 $(MAKE) all -j $(NPROCS) 1167f439c5dSYJwu2023 $(MAKE) write_diskimage-uefi || exit 1 1177f439c5dSYJwu2023 $(MAKE) qemu-uefi 1187f439c5dSYJwu2023 1192813126eSlogin# 编译并启动QEMU 1202813126eSloginrun: 1212813126eSlogin $(MAKE) all -j $(NPROCS) 1222813126eSlogin $(MAKE) write_diskimage || exit 1 1232813126eSlogin $(MAKE) qemu 1242813126eSlogin 1256d345b77SHoshuChiu# uefi方式启动,使用VNC Display作为图像输出 1266d345b77SHoshuChiurun-uefi-vnc: 1276d345b77SHoshuChiu $(MAKE) all -j $(NPROCS) 1286d345b77SHoshuChiu $(MAKE) write_diskimage-uefi || exit 1 1296d345b77SHoshuChiu $(MAKE) qemu-uefi-vnc 1306d345b77SHoshuChiu 1316d345b77SHoshuChiu# 编译并启动QEMU,使用VNC Display作为图像输出 1326d345b77SHoshuChiurun-vnc: 1336d345b77SHoshuChiu $(MAKE) all -j $(NPROCS) 1346d345b77SHoshuChiu $(MAKE) write_diskimage || exit 1 1356d345b77SHoshuChiu $(MAKE) qemu-vnc 1366d345b77SHoshuChiu 1372813126eSlogin# 在docker中编译,并启动QEMU 1382813126eSloginrun-docker: 1392813126eSlogin @echo "使用docker构建并运行" 1402813126eSlogin sudo bash tools/build_in_docker.sh || exit 1 1415ed4cd46Sguanjinquan $(MAKE) write_diskimage || exit 1 1422813126eSlogin $(MAKE) qemu 1435f578343STptogiar 144e92d0228SLoGinfmt: 145e92d0228SLoGin @echo "格式化代码" 146e92d0228SLoGin FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C kernel 147e92d0228SLoGin FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C user 148e26ca418SLoGin FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C build-scripts 149e92d0228SLoGin 1507b32f508SLoGinlog-monitor: 1517b32f508SLoGin @echo "启动日志监控" 1527b32f508SLoGin @sh -c "cd tools/debugging/logmonitor && cargo run --release -- --log-dir $(ROOT_PATH)/logs/ --kernel $(ROOT_PATH)/bin/kernel/kernel.elf" 1537b32f508SLoGin 154af354310SLoGin.PHONY: update-submodules 155af354310SLoGinupdate-submodules: 156af354310SLoGin @echo "更新子模块" 157*09d2bf52SLoGin @git submodule update --recursive 158af354310SLoGin @git submodule foreach git pull origin master 159af354310SLoGin 160af354310SLoGin.PHONY: update-submodules-by-mirror 161af354310SLoGinupdate-submodules-by-mirror: 162af354310SLoGin @echo "从镜像更新子模块" 163af354310SLoGin @git config --global url."https://git.mirrors.dragonos.org.cn/DragonOS-Community/".insteadOf https://github.com/DragonOS-Community/ 164af354310SLoGin @$(MAKE) update-submodules 165af354310SLoGin @git config --global --unset url."https://git.mirrors.dragonos.org.cn/DragonOS-Community/".insteadOf 166af354310SLoGin 1675f578343STptogiarhelp: 1685f578343STptogiar @echo "编译:" 1695f578343STptogiar @echo " make all -j <n> - 本地编译,不运行,n为要用于编译的CPU核心数" 1705f578343STptogiar @echo " make build - 本地编译,并写入磁盘镜像" 1715f578343STptogiar @echo " make docker - Docker编译,并写入磁盘镜像" 1725f578343STptogiar @echo "" 1735f578343STptogiar @echo "编译并运行:" 1745f578343STptogiar @echo " make run-docker - Docker编译,写入磁盘镜像,并在QEMU中运行" 1755f578343STptogiar @echo " make run - 本地编译,写入磁盘镜像,并在QEMU中运行" 1765f578343STptogiar @echo " make run-uefi - 以uefi方式启动运行" 1775f578343STptogiar @echo "" 1785f578343STptogiar @echo "运行:" 1795f578343STptogiar @echo " make qemu - 不编译,直接从已有的磁盘镜像启动运行" 1805f578343STptogiar @echo " make qemu-uefi - 不编译,直接从已有的磁盘镜像以UEFI启动运行" 1815f578343STptogiar @echo "" 1825f578343STptogiar @echo "" 1835f578343STptogiar @echo "注: 对于上述的run, run-uefi, qemu, qemu-uefi命令可以在命令后加上-vnc后缀,来通过vnc连接到DragonOS, 默认会在5900端口运行vnc服务器。如:make run-vnc " 184af354310SLoGin @echo "" 185af354310SLoGin @echo "其他:" 186af354310SLoGin @echo " make clean - 清理编译产生的文件" 187af354310SLoGin @echo " make fmt - 格式化代码" 188af354310SLoGin @echo " make log-monitor - 启动日志监控" 189af354310SLoGin @echo " make docs - 生成文档" 190af354310SLoGin @echo " make clean-docs - 清理文档" 191af354310SLoGin @echo "" 192af354310SLoGin @echo " make update-submodules - 更新子模块" 193af354310SLoGin @echo " make update-submodules-by-mirror - 从镜像更新子模块" 194af354310SLoGin 195