summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile52
1 files changed, 37 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 56ffd05..0a86795 100644
--- a/Makefile
+++ b/Makefile
@@ -1,27 +1,49 @@
-SOURCE_DIR=src
-BUILD_DIR=build
-ISO_DIR=isodir
+CC = i686-elf-gcc
+AS = i686-elf-as
+CFLAGS =
+MKDIR = mkdir -p
+RM = rm -rf
+CP = cp
+
+SOURCE_DIR = src
+BUILD_DIR = build
+ISO_DIR = isodir
+
+AS_SOURCE = boot.s
+C_SOURCE = kernel.c
+
+OBJ_FILES = boot.o kernel.o
+CRTBEGIN_OBJ:=$(shell $(CC) -print-file-name=crtbegin.o)
+CRTEND_OBJ:=$(shell $(CC) -print-file-name=crtend.o)
+
+OBJ = $(BUILD_DIR)/crti.o $(CRTBEGIN_OBJ) $(patsubst %,$(BUILD_DIR)/%,$(OBJ_FILES)) $(CRTEND_OBJ) $(BUILD_DIR)/crtn.o
+
+# Creating iso file
.PHONY: all
all: $(BUILD_DIR)/myos.bin
grub-file --is-x86-multiboot $(BUILD_DIR)/myos.bin
mkdir -p $(ISO_DIR)/boot/grub
- cp $(BUILD_DIR)/myos.bin $(ISO_DIR)/boot/myos.bin
- cp $(SOURCE_DIR)/grub.cfg $(ISO_DIR)/boot/grub/grub.cfg
+ $(CP) $(BUILD_DIR)/myos.bin $(ISO_DIR)/boot/myos.bin
+ $(CP) $(SOURCE_DIR)/grub.cfg $(ISO_DIR)/boot/grub/grub.cfg
grub-mkrescue -o myos.iso $(ISO_DIR)
-$(BUILD_DIR)/boot.o: $(SOURCE_DIR)/boot.s
- mkdir -p $(BUILD_DIR)
- i686-elf-as $(SOURCE_DIR)/boot.s -o $(BUILD_DIR)/boot.o
+# Linking object files
+$(BUILD_DIR)/myos.bin: $(OBJ)
+ $(MKDIR) $(BUILD_DIR)
+ $(CC) -T $(SOURCE_DIR)/linker.ld -o $(BUILD_DIR)/myos.bin -ffreestanding -O2 -nostdlib $(OBJ) -lgcc
-$(BUILD_DIR)/kernel.o: $(SOURCE_DIR)/kernel.c
- mkdir -p $(BUILD_DIR)
- i686-elf-gcc -c $(SOURCE_DIR)/kernel.c -o $(BUILD_DIR)/kernel.o -std=gnu99 -ffreestanding -O2 -Wall -Wextra
+# Compiling as sources
+$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.s
+ $(MKDIR) $(BUILD_DIR)
+ $(AS) $< -o $@
-$(BUILD_DIR)/myos.bin: $(BUILD_DIR)/kernel.o $(BUILD_DIR)/boot.o
- mkdir -p $(BUILD_DIR)
- i686-elf-gcc -T $(SOURCE_DIR)/linker.ld -o $(BUILD_DIR)/myos.bin -ffreestanding -O2 -nostdlib $(BUILD_DIR)/boot.o $(BUILD_DIR)/kernel.o -lgcc
+# Compiling C sources
+$(BUILD_DIR)/%.o: $(SOURCE_DIR)/%.c
+ $(MKDIR) $(BUILD_DIR)
+ $(CC) -c $< -o $@ -std=gnu99 -ffreestanding -O2 -Wall -Wextra
+# Cleaning
.PHONY: clean
clean:
- rm -rf $(BUILD_DIR) $(ISO_DIR) myos.iso
+ $(RM) $(BUILD_DIR) $(ISO_DIR) myos.iso