Saturday, September 17, 2016

Install FPC 3.1.1 + lazarus 1.7 on RASPBERRY PI 3 /RASPBIAN)

How to install latest FPC + LAZARUS on RASPBERRY PI 3 Step by step (thanks to rvk member of lazarus community)


# ======================================================
# Based on clean 2016-05-27-raspbian-jessie.img
# Total install time: 38 minutes (from complete scratch)
# by rvk (v.1.1, 2016-07-08)
# ======================================================

# ======================================================
# first some essentials (5.5 minutes)
# ======================================================
sudo -i
apt-get update
apt-get upgrade -y
apt-get autoremove
apt-get autoclean
reboot

# ======================================================
# install remote descktop serveer for rdp session win10
# only neede is headless RPI (1 minute)
# ======================================================
# https://www.maketecheasier.com/enabling-remote-desktop-access-on-raspberry-pi/
sudo apt-get -y install xrdp
sudo nano /etc/xrdp/xrdp.ini
bitmap_compression: no   # <-- change this line

# ======================================================
# some other essentials (2 minutes)
# ======================================================
sudo apt-get -y install build-essential p7zip-full subversion
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

# ======================================================
# we NEED to extend the swapfile (1 minute)
# ======================================================
sudo nano /etc/dphys-swapfile
CONF_SWAPSIZE=512   # <-- change this line
sudo /etc/init.d/dphys-swapfile stop
sudo /etc/init.d/dphys-swapfile start

# ======================================================
# if you're not on raspbian-jessie this could work too
# ======================================================
# dd if=/dev/zero of=/path/to/swapfile bs=1M count=512 # For 512MB swap file
# mkswap /path/to/swapfile
# swapon /path/to/swapfile

# ======================================================
# install fpc and lazarus trunk (total 28.5 minutes)
# ======================================================
sudo -i

# ------------------------------------------------------
# first fpc
# ------------------------------------------------------
mkdir /usr/local/fpc
cd /usr/local/fpc

# ------------------------------------------------------
# We need a bootstrap compiler fpc 3.0.0 (2.5 minutes)
# There is NONE AVAILABLE so we need to download complete
# fpc-3.0.0.arm-linux-raspberry1wq.tar
# ------------------------------------------------------
wget ftp://ftp.freepascal.org/pub/fpc/dist/3.0.0/arm-linux/fpc-3.0.0.arm-linux-raspberry1wq.tar
tar xvf fpc-3.0.0.arm-linux-raspberry1wq.tar
cd fpc-3.0.0.arm-linux
tar xvf binary.arm-linux.tar
tar zxvf base.arm-linux.tar.gz
cd ..

# ------------------------------------------------------
# checkout fpc trunk (3 minutes)
# ------------------------------------------------------
svn co http://svn.freepascal.org/svn/fpc/trunk trunk
svn export --force trunk trunktmp
cd trunktmp

# ------------------------------------------------------
# compile fpc trunk (11 minutes)
# ------------------------------------------------------
make all OPT="-dFPC_ARMHF" PP=/usr/local/fpc/fpc-3.0.0.arm-linux/lib/fpc/3.0.0/ppcarm

# ------------------------------------------------------
# install fpc trunk (2 minutes)
# ------------------------------------------------------
make install OPT="-dFPC_ARMHF" PREFIX=/usr/local PP=/usr/local/fpc/trunktmp/compiler/ppcarm
rm /usr/local/bin/ppcarm
rm /usr/local/bin/sameplecfg
ln -sf /usr/local/lib/fpc/3.1.1/ppcarm /usr/local/bin/ppcarm
ln -sf /usr/local/lib/fpc/3.1.1/samplecfg /usr/local/bin/samplecfg
make install sourceinstall OPT="-dFPC_ARMHF" PREFIX=/usr/local
rm /usr/share/fpcsrc
ln -sf /usr/local/share/src/fpc-3.1.1/fpc /usr/share/fpcsrc

# /usr/local/bin/fpcmkcfg -d basepath=/usr/local/lib/fpc/3.1.1 -o /usr/local/bin/fpc.cfg
# this doesn't seem to work correctly ???

samplecfg /usr/local/lib/fpc/3.1.1 /etc
# Running on linux
# Write permission in /etc.
# Writing sample configuration file to /etc/fpc.cfg
# Writing sample configuration file to /usr/local/lib/fpc/3.1.1/ide/text/fp.cfg
# Writing sample configuration file to /usr/local/lib/fpc/3.1.1/ide/text/fp.ini
# Writing sample configuration file to /etc/fppkg.cfg
# Writing sample configuration file to /etc/fppkg/default

# ------------------------------------------------------
# then Lazarus
# ------------------------------------------------------
mkdir /usr/local/lazarus
cd /usr/local/lazarus

# ------------------------------------------------------
# checkout lazarus trunk (1.5 minutes)
# ------------------------------------------------------
svn co http://svn.freepascal.org/svn/lazarus/trunk trunk
svn export --force trunk trunktmp
cd trunktmp

# ------------------------------------------------------
# compile lazarus trunk  (6.5 minutes)
# ------------------------------------------------------
make all OPT="-dFPC_ARMHF"

# ------------------------------------------------------
# install lazarus trunk  (2 minutes)
# ------------------------------------------------------
make install OPT="-dFPC_ARMHF" PREFIX=/usr/local

# ------------------------------------------------------
# remove menu-cache to make Lazarus visible in menu
# ------------------------------------------------------
exit  # from sudo
killall lxpanel
find ~/.cache/menus -name '*' -type f -print0 | xargs -0 rm
exit  # from pi

# ------------------------------------------------------
# connect on Windows via Remote Desktop Connecton (mstsc.exe)
# user pi password rapberry
# Menu > Programming > Lazarus
# create small test-project and run
# ------------------------------------------------------

# ======================================================
# note: recompiling lazarus as use pi
# will create a working copy under ~/.lazarus/bin
# ======================================================

Enjoy!