Setting MAKEFLAGS in Fink

From the Fink Wiki
Jump to: navigation, search


Building with multiple processors

Recent Apple computers come with multiple CPU cores which can greatly decrease the time it takes to build a package from source. Activating this ability in Fink can make managing large builds (think those that can last several hours) manageable.

For end users

Starting with fink-0.31.2, the fink tool now builds using multiple processors by default. Running fink configure will ask for the number of processors that fink can use during a build. No further actions are needed by end users.

Troubleshooting

If you run into a package that fails to build and suspect the failure is due to a multiprocessor build failure, run fink configure and set the number of available processors to 1 and try the build again. If it then succeeds, let the package maintainer know so that they can fix their package. You can restore the setting again by running fink configure once more.

For package maintainers

The number of processors (N) available to Fink will get set in the field MaxBuildJobs in /sw/etc/fink.conf. The value N is then appended to the variable MAKEFLAGS (as -jN) during CompileScript and TestScript. It is not appended during InstallScript.

The fink.conf setting can be overriden using the boolean field UseMaxBuildJobs in a .info file. When absent, empty, or set to 'true', fink will use as many processors as fink.conf declares. When set to 'false', -j1 will be added. For more information on the use of the UseMaxBuildJobs field, check the Packaging Reference.

Troubleshooting

Build failures can occur in some packages where the source is not able to deal with multithreaded compiling. This is often, but not always, manifested by an error about some file not being found. If your package fails this way, setting MaxBuildJobs: false is the quickest way to diagnose the problem. It should no longer be necessary to set MAKEFLAGS to enable or disable building with multiple processors (other normal uses of MAKEFLAGS are, of course, acceptable).

Passing Other Values to MAKEFLAGS

Dire Warnings

This section is not officially supported by Fink. If you run into any problems, make sure you first disable it before reporting any errors to maintainers or the mailing lists. Failure to do so will cause you to be shaved, covered in honey, and set upon by fire ants! Well, OK, perhaps that's a bit harsh. But really. Messing with system wide settings can make funny things happen. If it breaks in half, the only guarantee is that you get to keep both halves.

The examples below were originally created for parallel builds (see previous section), but can in theory can be amended for passing other values to MAKEFLAGS. The same caveats, disclaimers, etc. apply.

Getting Started

That said, it is technically possible to make use of distcc (or just multiple CPUs) when building packages from source in Fink, as long as the package(s) you're building support the MAKEFLAGS variable (anything that uses make, and possibly other things as well).

To do so, edit /sw/lib/perl5/Fink/PkgVersion.pm and look for the comment that says "# uncomment this to be able to use distcc -- not officially supported!" Uncomment the $defaults{'MAKEFLAGS'} line, and fink should no longer erase MAKEFLAGS from the build environment. Note that every time the fink package gets updated, you will have to do this again. You'll deal with it, I know you can. That's what you get for living on the bleeding edge.  ;)

Now, you'll have to make sure that MAKEFLAGS is actually *in* the environment. To do so, install the distcc-default package (you'll need the latest unstable version), and then edit the MAKEFLAGS= line in /sw/etc/distcc.conf as appropriate. Alternatively, if you don't care about distcc, you can make a /sw/etc/profile.d/localenvironment.sh file or similar, and set MAKEFLAGS in there.

When Issues Arise

The first thing to try is to just set MAKEFLAGS to "-j1" in your /sw/etc/distcc.conf or equivalent, and see if it builds. If it does, mail the maintainer for the package (fink info packagename) to add the following lines to his info file:

 NoSetMAKEFLAGS: true
 SetMAKEFLAGS: -j1

Many packages that I've personally had problems with build with that. You don't get a parallel build this way, but you also don't get a dead one.  :)

If you still have errors, try also setting CCACHE_CPP2=1. Some stuff bombs because it doesn't like the tricky way ccache runs things through the c preprocessor before getting passed on to the local gcc. In these cases you generally see an error about adding -fconstant-cfstrings to the command-line, or something similar. If that doesn't work, try setting DISTCC_HOSTS to an empty string.

 CompileScript: <<
   ./configure %c
   CCACHE_CPP2=1 make
 <<

...or...

 CompileScript: <<
   ./configure %c
   DISTCC_HOSTS='' MAKEFLAGS='-j1' make
 <<

That has fixed things in all cases where just MAKEFLAGS has not, other than the less obvious errors of builds completing, but missing files and such.

If you still have issues, you're on your own. See the top of this section.  ;)