aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Yamin <plasmaroo@gentoo.org>2006-02-22 04:01:23 +0000
committerTim Yamin <plasmaroo@gentoo.org>2006-02-22 04:01:23 +0000
commit07a0d2875d93c658d14a0ce87ce95b4150977596 (patch)
tree8dfa36a3e97fabcf0ac9ec3313d03c06ec45e361 /ebuild-writing/use-conditional-code
parentMore updates. Update the stylesheet adding a few new elements and more sh (diff)
downloaddevmanual-07a0d2875d93c658d14a0ce87ce95b4150977596.tar.gz
devmanual-07a0d2875d93c658d14a0ce87ce95b4150977596.tar.bz2
devmanual-07a0d2875d93c658d14a0ce87ce95b4150977596.zip
More goodies; change syntax highlighting mode within quotes for ebuilds.
git-svn-id: svn+ssh://svn.gentoo.org/var/svnroot/devmanual/trunk@5 176d3534-300d-0410-8db8-84e73ed771c3
Diffstat (limited to 'ebuild-writing/use-conditional-code')
-rw-r--r--ebuild-writing/use-conditional-code/text.xml62
1 files changed, 62 insertions, 0 deletions
diff --git a/ebuild-writing/use-conditional-code/text.xml b/ebuild-writing/use-conditional-code/text.xml
new file mode 100644
index 0000000..84fc490
--- /dev/null
+++ b/ebuild-writing/use-conditional-code/text.xml
@@ -0,0 +1,62 @@
+<?xml version="1.0"?>
+<guide self="ebuild-writing/use-conditional-code/">
+<chapter>
+<title>USE Flag Conditional Code</title>
+
+<body>
+<p>
+Often a particular block of code must only be executed if a given USE flag is
+set (or unset). For large blocks, <c>if use foo</c> is best, or for inverse tests
+either <c>if ! use foo</c> or <c>if use !foo</c> can be used (the former is more
+common and is recommended for readability). For single-statement conditions, the
+<c>use foo &amp;&amp; blah</c> (or <c>use foo || blah</c> for negatives) form is often more
+readable.
+</p>
+
+<p>
+The <c>if [ "`use foo`" ]</c> and <c>if [ -n "`use foo`" ]</c> forms which are
+occasionally seen in older code must <b>not</b> be used.
+</p>
+
+<note>
+<c>die</c> will not work as expected within a subshell, so code in the
+form <c>use foo &amp;&amp; ( blah ; blah )</c> should be avoided in favour of a proper if
+statement. See `die and Subshells`_.
+</note>
+
+<codesample lang="ebuild">
+ # USE conditional blocks...
+ if use livecd ; then
+ # remove some extra files for a small livecd install
+ rm -fr ${vimfiles}/{compiler,doc,ftplugin,indent}
+ fi
+
+ # Inverse USE conditional blocks...
+ if ! use cscope ; then
+ # the --disable-cscope configure arg doesn't quite work properly,
+ # so sed it out of feature.h if we're not USEing cscope.
+ sed -i -e '/# define FEAT_CSCOPE/d' src/feature.h || die "couldn't disable cscope"
+ fi
+
+ # USE conditional statements...
+ use ssl &amp;&amp; epatch ${FILESDIR}/${P}-ssl.patch
+ use sparc &amp;&amp; filter-flags -fomit-frame-pointer
+
+ # Inverse USE conditional statements...
+ use ncurses || epatch ${FILESDIR}/${P}-no-ncurses.patch
+</codesample>
+
+<p>
+For echoing content based upon a USE flag, there is often a better helper
+function available.
+</p>
+
+<p>
+You must not rely upon <c>use</c> producing an output -- this no longer happens.
+If you really need output displayed, use the <c>usev</c> function. The
+<c>useq</c> function is available for explicitly requesting no output.
+</p>
+</body>
+
+</chapter>
+</guide>