From e696779d2e042650041d6bf13a764bc10491678e Mon Sep 17 00:00:00 2001 From: Ta-Seen Date: Fri, 21 Jun 2024 03:12:42 +1000 Subject: [PATCH] build: use i686 ELF toolchain on macOS Homebrew doesn't provide an i386 ELF toolchain as an official formula, though one is available from the tap `nativeos/i386-elf-toolchain`. Unfortunately, the binaries included in this toolchain conflicts with the deprecated names for the official x86_64 ELF toolchain, blocking me from having both installed simultaneously (see [1] for more information). Fortunately, Homebrew provides an i686 ELF toolchain as an official formulua. Since the i686 cross compiler supports compiling to i386, I'll use it as the designated toolchain on macOS. [1] https://github.com/nativeos/homebrew-i386-elf-toolchain/issues/21 --- Makefile | 26 ++++++++++++++++++++------ README.md | 6 ++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 12ec2db..0a04f86 100644 --- a/Makefile +++ b/Makefile @@ -13,9 +13,9 @@ OBJECTS += $(patsubst $(SRCDIR)/%.S,$(OUTDIR)/%.S.o,$(ASM_SOURCES)) CXXFLAGS := -m32 -std=c++20 -nostdlib -Wall -Wextra -I $(LIBDIR) \ -fno-builtin -fno-exceptions -fno-rtti -fno-use-cxa-atexit -ASFLAGS = -LDFLAGS = -QEMUFLAGS = +ASFLAGS := +LDFLAGS := +QEMUFLAGS := ifeq ($(DEBUG),1) # Prepend debug flag to make it more prominent @@ -38,9 +38,23 @@ ifeq ($(UNAME),Linux) ASFLAGS += --32 LDFLAGS += -melf_$(ARCH) else - CXX = $(ARCH)-elf-g++ - AS = $(ARCH)-elf-as - LD = $(ARCH)-elf-ld + # Homebrew doesn't provide an i386 ELF toolchain as an official formula, + # though one is available from the tap `nativeos/i386-elf-toolchain`. + # Unfortunately, the binaries included in this toolchain conflicts with the + # deprecated names for the official x86_64 ELF toolchain, blocking me from + # having both installed simultaneously (see [1] for more information). + # + # Fortunately, Homebrew provides an i686 ELF toolchain as an official + # formulua. Since the i686 cross compiler supports compiling to i386, I'll + # use it as the designated toolchain on macOS. + # + # [1] https://github.com/nativeos/homebrew-i386-elf-toolchain/issues/21 + ARCH_ALIAS = $(if $(findstring i386,$(ARCH)), i686, $(ARCH)) + CXX = $(ARCH_ALIAS)-elf-g++ + AS = $(ARCH_ALIAS)-elf-as + LD = $(ARCH_ALIAS)-elf-ld + ASFLAGS += --32 -march=$(ARCH) + LDFLAGS += -melf_$(ARCH) endif .PHONY: kernel iso qemu clean diff --git a/README.md b/README.md index aa3ef54..3e88c6c 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,8 @@ build the project locally, you will need the following tools for your platform: - `make` - [`bear`][bear-gh] (optional) - GNU 32-Bit ELF toolchain - - macOS: [`i386-elf-toolchain`][i386-elf-toolchain] via Homebrew + - macOS: [`i686-elf-gcc`][i686-elf-gcc] and + [`i686-elf-binutils`][i686-elf-binutils] via Homebrew - Linux/WSL: `build-essential` - `.iso` creation and GRUB tools (optional)[^1]: - `xorriso` @@ -132,5 +133,6 @@ This fix was sourced from [this issue comment on `bear`'s GitHub repository][bea [bear-gh-issue-comment]: https://github.com/rizsotto/Bear/issues/561#issuecomment-1921214908 [bear-gh]: https://github.com/rizsotto/Bear [docker-bind-mounts]: https://docs.docker.com/storage/bind-mounts/ -[i386-elf-toolchain]: https://github.com/nativeos/homebrew-i386-elf-toolchain +[i686-elf-binutils]: https://formulae.brew.sh/formula/i686-elf-binutils#default +[i686-elf-gcc]: https://formulae.brew.sh/formula/i686-elf-gcc#default [wyoos-yt-playlist]: https://www.youtube.com/playlist?list=PLHh55M_Kq4OApWScZyPl5HhgsTJS9MZ6M