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!

**
READ THIS FIRST **

Introduction

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.

Requirements

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

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.

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

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:

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:

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:

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»;
var
i : integer;

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

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:

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 :pserver:cvs@cvs.freepascal.org:/FPC/CVS login

The CVS server should answer
with:

(Logging
in to cvs@cvs.freepascal.org)
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 :pserver:cvs@cvs.freepascal.org:/FPC/CVS 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

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.