Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Compile universal binaries by default UNIX
NOTE: this hint was developed under XCode2.4 and Mac OS X 10.4.8, it probably won't work on pre-Tiger systems.

We just got some MacBook Pros, and our lab is now mixed PPC and i386. We rely on a number of command line programs developed over the years and ported from various BSD-flavored systems. We decided to convert all these programs and libraries to universal binaries so that all the systems can copy them from a single installed prototype. However, the process of converting bunches of makefiles to universal binaries seemed to be kind of a pain, so I wrote a simple program to convert cc(1) to produce them by default. The source can be downloaded here.

This tiny program works by inserting three critical arguments into a standard cc command and then calling gcc with the revised argument vector. It is installed as a separate command called ccub, and optionally it can replace cc so that universal binaries are the default. There's more explanation in the tarball.

[kirkmc adds: Not tested.]
    •    
  • Currently 2.00 / 5
  You rated: 1 / 5 (4 votes cast)
 
[10,343 views]  

Compile universal binaries by default | 8 comments | Create New Account
Click here to return to the 'Compile universal binaries by default' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Compile universal binaries by default
Authored by: kyngchaos on Oct 31, '06 08:23:11AM

Now there's a cool idea! And it gets around the problem of libtool dropping the universal flags unless they are prefixed by -Xlinker or -Xcompiler, and depending on the version of libtool used, since this trick happens after libtool has mangled the cc command.

Note - it probably could have been done just as easily by a shell script, so there would nothing to compile. I might try that, but I'm not very good at shell scripting.



[ Reply to This | # ]
Compile universal binaries by default
Authored by: wgscott on Oct 31, '06 10:12:32AM

It appears to work.

Any chance of this for g++ and gfortran?



[ Reply to This | # ]
c++
Authored by: gshenaut on Nov 01, '06 07:10:04AM

OK, I set it up to do the same thing to c++, and there is also an "install-as-c++" option. It's in the new version of ccub.tgz.

However, I actually don't use c++, and so it's been tested extremely lightly.

As for gfortran, I don't even have that installed on my system. But if the compiler works the same as gcc, it should be easy to add the capability in the same way I added c++. You may have to think about whether to install links, like fortran/gfortran pointing to gfortran-4.0 (maybe that's how they install it already?). If this is done, and if the compiler's command line is the same, then it should be simple to add fortran. Otherwise, it might take a bit more work.

Greg Shenaut



[ Reply to This | # ]
c++
Authored by: wgscott on Nov 01, '06 05:58:31PM

I'll give it a try, but I won't have time for a few days.

For what it is worth, I did my own install and just installed using the real name into /usr/local/bin.

Then if I specify CC=ccub make, most Makefiles do the right thing.

One of the reasons is that this will wreak havok on programs that expect the normal cc, such as fink (and I assume darwinports).

The other thing one rapidly runs into is linking against libraries that are platform-specific. There is a lot of opportunity for pain, which is why fink (and I assume darwinports) made the decision not to do the universal binary thing.

Anyway, thanks for doing this.



[ Reply to This | # ]
Compile universal binaries by default
Authored by: aardvarko on Oct 31, '06 12:09:15PM

Mind that "make install-as-cc" deletes /usr/bin/cc rather than, say, moving it to /usr/bin/cc-old.



[ Reply to This | # ]
Compile universal binaries by default
Authored by: gshenaut on Oct 31, '06 06:41:31PM

/usr/bin/cc is a symlink that points to the same compiler (e.g., gcc-4.0) that /usr/bin/gcc points to, so I didn't see the point of cluttering up /usr/bin with a "cc-old" symlink. But perhaps it should have been an option.

Greg Shenaut



[ Reply to This | # ]
Compile universal binaries by default
Authored by: kyngchaos on Nov 01, '06 09:24:20AM

Another thought on the symlink install: don't mess with /usr/bin - Apple could break the custom symlink and you would have to redo it. instead, put it in /usr/local/bin (or your personal equivalent preference), and as long as /usr/local/bin is in your PATH before /usr/bin it will override the /usr/bin version.



[ Reply to This | # ]
kills informational flags
Authored by: kyngchaos on Nov 03, '06 05:41:40PM

Here's an odd one - a configure I found uses cc -dumpspecs to check for some features of the compiler. the dumpspecs flag doesn't work when the universal flags are added, all that's returned is null.

Maybe there are other informational flags that have the same problem?



[ Reply to This | # ]