Free Pascal for Xcode Integration Kit for Xcode 1.5


IMPORTANT NOTE: This Integration Kit only works for Xcode 1.1 thru 1.5. If you are using Xcode 2.0 or later, you need to download the latest kit (and latest FPC) available at the FreePascal downloads page. This page still serves to provide background on the Integration Kit, but be sure to download the correct kit to work with your version of Xcode!




Xcode is an integrated development environment which is part of the Apple developer tools, and it is included for free with Mac OS X 10.3.

Xcode is ready for the development in Assembler, C, C++, Objective-C, Java and AppleScript out of the box, that means it comes with a whole bunch of file and build specifications for these languages. Please note that the corresponding compilers are pure unix command line programs which are invoked by the way of sophisticated build scripts.

However, Xcode is NOT limited to the languages mentioned above. It already supports source code colouring for several other languages - among these are Pascal and FORTRAN. Although, there are some steps left to fully integrate one of these other languages.



This Integration Kit contains all the specifications and templates which are necessary to begin development in Free Pascal together with Xcode. It does neither contain Free Pascal nor Apples Xcode and Apples Universal PInterfaces.

Xcode and Mac OS X 10.3 are required. The Integration Kit works best with the latest Xcode 1.5. Project Builder at Mac OS X 10.2/10.1 is not compatible with the Integration Kit

The latest snapshot of FPC is currently 2.0.0, and it comes as a .dmg-diskimage containing an installer package. However, there is much development going on for Free Pascal for Mac OS X. So, if you want to live at the cutting edge then fetch your copy from CVS - it is not too difficult! If you are interested in CVS versions then please jump to the FPC/CVS-Quickstart section of this document.

Step 0 - If not already done, install Xcode, Free Pascal, and Apples Universal PInterfaces


Main Features

The New Project... command of the File menu of Xcode brings up a list of different project types. After installation of the templates from the integration package the list contains a Pascal Tool, a Pascal CGI, and a Pascal Carbon Application project template in the category Free Pascal.

The Pascal Tool template sets up a simple command line "Hello, World!" project.

The Pascal CGI template sets up a more sophisticated project. This shows how Pascal units fit into Xcode and also how to copy automatically the finished products to certain places - in this case to /Library/WebServer/CGI-Executables/ and to /Library/WebServer/Documents/. If Apache is set up correctly and running then after building the CGI you can test it directly by directing your web browser to http://localhost/«PROJECTNAME».html.

The Pascal Carbon Application template sets up a NIB based Carbon Application, which requires a patched version of Apples Universal PInterfaces. It links against the Carbon Framework and builds and runs out of the box.

Download the FreePascal for Xcode Integration Kit Version 1.1


Step 0 - If not already done, install Xcode, Free Pascal, and Apples Universal PInterfaces

  • Install the Apple developer tools. If you got a new Mac with a pristine Mac OS X 10.3.x installation then the installer package is already at your hard disk at /Applications/Installers.
  • If you purchased the Mac OS X 10.3 upgrade CDs then there should be also a CD called Mac OS X Xcode tools.
  • Otherwise, download and install the latest and the greatest package (350+ MB) from the
    Apple Developer Connection Member Site.
  • Download and install the latest FPC for Mac OS X package from
  • Download Apples Universal Interfaces
  • Install the FreePascal for Xcode Integration Kit


Only, if you want to learn more about the secrets of Free Pascal for Xcode then follow the remaining steps.

Step 1 - Update the Pascal Source File Specification

Step 2 - Update the Pascal Language Specification

Step 3 - Create Free Pascal Project Templates



Step 1 - Update the Pascal Source File Specification

Xcode looks at the extension of a given file to learn which sort of source code it contains. It knows already, that files ending in .pas contain Pascal source code. In order to tell Xcode that the extensions .p, .pp and .inc also belong to Pascal, the standard specification must be overwritten. For this, open the following file in a text editor:

/System/Library/PrivateFrameworks/DevToolsCore.framework/Versions/A/Resources/Standard file types.pbfilespec

Copy and paste the Pascal part to a new empty text file. At the first line add a comment with the description. In the section Extensions add ", p, pp, inc". And finally enclose everything between {} in (). After this, the text should look like this:

// Pascal Source File Specification
      Identifier = sourcecode.pascal;
      BasedOn = sourcecode;
      Name = "Pascal source files";
      Extensions = (pas, p, pp, inc);
      ComputerLanguage = pascal;
      AppliesToBuildRules = yes;

Save this file as PascalSource.pbfilespec into the following directory:

/Library/Application Support/Apple/Developer Tools/Specifications/

If the directory Specifications does not exist already then create it before.


Step 2 - Update the Pascal Language Specification

Xcode provides already syntax colouring for Pascal source fles. The standard language specification contains the directive CaseSensitive = NO which seems to be correct since Pascal is not a case sensitive language. A list of lower case keywords follows and because of the directive the Xcode editor should recognize for example and, AND, aNd etc. all as Pascal keywords - but this is not the case. It only colours lower case keywords in pascal source code properly. Because of this behaviour it is best to overwrite also the standard language specification. For this, open the following file in a text editor:

/System/Library/PrivateFrameworks/DevToolsCore.framework/Versions/A/Resources/Built-in languages.pblangspec

Copy and paste the Pascal part to a new empty text file. Duplicate each lowercase keyword with its uppercase pendant. After this, the text should look like this:

// Pascal Language Specification
      Identifier = pascal;
      Name = "Pascal";
      Description = "Pascal";
      BasedOn = "pbx_root_language";
      SourceScannerClassName = PBXPascalSourceScanner;
      SupportsIndentation = NO;
      Indentation = {
      SyntaxColoring = {
         CaseSensitive = NO;
         UnicodeSymbols = NO;
         IndexedSymbols = YES;
         CommentsCanBeNested = YES;
         String = (
            ( "'", "'" )
         MultiLineComment = (
            ( "{", "}" ),
            ( "(*", "*)" )
         SingleLineComment = ( "//" );
         Keywords = (
         AltKeywords = (

Save this file as PascalSource.pblangspec into the following directory:

/Library/Application Support/Apple/Developer Tools/Specifications/


Step 3 - Create Free Pascal Project Templates

  • create a new directory Pascal in the following driectory
    /Library/Application Support/Apple/Developer Tools/Project Templates/
  • locate the Standard Tool template directory at the following path
    /Library/Application Support/Apple/Developer Tools/Project Templates/Command Line Utility/Standard Tool
    and put a COPY of the whole directory into the newly created
    Pascal directory.

  • rename the copy to Pascal Tool and open that directory.
  • rename StandardTool.1 to PascalTool.1.
  • rename StandardTool.pbproj to PascalTool.pbproj.
  • open PascalTool.pbproj with Xcode.
  • open the information for main.c, for this select main.c from the file list and choose
    <Get Info> from the <Projekt> menu.
  • in the information window rename main.c to «PROJECTNAME».pas - note that by this way not only the file name but also all references to it in the project are changed.

  • change the file encoding to <Western (Mac OS Roman)>, confirm with <Convert>, and close the information window.
  • replace the contents of the file with a small working pascal program, for example:

    program «PROJECTNAME»;
          i : integer;

       for i := 1 to 5 do
          writeln('Hello, World!');

  • safe the file using <cmd>+<S>.
  • expand the section Targets at the left side and select the target «PROJECTNAME».
  • choose <Get Info> from the <Projekt> menu.
  • open the section <Rules>.
  • add a new rule by clicking at the <+> button at the lower left side of the information window.
  • choose <Pascal source files> from the <Process:> pop-up-menu.
  • choose <Custom script:> from the <using:> pop-up-menu.
  • enter the following two lines into the text field below the <using:> pop-up-menu:

    /usr/local/bin/ppcppc -g -vr $(INPUT_FILE_NAME) -FEbuild -o«PROJECTNAME»
  • enter the following line into the text field with the label <with output fles:>:


  • quit Xcode.
  • open the Pascal Tool directory with the Finder.
  • rename «PROJECTNAME».pas to PascalTool.pas.
  • delete the directory build.
  • <ctrl>-click on PascalTool.pbproj and select <Display Package> from the pop-up menu.

  • delete the file yourusername.pbxuser.
  • open the file TemplateInfo.plist with a text editor - file encoding "Western (Mac OS Roman)" - and change its contents to:
       FilesToRename = {
          "PascalTool.pas" = "«PROJECTNAME».pas";
          "PascalTool.1"   = "«PROJECTNAME».1";
       FilesToMacroExpand = (
       Description = "This project builds a command-line tool written in Pascal.";
  • close the PascalTool.pbproj package.
  • close the whole Project Templates directory tree.
  • launch Xcode by double clicking on its application icon - i.e. don´t open a project with Xcode.
  • select <New Project...> from the <File> menu.

  • select the just created template <Pascal Tool> from the section <Pascal> and click on the button <Next>.
  • enter a project name.
  • choose the project location and click on the button <Finish>.
  • from the <Build> menu select <Build and Run>.



Appendix A:  FPC/CVS-Quickstart

  • Make sure you installed everything according to Step 0 of this tutorial.
  • Connect to the internet.
  • Open the Terminal application.
  • Enter the following command sequence (see

    Choose the target directory - if you have a Development directory in your home directory, then why not let the FPC source tree go into there (however, any other place is OK also):

       cd ~/Development

    Login to the CVS pserver

       cvs -d login

    The CVS server should answer with:

       (Logging in to
       CVS password:

    The password is cvs. The following command creates a new directory fpc in the working directory and the latest source tree of Free Pascal is loaded into it:

       cvs -z 3 -d checkout fpc

    Depending on your connection to the internet this will take a while - so please be patient, and wait until the prompt reappears in Terminal.

  • Set the path to the new installed compiler. If your shell is bash then use:

       export PATH="$PATH":/usr/local/bin

  • for other shells like tcsh use:

       setenv PATH "$PATH":/usr/local/bin

    If you want to use FPC and its tools quite often from the command line then you might want to add the above path settings either to your .bashrc or .tcshrc file in order to make it permanent.

  • Build and install the compiler with the following command sequence:

       cd fpc
       make all
       sudo make install

    Please note: this will overwrite your old version of fpc with the just generated new one. Finally, clean up - after this you may go and test the new compiler with Xcode.

       make clean

  • CVS updates for Free Pascal can later be obtained by issuing following commands in Terminal. If you did not add the path to the FPC binaries permanently in your .bashrc or .tcshrc file then set it first, for bash use:

       export PATH="$PATH":/usr/local/bin

    or for tcsh use:

       setenv PATH "$PATH":/usr/local/bin

       cd ~/Developer/fpc
       make clean
       cvs -z 3 update -Pd
       make all
       sudo make install
       make clean

  • Frequently FPC happens to make a version jump. E.g. the current snapshot is version 2.0.0 while the CVS version is already at 2.0.1. In order to tell fpc to use the latest version you have to manually set a symbolic link in /usr/local/bin to it.
    (please, replace
    x and y by the appropriate digits!):

       cd /usr/local/bin
       sudo ln -sf /usr/local/lib/fpc/2.x.y/ppcppc ppcppc

    If you have problems with the new version, then you can switch back by changing back the symbolic link to some older version which resides in your /usr/local/lib/fpc directory



Appendix B:  Author

Dr. Rolf Jansen
Stephanienstra§e 19
D-76133 Karlsruhe

RJ at



Appendix C:  Copyright Notice and Terms of Use

Provided you agree to be bound by the following terms of use, the author Dr. Rolf Jansen claims NO copyright for the Free Pascal For Xcode Integration Kit and the information provided on this web page. This means it is Public Domain to all intelligent beings in the entire universe.

The terms of use are: Use it at your own risk.
This means, the author Dr. Rolf Jansen cannot be held responsible for anything resulting from using the Free Pascal For Xcode Integration Kit and the information provided on this web page.