1user_sub_dirs = apps 2 3SUBDIR_ROOTS := . 4DIRS := . $(shell find $(SUBDIR_ROOTS) -type d) 5GARBAGE_PATTERNS := *.o *.s~ *.s *.S~ *.c~ *.h~ sys_api_lib *.a 6GARBAGE := $(foreach DIR,$(DIRS),$(addprefix $(DIR)/,$(GARBAGE_PATTERNS))) 7 8 9tmp_output_dir=$(ROOT_PATH)/bin/tmp/user 10output_dir=$(ROOT_PATH)/bin/user 11 12CFLAGS := $(GLOBAL_CFLAGS) -I $(shell pwd)/libs -I $(shell pwd)/libs/libc/src/include 13current_CFLAGS := $(CFLAGS) 14 15ECHO: 16 @echo "$@" 17 18$(user_sub_dirs): ECHO sys_api_lib 19 20 $(MAKE) -C $@ all CFLAGS="$(CFLAGS)" tmp_output_dir="$(tmp_output_dir)" output_dir="$(output_dir)" sys_libs_dir="$(shell pwd)/libs" 21 22app: $(user_sub_dirs) 23 24all: app 25 26 $(shell if [ ! -e $(tmp_output_dir) ];then mkdir -p $(tmp_output_dir); fi) 27 $(shell if [ ! -e $(output_dir) ];then mkdir -p $(output_dir); fi) 28 29 @echo 用户态程序编译完成 30 31make_output_dir: ECHO 32 mkdir -p $(ROOT_PATH)/bin/user/ 33 mkdir -p $(ROOT_PATH)/bin/tmp/user 34 mkdir -p $(ROOT_PATH)/bin/sysroot/usr/include 35 mkdir -p $(ROOT_PATH)/bin/sysroot/usr/lib 36 37 $(shell if [ ! -e $(tmp_output_dir) ];then mkdir -p $(tmp_output_dir); fi) 38 $(shell if [ ! -e $(output_dir) ];then mkdir -p $(output_dir); fi) 39# 系统库 40 41sys_api_lib_stage_1: make_output_dir 42 @echo Building sys_api_lib... 43 $(MAKE) -C libs all CFLAGS="$(CFLAGS)" tmp_output_dir="$(tmp_output_dir)" output_dir="$(output_dir)" sys_libs_dir="$(shell pwd)/libs" 44 45 46sys_api_lib: sys_api_lib_stage_1 47 $(AR) crvs $(ROOT_PATH)/bin/sysroot/usr/lib/libc.a $(shell find ./libs/* -name "*.o") 48 $(shell find ./libs/* -name "*.o" | xargs -I {} cp {} $(ROOT_PATH)/bin/sysroot/usr/lib/) 49 $(shell cp -r $(ROOT_PATH)/user/libs/libc/src/include/* $(ROOT_PATH)/bin/sysroot/usr/include/) 50 $(shell cp -r $(ROOT_PATH)/user/libs/libc/src/arch/x86_64/c*.o $(ROOT_PATH)/bin/sysroot/usr/lib/) 51 52clean: 53 rm -rf $(GARBAGE) 54 $(MAKE) clean -C libs 55 @list='$(user_sub_dirs)'; for subdir in $$list; do \ 56 echo "Clean in dir: $$subdir";\ 57 cd $$subdir && $(MAKE) clean;\ 58 cd .. ;\ 59 done 60