xref: /DragonOS/user/Makefile (revision 5c4224e5a8244cb0fb32512e70354362fccd6321)
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.8
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	CC=gcc AS=as AR=ar LD=ld OBJCOPY=objcopy NM=nm 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	CC=gcc AS=as AR=ar LD=ld OBJCOPY=objcopy NM=nm 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_services
59
60	@echo 用户态程序编译完成
61
62copy_services: dadk_run
63	cp -r services/* $(ROOT_PATH)/bin/sysroot/etc/reach/system/
64
65
66
67
68.PHONY: clean
69clean:
70	rm -rf $(GARBAGE)
71	$(MAKE) dadk_clean
72	@list='$(user_sub_dirs)'; for subdir in $$list; do \
73		echo "Clean in dir: $$subdir";\
74		cd $$subdir && $(MAKE) clean;\
75		cd .. ;\
76	done
77
78.PHONY: fmt
79fmt:
80	FMT_CHECK=$(FMT_CHECK) $(MAKE) -C apps fmt
81