更新Makefile,提升编译速度

This commit is contained in:
fslongjin 2022-08-01 16:03:17 +08:00
parent bc1d2562c0
commit b2614801ac
6 changed files with 54 additions and 50 deletions

View File

@ -15,7 +15,6 @@ CFLAGS = $(GLOBAL_CFLAGS) -D $(PIC) -I $(shell pwd)
export ASFLAGS := --64 export ASFLAGS := --64
LD_LIST := head.o LD_LIST := head.o
OBJ_LIST := head.o
kernel_subdirs := common driver process debug filesystem time arch exception mm smp sched syscall ktest 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 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 ld -b elf64-x86-64 -z muldefs -o kernel head.o main.o $(shell find . -name "*.o") -T link.lds
# 生成kallsyms # 生成kallsyms
current_dir=$(pwd) current_dir=$(pwd)
@ -46,22 +45,23 @@ all: kernel
done 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 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 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: clean:

View File

@ -3,13 +3,15 @@ CFLAGS += -I .
kernel_common_subdirs:=libELF math 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 ECHO:
@list='$(kernel_common_subdirs)'; for subdir in $$list; do \ @echo "$@"
echo "make all in $$subdir";\
cd $$subdir;\ $(kernel_common_subdirs): ECHO
$(MAKE) all CFLAGS="$(CFLAGS)";\
cd ..;\ $(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)" PIC="$(PIC)"
done
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 glib.o: glib.c
gcc $(CFLAGS) -c glib.c -o glib.o gcc $(CFLAGS) -c glib.c -o glib.o

View File

@ -17,7 +17,7 @@ generate_kallsyms: kallsyms.o
nm -n $(kernel_root_path)/kernel | ./kallsyms > kallsyms.S nm -n $(kernel_root_path)/kernel | ./kallsyms > kallsyms.S
gcc -c kallsyms.S -o kallsyms.o gcc -c kallsyms.S -o kallsyms.o
echo "Kallsyms generated." @echo "Kallsyms generated."
clean: clean:

View File

@ -3,13 +3,15 @@ CFLAGS += -I .
kernel_driver_subdirs:=video interrupt usb pci uart acpi disk keyboard mouse multiboot2 timers kernel_driver_subdirs:=video interrupt usb pci uart acpi disk keyboard mouse multiboot2 timers
all: ECHO:
@list='$(kernel_driver_subdirs)'; for subdir in $$list; do \ @echo "$@"
echo "make all in $$subdir";\
cd $$subdir;\ $(kernel_driver_subdirs): ECHO
$(MAKE) all CFLAGS="$(CFLAGS)" PIC="$(PIC)";\
cd ..;\ $(MAKE) -C $@ all CFLAGS="$(CFLAGS)" ASFLAGS="$(ASFLAGS)" PIC="$(PIC)"
done
all: $(kernel_driver_subdirs)
clean: clean:
echo "Done." echo "Done."

View File

@ -1,4 +1,4 @@
user_sub_dirs = libs apps user_sub_dirs = apps
SUBDIR_ROOTS := . SUBDIR_ROOTS := .
DIRS := . $(shell find $(SUBDIR_ROOTS) -type d) DIRS := . $(shell find $(SUBDIR_ROOTS) -type d)
@ -11,29 +11,28 @@ output_dir=$(ROOT_PATH)/bin/user
CFLAGS := $(GLOBAL_CFLAGS) -I $(shell pwd)/libs CFLAGS := $(GLOBAL_CFLAGS) -I $(shell pwd)/libs
current_CFLAGS := $(CFLAGS) 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 $(tmp_output_dir) ];then mkdir -p $(tmp_output_dir); fi)
$(shell if [ ! -e $(output_dir) ];then mkdir -p $(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";\ $(MAKE) other_dirs
cd $$subdir;\
$(MAKE) all CFLAGS="$(CFLAGS)" tmp_output_dir="$(tmp_output_dir)" output_dir="$(output_dir)" sys_libs_dir="$(shell pwd)/libs";\
cd ..;\
done
# 系统库 # 系统库
sys_api_lib: sys_api_lib:
@list='./libs'; for subdir in $$list; do \ $(MAKE) -C libs all CFLAGS="$(CFLAGS)" tmp_output_dir="$(tmp_output_dir)" output_dir="$(output_dir)" sys_libs_dir="$(shell pwd)/libs"
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
clean: clean:

View File

@ -2,10 +2,11 @@
user_libs_sub_dirs=libc libsystem libKeyboard user_libs_sub_dirs=libc libsystem libKeyboard
all: ECHO:
@list='$(user_libs_sub_dirs)'; for subdir in $$list; do \ @echo "$@"
echo "make all in $$subdir";\
cd $$subdir;\ $(user_libs_sub_dirs): ECHO
$(MAKE) all CFLAGS="$(CFLAGS) -I $(shell pwd)";\
cd ..;\ $(MAKE) -C $@ all CFLAGS="$(CFLAGS) -I $(shell pwd)"
done
all: $(user_libs_sub_dirs)