Gentoo emerge a packet with a custom option passed to the configure

Gentoo is source based linux distro and each time we want to install a package in fact we compile it with the system program emerge. In most cases we have USE flags for everything we need about a package, but we can further pass custom options directly to the configure script of the package through the emerge program. Using this method we can tune more subtle the configuration stage of a package and still using the package manager of the system, which is always the preferred way!
For example we can install manually additional libraries in /usr/local/ or any other directory and we can use them passing the needed configuration to the configure script of the package. Let’s say we want to use a new feature of latest openssl library, but we do not want to install it globally and re-emerge everything linked to it, so we build it manually in a directory like /usr/local/openssl-1.1.1/ and we want to link our PHP against it, but the PHP is better to be installed by the emerge (the package manager), because it has many features like init script, global default path to configurations and so on. So we can execute the following command:

EXTRA_ECONF="--with-openssl-dir=/usr/local/openssl-1.1.1/" emerge -avt php

you can use EXTRA_ECONF=”” to include options, which do not have USE flags. However there is limitation, EXTRA_ECONF works only for autotools based ./configure scripts when the ebuild is using econf, so packets not using autotools ./configure scripts won’t include the extra options.
It is good practice to make persistent this configuration over builds, so we can use

/etc/portage/package.env

to save the configuration for future building of the package:

echo "EXTRA_ECONF=\"--with-openssl-dir=/usr/local/openssl-1.1.1/\"" > /etc/portage/env/php.conf
echo "dev-lang/php php.conf" > /etc/portage/package.env

Leave a Reply

Your email address will not be published. Required fields are marked *