<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE sections SYSTEM "/dtd/book.dtd">

<!-- The content of this document is licensed under the CC-BY-SA license -->
<!-- See http://creativecommons.org/licenses/by-sa/1.0 -->

<!-- $Header: /var/cvsroot/gentoo/xml/htdocs/doc/en/handbook/hb-working-use.xml,v 1.9 2004/03/01 05:43:42 swift Exp $ -->

<sections>
<section>
<title>What are USE-flags?</title>
<subsection>
<title>The ideas behind USE-flags</title>
<body>

<p>
When you are installing Gentoo (or any other distribution, or even operating
system for that matter) you make choices depending on the environment you are 
working with. A setup for a server differs from a setup for a workstation.
A gaming workstation differs from a 3D rendering workstation.
</p>

<p>
This is not only true for choosing what packages you want to install, but also
what features a certain package should support. If you don't need OpenGL, why
would you bother installing OpenGL and build OpenGL support in most of your
packages? If you don't want to use KDE, why would you bother compiling packages
with KDE-support if those packages work flawlessly without?
</p>

<p>
To help users in deciding what to install/activate and what not, we wanted the
user to specify his environment in an easy way. This forces the user into
deciding what he really wants and eases the process for Portage, our package 
managment system, to make useful decisions.
</p>

</body>
</subsection>
<subsection>
<title>Definition of a USE-flag</title>
<body>

<p>
Enter the USE-flags. Such a flag is a keyword that embodies support and
dependency-information for a certain concept. If you define a certain USE-flag, 
Portage will know that you want support for the chosen keyword. Of course
this also alters the dependency information for a package.
</p>

<p>
Let us take a look at a specific example: the <c>kde</c> keyword. If you do not
have this keyword in your <c>USE</c> variable, all packages that have
<e>optional</e> KDE support will be compiled <e>without</e> KDE support. All
packages that have an <e>optional</e> KDE dependency will be installed
<e>without</e> installing the KDE libraries (as dependency). If you have defined
the <c>kde</c> keyword, then those packages <e>will</e> be compiled with KDE
support, and the KDE libraries will be installed as dependency.
</p>

<p>
By correctly defining the keywords you will receive a system tailored
specifically to your needs.
</p>

</body>
</subsection>
<subsection>
<title>What USE-flags exist?</title>
<body>

<p>
There are two types of USE-flags: <e>global</e> and <e>local</e> USE-flags.
</p>

<ul>
  <li>
    A <e>global</e> USE-flag is used by several packages, system-wide. This is 
    what most people see as USE-flags.
  </li>
  <li>
    A <e>local</e> USE-flag is used by a single package to make package-specific
    decisions.
  </li>
</ul>

<p>
A list of available global USE-flags can be found <uri
link="/dyn/use-index.xml">online</uri> or locally in
<path>/usr/portage/profiles/use.desc</path>. A short (<e>very</e> incomplete)
snippet:
</p>

<pre caption="A short snippet of available USE-flags">
gtk     - Adds support for x11-libs/gtk+ (The GIMP Toolkit)
gtk2    - Use gtk+-2.0.0 over gtk+-1.2 in cases where a program supports both.
gtkhtml - Adds support for gnome-extra/gtkhtml
guile   - Adds support for dev-util/guile (interpreter for Scheme)
icc     - Use the Intel C++ Compiler if the package supports it
icc-pgo - Enable PGO data generation or use when use icc.
imap    - Adds support for IMAP
</pre>

</body>
</subsection>
</section>
<section>
<title>Using USE-flags</title>
<subsection>
<title>Declare permanent USE-flags</title>
<body>

<p>
In the hope you are convinced of the importance of USE-flags we will now inform
you how to declare USE-flags.
</p>

<p>
As previously mentioned, all USE-flags are declared inside the <c>USE</c>
variable. To make it easy for users to search and pick USE-flags, we already
provide a <e>default</e> USE setting. This setting is a collection of USE-flags
we think are commonly used by the Gentoo users. This default setting is declared
in the <path>/etc/make.profile/make.defaults</path> file. Let us take a look at
this default setting:
</p>

<pre caption="/etc/make.profile/make.defaults USE variable">
USE="x86 oss apm arts avi berkdb crypt cups encode foomaticdb gdbm gif gpm gtk 
     imlib jpeg kde gnome libg++ libwww mad mikmod motif mpeg ncurses nls 
     oggvorbis opengl pam pdflib png python qt quicktime readline sdl slang 
     spell ssl svga tcpd truetype X xml2 xmms xv zlib"
</pre>

<p>
As you can see, this variable already contains quite a lot of keywords. Do
<b>not</b> alter the <path>/etc/make.profile/make.defaults</path> file to tailor
the <c>USE</c> variable to your needs: changes in this file will be undone when
you update Portage!
</p>

<p>
To change this default setting, you need to add or remove keywords to the
<c>USE</c> variable. This is done globally by defining the <c>USE</c> variable 
in <path>/etc/make.conf</path>. In this variable you add the extra USE-flags you
require, or remove the USE-flags you don't want. This latter is done by
prefixing the keyword with the minus-sign ("-").
</p>

<p>
For instance, to remove support for KDE and QT but add support for ldap, the
following <c>USE</c> can be defined in <path>/etc/make.conf</path>:
</p>

<pre caption="An example USE setting in /etc/make.conf">
USE="-kde -qt ldap"
</pre>

</body>
</subsection>
<subsection>
<title>Declare temporary USE-flags</title>
<body>

<p>
Sometimes you want to set a certain USE-setting only once. Instead of editing
<path>/etc/make.conf</path> twice (to do and undo the USE-changes) you can just 
declare the USE-variable as environment variable.
</p>

<p>
As an example we will temporarily remove java from the USE-setting
during the installation of mozilla.
</p>

<note>
The <c>emerge</c> command will be discussed more thoroughly in <uri
link="?part=2&amp;chap=2">Portage and Software</uri>.
</note>

<pre caption="Using USE as evironment variable">
# <i>USE="-java" emerge mozilla</i>
</pre>

</body>
</subsection>
<subsection>
<title>Inheriting USE-flags</title>
<body>

<p>
Some packages don't only listen to USE-flags, but also provide USE-flags. When
you install such a package, the USE-flag they provide is added to your USE
setting. To view the list of packages that provide a USE-flag, check
<path>/etc/make.profile/use.defaults</path>:
</p>

<pre caption="A snippet from /etc/make.profile/use.defaults">
gnome           gnome-base/gnome
gtk             x11-libs/gtk+
qt              x11-libs/qt
kde             kde-base/kdebase
motif           x11-libs/openmotif
</pre>

</body>
</subsection>
<subsection>
<title>Precendence</title>
<body>

<p>
Of course there is a certain precendence on what setting has priority over the
USE setting. You don't want to declare <c>USE="-java"</c> only to see that
<c>java</c> is declared anyway. The precedence for the USE setting is, ordered
by priority (first has lowest priority):
</p>

<ol>
  <li>
    Default USE setting declared in <path>/etc/make.profile/make.defaults</path>
  </li>
  <li>
    Inherited USE setting if a package from
    <path>/etc/make.profile/use.defaults</path> is installed
  </li>
  <li>
    User-defined USE setting in <path>/etc/make.conf</path>
  </li>
  <li>
    User-defined USE setting as environment variable
  </li>
</ol>

<p>
To view the final <c>USE</c> setting as seen by Portage, run <c>emerge info</c>.
This will list all relevant variables (including the <c>USE</c> variable) with
the content used by Portage.
</p>

<pre caption="Running emerge info">
# <i>emerge info</i>
</pre>

</body>
</subsection>
</section>
<section>
<title>Package specific USE-flags</title>
<subsection>
<title>Viewing available USE-flags</title>
<body>

<p>
In the next chapter on <uri link="?part=2&amp;chap=2">Portage and Software</uri>
we will explain how to manage your installed software and how to work with 
<c>emerge</c>. However, we will give you a primer on <c>emerge</c> by showing
you how to view what USE-flags a package uses.
</p>

<p>
Let us take the example of <c>mozilla</c>: what USE-flags does it listen to? To
find out, we use <c>emerge</c> with the <c>--pretend</c> (don't really do
anything) and <c>--verbose</c> (give more output) options:
</p>

<pre caption="Viewing the used USE-flags">
# <i>emerge --pretend --verbose mozilla</i>
These are the packages that I would merge, in order:

Calculating dependencies ...done!
[ebuild  N    ] net-www/mozilla-1.5-r1 +java +crypt -ipv6 -gtk2 +ssl +ldap 
+gnome -debug +mozcalendar -mozaccess -mozxmlterm -moznoirc -moznomail
-moznocompose -moznoxft 
</pre>

<p>
<c>emerge</c> isn't the only tool for this job. In fact, we have a tool
dedicated to package information called <c>etcat</c> which resides in the
<c>gentoolkit</c> package. First, install <c>gentoolkit</c>:
</p>

<pre caption="Installing gentoolkit">
# <i>emerge --usepkg gentoolkit</i>
</pre>

<p>
Now run <c>etcat</c> with the <c>uses</c> argument to view the USE-flags of a
certain package. For instance, for the <c>gnumeric</c> package:
</p>

<pre caption="Using etcat to view used USE-flags">
# <i>etcat uses gnumeric</i>
[ Colour Code : <i>set</i> <comment>unset</comment> ]
[ Legend      : (U) Col 1 - Current USE flags        ]
[             : (I) Col 2 - Installed With USE flags ]

 U I [ Found these USE variables in : app-office/gnumeric-1.2.0 ]
 - - <comment>libgda</comment>  : Adds GNU Data Access (CORBA wrapper) support for gnumeric
 - - <comment>gnomedb</comment> : unknown
 + + <i>python</i>  : Adds support/bindings for the Python language
 + + <i>bonobo</i>  : Adds support for gnome-base/bonobo (Gnome CORBA interfaces)
</pre>

</body>
</subsection>
</section>
</sections>
