From b2614801ac87570a4aa23e52f5acbcbad08e3d23 Mon Sep 17 00:00:00 2001 From: fslongjin Date: Mon, 1 Aug 2022 16:03:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0Makefile=EF=BC=8C=E6=8F=90?= =?UTF-8?q?=E5=8D=87=E7=BC=96=E8=AF=91=E9=80=9F=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/Makefile | 24 ++++++++++++------------ kernel/common/Makefile | 16 +++++++++------- kernel/debug/Makefile | 2 +- kernel/driver/Makefile | 16 +++++++++------- user/Makefile | 31 +++++++++++++++---------------- user/libs/Makefile | 15 ++++++++------- 6 files changed, 54 insertions(+), 50 deletions(-) diff --git a/kernel/Makefile b/kernel/Makefile index 390d5dca..c813e863 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -15,7 +15,6 @@ CFLAGS = $(GLOBAL_CFLAGS) -D $(PIC) -I $(shell pwd) export ASFLAGS := --64 LD_LIST := head.o -OBJ_LIST := head.o kernel_subdirs := common driver process debug filesystem time arch exception mm smp sched syscall ktest @@ -34,7 +33,7 @@ main.o: main.c all: kernel - echo "Linking kernel..." + @echo "Linking kernel..." ld -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") -T link.lds # 生成kallsyms current_dir=$(pwd) @@ -46,22 +45,23 @@ all: kernel done # 重新链接 - echo "Re-Linking kernel..." + @echo "Re-Linking kernel..." ld -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") ./debug/kallsyms.o -T link.lds - echo "Generating kernel ELF file..." + @echo "Generating kernel ELF file..." # 生成内核文件 objcopy -I elf64-x86-64 -O elf64-x86-64 -R ".comment" -R ".eh_frame" kernel ../bin/kernel/kernel.elf - echo "Done." + @echo "Done." + +ECHO: + @echo "$@" + +$(kernel_subdirs): ECHO + + $(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)" PIC="$(PIC)" kernel_root_path="$(shell pwd)" -kernel: head.o main.o $(OBJ_LIST) +kernel: head.o main.o $(kernel_subdirs) - @list='$(kernel_subdirs)'; for subdir in $$list; do \ - echo "make all in $$subdir";\ - cd $$subdir;\ - $(MAKE) all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)" PIC="$(PIC)" kernel_root_path="$(shell pwd)";\ - cd ..;\ - done clean: diff --git a/kernel/common/Makefile b/kernel/common/Makefile index df1b3760..90971214 100644 --- a/kernel/common/Makefile +++ b/kernel/common/Makefile @@ -3,13 +3,15 @@ CFLAGS += -I . kernel_common_subdirs:=libELF math -all: glib.o printk.o cpu.o bitree.o kfifo.o wait_queue.o mutex.o wait.o unistd.o - @list='$(kernel_common_subdirs)'; for subdir in $$list; do \ - echo "make all in $$subdir";\ - cd $$subdir;\ - $(MAKE) all CFLAGS="$(CFLAGS)";\ - cd ..;\ - done +ECHO: + @echo "$@" + +$(kernel_common_subdirs): ECHO + + $(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)" PIC="$(PIC)" + +all: glib.o printk.o cpu.o bitree.o kfifo.o wait_queue.o mutex.o wait.o unistd.o $(kernel_common_subdirs) + glib.o: glib.c gcc $(CFLAGS) -c glib.c -o glib.o diff --git a/kernel/debug/Makefile b/kernel/debug/Makefile index 15102bbf..281c5633 100644 --- a/kernel/debug/Makefile +++ b/kernel/debug/Makefile @@ -17,7 +17,7 @@ generate_kallsyms: kallsyms.o nm -n $(kernel_root_path)/kernel | ./kallsyms > kallsyms.S gcc -c kallsyms.S -o kallsyms.o - echo "Kallsyms generated." + @echo "Kallsyms generated." clean: diff --git a/kernel/driver/Makefile b/kernel/driver/Makefile index 1a9ede91..972f7cb0 100644 --- a/kernel/driver/Makefile +++ b/kernel/driver/Makefile @@ -3,13 +3,15 @@ CFLAGS += -I . kernel_driver_subdirs:=video interrupt usb pci uart acpi disk keyboard mouse multiboot2 timers -all: - @list='$(kernel_driver_subdirs)'; for subdir in $$list; do \ - echo "make all in $$subdir";\ - cd $$subdir;\ - $(MAKE) all CFLAGS="$(CFLAGS)" PIC="$(PIC)";\ - cd ..;\ - done +ECHO: + @echo "$@" + +$(kernel_driver_subdirs): ECHO + + $(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)" PIC="$(PIC)" + +all: $(kernel_driver_subdirs) + clean: echo "Done." \ No newline at end of file diff --git a/user/Makefile b/user/Makefile index 747a3a2f..ebce6c1c 100644 --- a/user/Makefile +++ b/user/Makefile @@ -1,4 +1,4 @@ -user_sub_dirs = libs apps +user_sub_dirs = apps SUBDIR_ROOTS := . DIRS := . $(shell find $(SUBDIR_ROOTS) -type d) @@ -11,29 +11,28 @@ output_dir=$(ROOT_PATH)/bin/user CFLAGS := $(GLOBAL_CFLAGS) -I $(shell pwd)/libs current_CFLAGS := $(CFLAGS) -all: + +ECHO: + @echo "$@" + +$(user_sub_dirs): ECHO + + $(MAKE) -C $@ all CFLAGS="$(CFLAGS)" tmp_output_dir="$(tmp_output_dir)" output_dir="$(output_dir)" sys_libs_dir="$(shell pwd)/libs" + +other_dirs: $(user_sub_dirs) + +all: sys_api_lib $(shell if [ ! -e $(tmp_output_dir) ];then mkdir -p $(tmp_output_dir); fi) $(shell if [ ! -e $(output_dir) ];then mkdir -p $(output_dir); fi) - @list='$(user_sub_dirs)'; for subdir in $$list; do \ - echo "make all in $$subdir";\ - cd $$subdir;\ - $(MAKE) all CFLAGS="$(CFLAGS)" tmp_output_dir="$(tmp_output_dir)" output_dir="$(output_dir)" sys_libs_dir="$(shell pwd)/libs";\ - cd ..;\ - done +# 在成功编译系统库之后,开始编译用户态其他文件 + $(MAKE) other_dirs # 系统库 sys_api_lib: - @list='./libs'; for subdir in $$list; do \ - echo "make all in $$subdir";\ - cd $$subdir;\ - $(MAKE) all CFLAGS="$(CFLAGS)";\ - cd ..;\ - done + $(MAKE) -C libs all CFLAGS="$(CFLAGS)" tmp_output_dir="$(tmp_output_dir)" output_dir="$(output_dir)" sys_libs_dir="$(shell pwd)/libs" -# ld -b elf64-x86-64 -z muldefs -o $(tmp_output_dir)/sys_api_lib $(shell find ./libs -name "*.o") -#ld -b elf64-x86-64 -z muldefs -o sys_api_lib init.o $(shell find . -name "*.o") -T init.lds clean: diff --git a/user/libs/Makefile b/user/libs/Makefile index 2adcc764..4abb4b40 100644 --- a/user/libs/Makefile +++ b/user/libs/Makefile @@ -2,10 +2,11 @@ user_libs_sub_dirs=libc libsystem libKeyboard -all: - @list='$(user_libs_sub_dirs)'; for subdir in $$list; do \ - echo "make all in $$subdir";\ - cd $$subdir;\ - $(MAKE) all CFLAGS="$(CFLAGS) -I $(shell pwd)";\ - cd ..;\ - done \ No newline at end of file +ECHO: + @echo "$@" + +$(user_libs_sub_dirs): ECHO + + $(MAKE) -C $@ all CFLAGS="$(CFLAGS) -I $(shell pwd)" + +all: $(user_libs_sub_dirs)