The /etc/portage/bashrc file is a global bashrc file referenced by Portage. It is similar to the bashrc files under /etc/portage/env/, 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 /etc/portage/env files allowing Portage administrators to handle all the necessary conditional code manually.
- 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. EBUILD_PHASE, EBUILD_PHASE_FUNC (EAPI 5), or otherwise avoid using the global scope by only putting code into hook functions (e.g.
pre_pkg_setup()). 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 bashrc isn't sourced for the first time until after dependency resolution. If run with
--ask, bashrc is sourced for the first time shortly after interactive confirmation. Therefore, it isn't a complete replacement for the global make.conf. Anything that must be in the environment immediately can't be set by bashrc 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 make.defaults and make.globals. 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 bashrc to control behavior.
- Handbook:X86/Portage/Advanced#Using /etc/portage/bashrc and affiliated files
- /etc/portage — the primary configuration directory for Portage, Gentoo's package manager.
- /etc/portage/patches — provide a way for users to apply patches to package source code
- Portage Manpage
- Knowledge Base:Overriding environment variables per package