Important: You are required to change your passwords used for Gentoo services and set an email address for your Wiki account if you haven't done so. See the full announcement and Wiki email policy change for more information.

Knowledge Base:Overriding environment variables per package

From Gentoo Wiki
Jump to: navigation, search

Synopsis

The default environment variables during package builds are declared in /etc/portage/make.conf, but sometimes you want to override a particular variable (like CFLAGS or PORTAGE_TMPDIR) for a single package.

Environment

This article is applicable to all Gentoo Linux installations.

Analysis

Portage supports per-package environment settings through /etc/portage/package.env and the /etc/portage/env subdirectories.

  • Inside the /etc/portage/env directory, you create files that have the same syntax as make.conf and give it a sensible name. The filename will be used as the key to override settings.
  • Inside the /etc/portage/package.env file, you tell which of these files will be used on a per-package basis

Resolution

First, create the /etc/portage/env directory structure. This one will host the files that contain the variable declarations we want to use:

root # mkdir -p /etc/portage/env

Next, create the file(s) needed to override the settings. For instance, assume we need two specific overrides: one is for a package where we want to tweak the CFLAGS and FEATURES resulting in debug symbols to be built and the second one we want to update PORTAGE_TMPDIR as the package has a huge build storage requirement.

root # echo 'CFLAGS="-O2 -ggdb -pipe"' > /etc/portage/env/debug-cflags
root #
echo 'FEATURES="${FEATURES} nostrip"' >> /etc/portage/env/debug-cflags
root #
echo 'PORTAGE_TMPDIR="/home/build/tmp"' > /etc/portage/env/large-tmpdir

Finally, create or edit /etc/portage/package.env and point towards these override files for the specific packages:

File/etc/portage/package.envOverriding environment variables per package

media-video/mplayer debug-cflags
app-office/libreoffice large-tmpdir

Further Resources