Gerbil on MacOS

MacOS is well supported by gerbil.

Because there are many different versions and processors your configuration may be slightly different than expected. If anything at all seems out of the ordinary please file an issue ot get in touch another way and we'll be on top of it.

Homebrew Formula and Binaries

The simple way is to use the Homebrew Tap.

There are binaries as well as the ability to build the HEAD of master.

brew install mighty-gerbils/gerbil/gerbil-scheme

That repository is also available in the gerbil source as a subtree.

git subtree add --prefix macos/homebrew git@github.com:mighty-gerbils/homebrew-gerbil.git main --squash

Build from source

There are a few different ways to build a working gerbil on MacOS.

Install Dependencies

  • Install XCode: Open a terminal and run xcode-select --install

  • Compile and Install OpenSSL: We need it for crypto so cannot use the built in ssl.

    git clone https://github.com/openssl/openssl.git
    cd openssl;
    ./config && make
    sudo make install
    

Option 1) Use the built in Clang.

If you want to be as native as possible this is the easy way. Most of us have MacPorts and/or Homebrew and I can totally recommend using GCC, but once you have openssl this should work.

This takes a long time as clang is a lot slower to build. But the binary may outperform modern gcc and building binaries with clang without setting GERBIL_GCC is something so it's a toss up.

git clone https://github.com/mighty-gerbils/gerbil.git

# On Sonama, Silicon not Intel, we set the prefix as so.
# You may want it elsewhere.
cd gerbil;
./configure --prefix=/opt/gerbil && make
sudo make install

Option 2) Using GCC@13

If you want a faster compile time both for building gerbil and your own binaries gcc is the better idea. GERBIL_GCC should allow you to compile your own binaries with a different compiler if you ever need to use the weird MacOS headers that are not quite C.

You can install it using MacPorts or Homebrew.

MacPorts

sudo port -v install gcc13
mp () {
    echo "/opt/local/bin/$1"
}
export CC="$(mp gcc-mp-13)"
export GERBIL_GCC="$(mp gcc-mp-13)"
export CXX="$(mp g++-mp-13)"
export LDFLAGS='-Wl,-ld_classic'
export GERBIL_BUILD_CORES=4

cd $(mktemp -d);

git clone https://github.com/mighty-gerbils/gerbil.git

cd gerbil;
./configure --prefix=/opt/gerbil && make -j$GERBIL_BUILD_CORES
sudo make install

Homebrew

brew install gcc@13
bp () {
  echo $(brew --prefix gcc@13)/bin/$1
}
export CC="$(bp gcc-13)"
export GERBIL_GCC="$(bp gcc-13)"
export CXX="$(bp g++-13)"
export LDFLAGS='-Wl,-ld_classic'
export GERBIL_BUILD_CORES=4

cd $(mktemp -d);

git clone https://github.com/mighty-gerbils/gerbil.git

cd gerbil;
./configure --prefix=/opt/gerbil && make -j$GERBIL_BUILD_CORES
sudo make install

Option 3) Using a more recent Clang

Especially for an older Mac where the built in clang is ancient but we want some Objective-C like things that apple uses.

You can install it using MacPorts or Homebrew.

MacPorts

sudo port -v install clang-18
mp () {
    echo "/opt/local/bin/$1"
}
export CC="$(mp clang-mp-18)"
export GERBIL_GCC="$(mp clang-mp-18)"
export CXX="$(mp clang++-mp-18)"
export LDFLAGS='-Wl,-ld_classic'
export GERBIL_BUILD_CORES=4

cd $(mktemp -d);

git clone https://github.com/mighty-gerbils/gerbil.git

cd gerbil;
./configure --prefix=/opt/gerbil && make -j$GERBIL_BUILD_CORES
sudo make install

Homebrew

brew install llvm@17
bp () {
  echo $(brew --prefix llvm@17)/bin/$1
}
export CC="$(bp clang)"
export GERBIL_GCC="$(bp clang)"
export CXX="$(bp clang++)"
export LDFLAGS='-Wl,-ld_classic'
export GERBIL_BUILD_CORES=4

cd $(mktemp -d);

git clone https://github.com/mighty-gerbils/gerbil.git

cd gerbil;
./configure --prefix=/opt/gerbil && make -j$GERBIL_BUILD_CORES
sudo make install

Location and usage.

We now have the lastest gerbil setup in the default manner. The symlinks and paths are for our usage. Gerbil will, by default, look in the directory where it is installed always.

So, in this example, the current/ gerbil is in fact v0.18.1-51-gd9c691b1/. This allows us to have different versions installed and used while also giving us some $PATH's for running and including and linking.

% ls -l /opt/gerbil
total 0
lrwxr-xr-x  1 root  wheel   11  5 Mar 17:31 bin -> current/bin
lrwxr-xr-x  1 root  wheel   20  5 Mar 17:31 current -> v0.18.1-51-gd9c691b1
lrwxr-xr-x  1 root  wheel   15  5 Mar 17:31 include -> current/include
lrwxr-xr-x  1 root  wheel   11  5 Mar 17:31 lib -> current/lib
lrwxr-xr-x  1 root  wheel   13  5 Mar 17:31 share -> current/share
lrwxr-xr-x  1 root  wheel   11  5 Mar 17:31 src -> current/src
drwxr-xr-x  7 root  wheel  224  5 Mar 17:31 v0.18.1-51-gd9c691b1

MacPorts

The easy way.

cd ~/src/gerbil/macos/ports

prefix=/opt/local
SRC_CONF="${prefix}/etc/macports/sources.conf"

add_source () {
    SRC="${1:-`pwd`}"
    TMP="$(mktemp)"

    echo "file://$SRC" > $TMP
    cat ${SRC_CONF} >> $TMP
    sudo mv -v $TMP $SRC_CONF
}

maybe_add_source () {
    SRC="${1:-`pwd`}"
    grep -e "$SRC" "$SRC_CONF" || add_source $SRC
}

maybe_add_source
portindex

# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0

name                gerbil-scheme
version             0.18.1
categories          lang
platforms           darwin
license             {LGPL-2.1+ Apache-2}
maintainers         nomaintainer
description         Gerbil Scheme
long_description    Gerbil Scheme: A LISP for the 21st Century
homepage            https://cons.io

fetch.type          git
git.url             https://github.com/mighty-gerbils/gerbil.git
# git.branch          v0.18.1
git.branch          882e8292019f1c5f8fc8895f9e2751186974520c

depends_lib         port:openssl3 \
		    port:zlib

depends_build       port:autoconf

configure.args      --enable-march= --enable-dist

compiler.whitelist macports-gcc-13

build.cmd "export GERBIL_GCC='${configure.cc}'; make -j4"