# build rigctld

FROM debian:latest

RUN mkdir src
# this might be too much, but let's try it
RUN apt update
RUN apt install -y libconfig-dev autoconf libtool git gcc g++ make cmake libudev-dev libreadline-dev libusb-1.0-0-dev libavahi-common-dev libavahi-client-dev

# build hamlib/rigctld
FROM debian:latest AS farpn-base
# ENV DEBIAN_FRONTEND="noninteractive" TZ="Etc/UTC"

# this might be too much, but let's try it
RUN apt update
RUN apt update \
    && apt install -y build-essential libconfig-dev autoconf \
    libtool git gcc g++ make cmake libudev-dev libusb-1.0-0-dev \
    libavahi-common-dev libavahi-client-dev


# build hamlib/rigctld
FROM farpn-base AS rigctld-builder

RUN <<EOF
mkdir src
cd src
git clone --branch 4.6.5 --single-branch https://github.com/Hamlib/Hamlib.git
cd Hamlib
./bootstrap
./configure
make
EOF

FROM farpn-base AS rigctld
COPY --from=rigctld-builder /usr/local /usr/local
ENV LD_LIBRARY_PATH="/usr/local/lib"
CMD /bin/rigctld --model=$RIG_MODEL --rig-file=$RIG_DEVICE -serial-speed=$RIG_SPEED --port=$RIGCTLD_PORT $RIGCTLD_ARGS
