From 919359a69b7c2a4dc632aa00caf6ba1eece8c46c Mon Sep 17 00:00:00 2001 From: sb Date: Fri, 12 Jan 2024 00:12:22 -0500 Subject: [PATCH] Improve Makefile to allow building 32-bit targets on Linux using GCC - add necessary infrastructure to distinguish between OSs - reformulate targets to make more sense (while maintaining the documented "make iso" command) - remove generated bin files from git --- Makefile | 56 +++++++++++++++++++++++++++++++++++------------ bin/bootsect.bin | Bin 512 -> 0 bytes bin/kernel.bin | Bin 37152 -> 0 bytes 3 files changed, 42 insertions(+), 14 deletions(-) delete mode 100755 bin/bootsect.bin delete mode 100755 bin/kernel.bin 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 afe78312c02034fd85b374cf184f4dafc4ba6f51..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 512 zcmey>bE5A?-+{gdeJ}bh>|rqI5c^j1d*9uf7h4#1iZFBmdHa6U9B2Di!ys^+jiHv2 zVT;pQVg9BG49!5ELnGUt8is~qo<^twAdlhE-7O3ogwG26dJ)R7;li_&7m*Bx2c9GZ zyl`XKa1qG0XNYJ%!SpPFU*SMn^9e?Nr30@S_!;FaYWW$(1ZsB(Fo4|ybx|77Nem3H zR@HDY>|kJEWcdH!^*^9#Dg3)0Fcy6~3}rGDe>=SIRm}?q27~`w_}17kl(3u?c>Vc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