1b2614801Sfslongjinuser_sub_dirs = apps 20aec6827Sfslongjin 30aec6827SfslongjinSUBDIR_ROOTS := . 40aec6827SfslongjinDIRS := . $(shell find $(SUBDIR_ROOTS) -type d) 57285c927SloginGARBAGE_PATTERNS := *.o sys_api_lib *.a 60aec6827SfslongjinGARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(GARBAGE_PATTERNS))) 70aec6827Sfslongjin 80aec6827Sfslongjin 9afeca182Sfslongjintmp_output_dir=$(ROOT_PATH)/bin/tmp/user 10afeca182Sfslongjinoutput_dir=$(ROOT_PATH)/bin/user 11afeca182Sfslongjin 122bf5ee0eSloginCFLAGS := $(GLOBAL_CFLAGS) -I $(shell pwd)/libs -I $(shell pwd)/libs/libc/src/include -I $(shell pwd)/libs/libc/src/include/export 13afeca182Sfslongjincurrent_CFLAGS := $(CFLAGS) 14b2614801Sfslongjin 1526887c63SLoGinDADK_VERSION=$(shell dadk -V | awk 'END {print $$2}') 167285c927Slogin# 最小的DADK版本 17abf3f634SLoGinMIN_DADK_VERSION = 0.1.2 187285c927SloginDADK_CACHE_DIR = $(ROOT_PATH)/bin/dadk_cache 197285c927Slogin 207285c927Slogin# 旧版的libc安装路径 217285c927SloginOLD_LIBC_INSTALL_PATH=$(ROOT_PATH)/bin/sysroot/usr/old_libc 227285c927Slogin 23b2614801SfslongjinECHO: 24b2614801Sfslongjin @echo "$@" 25b2614801Sfslongjin 267285c927Slogin 277285c927Slogininstall_dadk: 287285c927Slogin# 如果未安装 297285c927Sloginifeq ("$(DADK_VERSION)", "") 307285c927Slogin @echo "\ndadk is not installed." 317285c927Slogin @echo "Please install dadk $(MIN_DADK_VERSION) or higher version" 327285c927Slogin @echo "\nYou can install dadk by running the following command:" 337285c927Slogin @echo "\n\tcargo install dadk" 347285c927Slogin @echo "\nOr you can install dadk from source by running the following command:" 357285c927Slogin @echo "\n\tcargo install --git https://github.com/DragonOS-Community/DADK.git" 367285c927Slogin @echo "\n" 37abf3f634SLoGin @echo "Auto installing dadk..." 38abf3f634SLoGin CC=gcc AS=as AR=ar LD=ld OBJCOPY=objcopy NM=nm cargo install dadk 397285c927Sloginelse 4026887c63SLoGin# 如果DADK版本过低,则自动更新 417285c927Slogin @echo "dadk version $(DADK_VERSION) installed" 42abf3f634SLoGin# 如果DADK版本过低,则自动更新 4326887c63SLoGinifneq ($(shell printf '%s\n%s' "$(DADK_VERSION)" "$(MIN_DADK_VERSION)" | sort -V | head -n1), $(MIN_DADK_VERSION)) 44abf3f634SLoGin @echo "dadk version is too low, please update to $(MIN_DADK_VERSION) or higher version" 45abf3f634SLoGin @echo "Updating dadk..." 46abf3f634SLoGin CC=gcc AS=as AR=ar LD=ld OBJCOPY=objcopy NM=nm cargo install dadk || (echo "dadk update failed" && exit 1) 47abf3f634SLoGin @echo "dadk updated" 48abf3f634SLoGinendif 497285c927Sloginendif 507285c927Slogin 51*6d81180bSLoGin.PHONY: dadk_run 527285c927Slogindadk_run: install_dadk 537285c927Slogin mkdir -p $(DADK_CACHE_DIR) 547285c927Slogin# 之所以在这里临时设置ARCH为空,是因为如果要设置这个环境变量,应当在DADK的配置文件中设置 557285c927Slogin ARCH= dadk --config-dir dadk/config --cache-dir $(DADK_CACHE_DIR) --dragonos-dir $(ROOT_PATH)/bin/sysroot build 567285c927Slogin ARCH= dadk --config-dir dadk/config --cache-dir $(DADK_CACHE_DIR) --dragonos-dir $(ROOT_PATH)/bin/sysroot install 577285c927Slogin 58*6d81180bSLoGin.PHONY: dadk_clean 597285c927Slogindadk_clean: install_dadk 60*6d81180bSLoGin dadk --config-dir dadk/config --cache-dir $(DADK_CACHE_DIR) --dragonos-dir $(ROOT_PATH)/bin/sysroot clean src 61*6d81180bSLoGin dadk --config-dir dadk/config --cache-dir $(DADK_CACHE_DIR) --dragonos-dir $(ROOT_PATH)/bin/sysroot clean target 627285c927Slogin 6356528782Sfslongjin$(user_sub_dirs): ECHO sys_api_lib 64b2614801Sfslongjin 65b2614801Sfslongjin $(MAKE) -C $@ all CFLAGS="$(CFLAGS)" tmp_output_dir="$(tmp_output_dir)" output_dir="$(output_dir)" sys_libs_dir="$(shell pwd)/libs" 66b2614801Sfslongjin 6756528782Sfslongjinapp: $(user_sub_dirs) 687285c927Slogin $(MAKE) dadk_run 69b2614801Sfslongjin 707285c927Sloginall: install_dadk app 712224c93eSguanjinquan 72e2a59dbdSfslongjin $(shell if [ ! -e $(tmp_output_dir) ];then mkdir -p $(tmp_output_dir); fi) 73e2a59dbdSfslongjin $(shell if [ ! -e $(output_dir) ];then mkdir -p $(output_dir); fi) 74e2a59dbdSfslongjin 7556528782Sfslongjin @echo 用户态程序编译完成 76e2a59dbdSfslongjin 772224c93eSguanjinquanmake_output_dir: ECHO 782224c93eSguanjinquan mkdir -p $(ROOT_PATH)/bin/user/ 792224c93eSguanjinquan mkdir -p $(ROOT_PATH)/bin/tmp/user 802224c93eSguanjinquan mkdir -p $(ROOT_PATH)/bin/sysroot/usr/include 812224c93eSguanjinquan mkdir -p $(ROOT_PATH)/bin/sysroot/usr/lib 822224c93eSguanjinquan 832224c93eSguanjinquan $(shell if [ ! -e $(tmp_output_dir) ];then mkdir -p $(tmp_output_dir); fi) 842224c93eSguanjinquan $(shell if [ ! -e $(output_dir) ];then mkdir -p $(output_dir); fi) 85e2a59dbdSfslongjin# 系统库 862224c93eSguanjinquan 872224c93eSguanjinquansys_api_lib_stage_1: make_output_dir 882224c93eSguanjinquan @echo Building sys_api_lib... 89b2614801Sfslongjin $(MAKE) -C libs all CFLAGS="$(CFLAGS)" tmp_output_dir="$(tmp_output_dir)" output_dir="$(output_dir)" sys_libs_dir="$(shell pwd)/libs" 90afeca182Sfslongjin 910aec6827Sfslongjin 922224c93eSguanjinquansys_api_lib: sys_api_lib_stage_1 932bf5ee0eSlogin 942bf5ee0eSlogin# 打包系统库 952bf5ee0eSlogin mkdir -p $(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp 967285c927Slogin mkdir -p $(OLD_LIBC_INSTALL_PATH)/include 977285c927Slogin mkdir -p $(OLD_LIBC_INSTALL_PATH)/lib 982bf5ee0eSlogin $(AR) x $(ROOT_PATH)/user/libs/libc/target/x86_64-unknown-none/release/liblibc.a --output=$(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp 997285c927Slogin $(AR) crvs $(OLD_LIBC_INSTALL_PATH)/lib/libc.a $(shell find ./libs/* -name "*.o") $(shell find $(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp/* -name "*.o") 1002bf5ee0eSlogin rm -rf $(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp 1012bf5ee0eSlogin# $(shell find ./libs/* -name "*.o" | xargs -I {} cp {} $(ROOT_PATH)/bin/sysroot/usr/lib/) 1027285c927Slogin $(shell cp -r $(ROOT_PATH)/user/libs/libc/src/include/export/* $(OLD_LIBC_INSTALL_PATH)/include/) 1037285c927Slogin $(shell cp -r $(ROOT_PATH)/user/libs/libc/src/arch/x86_64/c*.o $(OLD_LIBC_INSTALL_PATH)/lib/) 104afeca182Sfslongjin 105*6d81180bSLoGin.PHONY: clean 1060aec6827Sfslongjinclean: 1070aec6827Sfslongjin rm -rf $(GARBAGE) 1087285c927Slogin $(MAKE) dadk_clean 109237e95c6Swwc-15172310230 $(MAKE) clean -C libs 110237e95c6Swwc-15172310230 @list='$(user_sub_dirs)'; for subdir in $$list; do \ 111237e95c6Swwc-15172310230 echo "Clean in dir: $$subdir";\ 112237e95c6Swwc-15172310230 cd $$subdir && $(MAKE) clean;\ 113237e95c6Swwc-15172310230 cd .. ;\ 114237e95c6Swwc-15172310230 done 115afeca182Sfslongjin