Skip to content

Commit 289ab78

Browse files
jimfangxcmuellner
authored andcommitted
add: build instructions for mac arm
1 parent bd828e2 commit 289ab78

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

README.md

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Also available for Arch users on the AUR: [https://aur.archlinux.org/packages/ri
3434

3535
On macOS, you can use [Homebrew](http://brew.sh) to install the dependencies:
3636

37-
$ brew install python3 gawk gnu-sed make gmp mpfr libmpc isl zlib expat texinfo flock libslirp ncurses
37+
$ brew install python3 gawk gnu-sed make gmp mpfr libmpc isl zlib expat texinfo flock libslirp ncurses ninja bison m4 wget
3838

3939
When executing the instructions in this README, please use `gmake` instead of `make` to use the newly installed version of make.
4040
To build the glibc (Linux) on macOS, you will need to build within a case-sensitive file
@@ -111,6 +111,25 @@ This option only takes effect for the GNU toolchain.
111111
The toolchain has an option `--enable-strip` to control strip of host binaries,
112112
strip is disabled by default.
113113

114+
### Installation (MacOS ARM)
115+
116+
First, ensure you have cloned the toolchain repository in a case-sensitive volume.
117+
118+
Now source `macos.zsh` to setup the PATH variable so that the build scripts can use the tools from homebrew, which are needed to build the GNU toolchain.
119+
120+
Then, run configure with your desired flags - For example:
121+
```
122+
./configure --prefix=/Volumes/case-sensitive/opt/riscv --with-arch=rv64gc_zifencei --with-abi=lp64d --enable-linux --disable-gdb
123+
```
124+
125+
Then, raise the limit of open files. Run: `ulimit -n 65536`
126+
127+
Builds on MacOS are highly specific to OS versions and the versions of the developer tools installed. We recommend running `make check-binutils` first, which will help surface a some of the more frequent build errors we've seen without having to start a full build.
128+
129+
If `make check-binutils` errors, check the [following documentation](./macos-build.md) for a list of common errors when building on MacOS and their solutions.
130+
131+
When `make check-binutils` finishes successfully, you run the build normally with `make` or `make linux`.
132+
114133
### Troubleshooting Build Problems
115134

116135
Builds work best if installing into an empty directory. If you build a

macos-build.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# MacOS Build Common Errors
2+
3+
## fdopen macro redefinition error
4+
5+
During `make check-binutils`, you may see an error like this:
6+
```bash
7+
In file included from /Volumes/case-sensitive/riscv-gnu-toolchain/binutils/zlib/zlib/zutil.c:10:
8+
In file included from /Volumes/case-sensitive/riscv-gnu-toolchain/binutils/zlib/zlib/gzguts.h:21:
9+
In file included from /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/stdio.h:61:
10+
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/_stdio.h:322:7: error: expected identifier or '('
11+
322 | FILE *fdopen(int, const char *) __DARWIN_ALIAS_STARTING(__MAC_10_6, __IPHONE_2_0, __DARWIN_ALIAS(fdopen));
12+
| ^
13+
/Volumes/case-sensitive/riscv-gnu-toolchain/binutils/zlib/zlib/zutil.h:147:33: note: expanded from macro 'fdopen'
14+
147 | # define fdopen(fd,mode) NULL /* No fdopen() */
15+
| ^
16+
/Library/Developer/CommandLineTools/usr/lib/clang/17/include/__stddef_null.h:26:16: note: expanded from macro 'NULL'
17+
26 | #define NULL ((void*)0)
18+
| ^
19+
```
20+
21+
Then, upate the `binutils` repository to the latest commit on the `gdb-17-branch`. The easiest way to do this is (in the `riscv-gnu-toolchain` folder):
22+
23+
```bash
24+
rm -rf binutils
25+
git clone https://github.com/bminor/binutils-gdb binutils
26+
cd binutils
27+
git checkout gdb-17-branch
28+
cd ..
29+
```
30+
(The gdb-17-branch was last tested to be working on MacOS Tahoe 26.2 (25C56) on an M2 Max machine model A2779)
31+
32+
33+
## Bison/YACC related errors
34+
There may be missing files errors like this during `make`:
35+
```bash
36+
clang: error: no such file or directory: '/Volumes/case-sensitive/riscv-gnu-toolchain/binutils/binutils/sysinfo.c'
37+
clang: error: no input files
38+
gmake[3]: *** [Makefile:1897: sysinfo.o] Error 1
39+
gmake[3]: Leaving directory '/Volumes/case-sensitive/riscv-gnu-toolchain/build-binutils-newlib/binutils'
40+
```
41+
To fix this, you need to run some files manually through Bison in YACC mode:
42+
```bash
43+
cd binutils/binutils
44+
bison -y -o sysinfo.c sysinfo.y
45+
bison -y -d --defines=sysinfo.h -o sysinfo.c sysinfo.y
46+
bison -d --defines=arparse.h -o arparse.c arparse.y
47+
48+
cd binutils/ld
49+
bison -d --defines=ldgram.h -o ldgram.c ldgram.y
50+
```

macos.zsh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export PATH="/opt/homebrew/opt/bison/bin:$PATH"
2+
export PATH="/opt/homebrew/opt/gawk/libexec/gnubin:$PATH"
3+
export PATH="/opt/homebrew/opt/gnu-sed/libexec/gnubin:$PATH"
4+
export PATH="/opt/homebrew/opt/make/libexec/gnubin:$PATH"
5+
export PATH="/opt/homebrew/opt/expat/bin:$PATH"
6+
export PATH="opt/homebrew/opt/bison/bin:$PATH"
7+
export GNUMAKE="/opt/homebrew/opt/make/libexec/gnubin/make"
8+
export MAKE="/opt/homebrew/opt/make/libexec/gnubin/make"
9+
export PATH="/opt/homebrew/opt/m4:bin$PATH"
10+
alias gcc="/opt/homebrew/bin/gcc-15"
11+
alias gmp="opt/homebrew/Cellar/gmp/6.3.0/include/"

0 commit comments

Comments
 (0)