FROM alpine:3.19 AS base

RUN apk add --no-cache \
    build-base \
    musl-dev \
    git \
    cmake \
    autoconf \
    automake \
    libtool \
    pkgconf \
    openssl-dev \
    openssl-libs-static \
    zlib-dev \
    zlib-static \
    curl-dev \
    curl-static \
    libsecp256k1-dev \
    sqlite-dev \
    sqlite-static

# Alpine provides libsecp256k1 shared objects, but we need a static archive
# for fully-static musl linking. Build and install libsecp256k1.a in /usr/local.
RUN git clone --depth 1 https://github.com/bitcoin-core/secp256k1.git /tmp/secp256k1 && \
    cd /tmp/secp256k1 && \
    ./autogen.sh && \
    ./configure --enable-static --disable-shared --prefix=/usr/local && \
    make -j"$(nproc)" && \
    make install && \
    rm -rf /tmp/secp256k1

WORKDIR /src
