xref: /DragonOS/user/Makefile (revision b66beefd4e9ead61ee55f335246ebeb8277d3011)
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 -I $(shell pwd)/libs/libc/src/include/export
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
48# 打包系统库
49	mkdir -p $(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp
50	$(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
51	$(AR) crvs $(ROOT_PATH)/bin/sysroot/usr/lib/libc.a $(shell find ./libs/* -name "*.o") $(shell find $(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp/* -name "*.o")
52	rm -rf $(ROOT_PATH)/bin/tmp/user/sys_api_lib_build_tmp
53# $(shell find ./libs/* -name "*.o" | xargs -I {} cp {} $(ROOT_PATH)/bin/sysroot/usr/lib/)
54	$(shell cp -r $(ROOT_PATH)/user/libs/libc/src/include/export/* $(ROOT_PATH)/bin/sysroot/usr/include/)
55	$(shell cp -r $(ROOT_PATH)/user/libs/libc/src/arch/x86_64/c*.o $(ROOT_PATH)/bin/sysroot/usr/lib/)
56
57clean:
58	rm -rf $(GARBAGE)
59	$(MAKE) clean -C libs
60	@list='$(user_sub_dirs)'; for subdir in $$list; do \
61		echo "Clean in dir: $$subdir";\
62		cd $$subdir && $(MAKE) clean;\
63		cd .. ;\
64	done
65