Showing posts with label fpc. Show all posts
Showing posts with label fpc. Show all posts

Friday, October 30, 2020

Variant support in chakracore-delphi

The new experimental/variants branch of chakracore-delphi introduces some experimental support for Variants. It's now possible to write code similar to the following:

The example above is using Javascript built-in JSON object and its methods: parse and stringify. On Windows, it's possible to expose an Automation object to your script, using late (IDispatch) binding. An example of this is shown in the new WmiSample demo:

and its output:

For more example code, you can also check out the associated tests.

Tuesday, January 15, 2019

WebAssembly with Delphi and ChakraCore

chakracore-delphi now contains WasmSample, a new sample project using ChakraCore to load and run a WebAssembly module (in this case, an implementation of Conway's Game of Life).

It's based on Colin Eberhardt's blog post Writing WebAssembly By Hand (you can run the code in your browser here).

Sunday, November 11, 2018

Inheritance with chakracore-delphi

I've just pushed some updates to chakracore-delphi.

A new feature worth mentioning is support for inheritance (I mean Javascript-style, "prototypical inheritance") in both directions. Suppose the following hierarchy:

First, here is Shape the "superclass", defined in Javascript:



Next comes Circle, a "subclass" of Shape, defined in Javascript as well:



The following is Rectangle, defined in Pascal, as a "subclass" of Shape:



Here's Square, defined in Javascript again, as a "subclass" of Rectangle:



And finally here are the tests, demonstrating that
- (Javascript) Circle descends from (Javascript) Shape
- (Pascal) Rectangle descends from (Javascript) Shape
- (Javascript) Square descends from (Pascal) Rectangle



As always, you can grab the latest code on GitHub. Cheers!

Sunday, May 20, 2018

One of my favourite ways of multi-threading on Windows

Having blogged about a few bugs in multi-threading libraries recently, I want to show an easy and convenient alternative. It's minimalistic but it works.

On Windows, the I/O completion port offers a way to use a thread pool for your multi-threaded application. Designed primarily for efficient processing of asynchronous I/O, it supports files, named pipes, sockets and device control.

In addition to that, you can post your own packets to the port. Quoting from the documentation:
The PostQueuedCompletionStatus function allows an application to queue its own special-purpose completion packets to the I/O completion port without starting an asynchronous I/O operation.
An example of this is shown in the worker demo project (which uses no async I/O at all).

Sunday, April 15, 2018

Artificial Intelligence Transgender: Kings and Queens

Researching for some Natural Language Processing tasks for a .NET application recently, I've come across Facebook's FastText library.

FastText is an open-source, free, lightweight library that allows users to learn text representations and text classifiers. It works on standard, generic hardware. Models can later be reduced in size to even fit on mobile devices.
It's written in C++ and builds on modern Mac OS and Linux distributions. Since it uses some C++11 features, it requires a compiler with good C++11 support. Python bindings are included.

Using this library, you can train models which represent words as multi-dimensional vectors. The models can be queried to find correlations between these vectors in the multi-dimensional space. Depending on the volume and quality of your input data, as well as the training parameters you specify, you can obtain better or worse results to your queries. An introductory explanation of how it works: king - man + woman is queen; but why?

An unofficial FastText fork for Windows is available on GitHub. I'm using this as a starting point to create a DLL in Visual Studio, exposing the C++ classes in a "flattened" C-style API as described in the article Using C++ objects in Delphi by Rudy Velthuis. Such a DLL can also be used from .NET via platform invoke.

As a result, when it's done I'll be able to use this library from Python, .NET, Delphi/Free Pascal and JavaScript (by embedding ChakraCore).

Some examples of console output from my experiments:

King - Man + Woman = ? (JavaScript)

C:\Code\fasttextConsole\chakra\Win64\Debug>ftcc ft.js
Loading file "C:\Data\fasttext\wiki\enwik9.bin"...
done.
Computing vectors...
done.
positive words:
king woman
negative words:
man
"queen": 0.7796817421913147
"regnant": 0.7554017305374145
"consort": 0.7433754205703735
"daughter": 0.7231032848358154
"throne": 0.721994161605835

Berlin - Germany + Argentina = ? (C#)

C:\Code\fasttextConsole\cs\ftcs\bin\x64\Debug>ftcs
Loading file "C:\Data\fasttext\wiki\enwik9.bin"...done.
Computing vectors...done.
positive words:
berlin argentina
negative words:
germany
"aires": 0.8183396
"buenos": 0.8142648
"argentinan": 0.7616609
"argentinas": 0.7580159
"caracas": 0.740073

Berlin - Germany + Slovakia = ? (Free Pascal)

C:\Code\fasttextConsole\fpc\bin\x86_64-win64\Debug>ftc
Loading file 'C:\Data\fasttext\wiki\enwik9.bin'...done.
Computing vectors...done.
positive words:
berlin slovakia
negative words:
germany
'zagreb': 0.81 (Oops! ;-))
'bratislava': 0.79 (Yeah!)
'budapesti': 0.79
'slavonski': 0.79
'podgorica': 0.78

Playstation - Sony + Nintendo = ? (JavaScript)

C:\Code\fasttextConsole\chakra\Win64\Debug>ftcc ft.js
Loading file "C:\Data\fasttext\wiki\enwik9.bin"...
done.
Computing vectors...
done.
positive words:
playstation nintendo
negative words:
sony
"gamecube": 0.8729094862937927
"nintendogs": 0.8490696549415588
"playstationjapan": 0.840140163898468
"snes": 0.8312469720840454
"sega": 0.822517454624176

Here are some code examples:

1. C-style API (DLL exported functions)
2. Imports for .NET
3. Wrapper class for .NET
4. C# usage
5. Imports for Pascal
6. Pascal usage
7. Pascal class for ChakraCore host
8. JavaScript usage

Monday, April 02, 2018

First steps with Lazarus Qt5 interface

Steps for building and installing Qt5 for Lazarus

Using a quick test project with relevant code shown here: unit1.pas
I'm using Qt 5.6.2 because that's the version with which Lazarus qt5 interface has been tested. You can experiment with later versions, too.

Windows 32-bit

Using MinGW

$(LazarusDir): C:\fpcupdeluxe\lazarus
$(QtDir): C:\Qt\Qt5.6.2

- download: qt-opensource-windows-x86-mingw492-5.6.2.exe
- install
- open command prompt in the bindings directory $(LazarusDir)\lcl\interfaces\qt5\cbindings
set PATH=$(QtDir)\5.6\mingw49_32\bin;$(QtDir)\Tools\mingw492_32\bin;%PATH%
qmake
mingw32-make
mingw32-make install
$(FpcDir)\bin\i386-win32\strip.exe $(QtDir)\5.6\mingw49_32\bin\Qt5Pas1.dll



Windows 64-bit

Using Visual Studio 2015

$(LazarusDir): C:\fpcupdeluxe\lazarus
$(QtDir): C:\Qt\Qt5.6.2

- download: qt-opensource-windows-x86-msvc2015_64-5.6.2.exe
- install
- fix the binding sources in the bindings directory $(LazarusDir)\lcl\interfaces\qt5\cbindings to be able to compile with Visual Studio: patch
- open command prompt in the bindings directory $(LazarusDir)\lcl\interfaces\qt5\cbindings
set PATH=$(QtDir)\5.6\msvc2015_64\bin;%PATH%
"C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" amd64
qmake

- edit the Makefile to remove -Wfatal-errors from CXXFLAGS
nmake
nmake install



OSX 64-bit

$(LazarusDir): ~/fpcupdeluxe/lazarus
$(QtDir): ~/Qt5.6.2

- download: qt-opensource-mac-x64-clang-5.6.2.dmg
- install
- open terminal in the bindings directory $(LazarusDir)/lcl/interfaces/qt5/cbindings
PATH=$(QtDir)/5.6/clang_64/bin:$PATH
qmake
make
sudo make install



Linux 64-bit (Mint 18.3 Sylvia)

$(LazarusDir): ~/fpcupdeluxe/lazarus
$(QtDir): ~/Qt5.6.2

- make sure OpenGL headers are installed:
sudo apt install mesa-common-dev
sudo ln -s /usr/lib/x86_64-linux-gnu/mesa/libGL.so.1 /usr/lib/libGL.so
sudo ldconfig

- download: qt-opensource-linux-x64-5.6.2.run
- install
Modify the system-wide config in /usr/lib/x86_64-linux-gnu/qt-default/qtchooser/default.conf to point to your Qt5 directories:
$(QtDir)/5.6/gcc_64/bin
$(QtDir)/5.6/gcc_64/lib

- open terminal in the bindings directory $(LazarusDir)/lcl/interfaces/qt5/cbindings
qmake
make
sudo make install
sudo strip $(QtDir)/5.6/gcc_64/lib/libQt5Pas.so.1.2.6



Happy Easter!

Sunday, February 04, 2018

Friday, January 12, 2018

chakracore-delphi initial release

The initial release of chakracore-delphi is out, published under the MIT license.

Short summary:



Comments, ideas and of course pull requests are very welcome. Cheers!

Saturday, January 06, 2018

chakracore-delphi

With the initial release coming up soon, here are a few teaser screenshots of chakracore-delphi, a new opensource library with Delphi and Free Pascal bindings and classes for Microsoft's ChakraCore Javascript engine:


FPC 3.0.4 and Lazarus 1.8 build (win64):

FPC 3.0.4 and Lazarus 1.8 build (linux64):

FPC 3.0.4 and Lazarus 1.8 build (macosx64):

Delphi XE 10.2 Tokyo build (win64):

Delphi 2009 build (win32):

Delphi 7 build (win32):

and a tiny code snippet showing an example of embedding the Javascript engine and exposing some native methods to it:

Sunday, December 10, 2017

fpcupdeluxe

If you use Free Pascal and/or Lazarus and update them often to follow the development in trunk, or if you just need to use multiple versions side by side, have a look at fpcupdeluxe (GitHub).
It's a GUI front-end which lets you easily select a release and build it, including cross-compilers, with a click of a button. The result is installed into its own directory where it doesn't interfere with any other installations of Free Pascal and Lazarus.

If you haven't yet, check out the latest releases of both Free Pascal (3.0.4) and Lazarus (1.8) published recently.

Update: It seems the latest fpcupdeluxe (1.6.0k) now builds trunk without any problems, no tweaks necessary, so you can ignore the rest of this post.

As a side note, updating trunk today failed for me when it was trying to build the intermediate ("bootstrap") compiler. I haven't thoroughly investigated it but I think it's due to the fact that fpc 3.0.4 is now the required compiler to build trunk and I have found a quick fix which works for me now and comprises the following two steps:

1. Create a patch file with the following content in $(fpcupdeluxe)/patchfpc directory:


Index: Makefile.fpc
===================================================================
--- Makefile.fpc (revision 37707)
+++ Makefile.fpc (working copy)
@@ -21,7 +21,7 @@
 
 [prerules]
 REQUIREDVERSION=3.0.4
-REQUIREDVERSION2=3.0.2
+REQUIREDVERSION2=3.0.4
 
 
 # make versions < 3.77 (OS2 version) are buggy


and activate it in the fpcupdeluxe's settings (see screenshot below). This should "force" the bootstrap compiler 3.0.4 to be used instead of 3.0.2 as before.


2. Click "Trunk" and let fpcupdeluxe clone the 3.0.4 release into its fpcbootstrap subdirectory. This would still fail for me as for some reason the generated bootstrap compiler was still 3.0.2. Just replace the binary (ppcx64) with the 3.0.4 binary (you can build one yourself from source or copy it from the official release).

On the next click of the "Trunk" button, you should get a successful build of the current trunk fpc (3.1.1) and Lazarus (1.9). Updating the cross-compilers then worked for me again as well. I usually use x86_64-linux and cross-compile to arm-linux, i386-linux, x86_64-win64, i386-win32, x86_64-darwin and i386-darwin.

Saturday, July 04, 2015

FPC and Lazarus development environment (follow-up)

I've just done a fresh installation of Linux Mint 17.2 'Rafaela' MATE edition (64-bit) from scratch which went without a hitch. I've followed my previous notes to set up my FreePascal and Lazarus development environment, with success.

Saturday, May 30, 2015

FPC and Lazarus development environment

Notes on how to set up a FreePascal/Lazarus development environment on a Linux system, with cross-compiling for OSX and Windows. Intended as a future reference for myself and anybody else who might find them useful.
I'm using Linux Mint 17.1 'Rebecca' MATE 64-bit.

Initial installation

Install fpc

~ $ sudo apt-get install fpc fp-utils

Check installed version

The current maintained version is 2.6.2:
~ $ which fpc
/usr/bin/fpc
~ $ fpc -?
Free Pascal Compiler version 2.6.2-8 [2014/01/22] for x86_64
Copyright (c) 1993-2012 by Florian Klaempfl and others
/usr/lib/fpc/2.6.2/ppcx64 [options] <inputfile> [options] 

Hello, world!

Write a simple program to show the compiler version:
~/Development/Hello $ nano hello.pas
{$MACRO ON}
program Hello;
begin
  Writeln('Hello, world from FPC ', FPC_FULLVERSION, '!');
end.
Compile and run it:
~/Development/Hello $ fpc hello.pas
Free Pascal Compiler version 2.6.2-8 [2014/01/2/2] for x86_64
Copyright (c) 1993-2012 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling hello.pas
Linking hello
/usr/bin/ld.bfd: warning: link.res contains output sections; did you forget -T?
5 lines compiled, 0.2 sec
~/Development/Hello $ ./hello
Hello, world from FPC 20602!

Latest (trunk) installation

Get latest fpc

~/Development $ svn checkout http://svn.freepascal.org/svn/fpc/trunk fpc

Build latest fpc (linux-x86_64)

Use fpc 2.6.2 to build the latest fpc:

~/Development/fpc $ make distclean
~/Development/fpc $ make all install FPC=/usr/bin/fpc OPT=-gl INSTALL_PREFIX=~

Configuration

The original installation creates a symlink in /etc/fpc.cfg pointing to /etc/alternatives/fpc.cfg which itself is a symlink pointing to /etc/fpc-2.6.2.cfg. In the code below, we copy the original config file to ~/Development and fix the symlink to point to it.
~/Development $ cp /etc/fpc.cfg ~/Development
~/Development $ sudo rm /etc/fpc.cfg
~/Development $ sudo ln -s ~/Development/fpc.cfg /etc/fpc.cfg
Modify the new configuration file:
@@ -124,6 +124,8 @@
 -Cppentiumm
 -Oppentiumm
 #endif
+  -gw
+  -XR/usr/lib/apple/SDKs/MacOSX10.6.sdk
 #endif
 
 # -----------------------
@@ -141,17 +143,17 @@
 #-Fr/usr/lib/fpc/$fpcversion/msg/errorr.msg
 
 # searchpath for units and other system dependent things
--Fu/usr/lib/fpc/$fpcversion/units/$fpctarget
--Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/*
--Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/rtl
+-Fu~/lib/fpc/$fpcversion/units/$fpctarget
+-Fu~/lib/fpc/$fpcversion/units/$fpctarget/*
+-Fu~/lib/fpc/$fpcversion/units/$fpctarget/rtl
 
 #IFDEF FPCAPACHE_1_3
--Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd13/
+-Fu~/lib/fpc/$fpcversion/units/$fpctarget/httpd13/
 #ELSE
 #IFDEF FPCAPACHE_2_0
--Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd20
+-Fu~/lib/fpc/$fpcversion/units/$fpctarget/httpd20
 #ELSE
--Fu/usr/lib/fpc/$fpcversion/units/$fpctarget/httpd22
+-Fu~/lib/fpc/$fpcversion/units/$fpctarget/httpd22
 #ENDIF
 #ENDIF
 
@@ -160,7 +162,7 @@
 
 # path to the gcclib
 #ifdef cpui386
--Fl/usr/lib/gcc/x86_64-linux-gnu/4.8
+-Fl/usr/lib/gcc/x86_64-linux-gnu/4.8/32
 #endif
 #ifdef cpux86_64
 -Fl/usr/lib/gcc/x86_64-linux-gnu/4.8
@@ -168,11 +170,16 @@
 
 # searchpath for libraries
 #-Fl/usr/lib/fpc/$fpcversion/lib
-#-Fl/lib;/usr/lib
--Fl/usr/lib/fpc/$fpcversion/lib/$FPCTARGET
+#ifdef cpui386
+-Fl/usr/lib/i386-linux-gnu;/lib32;/usr/lib32
+#endif
+#ifdef cpux86_64
+-Fl/lib;/usr/lib
+#endif
+-Fl~/lib/fpc/$fpcversion/lib/$fpctarget
 
 # searchpath for tools
--FD/usr/lib/fpc/$fpcversion/bin/$FPCTARGET
+-FD~/lib/fpc/$fpcversion/bin/$fpctarget
 
 #IFNDEF CPUI386
 #IFNDEF CPUAMD64
@@ -241,7 +248,7 @@
 # If you don't want so much verbosity use
 #-vw
 # multiarch library search path
--Fl/usr/lib/$fpctarget-*
+-Fl~/lib/$fpctarget-*
 # Third party units should be installe in a, multi-arch compatible location.
 # Units should be installed in /usr/lib/$fpctarget-gnu/fp-units-2.6.2/$pkg/.
 # Ech fp-units package should install a configuration file called $pkg.cfg in

Create a symlink for the new compiler:
~/Development/fpc $ ln -s ~/lib/fpc/3.1.1/ppcx64 ~/bin/ppcx64

Hello, world! (linux-x86_64)

~/Development/Hello $ fpc hello.pas
Free Pascal Compiler version 3.1.1 [2015/05/29] for x86_64
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Linux for x86-64
Compiling hello.pas
Linking hello
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
5 lines compiled, 0.3 sec
~/Development/Hello $ ./hello
Hello, world from FPC 30101!

Cross-compiling

See useful tips here.

Linux

Install prerequisites

For cross-compiling to 32-bit Linux, install gcc-multilib and create a few links.
~ $ sudo apt-get install gcc-multilib
~ $ sudo ln -s /usr/lib/i386-linux-gnu/libX11.so.6 /usr/lib/i386-linux-gnu/libX11.so
~ $ sudo ln -s /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so.0 /usr/lib/i386-linux-gnu/libgtk-x11-2.0.so
~ $ sudo ln -s /usr/lib/i386-linux-gnu/libgdk_pixbuf-2.0.so.0 /usr/lib/i386-linux-gnu/libgdk_pixbuf-2.0.so
~ $ sudo ln -s /usr/lib/i386-linux-gnu/libgdk-x11-2.0.so.0 /usr/lib/i386-linux-gnu/libgdk-x11-2.0.so
~ $ sudo ln -s /usr/lib/i386-linux-gnu/libgobject-2.0.so.0 /usr/lib/i386-linux-gnu/libgobject-2.0.so
~ $ sudo ln -s /lib/i386-linux-gnu/libglib-2.0.so.0 /lib/i386-linux-gnu/libglib-2.0.so
~ $ sudo ln -s /usr/lib/i386-linux-gnu/libgthread-2.0.so.0 /usr/lib/i386-linux-gnu/libgthread-2.0.so
~ $ sudo ln -s /usr/lib/i386-linux-gnu/libgmodule-2.0.so.0 /usr/lib/i386-linux-gnu/libgmodule-2.0.so
~ $ sudo ln -s /usr/lib/i386-linux-gnu/libpango-1.0.so.0 /usr/lib/i386-linux-gnu/libpango-1.0.so
~ $ sudo ln -s /usr/lib/i386-linux-gnu/libcairo.so.2 /usr/lib/i386-linux-gnu/libcairo.so
~ $ sudo ln -s /usr/lib/i386-linux-gnu/libatk-1.0.so.0 /usr/lib/i386-linux-gnu/libatk-1.0.so

Cross-compiler for linux-i386

~ $ nano ~/bin/i386-linux-ld
#!/bin/bash
ld -A elf32-i386 $@
~ $ chmod +x ~/bin/i386-linux-ld
~ $ nano ~/bin/i386-linux-as
#!/bin/bash
as --32 $@
~ $ chmod +x ~/bin/i386-linux-as
~/Development/fpc $ make distclean OS_TARGET=linux CPU_TARGET=i386
~/Development/fpc $ make all crossinstall FPC=/usr/bin/fpc NOGDB=1 OS_TARGET=linux CPU_TARGET=i386 \
  INSTALL_PREFIX=~

Create a symlink for the new cross-compiler:
~ $ ln -s ~/lib/fpc/3.1.1/ppcross386 ~/bin/ppcross386

Hello, world! (linux-i386)

~/Development/Hello $ fpc -Pi386 hello.pas
Free Pascal Compiler version 3.1.1 [2015/05/29] for i386
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Linux for i386
Compiling hello.pas
Linking hello
/usr/bin/ld: warning: link.res contains output sections; did you forget -T?
5 lines compiled, 0.2 sec
~/Development/Hello $ ./hello
Hello, world from FPC 30101!

Windows

Cross-compiler for win32-i386

~/Development/fpc $ make distclean OS_TARGET=win32 CPU_TARGET=i386
~/Development/fpc $ make all crossinstall FPC=/usr/bin/fpc NOGDB=1 OS_TARGET=win32 CPU_TARGET=i386 INSTALL_PREFIX=~

Hello, world! (win32-i386)

~/Development/Hello $ fpc -Twin32 -Pi386 hello.pas
Free Pascal Compiler version 3.1.1 [2015/05/29] for i386
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Win32 for i386
Compiling hello.pas
Linking hello.exe
5 lines compiled, 0.0 sec, 26976 bytes code, 1284 bytes data

Cross-compiler for win64-x86_64

~/Development/fpc $ make distclean OS_TARGET=win64 CPU_TARGET=x86_64
~/Development/fpc $ make all crossinstall FPC=/usr/bin/fpc NOGDB=1 OS_TARGET=win64 CPU_TARGET=x86_64 \
  INSTALL_PREFIX=~

Hello, world! (win64-x86_64)

~/Development/Hello $ fpc -Twin64 -Px86_64 hello.pas
Free Pascal Compiler version 3.1.1 [2015/05/29] for x86_64
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Win64 for x64
Compiling hello.pas
Linking hello.exe
5 lines compiled, 0.1 sec, 33504 bytes code, 1364 bytes data

OSX

Install odcctools and SDK

Install ppa:flosoft/cross-apple manually (to use maverick):
~ $ sudo nano /etc/apt/sources.list
deb http://ppa.launchpad.net/flosoft/cross-apple/ubuntu maverick main 
deb-src http://ppa.launchpad.net/flosoft/cross-apple/ubuntu maverick main
~ $ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys D0611AA0
~ $ sudo apt-get update
~ $ sudo apt-get install apple-x86-odcctools
~ $ sudo apt-get install apple-uni-sdk-10.6
~ $ ln -s /usr/bin/i686-apple-darwin10-ld ~/bin/x86_64-darwin-ld
~ $ ln -s /usr/bin/i686-apple-darwin10-ld ~/bin/i386-darwin-ld
~ $ ln -s /usr/bin/i686-apple-darwin10-as ~/bin/x86_64-darwin-as
~ $ ln -s /usr/bin/i686-apple-darwin10-as ~/bin/i386-darwin-as

Cross-compiler for darwin-i386

~/Development/fpc make distclean OS_TARGET=darwin CPU_TARGET=i386
~/Development/fpc $ make crossall crossinstall FPC=/usr/bin/fpc NOGDB=1 OS_TARGET=darwin CPU_TARGET=i386 \
  INSTALL_PREFIX=~ BINUTILSPREFIX=i686-apple-darwin10- \
  OPT="-gl -gw -godwarfsets -XX -CX -Xd -Fl/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib"

Hello, world! (darwin-i386)

~/Development/Hello $ fpc -Tdarwin -Pi386 hello.pas
Free Pascal Compiler version 3.1.1 [2015/05/29] for i386
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Darwin for i386
Compiling hello.pas
Assembling (pipe) hello.s
Linking hello
5 lines compiled, 0.1 sec

Cross-compiler for darwin-x86_64

~/Development/fpc $ make distclean OS_TARGET=darwin CPU_TARGET=x86_64
~/Development/fpc $ make crossall crossinstall FPC=/usr/bin/fpc NOGDB=1 OS_TARGET=darwin CPU_TARGET=x86_64 \
  INSTALL_PREFIX=~ BINUTILSPREFIX=i686-apple-darwin10- \
  OPT="-gl -gw -godwarfsets -XX -CX -Xd -Fl/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib"

Hello, world! (darwin-x86_64)

~/Development/Hello $ fpc -Tdarwin -Px86_64 hello.pas
Free Pascal Compiler version 3.1.1 [2015/05/29] for x86_64
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Darwin for x86_64
Compiling hello.pas
Assembling (pipe) hello.s
Linking hello
5 lines compiled, 0.1 sec

Lazarus

Get latest Lazarus

~/Development $ svn checkout http://svn.freepascal.org/svn/lazarus/trunk lazarus

Build LCL

Build LCL for Windows native and GTK2, OSX Carbon (32-bit), OSX Cocoa (64-bit), Linux GTK2:
~/Development/lazarus $ make distclean registration lazutils lcl OS_TARGET=win32 CPU_TARGET=i386 LCL_PLATFORM=win32
~/Development/lazarus $ make distclean registration lazutils lcl OS_TARGET=win32 CPU_TARGET=i386 LCL_PLATFORM=gtk2
~/Development/lazarus $ make distclean registration lazutils lcl OS_TARGET=win64 CPU_TARGET=x86_64 \
  LCL_PLATFORM=win32
~/Development/lazarus $ make distclean registration lazutils lcl OS_TARGET=win64 CPU_TARGET=x86_64 \
  LCL_PLATFORM=gtk2
~/Development/lazarus $ make distclean registration lazutils lcl OS_TARGET=darwin CPU_TARGET=i386 \
  LCL_PLATFORM=carbon
~/Development/lazarus $ make distclean registration lazutils lcl OS_TARGET=darwin CPU_TARGET=x86_64 \
  LCL_PLATFORM=cocoa
~/Development/lazarus $ make distclean registration lazutils lcl OS_TARGET=linux CPU_TARGET=i386 LCL_PLATFORM=gtk2
~/Development/lazarus $ make distclean all OS_TARGET=linux CPU_TARGET=x86_64 LCL_PLATFORM=gtk2
~/Development/lazarus $ ./lazbuild --build-ide=
The last two commands above will fully build LCL and the Lazarus IDE.

Updating

I'm using the following script to update both fpc and Lazarus to the latest trunk and rebuild everything:
#!/bin/bash

rm -rf ~/lib/fpc/3.1.1/~units
mv ~/lib/fpc/3.1.1/units ~/lib/fpc/3.1.1/~units
cd ~/Development/fpc
make distclean > /dev/null
cd ~/Development/lazarus
make distclean > /dev/null

cd ~/Development
svn info fpc
svn update fpc

svn info lazarus
svn update lazarus

cd ~/Development/fpc

echo "**** FreePascal Windows 32-bit begin ****"
make distclean OS_TARGET=win32 CPU_TARGET=i386 > /dev/null
make all crossinstall FPC=/usr/bin/fpc NOGDB=1 OS_TARGET=win32 CPU_TARGET=i386 INSTALL_PREFIX=~
echo "**** FreePascal Windows 32-bit end ****"
echo
echo "**** FreePascal Windows 64-bit begin ****"
make distclean OS_TARGET=win64 CPU_TARGET=x86_64 > /dev/null
make all crossinstall FPC=/usr/bin/fpc NOGDB=1 OS_TARGET=win64 CPU_TARGET=x86_64 INSTALL_PREFIX=~
echo "**** FreePascal Windows 64-bit end ****"
echo
echo "**** FreePascal MacOSX 32-bit begin ****"
make distclean OS_TARGET=darwin CPU_TARGET=i386 > /dev/null
make crossall crossinstall FPC=/usr/bin/fpc NOGDB=1 OS_TARGET=darwin CPU_TARGET=i386 INSTALL_PREFIX=~ \
  BINUTILSPREFIX=i686-apple-darwin10- \
  OPT="-gl -gw -godwarfsets -XX -CX -Xd -Fl/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib"
echo "**** FreePascal MacOSX 32-bit end ****"
echo
echo "**** FreePascal MacOSX 64-bit begin ****"
make distclean OS_TARGET=darwin CPU_TARGET=x86_64 > /dev/null
make crossall crossinstall FPC=/usr/bin/fpc NOGDB=1 OS_TARGET=darwin CPU_TARGET=x86_64 INSTALL_PREFIX=~ \
  BINUTILSPREFIX=i686-apple-darwin10- \
  OPT="-gl -gw -godwarfsets -XX -CX -Xd -Fl/usr/lib/apple/SDKs/MacOSX10.6.sdk/usr/lib"
echo "**** FreePascal MacOSX 64-bit end ****"
echo
echo "**** FreePascal Linux 32-bit begin ****"
make distclean OS_TARGET=linux CPU_TARGET=i386 > /dev/null
make all crossinstall FPC=/usr/bin/fpc NOGDB=1 OS_TARGET=linux CPU_TARGET=i386 INSTALL_PREFIX=~
echo "**** FreePascal Linux 32-bit end ****"
echo
echo "**** FreePascal Linux 64-bit begin ****"
make distclean OS_TARGET=linux CPU_TARGET=x86_64 > /dev/null
make all install FPC=/usr/bin/fpc OPT=-gl OS_TARGET=linux CPU_TARGET=x86_64 INSTALL_PREFIX=~
echo "**** FreePascal Linux 64-bit end ****"
echo
cd ~/Development/lazarus

echo "**** LCL Windows 32-bit native begin ****"
make distclean registration lazutils lcl OS_TARGET=win32 CPU_TARGET=i386 LCL_PLATFORM=win32
echo "**** LCL Windows 32-bit native end ****"
echo
echo "**** LCL Windows 32-bit GTK2 begin ****"
make distclean registration lazutils lcl OS_TARGET=win32 CPU_TARGET=i386 LCL_PLATFORM=gtk2
echo "**** LCL Windows 32-bit GTK2 end ****"
echo
echo "**** LCL Windows 64-bit native begin ****"
make distclean registration lazutils lcl OS_TARGET=win64 CPU_TARGET=x86_64 LCL_PLATFORM=win32
echo "**** LCL Windows 64-bit native end ****"
echo
echo "**** LCL Windows 64-bit GTK2 begin ****"
make distclean registration lazutils lcl OS_TARGET=win64 CPU_TARGET=x86_64 LCL_PLATFORM=gtk2
echo "**** LCL Windows 64-bit GTK2 end ****"
echo
echo "**** LCL MacOSX 32-bit Carbon begin ****"
make distclean registration lazutils lcl OS_TARGET=darwin CPU_TARGET=i386 LCL_PLATFORM=carbon
echo "**** LCL MacOSX 32-bit Carbon end ****"
echo
echo "**** LCL MacOSX 64-bit Cocoa begin ****"
make distclean registration lazutils lcl OS_TARGET=darwin CPU_TARGET=x86_64 LCL_PLATFORM=cocoa
echo "**** LCL MacOSX 64-bit Cocoa end ****"
echo
echo "**** LCL Linux 32-bit GTK2 begin ****"
make distclean registration lazutils lcl OS_TARGET=linux CPU_TARGET=i386 LCL_PLATFORM=gtk2
echo "**** LCL Linux 32-bit GTK2 end ****"
echo
echo "**** Lazarus Linux 64-bit GTK2 begin ****"
make distclean all OS_TARGET=linux CPU_TARGET=x86_64 LCL_PLATFORM=gtk2
./lazbuild --build-ide=
echo "**** Lazarus Linux 64-bit GTK2 end ****"
echo

cd ~/Development/fpc
USEZIP=0 USETAR=bz2 make zipsourceinstall
mv fpc.source.tar.bz2 ..
cd ~/
tar --create --bzip2 --recursion bin > ~/Development/bin.tar.bz2
tar --create --bzip2 --recursion lib > ~/Development/lib.tar.bz2
cd ~/Development/lazarus
tar --create --bzip2 --recursion lcl/units > ~/Development/lcl.tar.bz2
tar --create --bzip2 --recursion components/lazutils/lib > ~/Development/lazutils.tar.bz2
tar --create --bzip2 --recursion packager/units > ~/Development/packager.tar.bz2

cd ~/Development

Hello, world! (with UI)

Now you can use the Lazarus IDE to create and cross-compile your projects.

Project Options

Hello from Linux

Hello from Windows

Hello from OSX

About Lazarus