#!/usr/bin/env bash
set -euo pipefail
# Build a static linux arm64 hledger binary.
# Run this on a throwaway debian arm64 vm.
sudo apt-get update
sudo apt-get install -y docker.io
mkdir -p output
sudo docker run --rm -v "$(pwd)/output:/output" alpine:3.21 sh -c '
set -e
apk add --no-cache \
curl git bash build-base binutils \
gmp-dev \
zlib-dev zlib-static \
libffi-dev \
ncurses-dev ncurses-static \
xz
# Install GHCup
curl --proto "=https" --tlsv1.2 -sSf https://get-ghcup.haskell.org | \
BOOTSTRAP_HASKELL_NONINTERACTIVE=1 \
BOOTSTRAP_HASKELL_INSTALL_STACK=0 \
BOOTSTRAP_HASKELL_INSTALL_HLS=0 \
sh
source /root/.ghcup/env
cabal update
cabal install hledger-1.51.1 \
--install-method=copy \
--overwrite-policy=always \
--installdir=/output \
--enable-executable-static \
--disable-shared \
--disable-executable-dynamic \
--ghc-option=-optl-static
strip /output/hledger
'
echo ""
file ./output/hledger
ldd ./output/hledger || echo "ok"