FROM ubuntu:jammy

RUN apt update && \
	apt install -y libgtk2.0-dev libgl-dev binutils-mingw-w64-i686 git wget zip && \
	rm -rf /var/lib/apt/lists/* && \
	ln -s /usr/bin/i686-w64-mingw32-windres /usr/bin/i386-win32-windres && \
	ln -s /usr/bin/i686-w64-mingw32-windres /usr/bin/windres

RUN cd /root && \
	export FPCVERSION=3.2.2 && \
	export LAZVERSION=2.2.2 && \
	wget --content-disposition https://sourceforge.net/projects/freepascal/files/Linux/$FPCVERSION/fpc-$FPCVERSION.x86_64-linux.tar/download && \
	wget --content-disposition https://sourceforge.net/projects/freepascal/files/Source/$FPCVERSION/fpc-$FPCVERSION.source.tar.gz/download && \
	tar xf fpc-$FPCVERSION.x86_64-linux.tar && \
	cd fpc-$FPCVERSION.x86_64-linux && \
	echo "/usr" | ./install.sh && \
	cd .. && \
	tar xf fpc-$FPCVERSION.source.tar.gz && \
	cd fpc-$FPCVERSION && \
	make crossinstall INSTALL_PREFIX=/usr OS_TARGET=win32 CPU_TARGET=i386 && \
	make clean && \
	ln -s /usr/lib/fpc/$FPCVERSION/ppcross386 /usr/bin/ppcross386 && \
	cd .. && \
	wget --content-disposition https://sourceforge.net/projects/lazarus/files/Lazarus%20Zip%20_%20GZip/Lazarus%20$LAZVERSION/lazarus-$LAZVERSION-0.tar.gz/download && \
	tar xf lazarus-$LAZVERSION-0.tar.gz && \
	cd lazarus && \
	make lazbuild && \
	cd /root && \
	rm -rf *.tar.gz fpc-$FPCVERSION*

RUN cd /root && \
	git clone --depth 1 https://github.com/blikblum/multilog && \
	git clone --depth 1 https://github.com/almindor/lnet && \
	~/lazarus/lazbuild --lazarusdir=~/lazarus --add-package-link ~/multilog/multiloglaz.lpk && \
	~/lazarus/lazbuild --lazarusdir=~/lazarus --add-package-link ~/lnet/lazaruspackage/lnetbase.lpk && \
	~/lazarus/lazbuild --lazarusdir=~/lazarus --add-package-link ~/lnet/lazaruspackage/lnetvisual.lpk