# https://www.gnu.org/software/make/manual/html_node/Setting.html
# := expanded variable, right-hand side can contain variables
# ?= only set if it doesn't have a value
# != execute a shell script on the right-hand side and assign its result to the left-hand side
include toolchain.makefile
OBJ_DIR := build
include src/makefile
include libk/makefile
AS_OBJ := $(addprefix $(OBJ_DIR)/, $(AS_OBJ))
CXX_OBJ := $(addprefix $(OBJ_DIR)/, $(CXX_OBJ))
CXX_TEST_OBJ := $(addprefix $(OBJ_DIR)/, $(CXX_TEST_OBJ))
CXX_INCLUDE := $(addprefix -I, $(CXX_INCLUDE))
# $@ is target
# $< is first dependency
# $^ is all dependencies
.PHONY: default clean test check-grub run
default: glitch.elf
glitch.elf: $(AS_OBJ) $(CXX_OBJ)
@echo " LD $@"
@$(LD) $(LD_FLAGS) -o $@ $(AS_OBJ) $(CXX_OBJ)
$(AS_OBJ): $(OBJ_DIR)/%.o: %.s
@mkdir -p $(@D)
@echo " AS $^"
@$(AS) -target $(TARGET) -nostdlib -Wall -Wextra -c $^ -o $@
$(CXX_OBJ) $(CXX_TEST_OBJ): $(OBJ_DIR)/%.o : %.cc
@mkdir -p $(@D)
@echo " CXX $^"
@$(CXX) -target $(TARGET) $(CXX_FLAGS) $(CXX_INCLUDE) -c $^ -o $@
clean:
rm -rf $(AS_OBJ) $(CXX_OBJ) $(CXX_TEST_OBJ) glitch.elf isodir
# testing
test: $(CXX_TEST_OBJ) check-grub
check-grub: glitch.elf
grub-file --is-x86-multiboot2 glitch.elf
# disk image
glitch.iso: glitch.elf grub/grub.cfg
@mkdir -p isodir/boot/grub
@cp glitch.elf isodir/boot/glitch.elf
@cp grub/grub.cfg isodir/boot/grub/grub.cfg
@$(BOOT) -o $@ isodir
run: glitch.iso
@$(EMU) $<