Sign in Join
Wiki copytemporary

Target MacOS: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
11*(Mac OS Classic only)*
22
33*MacOS* is the target for Mac OS Classic, i.e. the predecessor to macOS. macOS itself was previously marketed as Mac OS X and OS X. For macOS, see [[Target Darwin]].
44
55## Compiling in MPW
66
77Free Pascal can now be used in the [[MPW]] development environment.
88
99Free Pascal for MPW call assembler and linker via ToolServer. This means that you need ToolServer installed. This will normally not be an issue, since ToolServer is included in the MPW distribution.
1010
1111In rare instances, you might get the error message "Can't call the assembler, switching to external assembler." I do not know the origin of this, but it will help to restart. On Mac OS X you might need to restart even OSX. It might also indicate that you need to increase the memory setting for ToolServer.
1212
1313Another workaround for such problems is to let the compiler write out an MPW script (option -s). This will assemble and link when executed in MPW. This method can also be used if the compiler is to be called from a third program, to overcome the deadlock situation mentioned below under Dos.Exec.
1414
1515For crosscompiling e.g. from macOS to Mac OS Classic, see below.
1616
1717## Some tips
1818
1919### Choosing apptype
2020
2121For casual users, copying Pascal text only programs from a book, `{$APPTYPE CONSOLE}` is appropriate.
2222
2323If you want an MPW tool, use `{$APPTYPE TOOL}`.
2424
2525For maximum portability, the following:
2626
27-` {$IFDEF MACOS}`\
28-`   {$APPTYPE TOOL}`\
29-` {$ELSE}`\
30-`   {$APPTYPE CONSOLE}`\
31-` {$ENDIF}`
27+```text
28+ {$IFDEF MACOS}
29+ {$APPTYPE TOOL}
30+ {$ELSE}
31+ {$APPTYPE CONSOLE}
32+ {$ENDIF}
33+```
3234
3335... ensures it will be an MPW tool on Mac OS, and a console application in Delphi where {\$APPTYPE TOOL} is not recognized.
3436
3537### Resources
3638
3739Since 24-01-2004 mac style resources can be included with `{$R <resfile>}`. If the resource file ends with .r it is considered a Rez type resource file (in text form). For all other files (including .rsrc), binary resources are assumed. Several resource files can be included.
3840
3941### Error messages
4042
4143Errors, warnings, hints and other messages written by the compiler are in MPW format - that is you can execute them and the error location will be displayed.
4244
4345### Dos.Exec
4446
4547The procedure Dos.Exec is used to execute other programs. In MacOS this is supported, and the program(s?) which can be executed is MPW tools. An AppleEvent is sent to ToolServer which in turn executes the tool. A limitation is that ToolServer is not reentrant, so if a program which is called via Dos.Exec, in turn call Dos.Exec, it will be deadlocked.
4648
4749### Assembler symbols
4850
4951Internal symbols in the generated assembler files will have a lowercase "s" as part separator instead of "\$". The reason is that PPCAsm does not support \$.
5052
5153### QuickDraw globals
5254
5355There is a variable **qd** defined in System.pp for use as the QuickDraw global.
5456
5557For `{$APPTYE TOOL}` and `{$APPTYPE CONSOLE}` it is initialized, but for `{$APPTYPE GUI}` you have to initialize it yourself.
5658
5759## Debugging
5860
5961See [[MPW debugging]]
6062
6163## Global variables
6264
6365Currently all global variables are indirect, i.e. the entry in the TOC is always a pointer to data. (In the future small data items may be stored directly in the TOC)
6466
6567Thus all references to globals are via a construct like: `lwz rX, yyy[TC](r2) ;loads a pointer to a global into rX`
6668
6769## Cross compiling from Mac OS X to Mac OS
6870
6971Although not necessary nowadays when there exists a native compiler for target MacOS, here is some info on how to cross compile. See also [[Link on target]].
7072
7173### Crosscompiling step on macOS
7274
7375When compiling, add these options:
7476
75-` -Tmacos # target macos`\
76-` -st     # do not generate executable, link on target`
77+```text
78+ -Tmacos # target macos
79+ -st # do not generate executable, link on target
80+```
7781
7882If make is used, add `OPT=-st OS_TARGET=macos`
7983
8084Note that one must first build the RTL by issuing `make` in rtl/macos, with the above options, to be able to build other programs. The RTL must then be assembled and linked (see below) before compiling any program, otherwise the search paths in the link script will not be correct.
8185
8286You might also want to add option -a, then the link script will not delete unneeded files, in particular the assembler files (*.s). This can be useful if there are problems with the link scripts and you want to rerun it.
8387
8488### Assembling and linking step on Mac OS Classic
8589
8690In case that host and target machine is different, transfer the produced files (assembler files (*.s) and link script *_ppas) to the host.
8791
8892In Mac OS Classic, use MPW to assemble and link the output from FreePascal by executing the link script (which is an MPW script), with its directory as current directory. Unfortunately the link script does not(?) obtain the proper mac file type, so this has to be fixed first e.g. with the MPW command SetFile.
8993
9094Example: To build Hello World (together with the rtl unit system.pp), execute:
9195
92-` Directory HD:Projekt:FreePascal:fpc:rtl:macos`\
93-` SetFile -c 'MPS ' -t 'TEXT' system_ppas`\
94-` system_ppas   #executes the script`\
95-` Directory HD:Projekt:FreePascal:fpc:demo:text`\
96-` SetFile -c 'MPS ' -t 'TEXT' hello_ppas`\
97-` hello_ppas    #executes the script`
96+```text
97+ Directory HD:Projekt:FreePascal:fpc:rtl:macos
98+ SetFile -c 'MPS ' -t 'TEXT' system_ppas
99+ system_ppas #executes the script
100+ Directory HD:Projekt:FreePascal:fpc:demo:text
101+ SetFile -c 'MPS ' -t 'TEXT' hello_ppas
102+ hello_ppas #executes the script
103+```
98104
99105------------------------------------------------------------------------
100106
101107*Above circa 2004/5.*
102108
103109### Working notes: situation as of late 2012
104110
105111The objective here is to build PPC and possibly 68K compilers, first as cross-compilers to run on a PC and then to run natively on Mac OS 9. Part of the incentive for this is to investigate whether a PPC Mac, e.g. my (MarkMLl) G3 beige with "Old World" ROMs, is a usable testbed for the fixed 68K compiler which Sven has added to trunk at around 2.8.
106112
107113On e.g. Debian Linux, build and install cross-binutils:
108114
109-`tar xjf binutils-2.20.1.tar.bz2`\
110-`cd binutils-2.20.1`\
111-`./configure --prefix=/usr/local/powerpc-linux powerpc-linux-gnu`\
112-`make`\
113-`sudo make install`\
114-`sudo ln -s /usr/local/powerpc-linux/bin/as /usr/local/bin/powerpc-linux-as`\
115-`sudo ln -s /usr/local/powerpc-linux/bin/ld /usr/local/bin/powerpc-linux-ld`\
116-`sudo ln -s /usr/local/powerpc-linux/bin/ar /usr/local/bin/powerpc-linux-ar`\
117-`sudo ln -s /usr/local/powerpc-linux/bin/objdump /usr/local/bin/powerpc-linux-objdump`\
118-`sudo ln -s /usr/local/powerpc-linux/bin/objcopy /usr/local/bin/powerpc-linux-objcopy`\
119-`sudo ln -s /usr/local/powerpc-linux/bin/strip /usr/local/bin/powerpc-linux-strip`\
120-`powerpc-linux-ld -V`
115+```text
116+tar xjf binutils-2.20.1.tar.bz2
117+cd binutils-2.20.1
118+./configure --prefix=/usr/local/powerpc-linux powerpc-linux-gnu
119+make
120+sudo make install
121+sudo ln -s /usr/local/powerpc-linux/bin/as /usr/local/bin/powerpc-linux-as
122+sudo ln -s /usr/local/powerpc-linux/bin/ld /usr/local/bin/powerpc-linux-ld
123+sudo ln -s /usr/local/powerpc-linux/bin/ar /usr/local/bin/powerpc-linux-ar
124+sudo ln -s /usr/local/powerpc-linux/bin/objdump /usr/local/bin/powerpc-linux-objdump
125+sudo ln -s /usr/local/powerpc-linux/bin/objcopy /usr/local/bin/powerpc-linux-objcopy
126+sudo ln -s /usr/local/powerpc-linux/bin/strip /usr/local/bin/powerpc-linux-strip
127+powerpc-linux-ld -V
128+```
121129
122130Do the same for m68k-linux-gnu.
123131
124132Build a cross-compiler to run on a PC but targeting PPC:
125133
126-`cd /usr/local/src/fpc/fpc-trunk`\
127-`export PP=`\
128-`make "OPT=-O- -g" -C compiler powerpc`\
129-`mv compiler/ppcppc compiler/ppcXppc`
134+```text
135+cd /usr/local/src/fpc/fpc-trunk
136+export PP=
137+make "OPT=-O- -g" -C compiler powerpc
138+mv compiler/ppcppc compiler/ppcXppc
139+```
130140
131141Renaming the compiler prevents it from being deleted by make clean etc., consider extending that OPT setting with -dEXTDEBUG.
132142
133143Build a native RTL and compiler:
134144
135-`export PP=/usr/local/src/fpc/fpc-trunk/compiler/ppcXppc`\
136-`make CPU_TARGET=powerpc OS_TARGET=macos "CROSSOPT=-st" rtl`\
137-`make CPU_TARGET=powerpc OS_TARGET=macos "CROSSOPT=-st" compiler`
145+```text
146+export PP=/usr/local/src/fpc/fpc-trunk/compiler/ppcXppc
147+make CPU_TARGET=powerpc OS_TARGET=macos "CROSSOPT=-st" rtl
148+make CPU_TARGET=powerpc OS_TARGET=macos "CROSSOPT=-st" compiler
149+```
138150
139151Bringing macos/sysdir.inc up to date shows that the amiga, embedded, watcom and symbian OS targets are similarly falling behind. It's instructive to compare the amiga target (which has not been updated) with the morphos target (which has).
140152
141153There's also a problem inside the compiler itself where entries of type AT_NONE are being generated but not handled.
142154
143155To be continued.
144156
145157---
146158*From the Free Pascal wiki, page "Target MacOS", as it stood on 2019-12-16 after a change by FTurtle, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*

Back to history