Skip to content

Commit

Permalink
Makefile: Make it build out-of-the-box on macOS
Browse files Browse the repository at this point in the history
This requires a few dependencies installed with Homebrew.

Signed-off-by: Hector Martin <[email protected]>
  • Loading branch information
marcan committed Nov 8, 2021
1 parent a4e922e commit 1e6c856
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
39 changes: 27 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
ARCH := aarch64-linux-gnu-
ARCH ?= aarch64-linux-gnu-

ifeq ($(shell uname),Darwin)
USE_CLANG ?= 1
$(info INFO: Building on Darwin)
ifeq ($(shell uname -p),arm)
TOOLCHAIN ?= /opt/homebrew/opt/llvm/bin/
else
TOOLCHAIN ?= /usr/local/opt/llvm/bin/
endif
$(info INFO: Toolchain path: $(TOOLCHAIN))
endif

ifeq ($(USE_CLANG),1)
CC := clang --target=$(ARCH)
AS := clang --target=$(ARCH)
LD := ld.lld
OBJCOPY := llvm-objcopy
CC := $(TOOLCHAIN)clang --target=$(ARCH)
AS := $(TOOLCHAIN)clang --target=$(ARCH)
LD := $(TOOLCHAIN)ld.lld
OBJCOPY := $(TOOLCHAIN)llvm-objcopy
CLANG_FORMAT := $(TOOLCHAIN)clang-format
EXTRA_CFLAGS ?=
else
CC := $(ARCH)gcc
AS := $(ARCH)gcc
LD := $(ARCH)ld
OBJCOPY := $(ARCH)objcopy
CC := $(TOOLCHAIN)$(ARCH)gcc
AS := $(TOOLCHAIN)$(ARCH)gcc
LD := $(TOOLCHAIN)$(ARCH)ld
OBJCOPY := $(TOOLCHAIN)$(ARCH)objcopy
CLANG_FORMAT := clang-format
EXTRA_CFLAGS ?= -Wstack-usage=1024
endif

CFLAGS := -O2 -Wall -g -Wundef -Werror=strict-prototypes -fno-common -fno-PIE \
Expand All @@ -18,7 +33,7 @@ CFLAGS := -O2 -Wall -g -Wundef -Werror=strict-prototypes -fno-common -fno-PIE \
-ffreestanding -fpic -ffunction-sections -fdata-sections \
-nostdinc -isystem $(shell $(CC) -print-file-name=include) -isystem sysinc \
-fno-stack-protector -mgeneral-regs-only -mstrict-align -march=armv8.2-a \
-Wstack-usage=1024
$(EXTRA_CFLAGS)

LDFLAGS := -T m1n1.ld -EL -maarch64elf --no-undefined -X -Bsymbolic \
-z notext --no-apply-dynamic-relocs --orphan-handling=warn \
Expand Down Expand Up @@ -87,9 +102,9 @@ all: build/$(TARGET) $(DTBS)
clean:
rm -rf build/*
format:
clang-format -i src/*.c src/*.h sysinc/*.h
$(CLANG_FORMAT) -i src/*.c src/*.h sysinc/*.h
format-check:
clang-format --dry-run --Werror src/*.c src/*.h sysinc/*.h
$(CLANG_FORMAT) --dry-run --Werror src/*.c src/*.h sysinc/*.h

build/dtb/%.dts: dts/%.dts
@echo " DTCPP $@"
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ The output will be in build/m1n1.macho.

To build on a native arm64 machine, use `make ARCH=`.

Building on ARM64 macOS is supported with clang and LLVM; you need to use Homebrew to
install the required dependencies:

```shell
$ brew install llvm imagemagick dtc
```

After that, just type `make`.

### Building using the container setup

If you have a container runtime installed, like Podman or Docker, you can make use of the compose setup, which contains all build dependencies.
Expand Down

0 comments on commit 1e6c856

Please sign in to comment.