Review tlib building

This commit is contained in:
Baptiste Wicht 2016-08-06 22:58:59 +02:00
parent 7839d6d5b3
commit a784cb50fa
3 changed files with 33 additions and 21 deletions

View File

@ -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

25
cpp.mk
View File

@ -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

View File

@ -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