# Uses python (based on debian 10 buster)
FROM gcc:4.9 as build

RUN mkdir /opt/build
COPY custom/src /opt/build

WORKDIR /opt/build

# Generate the shared library
RUN gcc -Wall -Werror -fpic -c upper.c
RUN gcc -shared -o libupper.so upper.o

# Compile main with the shared library (which is still local here)
RUN gcc -L. -Wall -o main main.c -lupper

FROM docker.io/debian:bullseye-slim
RUN mkdir -p /opt/build

# Add fakechroot to allow decoupling from host operating system without root permission
RUN apt-get update && apt-get install -y --no-install-recommends fakechroot \
    && apt-get clean && rm -rf /var/lib/apt/lists/* # Clean up to keep the image size as small as possible

# Copy the generated lib and executable
WORKDIR /opt/build
COPY --from=build /opt/build .

# Configure the shared library
RUN mv libupper.so /usr/lib && ldconfig

CMD ["/bin/bash"]

