It seems to me that the ideal flag to be using in CFLAGS for Gentoo on OSX is Apple's -fast flag. Basically, this switch turns on a boatload of optimizations with the intention of produced the fastest code possible. There is, however, one problem: The -fast flag turns on -mdynamic-no-pic by default. This means that the code generated can't be used in a shared library. The fix for this is to combine -fast with -fPIC (a platform-independent GCC flag meaning "generate Position Independent Code). However, you ideally want to only use -fPIC when you really need it, since there can be as much as a 5% speed hit when it's on.

At first glance, it seems like this is an easy problem to solve since several common platforms (including x86 Linux!) require -fPIC for shared code, and therefore, most Makefiles have the logic to deal with building dynamic and static objects separately with different flag settings. However, my investigations show that the standard gnu config scripts special-case Mac OS X and do NOT use -fPIC for dynamic objects since, in the absence of the -fast flag, -fPIC is on by default. So, there are probably hundreds of packages which specifically avoid using -fPIC on OS X...

My first thought was just to create patches for each of these packages, but this gets out of hand VERY quickly, the aforementioned GNU config files are very hairy and hand creating each patch could be a WHOLE lot of work.

One thing has occurred to me, however. The basic structure of all of those config files is about the same; in fact, the lines that need to be changed are very nearly identical. It should be possible -- indeed easy -- to create a script that would be invoked during unpacking that would look for those lines in config* files and update them appropriately.

Note that there are several lines like this in each configure file, and in many packages (gettext is one) there are multiple configure scripts. In fact, gettext alone has 44 instances where the change is required!

Joined: 04 Sep 2002Posts: 287Location: where the hell is Tesuque, New Mexico?

Posted: Fri May 13, 2005 11:02 pm Post subject:

Excellent post!

Just a comment: I've been using

Code:

CFLAGS="-fast -mcpu=7450 -fPIC -pipe"

for a long time... some basic things break, and when they fail to compile, they break in very odd ways (the compiler error message is NOT a readable, "Please don't use -fast", but instead is something in martian like ".__DATA linkage cruft").

As I'm typing this, gnupg failed to build because of -fast; use -O2 for that one!