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