Skip to content

Commit

Permalink
build: use i686 ELF toolchain on macOS
Browse files Browse the repository at this point in the history
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] nativeos/homebrew-i386-elf-toolchain#21
  • Loading branch information
ta5een committed Jun 20, 2024
1 parent f85d510 commit e696779
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
26 changes: 20 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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

0 comments on commit e696779

Please sign in to comment.