diff --git a/Makefile b/Makefile index af179a4..a6e1171 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,39 @@ -CC=i386-elf-gcc -ASM=i386-elf-as -LD=i386-elf-ld +.PHONY: all dirs clean proper iso + +UNAME=$(shell uname | tr a-z A-Z) +ifneq ($(findstring LINUX, $(UNAME)),) + BUILD_OS=LINUX +endif +ifneq ($(findstring DARWIN, $(UNAME)),) + BUILD_OS=MACOSX +endif +ifeq ($(BUILD_OS),) + $(error $(UNAME) support has not yet been coded into this Makefile) +endif + + +ifeq ($(BUILD_OS),MACOSX) + CC=i386-elf-gcc + ASM=i386-elf-as + LD=i386-elf-ld + ASFLAGS= + LDFLAGS= + BSCTFLAGS= +endif +ifeq ($(BUILD_OS),LINUX) + CC=gcc + ASM=as + LD=ld + ASFLAGS=--32 + LDFLAGS=-m elf_i386 -s + BSCTFLAGS:=$(LDFLAGS) +endif GFLAGS= CCFLAGS=-m32 -std=c11 -O2 -g -Wall -Wextra -Wpedantic -Wstrict-aliasing CCFLAGS+=-Wno-pointer-arith -Wno-unused-parameter CCFLAGS+=-nostdlib -nostdinc -ffreestanding -fno-pie -fno-stack-protector CCFLAGS+=-fno-builtin-function -fno-builtin -ASFLAGS= -LDFLAGS= BOOTSECT_SRCS=\ src/stage0.S @@ -23,16 +48,19 @@ BOOTSECT=bootsect.bin KERNEL=kernel.bin ISO=boot.iso -all: dirs bootsect kernel +all: iso +iso: dirs $(ISO) +proper: clean all dirs: mkdir -p bin clean: - rm ./**/*.o - rm ./*.iso - rm ./**/*.elf - rm ./**/*.bin + rm -f ./**/*.o + rm -f ./*.iso + rm -f ./**/*.elf + rm -f ./**/*.bin + rm -f $(BOOTSECT) $(KERNEL) %.o: %.c $(CC) -o $@ -c $< $(GFLAGS) $(CCFLAGS) @@ -40,13 +68,13 @@ clean: %.o: %.S $(ASM) -o $@ -c $< $(GFLAGS) $(ASFLAGS) -bootsect: $(BOOTSECT_OBJS) - $(LD) -o ./bin/$(BOOTSECT) $^ -Ttext 0x7C00 --oformat=binary +$(BOOTSECT): $(BOOTSECT_OBJS) + $(LD) -o ./bin/$(BOOTSECT) $^ $(BSCTFLAGS) -Ttext 0x7C00 --oformat=binary -kernel: $(KERNEL_OBJS) +$(KERNEL): $(KERNEL_OBJS) $(LD) -o ./bin/$(KERNEL) $^ $(LDFLAGS) -Tsrc/link.ld -iso: bootsect kernel +$(ISO): $(BOOTSECT) $(KERNEL) dd if=/dev/zero of=boot.iso bs=512 count=2880 dd if=./bin/$(BOOTSECT) of=boot.iso conv=notrunc bs=512 seek=0 count=1 dd if=./bin/$(KERNEL) of=boot.iso conv=notrunc bs=512 seek=1 count=2048 diff --git a/bin/bootsect.bin b/bin/bootsect.bin deleted file mode 100755 index afe7831..0000000 Binary files a/bin/bootsect.bin and /dev/null differ diff --git a/bin/kernel.bin b/bin/kernel.bin deleted file mode 100755 index 8a97426..0000000 Binary files a/bin/kernel.bin and /dev/null differ