summaryrefslogtreecommitdiffstats
path: root/makefile
diff options
context:
space:
mode:
Diffstat (limited to 'makefile')
-rw-r--r--makefile59
1 files changed, 37 insertions, 22 deletions
diff --git a/makefile b/makefile
index 67ef81b..71a7a6c 100644
--- a/makefile
+++ b/makefile
@@ -1,33 +1,48 @@
-CC = i686-elf-g++# compiler
-LD = ld# linker
-ASM = nasm# assembler
+CC = i686-elf-g++
+LD = ld
+ASM = nasm
# test -O2 flag
-CFLAGS = -c -m32 -Wall -ffreestanding -nostdinc -nostdlib -lgcc# c compiler flags
-# flag elf32 allow decrease object file size
-AFLAGS = -f elf32# asm compiler flags
-BDIR = build# build directory
+CFLAGS = -c -m32 -Wall -ffreestanding -nostdinc -nostdlib -lgcc
+AFLAGS = -f elf32
+LDFLAGS = -m elf_i386
-.PHONY: install
+CFILES = $(shell find ./ -type f \( -name \*.cpp -o -name \*.c \))
+AFILES = $(shell find ./ -type f \( -iname \*.s -o -name \*.asm \))
+LDFILE = $(shell find ./ -type f -name *.ld)
+SOURCE_FILES = $(CFILES) $(AFILES)
+OBJ_FILES = $(addprefix $(BDIR)/, $(addsuffix .o, $(basename $(SOURCE_FILES))))
-install: build
- @echo "Creating an iso image of OS"
- cp ./$(BDIR)/kernel.bin ./iso/os/
- grub-mkrescue -o ./$(BDIR)/kernel.iso ./iso
+OS_BINARY = $(BDIR)/kernel.bin
+BDIR = ./build
-build:
- mkdir $(BDIR)
- @echo "Compile source files..."
- $(CC) $(CFLAGS) -o ./$(BDIR)/kernel.o ./kernel/kernel.c
- $(CC) $(CFLAGS) -o ./$(BDIR)/VGADisplay.o ./arch/x86/io/VGADisplay.cpp
- $(CC) $(CFLAGS) -o ./$(BDIR)/TypeConverter.o ./arch/x86/inc/TypeConverter.cpp
- $(CC) $(CFLAGS) -o ./$(BDIR)/GlobalObj.o ./arch/x86/io/GlobalObj.cpp
- $(ASM) $(AFLAGS) -o ./$(BDIR)/boot.o ./kernel/boot.s
+.PHONY: install $(SOURCE_FILES)
+
+build: startbuild $(SOURCE_FILES)
@echo "Link object files..."
- $(LD) -m elf_i386 -o ./$(BDIR)/kernel.bin -T ./kernel/linker.ld ./$(BDIR)/*.o
+ $(LD) $(LDFLAGS) -o $(OS_BINARY) -T $(LDFILE) $(OBJ_FILES)
@echo "Project was built"
+$(CFILES):
+ mkdir -p $(BDIR)/$(@D)
+ $(CC) $(CFLAGS) -o $(BDIR)/$(addsuffix .o, $(basename $@)) $@
+
+$(AFILES):
+ mkdir -p $(BDIR)/$(@D)
+ $(ASM) $(AFLAGS) -o $(BDIR)/$(addsuffix .o, $(basename $@)) $@
+
+startbuild:
+ @echo $(OBJ_FILES)
+ mkdir $(BDIR)
+ @echo "Compile source files..."
+
+install:
+ @echo "Creating an iso image of OS"
+ cp ./$(BDIR)/kernel.bin ./iso/os/
+ grub-mkrescue -o ./$(BDIR)/kernel.iso ./iso
+
clean:
- rm -rf ./build
+ rm -rf $(BDIR)
+ rm -rf ./iso/os/kernel.bin
run:
qemu-system-i386 -cdrom ./$(BDIR)/kernel.iso