Building a library in Universal Binary format

The Apple Inc. put nice documents on building a Unix program as a Universal Binary format.

The 1st one is for Unix geek, while the 2nd one is for IDE addicts.
Each has its own pros and cons.
    The 1st one doesn’t require a project to be converted. However, it is pretty hard to figure out what is going on and what started being wrong. Things are scrolled up and text is written in the screen without any indentation or separation based on context.
    The 2nd one, on the other hand, uses the Xcode to compile. However, the Xcode just works as a shell to the configure script. You are making just a dummy project in which a script to invoke ./configure is in. What is more important aspect fundamentally here is that the 1st approach tries compile the source codes in one step. In its CFLAGS and LDFLAGS, you issue -arch ppc -arch i386. So, the gcc compiles source codes in combination of the two. And you don’t need a “merge” stage. However, the 2nd approach let the gcc compile and link the sources and the objects files for each architecture. You need to invoke the lipo to tie the two generated library or executable. 
Which one do you like more? Well..as for the lipo approach, you can do it in the console also. So, you need to choose one according to convenience of building. Yeah.. the 1st approach seems to be easier. However, some open source projects cannot be built by the 1st approach. For example, the postgreSQL can’t be built by the 1st approach. It fails in compiling. I don’t know why. But somewhere I heard that they way the gcc optimize codes is different for the two approach.
    There is the 3rd one. It requires you some time to reorganize the source code structure or directory structure. (Not necessarily) So, you need to understand each and every configure script and Makefile contents. What you do here is to make a genuine Xcode project. Once things are done, it is much trouble-free than the 1st and the 2nd approach, because information is located where it can be easily found, like the property of projects, etc. Some people don’t like IDE-centric approach like this 3rd one. They usually say that it is inconvenient for batch-building. Well… not true. You can issue build command in a console window without running the Xcode.
OK, so far we thought about 3 ways of building very Unix-like project.
Now, I would like to fix something described in the Apple document.
For the 1st document mentioned above, there is something wrong for Leopard-era.

env CFLAGS=”-O -g -isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch i386 -arch ppc” \
LDFLAGS=”-arch i386 -arch ppc” ./configure –prefix=${HOME}/Hello –disable-dependency-tracking

    You need to add -mmacosx-version-min=10.4, for example to the CFLAGS. On Leopard Intel Mac, the resultant binary size is very different from the case without the option, although the source code doesn’t use any Cocoa/Carbon framework. In default, the 10.5 leopard gcc seems to strip codes more aggressively. So, for some static functions, they can be removed although they are actually used.   Another thing I would like to mention is the -isysroot /Developer/SDKs/MacOSX10.4u.sdk.
What the option means is that it will use the 10.4 universal SDK. It is very important to determine what version of the MacOS X is targetted. Even when the open source project doesn’t use any Cocoa functions, it is better to include that option. You can easily see that the file size is different between the two cases with and without the option.    

As a closure, I would like to mention that the 10.4u SDK seems to be different on PPC mac and Intel Mac. Although they are all 10.4u SDK, the result of compilation seems to be different. the one distributed with/for  Intel Mac doesn’t seem to be correct sometimes. I need to confirm this.

 

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: