/etc/portage/bashrc

Synopsis
This is a global similar to the  files under, except always sourced for every package. It can either be used to setup a global environment common to all ebuilds, or as an alternative to the files allowing you to handle all the necessary conditional code manually.

Gotchas

 * It is important to note that this file will be sourced multiple times during the build, at least once per phase plus several other times. You must therefore control when your code is executed using e.g.,   (EAPI 5), or otherwise avoid using the global scope by only putting code into hook functions (e.g.  ). See bug 250240. It is especially important to restrict this in order to avoid unintentionally clobbering changes made throughout the ebuild. For example, if flag-o-matic code for a specific ebuild would normally overwrite default CFLAGS you've set, you wouldn't want to blindly squash those by repeatedly resetting them with each phase function (except on a per-package basis, when you know what you're doing).


 * The global isn't sourced for the first time until after dependency resolution. If run with ,  is sourced for the first time shortly after interactive confirmation. Therefore, it isn't a complete replacement for the global . Anything that must be in the environment immediately can't be set by  such as USE flags, FEATURES, etc. The portage documentation doesn't provide a complete list of contradictions, so be careful.


 * Portage doesn't save the initial environment prior to being mangled by Portage's global and . You therefore have no direct way of determining whether an environment variable was supplied by the user (e.g. CFLAGS), or set by portage, so you can't guarantee using the environment by your  to control behavior.

Example
This is an example global that acts as a minimal loader for user-defined hooks. There are many other good examples out there. It is primarily for setting up CFLAGS and to further define hook functions on a per-package basis. You define "flag groups" by adding to the  2D associative array within the   function. Calling this function with an array name and list of group names will create an associative array whose keys are set to the union of the flags in the given groups. You can then manipulate that array per-package by defining hook functions whose names are defined in the  array of the   function.