Makefile 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. # 导入环境变量
  2. include env.mk
  3. export ROOT_PATH=$(shell pwd)
  4. SUBDIRS = kernel user tools build-scripts
  5. # todo: 增加参数,判断是否在QEMU中仿真,若是,则启用该环境变量
  6. # export EMULATOR=__QEMU_EMULATION__
  7. # 计算cpu核心数
  8. NPROCS:=1
  9. OS:=$(shell uname -s)
  10. ifeq ($(OS),Linux)
  11. NPROCS:=$(shell grep -c ^processor /proc/cpuinfo)
  12. endif
  13. ifeq ($(OS),Darwin) # Assume Mac OS X
  14. NPROCS:=$(shell system_profiler | awk '/Number Of CPUs/{print $4}{next;}')
  15. endif
  16. # 检查是否需要进行fmt --check
  17. # 解析命令行参数
  18. FMT_CHECK?=0
  19. ifeq ($(FMT_CHECK), 1)
  20. FMT_CHECK=--check
  21. else
  22. FMT_CHECK=
  23. endif
  24. # Check if ARCH matches the arch field in dadk-manifest.toml
  25. check_arch:
  26. @bash tools/check_arch.sh
  27. # ===> Following are oscomp specific
  28. .PHONY: all
  29. all:
  30. #@make ARCH=x86_64 ci-build
  31. @make ARCH=riscv64 ci-build
  32. ci-get-testcase:
  33. ifneq ($(REGET), 1)
  34. @echo "测试用例已经获取,跳过获取步骤。如需重新获取,请设置 REGET=1"
  35. endif
  36. @cd oscomp && sh ci-testcase.sh
  37. ci-update-submodules:
  38. @echo "更新子模块"
  39. @sudo chown -R $(shell whoami) .
  40. @git submodule update --recursive --init
  41. ci-build: ci-kernel ci-user ci-gendisk
  42. ci-run: ci-build ci-start
  43. ci-kernel: ci-update-submodules
  44. @echo "Compile $(ARCH) Kernel..."
  45. @$(MAKE) -C ./kernel all ARCH=$(ARCH) || (echo "Kernel compilation failed" && exit 1)
  46. ci-user:
  47. @echo "Compile $(ARCH) User..."
  48. @$(MAKE) -C ./user all ARCH=$(ARCH) FORCE_UNSAFE_CONFIGURE=1 || (echo "User compilation failed" && exit 1)
  49. ci-gendisk:
  50. @echo "Generate disk image"
  51. ifeq ($(ARCH),x86_64)
  52. @bash -c "cd tools && bash grub_auto_install.sh"
  53. endif
  54. @bash -c "cd oscomp && sudo DADK=$(DADK) ARCH=$(ARCH) bash write_disk_image.sh --bios=legacy"
  55. ci-start:
  56. @echo "Booting $(ARCH)"
  57. @cd oscomp && bash ci-start-$(ARCH).sh
  58. .PHONY: kernel user write_diskimage write_diskimage-uefi qemu qemu-nographic qemu-uefi qemu-vnc qemu-uefi-vnc
  59. kernel user write_diskimage write_diskimage-uefi qemu qemu-nographic qemu-uefi qemu-vnc qemu-uefi-vnc:
  60. @echo "The target \"$@\" is deprecated in this branch. Please use ci-* target instead."
  61. @echo "To see the available targets, run \"make help\"."
  62. @false
  63. # <===
  64. .PHONY: clean
  65. clean:
  66. @rm -rf bin
  67. @list='$(SUBDIRS)'; for subdir in $$list; do \
  68. echo "Clean in dir: $$subdir";\
  69. cd $$subdir && $(MAKE) clean;\
  70. cd .. ;\
  71. done
  72. .PHONY: ECHO
  73. ECHO:
  74. @echo "$@"
  75. docs: ECHO
  76. bash -c "cd docs && make html && cd .."
  77. clean-docs:
  78. bash -c "cd docs && make clean && cd .."
  79. gdb:
  80. ifeq ($(ARCH), x86_64)
  81. rust-gdb -n -x tools/.gdbinit
  82. else
  83. gdb-multiarch -n -x tools/.gdbinit
  84. endif
  85. fmt:
  86. @echo "格式化代码"
  87. FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C kernel
  88. FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C user
  89. FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C build-scripts
  90. log-monitor:
  91. @echo "启动日志监控"
  92. @sh -c "cd tools/debugging/logmonitor && cargo run --release -- --log-dir $(ROOT_PATH)/logs/ --kernel $(ROOT_PATH)/bin/kernel/kernel.elf"
  93. .PHONY: update-submodules
  94. update-submodules:
  95. @echo "更新子模块"
  96. @git submodule update --recursive --init
  97. .PHONY: update-submodules-by-mirror
  98. update-submodules-by-mirror:
  99. @echo "从镜像更新子模块"
  100. @git config --global url."https://git.mirrors.dragonos.org.cn/DragonOS-Community/".insteadOf https://github.com/DragonOS-Community/
  101. @$(MAKE) update-submodules
  102. @git config --global --unset url."https://git.mirrors.dragonos.org.cn/DragonOS-Community/".insteadOf
  103. help:
  104. @echo "用法:"
  105. @echo " make <target> ARCH=<arch>"
  106. @echo ""
  107. @echo "Example:"
  108. @echo " make ci-run ARCH=riscv64"
  109. @echo ""
  110. @echo "When <arch> is not specified, the default value in env.mk will be used."
  111. @echo ""
  112. @echo "Targets:"
  113. @echo " make ci-run - 本地编译,写入磁盘镜像,并在QEMU中运行"
  114. @echo " make ci-kernel - 编译内核"
  115. @echo " make ci-gendisk - 写入磁盘镜像"
  116. @echo " make ci-build - 编译并写入磁盘镜像"
  117. @echo " make ci-start - 不编译,直接启动运行"
  118. @echo ""
  119. @echo "其他:"
  120. @echo " make all - 用于 CI 编译"
  121. @echo " make clean - 清理编译产生的文件"
  122. @echo " make fmt - 格式化代码"
  123. @echo " make log-monitor - 启动日志监控"
  124. @echo " make docs - 生成文档"
  125. @echo " make clean-docs - 清理文档"
  126. @echo ""
  127. @echo " make update-submodules - 更新子模块"
  128. @echo " make update-submodules-by-mirror - 从镜像更新子模块"