1# 导入环境变量 2include env.mk 3 4 5export ROOT_PATH=$(shell pwd) 6 7SUBDIRS = kernel user tools build-scripts 8 9 10 11# todo: 增加参数,判断是否在QEMU中仿真,若是,则启用该环境变量 12# export EMULATOR=__QEMU_EMULATION__ 13 14# 计算cpu核心数 15NPROCS:=1 16OS:=$(shell uname -s) 17 18ifeq ($(OS),Linux) 19 NPROCS:=$(shell grep -c ^processor /proc/cpuinfo) 20endif 21ifeq ($(OS),Darwin) # Assume Mac OS X 22 NPROCS:=$(shell system_profiler | awk '/Number Of CPUs/{print $4}{next;}') 23endif 24 25 26 27# 检查是否需要进行fmt --check 28# 解析命令行参数 29FMT_CHECK?=0 30 31ifeq ($(FMT_CHECK), 1) 32 FMT_CHECK=--check 33else 34 FMT_CHECK= 35endif 36 37 38.PHONY: all 39all: kernel user 40 41 42.PHONY: kernel 43kernel: 44 mkdir -p bin/kernel/ 45 46 $(MAKE) -C ./kernel all ARCH=$(ARCH) || (sh -c "echo 内核编译失败" && exit 1) 47 48.PHONY: user 49user: 50 $(MAKE) -C ./user all ARCH=$(ARCH) || (sh -c "echo 用户程序编译失败" && exit 1) 51 52.PHONY: clean 53clean: 54 @list='$(SUBDIRS)'; for subdir in $$list; do \ 55 echo "Clean in dir: $$subdir";\ 56 cd $$subdir && $(MAKE) clean;\ 57 cd .. ;\ 58 done 59 60.PHONY: ECHO 61ECHO: 62 @echo "$@" 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 70docs: ECHO 71 bash -c "cd docs && make html && cd .." 72 73clean-docs: 74 bash -c "cd docs && make clean && cd .." 75 76gdb: 77ifeq ($(ARCH), x86_64) 78 rust-gdb -n -x tools/.gdbinit 79else 80 gdb-multiarch -n -x tools/.gdbinit 81endif 82 83# 写入磁盘镜像 84write_diskimage: 85 @echo "write_diskimage arch=$(ARCH)" 86 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 .." 87 88# 写入磁盘镜像(uefi) 89write_diskimage-uefi: 90 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 .." 91# 不编译,直接启动QEMU 92qemu: 93 sh -c "cd tools && bash run-qemu.sh --bios=legacy --display=window && cd .." 94# 不编译,直接启动QEMU(UEFI) 95qemu-uefi: 96 sh -c "cd tools && bash run-qemu.sh --bios=uefi --display=window && cd .." 97# 不编译,直接启动QEMU,使用VNC Display作为图像输出 98qemu-vnc: 99 sh -c "cd tools && bash run-qemu.sh --bios=legacy --display=vnc && cd .." 100# 不编译,直接启动QEMU(UEFI),使用VNC Display作为图像输出 101qemu-uefi-vnc: 102 sh -c "cd tools && bash run-qemu.sh --bios=uefi --display=vnc && cd .." 103 104# 编译并写入磁盘镜像 105build: 106 $(MAKE) all -j $(NPROCS) 107 $(MAKE) write_diskimage || exit 1 108 109# 在docker中编译,并写入磁盘镜像 110docker: 111 @echo "使用docker构建" 112 sudo bash tools/build_in_docker.sh || exit 1 113 $(MAKE) write_diskimage || exit 1 114 115# uefi方式启动 116run-uefi: 117 $(MAKE) all -j $(NPROCS) 118 $(MAKE) write_diskimage-uefi || exit 1 119 $(MAKE) qemu-uefi 120 121# 编译并启动QEMU 122run: 123 $(MAKE) all -j $(NPROCS) 124 $(MAKE) write_diskimage || exit 1 125 $(MAKE) qemu 126 127# uefi方式启动,使用VNC Display作为图像输出 128run-uefi-vnc: 129 $(MAKE) all -j $(NPROCS) 130 $(MAKE) write_diskimage-uefi || exit 1 131 $(MAKE) qemu-uefi-vnc 132 133# 编译并启动QEMU,使用VNC Display作为图像输出 134run-vnc: 135 $(MAKE) all -j $(NPROCS) 136 $(MAKE) write_diskimage || exit 1 137 $(MAKE) qemu-vnc 138 139# 在docker中编译,并启动QEMU 140run-docker: 141 @echo "使用docker构建并运行" 142 sudo bash tools/build_in_docker.sh || exit 1 143 $(MAKE) write_diskimage || exit 1 144 $(MAKE) qemu 145 146fmt: 147 @echo "格式化代码" 148 FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C kernel 149 FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C user 150 FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C build-scripts 151 152log-monitor: 153 @echo "启动日志监控" 154 @sh -c "cd tools/debugging/logmonitor && cargo run --release -- --log-dir $(ROOT_PATH)/logs/ --kernel $(ROOT_PATH)/bin/kernel/kernel.elf" 155 156.PHONY: update-submodules 157update-submodules: 158 @echo "更新子模块" 159 @git submodule update --recursive 160 @git submodule foreach git pull origin master 161 162.PHONY: update-submodules-by-mirror 163update-submodules-by-mirror: 164 @echo "从镜像更新子模块" 165 @git config --global url."https://git.mirrors.dragonos.org.cn/DragonOS-Community/".insteadOf https://github.com/DragonOS-Community/ 166 @$(MAKE) update-submodules 167 @git config --global --unset url."https://git.mirrors.dragonos.org.cn/DragonOS-Community/".insteadOf 168 169help: 170 @echo "编译:" 171 @echo " make all -j <n> - 本地编译,不运行,n为要用于编译的CPU核心数" 172 @echo " make build - 本地编译,并写入磁盘镜像" 173 @echo " make docker - Docker编译,并写入磁盘镜像" 174 @echo "" 175 @echo "编译并运行:" 176 @echo " make run-docker - Docker编译,写入磁盘镜像,并在QEMU中运行" 177 @echo " make run - 本地编译,写入磁盘镜像,并在QEMU中运行" 178 @echo " make run-uefi - 以uefi方式启动运行" 179 @echo "" 180 @echo "运行:" 181 @echo " make qemu - 不编译,直接从已有的磁盘镜像启动运行" 182 @echo " make qemu-uefi - 不编译,直接从已有的磁盘镜像以UEFI启动运行" 183 @echo "" 184 @echo "" 185 @echo "注: 对于上述的run, run-uefi, qemu, qemu-uefi命令可以在命令后加上-vnc后缀,来通过vnc连接到DragonOS, 默认会在5900端口运行vnc服务器。如:make run-vnc " 186 @echo "" 187 @echo "其他:" 188 @echo " make clean - 清理编译产生的文件" 189 @echo " make fmt - 格式化代码" 190 @echo " make log-monitor - 启动日志监控" 191 @echo " make docs - 生成文档" 192 @echo " make clean-docs - 清理文档" 193 @echo "" 194 @echo " make update-submodules - 更新子模块" 195 @echo " make update-submodules-by-mirror - 从镜像更新子模块" 196 197