Bootstrapping FPC for a new architecture

Without pre-compiled binaries

On the bootstrapping machine

1. Check out FPC from Git:

   $ git https://gitlab.com/freepascal.org/fpc/source.git fpc-src

2. Install fpc and the gcc cross toolchain for the target architecture:

   $ apt install fpc gcc-m68k-linux-gnu g++-m68k-linux-gnu cpp-m68k-linux-gnu

4. Enter FPC source directory and build a cross-compiler:

   $ cd fpc-src
   ~/fpc-src $ BINUTILSPREFIX=m68k-linux-gnu- make crossall crossinstall CPU_TARGET=m68k CROSSOPT="-Cp68020 -Cf68881 -CaDEFAULT" OS_TARGET=linux FPC=/usr/lib/x86_64-linux-gnu/fpc/3.2.2/ppcx64 INSTALL_PREFIX=/home/glaubitz/fpc-m68k/

5. Build the native compiler:

   ~/fpc-src $ BINUTILSPREFIX=m68k-linux-gnu- make compiler CPU_TARGET=m68k OS_TARGET=linux FPC=/home/glaubitz/fpc-m68k/lib/fpc/3.3.1/ppcross68k CROSSOPT="-Cp68020 -Cf68881 -CaDEFAULT -Fu/home/fpc-m68k/lib/fpc/3.3.1//units/*"

Note: The options for CROSSOPT can be obtained by running "ppcross$CPU" after the initial build without parameters:

   ~/fpc-src $ ./compiler/ppcross68k -ic
   68000
   68020
   68040
   68060
   ISAA
   ISAA+
   ISAB
   ISAC
   CFV4E
   ~/fpc-src $ ./compiler/ppcross68k -if 
   SOFT
   LIBGCC
   68881
   COLDFIRE
   ~/fpc-src $ ./compiler/ppcross68k -ia
   DEFAULT
   ~/fpc-src $

6. Copy target compiler into directory of cross-compiler:

   ~/fpc-src $ cp -av compiler/ppc68k /home/glaubitz/fpc-m68k/lib/fpc/3.3.1/

7. Tar the target compiler up to transport it to the target machine:

   ~/fpc-src $ cd
   $ tar czf fpc-m68k.tgz /home/glaubitz/fpc-m68k

On the target machine

1. Check out FPC from Git:

   $ git https://gitlab.com/freepascal.org/fpc/source.git fpc-src

2. Untar cross-compiled target compiler:

   $ tar xf fpc-m68k.tgz

3. Build FPC with the bootstrapped FPC:

   $ make FPC=/home/glaubitz/fpc-m68k/lib/fpc/3.3.1/ppcm68k FPCDIR=/home/glaubitz/fpc-m68k/lib/fpc/3.3.1/ OVERRIDEVERSIONCHECK=1 all

4. Install the newly built FPC:

   $ make FPC=/home/glaubitz/fpc-m68k/lib/fpc/3.3.1/ppcm68k FPCDIR=/home/glaubitz/fpc-m68k/lib/fpc/3.3.1/ OVERRIDEVERSIONCHECK=1 install INSTALL_PREFIX=/home/glaubitz/fpc CPU_TARGET=m68k

Then skip to Creating the Debian package

With pre-compiled binaries

1. Download the binaries for your architecture from ftp://ftp.freepascal.org/pub/fpc/dist/ (chose the latest version, then your target).

   $ wget --no-check-certificate https://downloads.sourceforge.net/project/freepascal/Linux/3.0.2/fpc-3.0.2.mipsel-linux.tar

2. Extract the tarball

   $ tar xf fpc-3.0.2.mipsel-linux.tar

3. Run install.sh to install fpc into your home directory or /usr/local (the latter requires root privileges)

   $ cd fpc-3.0.2.mipsel-linux
   $ ./install.sh

Creating the Debian package

# export PATH=$PATH:/home/glaubitz/fpc-3.0.2/bin/:/home/glaubitz/fpc-3.0.2/lib/fpc/3.0.2/                                                                                                                                                                                                                                                                                                  
# apt-get install devscripts dh-exec                                                                                                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                                                                                                           
diff -Nru old/fpc-3.0.2+dfsg/debian/rules new/fpc-3.0.2+dfsg/debian/rules                                                                                                                                                                                                                                                                                                                  
--- old/fpc-3.0.2+dfsg/debian/rules     2017-04-09 11:44:58.000000000 +0200                                                                                                                                                                                                                                                                                                                
+++ new/fpc-3.0.2+dfsg/debian/rules     2017-05-30 23:52:09.875391597 +0200                                                                                                                                                                                                                                                                                                                
@@ -57,6 +57,9 @@                                                                                                                                                                                                                                                                                                                                                                          
 ifeq ($(CPU_TARGET),sparc)                                                                                                                                                                                                                                                                                                                                                                
 PPSUF=sparc                                                                                                                                                                                                                                                                                                                                                                               
 endif                                                                                                                                                                                                                                                                                                                                                                                     
+ifeq ($(CPU_TARGET),mipsel)                                                                                                                                                                                                                                                                                                                                                               
+PPSUF=mipsel                                                                                                                                                                                                                                                                                                                                                                              
+endif                                                                                                                                                                                                                                                                                                                                                                                     
                                                                                                                                                                                                                                                                                                                                                                                           
 ifneq ($(CPU_SOURCE),$(CPU_TARGET))                                                                                                                                                                                                                                                                                                                                                       
 PPPRE=ppcross

diff -Nru old/fpc-3.0.2+dfsg/debian/fp-units-gfx.install.in new/fpc-3.0.2+dfsg/debian/fp-units-gfx.install.in
--- old/fpc-3.0.2+dfsg/debian/fp-units-gfx.install.in   2017-04-09 11:44:58.000000000 +0200
+++ new/fpc-3.0.2+dfsg/debian/fp-units-gfx.install.in   2017-05-30 23:44:24.519488161 +0200
@@ -1,11 +1,11 @@
 #! /usr/bin/dh-exec
 usr/lib/fpc/*/*/*/ggi*
-usr/lib/fpc/*/*/*/graph*        [!linux-arm64 !linux-armel !linux-armhf !linux-ppc64]
+usr/lib/fpc/*/*/*/graph*        [!linux-arm64 !linux-armel !linux-armhf !linux-mipsel !linux-ppc64]
 usr/lib/fpc/*/*/*/hermes*
 usr/lib/fpc/*/*/*/imagemagick*
 usr/lib/fpc/*/*/*/libgd*
 usr/lib/fpc/*/*/*/libpng*
-usr/lib/fpc/*/*/*/opencl*       [!freebsd-any !linux-arm64 !linux-armel !linux-armhf !linux-powerpc !linux-ppc64]
+usr/lib/fpc/*/*/*/opencl*       [!freebsd-any !linux-arm64 !linux-armel !linux-armhf !linux-mipsel !linux-powerpc !linux-ppc64]
 usr/lib/fpc/*/*/*/opengl*
 usr/lib/fpc/*/*/*/opengles*
 usr/lib/fpc/*/*/*/ptc*          [!freebsd-any]

Description: In order to add support for arm64, we need a man-page
Source: upstream

Index: fpc/install/man/man1/ppcmipsel.1
===================================================================
--- /dev/null
+++ fpc/install/man/man1/ppcmipsel.1
@@ -0,0 +1,33 @@
+.TH ppcmipsel 1 "30 may 1999" "Free Pascal" "Free Pascal Compiler"
+.SH NAME
+ppcmipsel \- Free Pascal Compiler (FPC) binary, name derived 
+from Portable Pascal Compiler
+
+.SH SYNOPSIS
+
+.B "ppcmipsel [options] [sourcefile]"
+.BR
+
+.SH DESCRIPTION
+This binary is the back-end binary of the
+.I Free Pascal Compiler (FPC)
+which is a
+.I Turbo Pascal
+and
+.I Delphi (7.0) 
+compatible standalone (non GCC frontend) multitarget Pascal compiler.
+
+This binary should not be called directly, instead the 
+.B fpc
+program should be used instead. 
+It will choose the right back-end for compiling units for the requested platforms.
+
+.SH OPTIONS
+
+For a complete list of all supported command-line options, see the
+.BR fpc (1)
+manual page.
+
+.SH SEE ALSO
+.BR  fpc (1)
+

# dpkg-buildpackage -d -nc -B
# debsign <changes file>
# dput ftp-master *changes