Makefile 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. user_sub_dirs = apps
  2. SUBDIR_ROOTS := .
  3. DIRS := . $(shell find $(SUBDIR_ROOTS) -type d)
  4. GARBAGE_PATTERNS := *.o *.a
  5. GARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(GARBAGE_PATTERNS)))
  6. DADK_VERSION=$(shell dadk -V | awk 'END {print $$2}')
  7. # 最小的DADK版本
  8. MIN_DADK_VERSION = 0.1.11
  9. DADK_CACHE_DIR = $(ROOT_PATH)/bin/dadk_cache
  10. ECHO:
  11. @echo "$@"
  12. install_dadk:
  13. # 如果未安装
  14. ifeq ("$(DADK_VERSION)", "")
  15. @echo "\ndadk is not installed."
  16. @echo "Please install dadk $(MIN_DADK_VERSION) or higher version"
  17. @echo "\nYou can install dadk by running the following command:"
  18. @echo "\n\tcargo install dadk"
  19. @echo "\nOr you can install dadk from source by running the following command:"
  20. @echo "\n\tcargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v$(MIN_DADK_VERSION)"
  21. @echo "\n"
  22. @echo "Auto installing dadk..."
  23. cargo install dadk
  24. else
  25. # 如果DADK版本过低,则自动更新
  26. @echo "dadk version $(DADK_VERSION) installed"
  27. # 如果DADK版本过低,则自动更新
  28. ifneq ($(shell printf '%s\n%s' "$(DADK_VERSION)" "$(MIN_DADK_VERSION)" | sort -V | head -n1), $(MIN_DADK_VERSION))
  29. @echo "dadk version is too low, please update to $(MIN_DADK_VERSION) or higher version"
  30. @echo "Updating dadk..."
  31. cargo install --git https://git.mirrors.dragonos.org.cn/DragonOS-Community/DADK.git --tag v$(MIN_DADK_VERSION) || (echo "dadk update failed" && exit 1)
  32. @echo "dadk updated"
  33. endif
  34. endif
  35. .PHONY: dadk_run
  36. dadk_run: install_dadk
  37. mkdir -p $(DADK_CACHE_DIR)
  38. dadk --config-dir dadk/config --cache-dir $(DADK_CACHE_DIR) --dragonos-dir $(ROOT_PATH)/bin/sysroot build
  39. dadk --config-dir dadk/config --cache-dir $(DADK_CACHE_DIR) --dragonos-dir $(ROOT_PATH)/bin/sysroot install
  40. .PHONY: dadk_clean
  41. dadk_clean: install_dadk
  42. @echo dadk_clean
  43. # 不运行dadk clean的原因是,把clean的工作交给应用程序自己去做,这样可以节省编译时间
  44. #dadk --config-dir dadk/config --cache-dir $(DADK_CACHE_DIR) --dragonos-dir $(ROOT_PATH)/bin/sysroot clean src
  45. #dadk --config-dir dadk/config --cache-dir $(DADK_CACHE_DIR) --dragonos-dir $(ROOT_PATH)/bin/sysroot clean target
  46. all:
  47. mkdir -p $(ROOT_PATH)/bin/sysroot
  48. $(MAKE) dadk_run
  49. $(MAKE) copy_sysconfig
  50. @echo 用户态程序编译完成
  51. copy_sysconfig: dadk_run
  52. cp -r sysconfig/* $(ROOT_PATH)/bin/sysroot/
  53. .PHONY: clean
  54. clean:
  55. rm -rf $(GARBAGE)
  56. $(MAKE) dadk_clean
  57. @list='$(user_sub_dirs)'; for subdir in $$list; do \
  58. echo "Clean in dir: $$subdir";\
  59. cd $$subdir && $(MAKE) clean;\
  60. cd .. ;\
  61. done
  62. .PHONY: fmt
  63. fmt:
  64. FMT_CHECK=$(FMT_CHECK) $(MAKE) -C apps fmt