From a784cb50fa26a6fa047700e22ee8be0740aa94b1 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Sat, 6 Aug 2016 22:58:59 +0200 Subject: [PATCH] Review tlib building --- Makefile | 4 ++-- cpp.mk | 25 +++++++++++++++++++++++-- tlib/Makefile | 25 ++++++++----------------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index 2d0962bd..26702b34 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ kernel/debug/kernel.bin: force_look init/debug/init.bin: force_look cd init; $(MAKE) -tlib/libtlib.a: force_look +tlib/debug/libtlib.a: force_look cd tlib; $(MAKE) bootloader/stage1.bin: force_look @@ -17,7 +17,7 @@ bootloader/stage1.bin: force_look bootloader/stage2.bin: force_look cd bootloader; $(MAKE) stage2.bin -programs: force_look tlib/libtlib.a +programs: force_look tlib/debug/libtlib.a cd programs/; ${MAKE} dist compile: bootloader/stage1.bin bootloader/stage2.bin init/debug/init.bin kernel/debug/kernel.bin programs diff --git a/cpp.mk b/cpp.mk index 2f693115..83d12c46 100644 --- a/cpp.mk +++ b/cpp.mk @@ -39,8 +39,8 @@ KERNEL_LINK_FLAGS=$(COMMON_LINK_FLAGS) -T linker.ld LIB_FLAGS=$(COMMON_CPP_FLAGS) $(FLAGS_64) $(WARNING_FLAGS) -mcmodel=small -fPIC -ffunction-sections -fdata-sections LIB_LINK_FLAGS=$(COMMON_CPP_FLAGS) $(FLAGS_64) $(WARNING_FLAGS) -mcmodel=small -fPIC -Wl,-gc-sections -PROGRAM_FLAGS=$(COMMON_CPP_FLAGS) $(FLAGS_64) $(WARNING_FLAGS) -I../../tlib/include/ -I../../printf/include/ -static -L../../tlib/ -ltlib -mcmodel=small -fPIC -PROGRAM_LINK_FLAGS=$(COMMON_CPP_FLAGS) $(FLAGS_64) $(WARNING_FLAGS) $(COMMON_LINK_FLAGS) -static -L../../tlib/ -ltlib -mcmodel=small -fPIC -z max-page-size=0x1000 -T ../linker.ld -Wl,-gc-sections +PROGRAM_FLAGS=$(COMMON_CPP_FLAGS) $(FLAGS_64) $(WARNING_FLAGS) -I../../tlib/include/ -I../../printf/include/ -static -L../../tlib/debug/ -ltlib -mcmodel=small -fPIC +PROGRAM_LINK_FLAGS=$(COMMON_CPP_FLAGS) $(FLAGS_64) $(WARNING_FLAGS) $(COMMON_LINK_FLAGS) -static -L../../tlib/debug/ -ltlib -mcmodel=small -fPIC -z max-page-size=0x1000 -T ../linker.ld -Wl,-gc-sections NO_COLOR=\x1b[0m MODE_COLOR=\x1b[31;01m @@ -113,3 +113,24 @@ debug/$(1): $(O_FILES) link: debug/$(1) endef + +# Generate the rules for the CPP files of a directory +define tlib_compile_cpp_folder + +debug/$(1)/%.cpp.d: $(1)/%.cpp + @ mkdir -p debug/$(1)/ + @ $(CXX) $(LIB_FLAGS) -MM -MT debug/$(1)/$$*.cpp.o $(1)/$$*.cpp | sed -e 's@^\(.*\)\.o:@\1.d \1.o:@' > $$@ + +debug/$(1)/%.cpp.o: $(1)/%.cpp + @ mkdir -p debug/$(1)/ + @ echo -e "$(MODE_COLOR)[debug]$(NO_COLOR) Compile (tlib) $(FILE_COLOR)$(1)/$$*.cpp$(NO_COLOR)" + @ $(CXX) $(LIB_FLAGS) -c $$< -o $$@ + +folder_cpp_files := $(wildcard $(1)/*.cpp) +folder_d_files := $$(folder_cpp_files:%.cpp=debug/%.cpp.d) +folder_o_files := $$(folder_cpp_files:%.cpp=debug/%.cpp.o) + +D_FILES := $(D_FILES) $$(folder_d_files) +O_FILES := $(O_FILES) $$(folder_o_files) + +endef diff --git a/tlib/Makefile b/tlib/Makefile index f51fb3de..b41a781f 100644 --- a/tlib/Makefile +++ b/tlib/Makefile @@ -1,25 +1,16 @@ -default: libtlib.a +default: debug/libtlib.a include ../cpp.mk -CPP_FILES=$(wildcard src/*.cpp) +$(eval $(call tlib_compile_cpp_folder,src)) -D_FILES=$(CPP_FILES:%.cpp=%.cpp.d) - -O_FILES=$(CPP_FILES:%.cpp=%.cpp.o) - -src/%.cpp.d: $(CPP_FILES) - @ $(CXX) $(LIB_FLAGS) -MM -MT src/$*.cpp.o src/$*.cpp | sed -e 's@^\(.*\)\.o:@\1.d \1.o:@' > $@ - -src/%.cpp.o: - $(CXX) $(LIB_FLAGS) -c $< -o $@ +debug/libtlib.a: $(O_FILES) + @ mkdir -p debug/ + @ echo -e "$(MODE_COLOR)[debug]$(NO_COLOR) Link (tlib) $(FILE_COLOR)$@$(NO_COLOR)" + @ ${AR} rcs debug/libtlib.a ${O_FILES} -include $(D_FILES) -libtlib.a: $(O_FILES) - ${AR} rcs libtlib.a ${O_FILES} - clean: - rm -f libtlib.a - rm -f $(O_FILES) - rm -f $(D_FILES) + @ echo -e "Remove compiled files (deps/objects)" + @ rm -rf debug