cat << 'EEOF' > laz
#!/bin/sh
# ======================================================
# by rvk (v.1.3, 2019-08-26)
# ======================================================
echo ""
echo "=============================================================="
echo "Running on: $([ -f /proc/device-tree/model ] && cat /proc/device-tree/model || cat /sys/devices/virtual/dmi/id/product_name)"
BASE=$HOME/dev
mkdir -p $BASE
cd $BASE
begin=$(date +%s)
# ======================================================
# minimal swap space needed is 1024MB
# ======================================================
while true; do
# FREESWAP=$(swapon -s | tail -n 1 | awk '{print $3}')
FREESWAP=$(free | tail -n1 | awk '{print $2}')
if [ $FREESWAP -lt 900000 ]; then
# we can increase this if /etc/dphys-swapfile exists
echo "Swap size is too small. Minimum required is 1024MB.";
[ -f /etc/dphys-swapfile ] && {
echo "=============================================================="
free -h
echo "Setting in /etc/dphys-swapfile $(cat /etc/dphys-swapfile | grep CONF_SWAPSIZE)"
echo "Current size is $FREESWAP"
echo "=============================================================="
while true; do
read -p "Do you want to increase it to 1024MB? (y/n) " yn
case $yn in
[Yy]* ) break;;
[Nn]* ) echo >&2 "Please increase the swap space manually. Aborting..."; exit 1;;
* ) echo "Please answer yes or no.";;
esac
done
echo "Increasing value and restarting swap"
sudo sed -i 's/CONF_SWAPSIZE=[0-9]*$/CONF_SWAPSIZE=1024/g' /etc/dphys-swapfile
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile restart
echo "=============================================================="
} || {
echo >&2 "Please increase the swap space manually. Aborting..."; exit 1;
}
else
break;
fi
done
# ======================================================
# update packages list to latest version
# ======================================================
echo "=============================================================="
echo ""
echo "Updating package list to latest version (sudo needed)"
echo ""
apt-get --version >/dev/null 2>&1 || { echo >&2 "I require apt-get but it's not installed. Aborting."; exit 1; }
sudo apt-get update >/dev/null || { echo >&2 "apt-get update cannot be run. Aborting."; exit 1; }
# ======================================================
# some other essentials
# ======================================================
echo "=============================================================="
echo ""
echo "Installing required packages (sudo used)"
echo ""
sudo apt-get -y install build-essential bzip2 p7zip-full subversion >/dev/null
sudo apt-get -y install libx11-dev libgdk-pixbuf2.0-dev libcairo2-dev lpango-1.0 libpangox-1.0-dev xorg-dev libatk1.0-dev libgtk2.0-dev >/dev/null
sudo apt-get -y install libssl-dev >/dev/null # for all your ssl stuff
#sudo apt-get install -y freetds-dev
sudo apt-get -y install pv >/dev/null # pipeviewer for progress http://www.catonmat.net/blog/unix-utilities-pipe-viewer/
svn --version >/dev/null 2>&1 || { echo >&2 "I require svn but it's not installed. Aborting."; exit 1; }
# ======================================================
# We need a bootstrap compiler fpc 3.0.4
# There is NONE AVAILABLE so we need to download complete
# fpc-3.0.4.arm-linux-raspberry1wq.tar
# in virtualbox Rasbian stretch we need i386
# ======================================================
CPU=$(uname -m)
if [ "$CPU" = "armv7l" ]; then # note L not 1
echo "Compiling for ARMv7 Processor (Pi2 and Pi3 only)"
OPTIONS_FPC="-g -gl -O2 -Xs -CX -XX -v0 -vh- -dFPC_ARMHF"
OPTIONS_LAZ="-v0"
OS_TARGET="linux"
CPU_TARGET="arm"
COMP3_DOWNLOAD="ftp://ftp.freepascal.org/pub/fpc/dist/3.0.4/arm-linux/fpc-3.0.4.arm-linux-eabihf-raspberry.tar"
COMP3_DOWNLOAD="fp-compiler"
COMP=ppcarm
elif [ "$CPU" = "x86_64" ]; then
echo "Compiling for x64 Processor"
OPTIONS_FPC="-g -gl -O2 -Xs -CX -XX -v0"
OPTIONS_LAZ="-v0"
OS_TARGET="linux"
CPU_TARGET="x86_64"
COMP3_DOWNLOAD="ftp://ftp.freepascal.org/pub/fpc/dist/3.0.4/x86_64-linux/fpc-3.0.4.x86_64-linux.tar" # complete version
COMP3_DOWNLOAD="ftp://ftp.freepascal.org/pub/fpc/dist/3.0.4/bootstrap/x86_64-linux-ppcx64.bz2" # bootstrap
COMP=ppcx64
elif [ "$CPU" = "i686" ]; then
echo "Compiling for i686 Processor"
OPTIONS_FPC="-g -gl -O2 -Xs -CX -XX -v0"
OPTIONS_LAZ="-v0"
OS_TARGET="linux"
CPU_TARGET="i386"
COMP3_DOWNLOAD="ftp://ftp.freepascal.org/pub/fpc/dist/3.0.4/i386-linux/fpc-3.0.4.i386-linux.tar" # complete version
COMP=ppc386
else
echo >&2 "$CPU is not supported as processor (needed armv7l/x86_64/i686). Aborting."; exit 1;
fi
# ------------------------------------------------------
if [ ! -x ./compiler3/$COMP ]; then
if echo "$COMP3_DOWNLOAD" | grep -q "fp-compiler"; then
echo "Downloading package fp-compiler-3.0.4"
echo ""
mkdir -p ./compiler3
apt-get download fp-compiler-3.0.4
dpkg-deb --fsys-tarfile fp-compiler*.deb | tar -x ./usr/lib/arm-linux-gnueabihf/fpc/3.0.4/ppcarm --strip-components 6
mv ppcarm ./compiler3
rm ./fp-compiler*.deb
else
if echo "$COMP3_DOWNLOAD" | grep -q "\.bz2"; then
echo "Downloading bootstrap compiler 3.0.4"
echo ""
wget --continue --quiet --show-progress -O compiler3.bz2 $COMP3_DOWNLOAD
echo ""
[ -f ./compiler3.bz2 ] || { echo >&2 "Download of bootstrap compiler failed. Aborting."; exit 1; }
mkdir -p ./compiler3
bzip2 -d -c compiler3.bz2 > ./compiler3/$COMP
chmod ug+rx ./compiler3/ppcx64
rm ./compiler3.bz2
else
echo "Downloading compiler 3.0.4"
echo ""
wget --continue --quiet --show-progress -O compiler3.tar $COMP3_DOWNLOAD
echo ""
[ -f ./compiler3.tar ] || { echo >&2 "Download of bootstrap compiler failed. Aborting."; exit 1; }
mkdir -p ./compiler3/ex
tar xf compiler3.tar -C ./compiler3/ex --strip=1 >/dev/null
tar xvf ./compiler3/ex/binary.*-linux.tar -C ./compiler3/ex >/dev/null
tar zxvf ./compiler3/ex/base.*-linux.tar.gz -C ./compiler3/ex >/dev/null
mv $(find -name $COMP) ./compiler3
rm ./compiler3/ex -Rf
rm ./compiler3.tar
fi
fi
fi
[ -x ./compiler3/$COMP ] || { echo >&2 "Bootstrap $BASE/compiler3/$COMP compiler not found. Aborting."; exit 1; }
# ======================================================
# downloading fpc and lazarus
# ======================================================
echo "=============================================================="
echo ""
echo "Downloading FPC sources $(svn info fpc 2>&1 | grep Rev:)"
echo ""
# svn co https://svn.freepascal.org/svn/fpc/trunk fpc -r42644 >/dev/null
svn co https://svn.freepascal.org/svn/fpc/trunk fpc >/dev/null
[ -f ./fpc/Makefile ] || { echo >&2 "Download of fpc failed. Aborting."; exit 1; }
echo "Now: $(svn info fpc | grep Rev:)"
echo ""
echo "Downloading Lazarus sources $(svn info lazarus 2>&1 | grep Rev:)"
echo ""
# svn co https://svn.freepascal.org/svn/lazarus/trunk lazarus -r61689 >/dev/null
svn co https://svn.freepascal.org/svn/lazarus/trunk lazarus >/dev/null
[ -f ./lazarus/Makefile ] || { echo >&2 "Download of fpc failed. Aborting."; exit 1; }
echo "Now: $(svn info lazarus | grep Rev:)"
echo ""
# ======================================================
# compiling fpc
# ======================================================
echo "=============================================================="
echo ""
echo "Now compiling FPC, this will take some time"
echo ""
cd $BASE/fpc
make -s all install OPT="$OPTIONS_FPC" OS_TARGET=$OS_TARGET CPU_TARGET=$CPU_TARGET INSTALL_PREFIX=$BASE/fpc PP=$BASE/compiler3/$COMP \
| pv -l -bp >$BASE/fpc.log \
|| { echo >&2 "Compilation of FPC failed. Aborting."; exit 1; }
cd $BASE
[ -x ./fpc/bin/fpc ] || { echo >&2 "Something went wrong compiling FPC. Aborting."; exit 1; }
echo ""
echo "Doing some extra configuration"
[ -f $HOME/.fpc.cfg ] && rm $HOME/.fpc.cfg
ln -sf $BASE/fpc/lib/fpc/3.3.1/$COMP $BASE/fpc/bin/$COMP
ln -sf $BASE/fpc/lib/fpc/3.3.1/samplecfg $BASE/fpc/bin/samplecfg
$BASE/fpc/bin/fpcmkcfg -d basepath=$BASE/fpc -o $HOME/.fpc.cfg
# sudo find / -name crtbegin.o
# This library needs to be added to the fpc.cfg file.
cat << EOF >> $HOME/.fpc.cfg
-Fu$BASE/fpc/lib/fpc/\$fpcversion/units/\$fpctarget
-Fu$BASE/fpc/lib/fpc/\$fpcversion/units/\$fpctarget/*
-Fu$BASE/fpc/lib/fpc/\$fpcversion/units/\$fpctarget/rtl
-Fl$(find / -name crtbegin.o -printf '%h\n' 2>/dev/null | head -n 1)
-FD$BASE/fpc/bin
EOF
echo ""
# ======================================================
# compiling lazarus
# ======================================================
echo "=============================================================="
echo ""
echo "Now compiling Lazarus, this will take some time"
echo ""
cd $BASE/lazarus
make -s bigide OS_TARGET=$OS_TARGET CPU_TARGET=$CPU_TARGET OPT="$OPTIONS_LAZ" PP="$BASE/fpc/bin/fpc" \
| pv -l -bp >$BASE/laz.log \
|| { echo >&2 "Compilation of Lazarus failed. Aborting."; exit 1; }
cd $BASE
[ -f ./lazarus/lazarus ] || { echo >&2 "Something went wrong compiling Lazarus. Aborting."; exit 1; }
echo ""
echo "Doing some extra configuration"
echo ""
# set path withhout old fpc
PATH=$(echo $PATH | sed "s|$BASE/fpc/bin\:||g")
# strip previous $BASE from .profile
sed -i '/# FPC PATH/,/fi/d' $HOME/.profile
cat << EOF >> $HOME/.profile
# FPC PATH
if [ -d $BASE/fpc/bin ] ; then
PATH="$BASE/fpc/bin:\$PATH"
fi
EOF
# replace all double empty lines with one
sed -i '/^$/N;/^\n$/D' $HOME/.profile
cat << EOF > $HOME/Desktop/Lazarus.desktop
[Desktop Entry]
Name=Lazarus
Comment=Lazarus
Icon=$BASE/lazarus/images/ide_icon48x48.png
Exec=$BASE/lazarus/startlazarus
Path=$BASE/lazarus
Type=Application
Encoding=UTF-8
Terminal=false
Categories=None;
EOF
end=$(date +%s)
echo "=============================================================="
echo ""
echo "$((($end-$begin) / 60)) minutes and $((($end-$begin) % 60)) seconds elapsed."
echo ""
echo "We are done. Please logout and back in before starting Lazarus"
echo "Otherwise you need to supply the fpc location on 1st start"
echo ""
echo "=============================================================="
echo ""
EEOF