[fpc-pascal] How to compile Lazarus program using only FPC?

Tony Whyman tony.whyman at mccallumwhyman.com
Thu Sep 24 17:59:53 CEST 2015


Rather than going down the lazbuild path as others have suggested, you 
might want to think about fpcmake and creating a "Makefile.fpc" for your 
project. That should be the standard way of building a lazarus project 
just using fpc.

You will need to write a Makefile.fpc that does the same job as the 
lazarus .lpi file and include the LCL and components you use in the 
search paths but once you have done it once, its very easy to copy and 
paste to then next project. Here's a snippet that I often use:

[compiler]
options= -Scghi -O3 -CX -Xs -vewnhi -l -dUseCThreads -dLCL 
-dLCL$(INTERFACE)
unittargetdir=units/$(CPU_TARGET)-$(OS_TARGET)
unitdir= $(LZSOURCE) .

[target]
programs=myprogram

where I have defined under [prerules}

SRCDIR=/my/path/to/lazarus

LZSOURCE=\
$(SRCDIR)/lazarus/components/cairocanvas/lib/$(CPU_TARGET)-$(OS_TARGET)/$(INTERFACE) 
\
$(SRCDIR)/lazarus/components/lazcontrols/lib/$(CPU_TARGET)-$(OS_TARGET)/$(INTERFACE) 
\
$(SRCDIR)/lazarus/components/ideintf/units/$(CPU_TARGET)-$(OS_TARGET)/$(INTERFACE) 
\
$(SRCDIR)/lazarus/packager/units/$(CPU_TARGET)-$(OS_TARGET)/ \
$(SRCDIR)/lazarus/lcl/units/$(CPU_TARGET)-$(OS_TARGET)/ \
$(SRCDIR)/lazarus/components/lazutils/lib/$(CPU_TARGET)-$(OS_TARGET)/ \
$(SRCDIR)/lazarus/lcl/units/$(CPU_TARGET)-$(OS_TARGET)/$(INTERFACE) \
$(SRCDIR)/lazarus/components/memds/lib/$(CPU_TARGET)-$(OS_TARGET)/$(INTERFACE) 
\
$(SRCDIR)/lazarus/components/printers/lib/$(CPU_TARGET)-$(OS_TARGET)/$(INTERFACE) 


Note that this includes a few common components. You need to include the 
path to each component you are using which may vary from the above. The 
above also assumes that the components have already been compiled - 
which should be true if they are included in the IDE.

To build for a GTK2 target, you will then need to run:

export FPCDIR=/usr/lib/fpc/`fpc -iV`
fpcmake  Makefile.fpc
make INTERFACE=gtk2

If you are running on Windows then you will do something like:
FPCDIR=<whereever fpc is>
fpcmake  Makefile.fpc
make INTERFACE=win32

I tend to perform Windows builds using a cross compiler on Linux, 
because its so much easier to script. The you will call something like:

export FPCDIR=/usr/lib/fpc/`fpc -iV`
fpcmake -r -Ti386-win32 Makefile.fpc
make OS_TARGET=win32 CPU_TARGET=i386 BINUTILSPREFIX=amd64-mingw32msvc- 
INTERFACE=win32

Tony Whyman
MWA



On 24/09/15 14:48, Bo Berglund wrote:
> I want to check my options regarding Lazarus and FPC.
>
> If I develop a program on Windows Lazarus, move it to Debian Lazarus
> (x86) and then finally want to compile on ARM on for example Raspberry
> Pi but outside of Lazarus, how is that done?
> Does FPC recognize the Lazarus project file such that paths etc are
> observed?
> Or is thare a separate file for FPC I have to prepare in order to set
> the unit paths?
>
>




More information about the fpc-pascal mailing list