Serenity Operating System
1#!/usr/bin/env bash
2
3# This script builds the mold linker that can optionally be used for linking
4# the SerenityOS userland.
5set -e
6
7DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
8
9NPROC="nproc"
10SYSTEM_NAME="$(uname -s)"
11
12if [ "$SYSTEM_NAME" = "OpenBSD" ]; then
13 NPROC="sysctl -n hw.ncpuonline"
14elif [ "$SYSTEM_NAME" = "FreeBSD" ]; then
15 NPROC="sysctl -n hw.ncpu"
16elif [ "$SYSTEM_NAME" = "Darwin" ]; then
17 NPROC="sysctl -n hw.ncpu"
18fi
19
20[ -z "$MAKEJOBS" ] && MAKEJOBS=$($NPROC)
21
22mkdir -p "$DIR"/Tarballs
23pushd "$DIR"/Tarballs
24
25if [ "$1" = "--git" ]; then
26 [ ! -d mold ] && git clone https://github.com/rui314/mold.git
27
28 cd mold
29
30 git pull
31else
32 VERSION=1.5.1
33 [ ! -e mold-$VERSION.tar.gz ] && curl -L "https://github.com/rui314/mold/archive/refs/tags/v$VERSION.tar.gz" -o mold-$VERSION.tar.gz
34 [ ! -e mold-$VERSION ] && tar -xzf mold-$VERSION.tar.gz
35 cd mold-$VERSION
36fi
37
38MOLD_BUILD="$DIR"/Build/mold
39cmake -B "$MOLD_BUILD" -S. -DCMAKE_INSTALL_PREFIX="$DIR"/Local/mold
40make -C "$MOLD_BUILD" install -j"$MAKEJOBS"
41
42popd