While searching for a solution how to define per-package CFLAGS and sifting through various postings on that issue, I noticed that a simple solution to the problem seems already to be built into Portage.
And it works right out of the box, without adding any custom scripts to /etc/portage/bashrc!
Well, at least it does in the 2006.1 profile, because the feature is actually a part of the profile, not of Portage itself.
But there are good chances it might work for older profiles as well, because the feature is part of the base profile, which all other profiles are based upon.
I found the feature when examining the files in the various profile directories, where I encountered the file
/usr/portage/profiles/base/profile.bashrc
which obviously sources script files from
/etc/portage/env/category/package
For instance, when I added a file /etc/portage/env/app-text/unix2dos
containing the line
Code: Select all
CFLAGS="-Werror"So, if you want to use different CFLAG/CXXFLAGS/FEATURES (or other variables set in /etc/make.conf) for a specific package, create a text file
/etc/portage/env/category/package
and add your overrides in exactly the same way you would otherwise do in the command line manually.
For instance, instead of doing a
Code: Select all
CFLAGS="-O3" emerge --oneshot gcccontaining the line
Code: Select all
CFLAGS="-O3"Code: Select all
emerge --oneshot gccThe next I will try to do is creating symlinks instead of real files in /etc/portage/env.
This should allow me to share a single file with non-standard stronger optimizations settings in the /etc/portage/env subdirectories without a need to copy the same file into several subdirectories.
It will also be easier to modify the settings if they are stored only in a single place.
I will thus create only a single physical settings file for each group of related options (one file for stronger optimization, another one for buggy packages to be compiled with FEATURES="nostrip", etc), and refer to them only via symlinks from within /etc/portage/env.
Has anyone else already found and used that obviously undocumented system profile feature?
I would really like to learn of any experiences, potential drawbacks, and generally the opinons of others before I make heavy use of this /etc/portage/env feature in my live system!
Anyway, it looks quite promising so far.
What I still have to find out is whether the per-package variables set that way are additive, or whether they replace the default values from the current profile or /etc/make.conf.
UPDATE: I have now written a minimalist ebuild for testing the behaviour when specifying flags in /etc/portage/env.
The result is: The settings in the /etc/portage/env files completely replace all settings from the matching variables in /etc/make.conf.
However, at the time when the /etc/portage/env files are called (are sourced as shell scripts), the /etc/make.conf settings are already available in the respective environment variables.
Which means you can use code like
Code: Select all
CFLAGS="$CFLAGS -O3"
CXXFLAGS="$CXXFLAGS -O3"
Alternatively, all the power of the shell's scripting language can be unleashed to filter out / replace unwanted flags from the original /etc/make.conf settings.
Or, just choke on the /etc/make.conf settings and simply specify all the CFLAGS/CXXFLAGS you want to use, completely replacing the /etc/make.conf settings.








