xref: /DragonOS/user/Makefile (revision 539ee3eaeb83834e020efbb7582ed5ce2e9646ce)
1user_sub_dirs = apps
2
3DADK_VERSION=$(shell dadk -V | awk 'END {print $$2}')
4# 最小的DADK版本
5MIN_DADK_VERSION = 0.1.11
6DADK_CACHE_DIR = $(ROOT_PATH)/bin/dadk_cache
7
8ECHO:
9	@echo "$@"
10
11
12install_dadk:
13# 如果未安装
14ifeq ("$(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
24else
25# 如果DADK版本过低,则自动更新
26	@echo "dadk version $(DADK_VERSION) installed"
27# 如果DADK版本过低,则自动更新
28ifneq ($(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"
33endif
34endif
35
36.PHONY: dadk_run
37dadk_run: install_dadk
38	mkdir -p $(DADK_CACHE_DIR)
39	dadk --config-dir dadk/config --cache-dir $(DADK_CACHE_DIR) --dragonos-dir $(ROOT_PATH)/bin/sysroot build
40	dadk --config-dir dadk/config --cache-dir $(DADK_CACHE_DIR) --dragonos-dir $(ROOT_PATH)/bin/sysroot install
41
42.PHONY: dadk_clean
43dadk_clean: install_dadk
44	@echo dadk_clean
45# 不运行dadk clean的原因是,把clean的工作交给应用程序自己去做,这样可以节省编译时间
46#dadk --config-dir dadk/config --cache-dir $(DADK_CACHE_DIR) --dragonos-dir $(ROOT_PATH)/bin/sysroot clean src
47#dadk --config-dir dadk/config --cache-dir $(DADK_CACHE_DIR) --dragonos-dir $(ROOT_PATH)/bin/sysroot clean target
48
49all:
50	mkdir -p $(ROOT_PATH)/bin/sysroot
51
52	$(MAKE) dadk_run
53	$(MAKE) copy_sysconfig
54
55	@echo 用户态程序编译完成
56
57copy_sysconfig: dadk_run
58	cp -r sysconfig/* $(ROOT_PATH)/bin/sysroot/
59
60
61.PHONY: clean
62clean:
63	$(MAKE) dadk_clean
64	@list='$(user_sub_dirs)'; for subdir in $$list; do \
65		echo "Clean in dir: $$subdir";\
66		cd $$subdir && $(MAKE) clean;\
67		cd .. ;\
68	done
69
70.PHONY: fmt
71fmt:
72	FMT_CHECK=$(FMT_CHECK) $(MAKE) -C apps fmt
73