Compile in subfolder

This commit is contained in:
Baptiste Wicht 2016-07-17 21:00:31 +02:00
parent 1473e4eb81
commit 91a37f5b07
3 changed files with 36 additions and 26 deletions

View File

@ -17,13 +17,13 @@ bootloader/stage2.bin: force_look
programs: force_look tlib/libtlib.a
cd programs/; ${MAKE} dist
compile: bootloader/stage1.bin bootloader/stage2.bin kernel/kernel.bin programs
compile: bootloader/stage1.bin bootloader/stage2.bin kernel/debug/kernel.bin programs
hdd.img:
dd if=/dev/zero of=hdd.img bs=516096c count=1000
(echo n; echo p; echo 1; echo ""; echo ""; echo t; echo c; echo a; echo 1; echo w;) | sudo fdisk -u -C1000 -S63 -H16 hdd.img
thor.flp: hdd.img bootloader/stage1.bin bootloader/stage2.bin kernel/kernel.bin programs
thor.flp: hdd.img bootloader/stage1.bin bootloader/stage2.bin kernel/debug/kernel.bin programs
mkdir -p mnt/fake/
dd if=bootloader/stage1.bin of=hdd.img conv=notrunc
dd if=bootloader/stage2.bin of=hdd.img seek=1 conv=notrunc
@ -33,7 +33,7 @@ thor.flp: hdd.img bootloader/stage1.bin bootloader/stage2.bin kernel/kernel.bin
sudo mkdir mnt/fake/bin/
sudo mkdir mnt/fake/sys/
sudo mkdir mnt/fake/dev/
sudo /bin/cp kernel/kernel.bin mnt/fake/
sudo /bin/cp kernel/debug/kernel.bin mnt/fake/
sudo /bin/cp programs/dist/* mnt/fake/bin/
sleep 0.1
sudo /bin/umount mnt/fake/

40
cpp.mk
View File

@ -40,38 +40,48 @@ LIB_LINK_FLAGS=$(FLAGS_64) $(WARNING_FLAGS) -mcmodel=small -fPIC -Wl,-gc-section
PROGRAM_FLAGS=$(FLAGS_64) $(WARNING_FLAGS) -I../../tlib/include/ -I../../printf/include/ -static -L../../tlib/ -ltlib -mcmodel=small -fPIC
PROGRAM_LINK_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
NO_COLOR=\x1b[0m
MODE_COLOR=\x1b[31;01m
FILE_COLOR=\x1b[35;01m
# Generate the rules for the CPP files of a directory
define compile_cpp_folder
$(1)/%.cpp.d: $(1)/%.cpp
@ $(CXX) $(KERNEL_CPP_FLAGS_64) $(THOR_FLAGS) $(WARNING_FLAGS) -MM -MT $(1)/$$*.cpp.o $$< | sed -e 's@^\(.*\)\.o:@\1.d \1.o:@' > $$@
debug/$(1)/%.cpp.d: $(1)/%.cpp
@ mkdir -p debug/$(1)/
@ $(CXX) $(KERNEL_CPP_FLAGS_64) $(THOR_FLAGS) $(WARNING_FLAGS) -MM -MT debug/$(1)/$$*.cpp.o $$< | sed -e 's@^\(.*\)\.o:@\1.d \1.o:@' > $$@
$(1)/%.cpp.o: $(1)/%.cpp
$(CXX) $(KERNEL_CPP_FLAGS_64) $(THOR_FLAGS) $(WARNING_FLAGS) -c $$< -o $(1)/$$*.cpp.o
debug/$(1)/%.cpp.o: $(1)/%.cpp
@ mkdir -p debug/$(1)/
@ echo -e "$(MODE_COLOR)[debug]$(NO_COLOR) Compile $(FILE_COLOR)$(1)/$$*.cpp$(NO_COLOR)"
@ $(CXX) $(KERNEL_CPP_FLAGS_64) $(THOR_FLAGS) $(WARNING_FLAGS) -c $$< -o $$@
folder_cpp_files := $(wildcard $(1)/*.cpp)
folder_d_files := $(folder_cpp_files:%.cpp=%.cpp.d)
folder_o_files := $(folder_cpp_files:%.cpp=%.cpp.o)
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)
D_FILES := $(D_FILES) $$(folder_d_files)
O_FILES := $(O_FILES) $$(folder_o_files)
endef
# Generate the rules for the APCICA C files of a components subdirectory
define acpica_folder_compile
acpica/source/components/$(1)/%.c.d: acpica/source/components/$(1)/%.c
debug/acpica/source/components/$(1)/%.c.d: acpica/source/components/$(1)/%.c
@ mkdir -p debug/acpica/source/components/$(1)/
@ $(CXX) $(ACPICA_C_FLAGS) $(THOR_FLAGS) -MM -MT acpica/source/components/$(1)/$$*.c.o $$< | sed -e 's@^\(.*\)\.o:@\1.d \1.o:@' > $$@
acpica/source/components/$(1)/%.c.o: acpica/source/components/$(1)/%.c
$(CC) $(ACPICA_C_FLAGS) $(THOR_FLAGS) -c $$< -o $$@
debug/acpica/source/components/$(1)/%.c.o: acpica/source/components/$(1)/%.c
@ mkdir -p debug/acpica/source/components/$(1)/
@ echo -e "$(MODE_COLOR)[debug]$(NO_COLOR) Compile (ACPICA) $(FILE_COLOR)$(1)/$$*.cpp$(NO_COLOR)"
@ $(CC) $(ACPICA_C_FLAGS) $(THOR_FLAGS) -c $$< -o $$@
acpica_folder_c_files := $(wildcard acpica/source/components/$(1)/*.c)
acpica_folder_d_files := $$(acpica_folder_c_files:%.c=%.c.d)
acpica_folder_o_files := $$(acpica_folder_c_files:%.c=%.c.o)
acpica_folder_d_files := $$(acpica_folder_c_files:%.c=debug/%.c.d)
acpica_folder_o_files := $$(acpica_folder_c_files:%.c=debug/%.c.o)
D_FILES += $$(acpica_folder_d_files)
O_FILES += $$(acpica_folder_o_files)
D_FILES := $(D_FILES) $$(acpica_folder_d_files)
O_FILES := $(O_FILES) $$(acpica_folder_o_files)
endef

View File

@ -1,4 +1,4 @@
default: kernel.bin
default: debug/kernel.bin
include ../cpp.mk
@ -54,15 +54,15 @@ $(eval $(call acpica_folder_compile,utilities))
LINK_O_FILES=$(SPECIAL_O_FILES) $(O_FILES)
kernel.bin: $(LINK_O_FILES)
$(CXX) $(KERNEL_LINK_FLAGS) $(KERNEL_CPP_FLAGS_64) -o kernel.bin.o $(LINK_O_FILES)
$(OC) -R .note -R .comment -O binary --set-section-flags .bss=alloc,load,contents kernel.bin.o kernel.bin
debug/kernel.bin: $(LINK_O_FILES)
@ mkdir -p debug/
@ echo -e "$(MODE_COLOR)[debug]$(NO_COLOR) Link $(FILE_COLOR)$@$(NO_COLOR)"
@ $(CXX) $(KERNEL_LINK_FLAGS) $(KERNEL_CPP_FLAGS_64) -o $@.o $(LINK_O_FILES)
@ $(OC) -R .note -R .comment -O binary --set-section-flags .bss=alloc,load,contents $@.o $@
clean:
@ echo -e "Remove deps files"
@ rm -f $(D_FILES)
@ echo -e "Remove object files"
@ rm -f $(O_FILES)
@ echo -e "Remove compiled files (deps/objects)"
@ rm -rf debug
@ rm -f crti.o
@ rm -f crts.o
@ echo -e "Remove bin files"