浏览代码

更新Makefile,提升编译速度

fslongjin 2 年之前
父节点
当前提交
b2614801ac
共有 6 个文件被更改,包括 55 次插入51 次删除
  1. 12 12
      kernel/Makefile
  2. 9 7
      kernel/common/Makefile
  3. 1 1
      kernel/debug/Makefile
  4. 9 7
      kernel/driver/Makefile
  5. 16 17
      user/Makefile
  6. 8 7
      user/libs/Makefile

+ 12 - 12
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: head.o main.o $(OBJ_LIST)
+$(kernel_subdirs): ECHO
+
+	$(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)" PIC="$(PIC)" kernel_root_path="$(shell pwd)"
+
+
+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: 

+ 9 - 7
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

+ 1 - 1
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:

+ 9 - 7
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."

+ 16 - 17
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
-
-# 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
+	$(MAKE) -C libs all CFLAGS="$(CFLAGS)" tmp_output_dir="$(tmp_output_dir)" output_dir="$(output_dir)" sys_libs_dir="$(shell pwd)/libs"
+
 
 
 clean: 

+ 8 - 7
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
+ECHO:
+	@echo "$@"
+
+$(user_libs_sub_dirs): ECHO
+
+	$(MAKE) -C $@ all CFLAGS="$(CFLAGS) -I $(shell pwd)"
+
+all: $(user_libs_sub_dirs)