FROM debian:bullseye

ARG MIRANDA_TGZ

RUN apt-get update && apt-get install -y \
    build-essential \
    nano \
    vim-tiny \
    byacc \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

COPY ${MIRANDA_TGZ} .

RUN mkdir miranda && \
    tar -xzf ${MIRANDA_TGZ} \
    -C miranda \
    --strip-components=1

WORKDIR /app/miranda

# Fix GCC moderno, agrega '-fcommon' para permitir múltiples definiciones de variables
RUN sed -i 's/^CC = gcc -w/CC = gcc -w -fcommon/' Makefile

RUN make

RUN mkdir -p /app/code

CMD ["./mira"]