Makefile 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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-update-submodules:
  33. @echo "更新子模块"
  34. @sudo chown -R $(shell whoami) .
  35. @git submodule update --recursive --init
  36. ci-build: ci-kernel ci-user ci-gendisk
  37. ci-run: ci-build ci-start
  38. ci-kernel: ci-update-submodules
  39. @echo "Compile $(ARCH) Kernel..."
  40. @$(MAKE) -C ./kernel all ARCH=$(ARCH) || (echo "Kernel compilation failed" && exit 1)
  41. ci-user:
  42. @echo "Compile $(ARCH) User..."
  43. @$(MAKE) -C ./user all ARCH=$(ARCH) FORCE_UNSAFE_CONFIGURE=1 || (echo "User compilation failed" && exit 1)
  44. ci-gendisk:
  45. @echo "Generate disk image"
  46. ifeq ($(ARCH),x86_64)
  47. @bash -c "cd tools && bash grub_auto_install.sh"
  48. endif
  49. @bash -c "cd oscomp && sudo DADK=$(DADK) ARCH=$(ARCH) bash write_disk_image.sh --bios=legacy"
  50. ci-start:
  51. @echo "Booting $(ARCH)"
  52. @cd oscomp && bash ci-start-$(ARCH).sh
  53. .PHONY: kernel user write_diskimage write_diskimage-uefi qemu qemu-nographic qemu-uefi qemu-vnc qemu-uefi-vnc
  54. kernel user write_diskimage write_diskimage-uefi qemu qemu-nographic qemu-uefi qemu-vnc qemu-uefi-vnc:
  55. @echo "The target \"$@\" is deprecated in this branch. Please use ci-* target instead."
  56. @echo "To see the available targets, run \"make help\"."
  57. @false
  58. # <===
  59. .PHONY: clean
  60. clean:
  61. @list='$(SUBDIRS)'; for subdir in $$list; do \
  62. echo "Clean in dir: $$subdir";\
  63. cd $$subdir && $(MAKE) clean;\
  64. cd .. ;\
  65. done
  66. .PHONY: ECHO
  67. ECHO:
  68. @echo "$@"
  69. docs: ECHO
  70. bash -c "cd docs && make html && cd .."
  71. clean-docs:
  72. bash -c "cd docs && make clean && cd .."
  73. gdb:
  74. ifeq ($(ARCH), x86_64)
  75. rust-gdb -n -x tools/.gdbinit
  76. else
  77. gdb-multiarch -n -x tools/.gdbinit
  78. endif
  79. fmt: check_arch
  80. @echo "格式化代码"
  81. FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C kernel
  82. FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C user
  83. FMT_CHECK=$(FMT_CHECK) $(MAKE) fmt -C build-scripts
  84. log-monitor:
  85. @echo "启动日志监控"
  86. @sh -c "cd tools/debugging/logmonitor && cargo run --release -- --log-dir $(ROOT_PATH)/logs/ --kernel $(ROOT_PATH)/bin/kernel/kernel.elf"
  87. .PHONY: update-submodules
  88. update-submodules:
  89. @echo "更新子模块"
  90. @git submodule update --recursive --init
  91. .PHONY: update-submodules-by-mirror
  92. update-submodules-by-mirror:
  93. @echo "从镜像更新子模块"
  94. @git config --global url."https://git.mirrors.dragonos.org.cn/DragonOS-Community/".insteadOf https://github.com/DragonOS-Community/
  95. @$(MAKE) update-submodules
  96. @git config --global --unset url."https://git.mirrors.dragonos.org.cn/DragonOS-Community/".insteadOf
  97. help:
  98. @echo "用法:"
  99. @echo " make <target> ARCH=<arch>"
  100. @echo ""
  101. @echo "Example:"
  102. @echo " make ci-run ARCH=riscv64"
  103. @echo ""
  104. @echo "When <arch> is not specified, the default value in env.mk will be used."
  105. @echo ""
  106. @echo "Targets:"
  107. @echo " make ci-run - 本地编译,写入磁盘镜像,并在QEMU中运行"
  108. @echo " make ci-kernel - 编译内核"
  109. @echo " make ci-gendisk - 写入磁盘镜像"
  110. @echo " make ci-build - 编译并写入磁盘镜像"
  111. @echo " make ci-start - 不编译,直接启动运行"
  112. @echo ""
  113. @echo "其他:"
  114. @echo " make all - 用于 CI 编译"
  115. @echo " make clean - 清理编译产生的文件"
  116. @echo " make fmt - 格式化代码"
  117. @echo " make log-monitor - 启动日志监控"
  118. @echo " make docs - 生成文档"
  119. @echo " make clean-docs - 清理文档"
  120. @echo ""
  121. @echo " make update-submodules - 更新子模块"
  122. @echo " make update-submodules-by-mirror - 从镜像更新子模块"