Discussion:
Newbee - porting Windows & Unix code - where to start
(too old to reply)
Markus Zingg
2004-05-25 19:07:47 UTC
Permalink
Dear group

I do have a 20+ year backround in developping all kind of C software
on various platforms including Unixes and Windows. However, I now have
to port a little tool to the Macintosh world and so far never touched
a Mac. I do have a Ei-Mac (spelling?) with the bare OS9 installed at
hands. The tool which actually does some UDP network IO and should
prompt the user with some windows should run on Os9 and later (if this
is possible).

I do have the following questions:

- Which compiler / debuger etc. should I use? I'm on a tight budget
hence would prefer freeware. I don't need bells and whistles - just a
C compiler and debugger is fine. I don't mind GUI stuff though.

- Where should I start? Is there a tutorial that centers around
porting from other platforms to the Mac (i.e. compareing Win32 API
with mac or similar?) or any other good point to start? Here I would
prefer online sources but I'm willing to buy a book if needed.

- Is it possible at all to compile a program under OS9 which is
useable under OSX or do I have to compile for both OS's ?

- Is it possible to create a CD that will autoboot on Windows and
Macintoshes provided I put the propper executeable files on it or is
the CD format the Mac uses so totally differnt?

TIA

Markus
Reinder Verlinde
2004-05-25 20:20:46 UTC
Permalink
Post by Markus Zingg
I do have a 20+ year backround in developping all kind of C software
on various platforms including Unixes and Windows. However, I now have
to port a little tool to the Macintosh world and so far never touched
a Mac. I do have a Ei-Mac (spelling?)
I do have a Ei-Mac (spelling?)
It's either iMac or eMac. See store.apple.com
Post by Markus Zingg
with the bare OS9 installed at
hands. The tool which actually does some UDP network IO and should
prompt the user with some windows should run on Os9 and later (if this
is possible).
The first question you should consider is 'do I really need Mac OS 9
support?'. If you stick to Mac OS X you probably can leverage your
existing Unix knowledge. The learning curve for Mac OS 9 networking will
be a lot higher.
Post by Markus Zingg
- Which compiler / debuger etc. should I use?
Mac OS 9 has Macintosh Programmers Workshop (MPW)
<http://developer.apple.com/tools/mpw-tools/>. It has a Unix-inspired
command line, but be prepared for a learning curve.

As a assembly-level debugger, you can use MacsBug
<http://developer.apple.com/tools/debuggers/MacsBug/>

Mac OS X ships with gcc and gdb, and a free GUI
<http://developer.apple.com/tools/xcode/>
Post by Markus Zingg
- Where should I start? Is there a tutorial that centers around
porting from other platforms to the Mac (i.e. compareing Win32 API
with mac or similar?) or any other good point to start?
<http://developer.apple.com/referencelibrary/GettingStarted/GS_Porting/in
dex.html>
Post by Markus Zingg
- Is it possible at all to compile a program under OS9 which is
useable under OSX or do I have to compile for both OS's ?
It may be possible to create a 'Carbon' application under Mac OS 9 that
runs on both platforms, but I think you will want to develop under Mac
OS X (it has such things as protected memory and preemptive multitasking)
Post by Markus Zingg
- Is it possible to create a CD that will autoboot on Windows and
Macintoshes provided I put the propper executeable files on it or is
the CD format the Mac uses so totally differnt?
The Mac reads Windows CDs fine. I am not sure whether autorun still is
available on Mac OS X. It is a virus vector.

Reinder
Markus Zingg
2004-05-25 20:50:31 UTC
Permalink
Reinder,
Post by Reinder Verlinde
Post by Markus Zingg
I do have a Ei-Mac (spelling?)
It's either iMac or eMac. See store.apple.com
From visiting the store.apple.com it looks like an eMac. I don't have
it right here - hence could not check on the device. Thanks for the
pointer.
Post by Reinder Verlinde
Post by Markus Zingg
with the bare OS9 installed at
hands. The tool which actually does some UDP network IO and should
prompt the user with some windows should run on Os9 and later (if this
is possible).
The first question you should consider is 'do I really need Mac OS 9
support?'. If you stick to Mac OS X you probably can leverage your
existing Unix knowledge. The learning curve for Mac OS 9 networking will
be a lot higher.
Unfortunately OS 9 is an absolut requierement since marketing told
that our targeted audience is widely useing it. Can't judge wether
this is true or not but well, it's a requirement.

I was reading some of the docs that are online available about
networking under OS 9. I did not found the API to be so very odd.

It's probably important to understand that the software I have to port
is just an installation program to perform the initial networking
configuration of a device we manufacture and which is suposed to also
cooperate with Mac installations. The programm really mostly consist
of a welcome screen, a screen to choose the language and one to enter
IP configuration information for the device. Technically all it must
do is send and read some UDP packets to / from the deivice - really
noting fancy.
Post by Reinder Verlinde
Post by Markus Zingg
- Which compiler / debuger etc. should I use?
Mac OS 9 has Macintosh Programmers Workshop (MPW)
<http://developer.apple.com/tools/mpw-tools/>. It has a Unix-inspired
command line, but be prepared for a learning curve.
As a assembly-level debugger, you can use MacsBug
<http://developer.apple.com/tools/debuggers/MacsBug/>
Uhh - no C level debugger? Well, life is harsh sometimes :-)
Post by Reinder Verlinde
Mac OS X ships with gcc and gdb, and a free GUI
<http://developer.apple.com/tools/xcode/>
Post by Markus Zingg
- Where should I start? Is there a tutorial that centers around
porting from other platforms to the Mac (i.e. compareing Win32 API
with mac or similar?) or any other good point to start?
<http://developer.apple.com/referencelibrary/GettingStarted/GS_Porting/in
dex.html>
Post by Markus Zingg
- Is it possible at all to compile a program under OS9 which is
useable under OSX or do I have to compile for both OS's ?
It may be possible to create a 'Carbon' application under Mac OS 9 that
runs on both platforms, but I think you will want to develop under Mac
OS X (it has such things as protected memory and preemptive multitasking)
Could you elaborate on this carbon application thingy? Is this a
certain developement envireonement or just some conservative codeing
style etc? If it's the latter, how does low level network programing
fit into the picture? Or does OSX have some sort of sandbox/emulator
embedded that allows to run older app's in compatibilty mode or such?

The installation tool I have to write does not ask much in the area of
what OSX could offer, so I figure I will be much happier with code
that runs on both platforms unchanged. I'm therefore much more
interested in having a solution that runs on both platforms.
Post by Reinder Verlinde
Post by Markus Zingg
- Is it possible to create a CD that will autoboot on Windows and
Macintoshes provided I put the propper executeable files on it or is
the CD format the Mac uses so totally differnt?
The Mac reads Windows CDs fine. I am not sure whether autorun still is
available on Mac OS X. It is a virus vector.
ok

Markus
Reinder Verlinde
2004-05-25 23:09:10 UTC
Permalink
Post by Markus Zingg
From visiting the store.apple.com it looks like an eMac.
It might also be an older iMac, like this one
<http://applehistory.norhost.net/imac.html>
Post by Markus Zingg
Uhh - no C level debugger? Well, life is harsh sometimes :-)
Well, there are high-level debuggers, but I thought you need a low-level
one to debug networking stuff, and I am not sure whether Apple still has
a free high-level one (a quick check shows that there is one:
<http://developer.apple.com/tools/debuggers/PowerMacDebugger/>)
Post by Markus Zingg
Could you elaborate on this carbon application thingy?
Carbon is a set of APIs that is available both on Mac OS 9 and Mac OS X
(on Mac OS 9, you may need to ship an extension that implements some of
the APIs)
Post by Markus Zingg
how does low level network programing fit into the picture?
I don't know that much about that. On Mac OS 9, I would guess that you
need to look up 'Open Transport' on the Apple site
<http://developer.apple.com/macos/opentransport/>
Post by Markus Zingg
Or does OSX have some sort of sandbox/emulator
embedded that allows to run older app's in compatibilty mode or such?
It has such a thing, but it may not be installed. Even if it is
installed, users will not like it if your application uses it. It makes
your application look old, giving the impression that your hardware is
not well-supported (similar to the way seeing a Windows 3.1 file
selector in a modern Windows application does not increase one's trust
in an application)

Finally: I can't see how getting Mac OS 9 knowledge for this one
installer can be economical (for the Mac OS X part, one could argue that
getting to know Mac OS X is worth something, but investing time to get
to know development environments on Mac OS 9?). Have you considered
hiring somebody with Mac knowledge to do this? (and no, I am not
soliciting)

Reinder
Patrick Machielse
2004-05-26 10:49:42 UTC
Permalink
Post by Reinder Verlinde
Post by Markus Zingg
Could you elaborate on this carbon application thingy?
Carbon is a set of APIs that is available both on Mac OS 9 and Mac OS X
(on Mac OS 9, you may need to ship an extension that implements some of
the APIs)
To be precise, Carbon is a cleaned up version of the old Mac OS API's.
It was created to make it possible to migrate programs written for (say)
Mac OS 7 to Mac OS X. Carbon today is used for the bulk of commercial
software. Although Mac OS 9 has been decleared 'dead', the Carbon API's
are still very much alive. This means that nowadays you can develop
Carbon programs that are not compatible with OS 9. As long as you are
aware of this, this shouldn't be a limitation for your use though.

Have you (Markus) considered using Java? It is available on both OS 9
(1.1.8) and OS X (1.3+) I imagine at least the gui part would be easier
to program. Don't know how easy it would be to talk to you device, or
maybe you can just write a configuration file?

Patrick Machielse
Markus Zingg
2004-05-26 11:16:45 UTC
Permalink
Patrick,

Thanks for your reply.
Post by Patrick Machielse
To be precise, Carbon is a cleaned up version of the old Mac OS API's.
Any pointer to this specification / documentation?
Post by Patrick Machielse
It was created to make it possible to migrate programs written for (say)
Mac OS 7 to Mac OS X.
Does "migrate" mean recompiling sourcecode or is such software binary
compatible among mac os versions?
Post by Patrick Machielse
Carbon today is used for the bulk of commercial
software. Although Mac OS 9 has been decleared 'dead', the Carbon API's
are still very much alive. This means that nowadays you can develop
Carbon programs that are not compatible with OS 9. As long as you are
aware of this, this shouldn't be a limitation for your use though.
Have you (Markus) considered using Java?
Not yet, but now that you mention it I might take a closer look.
Post by Patrick Machielse
It is available on both OS 9
(1.1.8) and OS X (1.3+) I imagine at least the gui part would be easier
to program.
The key question here would be if java is installed and available by
default on all Macs.Our marketing really want a solution where the
installation CD can be inserted into the machine and the program start
up. (OK, if this should not work due to security limitations on say
OSX we could live with that cause the users obviousely would not
expect such behaviour and should be able to know how to start a
program off a CD)
Post by Patrick Machielse
Don't know how easy it would be to talk to you device, or
maybe you can just write a configuration file?
Configuration file is IMHO no option. This is not about installing a
driver or such. All networking protocols needed to use the device are
available to Mac Applications already. It's really just about
configureing the IP parameters of the device in a non DHCP scenario
wehre all of the network consists exclusively of macs (no Windows or
Linux PC's around or wanted). The program simply broadcasts some UDP
packets into the current network segment which are then echoed by the
device(s) and allow for the initial configuration. I doubth that
scripting of any sort could solve this (ok, I obviousely don't know
what's available to what level on a mac in this area) but it's
important to understand that the complete networking protocol to do
the configuratoin is finished and that the devices are in production
already. I.e. it's not an option to add any code on the device end.
That's really also not needed if I can handcraft a UDP packet on a mac
which seems to be possible.

Markus
David Phillip Oster
2004-05-26 16:22:31 UTC
Permalink
Post by Markus Zingg
Post by Patrick Machielse
To be precise, Carbon is a cleaned up version of the old Mac OS API's.
Any pointer to this specification / documentation?
<http://developer.apple.com/carbon/>

and

<http://developer.apple.com/documentation/Carbon/Carbon.html>
Post by Markus Zingg
Post by Patrick Machielse
It was created to make it possible to migrate programs written for (say)
Mac OS 7 to Mac OS X.
Does "migrate" mean recompiling sourcecode or is such software binary
compatible among mac os versions?
In 1984, Macs were introduced with files with resource forks.
Applications were files of type 'APPL', with a resource fork containing
'CODE' resources. Resource 'CODE' 0 held a segment descriptor table,
and resources 'CODE' 1..n held the executable code for the segments.
Operating system calls were accessed through Motorola TRAP instructions.

These TRAP instructions are specified in the .h files, for example if
you look in Quickdraw.h in the :Universal:Headers:CIncludes: folder,
you'll see stuff looking like:

void PaintRect(const Rect * r) ONEWORDINLINE(0xA8A2);

where ONEWORDINLINE is a macro, which, on a 68K compiler, tells the
compiler everything it needs to generate a call to the O.S.

In the '90s, when Apple switched to the PowerPC, they added PowerPC
executable code in PEF, the "Preferred Executable Format" for the
PowerPC architecture, defined by IBM, the source of the PowerPC chip.,
usually in the data fork, and if an application contained a 'cfrg' 0
resource, then PowerPC macs would use it to find the PowerPC executable
code, while 68k macs would continue to execute the 68k version of the
application. That way, you could have a single file that would appear as
an application in the Finder, and run correctly on either 68K or PowerPC
Macs. Applications that had both 68K and PowerPC code would get the
"native" one loaded on the specific Mac they were running on that time,
so would not just run on all Macs, but would run as fast as possible on
the current Mac, they were known as "fat" applications.

The switching was very fast, and the user could use a mix of 68k and
PowerPC programs seamlessly, without caring about which was which.

The PowerPC doesn't use a TRAP instruction to access the O.S., instead
it uses a scheme where you must link against a "stub library", and when
the user trys to run the program, the loader component of the operating
system matches the stub library with actual shared libraries that are
kept in the :System Folder:Extensions: folder. This is the DLL Hell
problem familiar to Windows users, saved only by the Mac's lack of a
fragile registry.

Apple also added the "Mixed Mode Manager", a convention for wrapping
function pointers that decorates them with info for how they should be
interpreted. Using the Mixed Mode Manager, PowerPC programs could call
68k plugins, and 68K programs could call PowerPC plugins, and each could
call callback routines in the other processor architecture. Different
linker formats were also supported, for example original 68k and also
CFM-68k.

Then some people who were unaware of Apple's history and traditions took
over, and instead of extending the mixed mode manager and the cfrg
system, and instead of continuing with the executable format that the
PowerPC was designed for, they switched to the one that happened to come
from GNU's gcc (Mach-O). They also usurped the names of all the O.S.
calls, now the programmer links with either InterfaceLib (old style
PowerPC) or CarbonLib (new style PowerPC) stub libraries, and if Carbon,
adds a 'carb' 0 resource. Now the loader loads against InterfaceLib or
CarbonLib, and you are up and running. What this means is you can't have
a single file that is recognized and run as a native application on all
Macs: if it has PowerPC code, and that code uses CarbonLib, then it
won't run on early PowerPC Macs that don't have the CarbonLib shared
library installed. (It was an optional component before OS 9.)

The Carbon API is available on OS X still, both as PEF and as Mach-O,
but new development is only present in the Mach-O version. You can,
with some pain in a Carbon PEF program, programmaticly load a Mach-O
shared library into RAM and extract function pointers from it, and with
some pain, pass a PEF callback to a Mach-O call and vice versa, but it
is painful.

Instead of seamlessly running earlier apps, OS X starts a slow classic
Mac emulator, which only runs if the user has the optional OS 9
installed. the emulator, called "Classic" takes about a minute to start,
so a Mac user usually says, "Oh, Shit" the first time he double clicks
on a classic app after booting his OS X machine.

There was a third-party post-linker for the Metrowerks C/C++ compiler
called FatCarbon that got around this problem, and let you build an app
that had two copies of your PowerPC code in it, one that linked with
InterfaceLib, and one with CarbonLib, and FatCarbon would arrange for
the CarbonLib version to be used if the shared library for CarbonLib was
actually present.

So, there we stand: classic 68K code resources, PowerPC in PEF format
linked against InterfaceLib, PowerPC in PEF format linked against
CarbonLib, PowerPC in Mach-O format, all generated from the same source
code, but you can't package all of them usefully into a single file that
will be recognized as an executable application on all Macs. What you
can do is: register your four-byte application signature on Apple's web
site (you should do this anyway), and make the document's icon look like
an app. The real apps would be buried in folder, automaticly launched
when you double click on the document (because the Finder has made an
appropriate desktop database on the partition that you cloned the CD
from.) that launches the appropiate app: bundled for OSX, otherwise
classic 68K code or InterfaceLib PowerPC PEF.

Hire an expert. Don't try to get all these details right on the first
Mac program you've ever written.
Patrick Machielse
2004-05-26 19:41:07 UTC
Permalink
Post by Markus Zingg
Post by Patrick Machielse
To be precise, Carbon is a cleaned up version of the old Mac OS API's.
Any pointer to this specification / documentation?
I don't have the exact url at hand, but <http://developer.apple.com>
should come close. The documentation on the site has improved vastly
over the last year. Be sure to sign on for a free 'online' membership to
Apple Developer Connection (ADC) so you can download the latest
software. Also check out the mailing lists for developers hosted by
Apple <http://search.lists.apple.com/>. Lots of smart people there...
Post by Markus Zingg
Post by Patrick Machielse
It was created to make it possible to migrate programs written for (say)
Mac OS 7 to Mac OS X.
Does "migrate" mean recompiling sourcecode or is such software binary
compatible among mac os versions?
If you compile on OS 9 you end up with a binary in the 'PEF' format.
This can be executed by both OS 9 and OS X systems. On OS X however you
can only compile to the newer Mach-O binary format, which cannot be
executed by OS 9 systems. If you want to create a single binary for Mac
OS 9 (aka 'Classic') and OS X you will have to compile on OS 9. (which
means you don't have to whorry about using new Carbon calls either)

(I'm not speaking from experience here, but this is how I 'remember'.
Please visit the Apple docs for the definitive answer)
Post by Markus Zingg
Post by Patrick Machielse
Have you (Markus) considered using Java?
Not yet, but now that you mention it I might take a closer look.
Maybe you can put the configuration code in a single, platform specific
C function you call using JNI. (again: no experience here ;-) )
Post by Markus Zingg
Post by Patrick Machielse
It is available on both OS 9 (1.1.8) and OS X (1.3+) I imagine at least
the gui part would be easier to program.
The key question here would be if java is installed and available by
default on all Macs. Our marketing really want a solution where the
installation CD can be inserted into the machine and the program start
up.
And rightly so! On OS X Java is _allways_ installed. On OS 9 you can opt
out of Java during the install, I think. But installing OS 9 is too long
ago for me, luckily! Apple does provide a JVM installer for OS 9 which
you can distribute with your product.

Good luck,

Patrick
Eric Albert
2004-05-27 05:55:20 UTC
Permalink
Post by Patrick Machielse
Post by Markus Zingg
Post by Patrick Machielse
Have you (Markus) considered using Java?
Not yet, but now that you mention it I might take a closer look.
Maybe you can put the configuration code in a single, platform specific
C function you call using JNI. (again: no experience here ;-) )
Or just write it all in Java if you can. :)
Post by Patrick Machielse
Post by Markus Zingg
Post by Patrick Machielse
It is available on both OS 9 (1.1.8) and OS X (1.3+) I imagine at least
the gui part would be easier to program.
The key question here would be if java is installed and available by
default on all Macs. Our marketing really want a solution where the
installation CD can be inserted into the machine and the program start
up.
And rightly so! On OS X Java is _allways_ installed. On OS 9 you can opt
out of Java during the install, I think. But installing OS 9 is too long
ago for me, luckily! Apple does provide a JVM installer for OS 9 which
you can distribute with your product.
Java is installed by default on Mac OS 9. You can opt out of it during
the install, but very, very few people did so. You had to dig through a
few levels of dialogs and controls to find the check box that let you
turn it off.

-Eric
--
Eric Albert ***@cs.stanford.edu
http://rescomp.stanford.edu/~ejalbert/
Toby Thain
2004-05-26 12:24:40 UTC
Permalink
Post by Reinder Verlinde
...
Post by Markus Zingg
- Is it possible at all to compile a program under OS9 which is
useable under OSX or do I have to compile for both OS's ?
It may be possible to create a 'Carbon' application under Mac OS 9 that
runs on both platforms
This is definitely possible if you confine yourself to the Carbon API.

T
Simon Slavin
2004-05-27 16:58:56 UTC
Permalink
On 25/05/2004, Markus Zingg wrote in message
Post by Markus Zingg
- Is it possible at all to compile a program under OS9 which is
useable under OSX or do I have to compile for both OS's ?
The difference between developing for OS 9 and developing for
OS X is like the difference between Windows 2.0 and Windows NT.
With your Unix background you'll find learning OS X very easy.
Learning OS 9 will be absolute hell and involve you learning all
sorts of obsolete APIs, and it will stop you using a lot of the
more cool functions of OS X.

I'd strongly suggest that you stick to OS X. If you do that,
you can use the very high-power free development tools which
come with OS X and give full access to all the necessary
documentation, libraries and compilers you need to develop
professional OS X applications.
Post by Markus Zingg
- Is it possible to create a CD that will autoboot on Windows and
Macintoshes provided I put the propper executeable files on it or is
the CD format the Mac uses so totally differnt?
There is no autoboot function for OS X. It would be too easy
to write a virus which exploited it. Macintosh users are clever
enough to start an application themselves when they want to.

Simon.
--
Using pre-release version of newsreader.
Please tell me if it does weird things.
Loading...