[fpc-pascal] troubles adding a second target
Jonas Maebe
jonas.maebe at elis.ugent.be
Sat Feb 7 11:19:49 CET 2009
On 07 Feb 2009, at 09:20, Ken G. Brown wrote:
> MacOS X 10.5.6, fpc 2.2.2, Xcode 3.1.2
>
> I have a working project started from the fpc supplied template.
>
> I've tried to add a second target for testing which is more or less
> a copy of the first, although the source code has been duplicated
> and renamed and located in a subfolder of the project folder.
>
> I added a carbon application target since there was no Pascal
> option in the Add Target function.
That's correct. The only way to compile Pascal code in Xcode is by
setting up everything manually. I don't know what you want to build in
this extra target, so I cannot say whether "application" is
appropriate or not.
> I made sure that the membership checkboxes were only including the
> new source files in the new target.
>
> At first I got errors that there was no build rule for the new
> source. So I added a rule for Pascal Source Files with custom script
> by analogy from the working target.
> There was nothing to be seen in the custom script text box in the
> rule from the working target, and I added a copy of what was in the
> 'with output files:' text box
> $(DERIVED_SOURCES_DIR)-$(CURRENT_VARIANT)/$(CURRENT_ARCH)/$
> (INPUT_FILE_BASE).s
>
> Now when I try to build the new target, I get the following error:
> /bin/sh -c
> /bin/sh: -c: option requires an argument
>
> Where does the custom script have to be set up? How does this work?
It is not trivial. The way it works with a single program target is
that the "fpc" target compiles all Pascal code to assembler code. It
knows which source file to compile because there is a Project setting
called "FPC_MAIN_FILE" that points to the main Pascal program file.
The "fpc" target points the compiler to this file, and the compiler
then automatically compiles this file and all units used by it.
The program target is dependent on this fpc target (this is done by
dragging the "fpc" target on top of the program target), so the fpc
target is executed first by Xcode. The program target itself then
assembles the generated assembler files (the .../$(INPUT_FILE_BASE).s
files mentioned above) into object code. Together with the libfpc.a
library, also generated by the fpc target and added to the "Link
Binary with Libraries" phase of the program target, the Pascal code is
linked into the program by Xcode.
If you add a new target which should compile different Pascal sources,
the problem is you either have to
a) add a duplicate fpc target which uses FPC_MAIN_FILE2 or so
(requires changing the "Compile Pascal Sources" script phase of that
target, replacing all occurrences of FPC_MAIN_FILE with
FPC_MAIN_FILE2), add an FPC_MAIN_FILE2 setting to your project
settings pointing to the main file for this new program, and make your
new program target dependent on this duplicated fpc target
b) make the new program target dependent on the original "fpc" target,
but change the project's FPC_MAIN_FILE setting every time you switch
targets.
All in all, it's probably easier to simply use separate projects
(unless there is a more convenient option I didn't think of).
Jonas
More information about the fpc-pascal
mailing list