Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makefile is unreadable and nonsensical garbage #91

Open
jonstr-osdev opened this issue Mar 5, 2024 · 0 comments
Open

Makefile is unreadable and nonsensical garbage #91

jonstr-osdev opened this issue Mar 5, 2024 · 0 comments

Comments

@jonstr-osdev
Copy link

jonstr-osdev commented Mar 5, 2024

I'm not going to create a PR and bug for a merge for this. This Makefile file DEMANDS some updates not only for readability but simply for robustness. No one should ever see the current Makefile as an example as it is so atrociously wrong by any conventional standard. Here is a Makefile compatible with the ep2 branch that is a bit more robust and readable.

# Directories
SRC_DIR := src
BUILD_DIR := build
DIST_DIR := dist
ASM_DIR := $(SRC_DIR)/impl/x86_64
C_DIR := $(SRC_DIR)/impl/x86_64
KERNEL_C_DIR := $(SRC_DIR)/impl/kernel
ISO_DIR := targets/x86_64/iso

# Toolchain
AS := nasm
CC := x86_64-elf-gcc
LD := x86_64-elf-ld
GRUB_MKRESCUE := grub-mkrescue

# Flags
ASMFLAGS := -f elf64
CFLAGS := -I$(SRC_DIR)/intf -ffreestanding -MMD -MP
LDFLAGS := -n -T targets/x86_64/linker.ld

# Source files
ASM_SRC := $(shell find $(ASM_DIR) -name '*.asm')
C_SRC := $(shell find $(C_DIR) $(KERNEL_C_DIR) -name '*.c')

# Object files
OBJ := $(ASM_SRC:$(ASM_DIR)/%.asm=$(BUILD_DIR)/%.o) $(C_SRC:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)

# Dependency files
DEP := $(OBJ:.o=.d)

# Target
TARGET := $(DIST_DIR)/x86_64/kernel.bin
ISO := $(DIST_DIR)/x86_64/kernel.iso

# Rules
all: $(ISO)

$(ISO): $(TARGET)
	@mkdir -p $(ISO_DIR)/boot
	cp $(TARGET) $(ISO_DIR)/boot/kernel.bin
	$(GRUB_MKRESCUE) /usr/lib/grub/i386-pc -o $(ISO) $(ISO_DIR)

$(TARGET): $(OBJ)
	@mkdir -p $(@D)
	$(LD) $(LDFLAGS) -o $@ $^

# Assembly source
$(BUILD_DIR)/%.o: $(ASM_DIR)/%.asm
	@mkdir -p $(@D)
	$(AS) $(ASMFLAGS) $< -o $@

# C source
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
	@mkdir -p $(@D)
	$(CC) $(CFLAGS) -c $< -o $@

# Include dependency files
-include $(DEP)

.PHONY: clean
clean:
	rm -rf $(BUILD_DIR) $(DIST_DIR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant