aboutsummaryrefslogtreecommitdiff
blob: 6c3207d088f9a0cc83bc3bd2267c14ce69c9996e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
<?xml version="1.0" encoding="UTF-8"?>
<guide self="general-concepts/dependencies/">
<chapter>
<title>Dependencies</title>
<body>

<p>
Automatic dependency resolution is one of the most useful features
provided by <c>emerge</c>.
</p>

<p>
You are encouraged to sort dependencies alphabetically, with unconditional
dependencies grouped together, then all conditional dependencies. There is an
exception: you may sort dependencies as per upstream listings if it eases
checking for changes. Some projects may have different policies <d/> consult
them if you're not sure.
</p>

<p>
Please also see the following section on
<uri link="::general-concepts/ebuild-revisions/"/>
for how dependencies and revisions interact.
</p>

</body>

<section>
<title>Dependency types</title>

<subsection>
<title>CHOST vs CBUILD</title>
<body>

<p>
In order to avoid ambiguity, we use the following terms to indicate different
systems when cross-compiling.  They serve as a shorthand for an overall system
in addition to their literal value (e.g. $CHOST).
</p>

<dl>
  <dt>CBUILD</dt>
  <dd>
    The system on which the build is performed.  Dependencies that apply
    to the CBUILD system can be executed during build time.
  </dd>

  <dt>CHOST</dt>
  <dd>
    The system on which the package is going to be executed.  When
    cross-compiling, dependencies applying to CHOST can not be executed.
  </dd>
</dl>

<p>
When cross-compiling, CBUILD and CHOST are naturally different, as are the
actual install paths for the different types of dependencies.
</p>

<p>
Note however that, while cross-compiling is used to help explain these concepts,
it is not strictly required.  CBUILD and CHOST could target the exact same
hardware, but be installed into distinct SYSROOT/ROOT paths.  The dependency
distinctions still apply even if it isn't, strictly speaking, cross-compiling.
</p>

</body>
</subsection>

<subsection>
<title>Build dependencies</title>
<body>

<p>
Build dependencies are used to specify any dependencies that are required
to unpack, patch, compile, test or install the package (but see
<uri link="::general-concepts/dependencies/#Implicit system dependency"/> for
exemptions).
</p>

<p>
Starting with EAPI 7, build dependencies are split into two variables:
<c>BDEPEND</c> and <c>DEPEND</c>. <c>BDEPEND</c> specifies dependencies
applicable to CBUILD, i.e. programs that need to be executed during the build,
e.g. <c>virtual/pkgconfig</c>. <c>DEPEND</c> specifies dependencies for CHOST,
i.e. packages that need to be found on built system, e.g. libraries and headers.
</p>

<p>
In earlier EAPIs, all build dependencies are placed in <c>DEPEND</c>.
</p>

</body>
</subsection>

<subsection>
<title>Runtime dependencies</title>
<body>

<p>
The <c>RDEPEND</c> ebuild variable should specify any dependencies which are
required at runtime. This includes libraries (when dynamically linked), any data
packages and (for interpreted languages) the relevant interpreter.
</p>

<p>
Note that when installing from a binary package, only <c>RDEPEND</c> will be
checked. It is therefore necessary to include items even if they are also listed
in <c>DEPEND</c>.
</p>

<p>
Items which are in <c>RDEPEND</c> but not <c>DEPEND</c> could <e>in theory</e> be merged
<e>after</e> the target package. Portage does not currently do this.
</p>

</body>
</subsection>

<subsection>
<title>Post dependencies</title>
<body>

<p>
The <c>PDEPEND</c> variable specifies runtime dependencies that do not strictly
require being satisfied immediately. They can be merged <e>after</e>
the package. This variable is used purely to resolve circular dependencies,
while in general case <c>RDEPEND</c> should be used instead.
</p>

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

<section>
<title>Dependency syntax</title>

<subsection>
<title>Basic dependency syntax</title>
<body>

<p>
A basic <c>DEPEND</c> specification might look like the following:
</p>

<codesample lang="ebuild">
DEPEND="dev-lang/ruby
	dev-ruby/ruby-gtk2
	dev-ruby/mysql-ruby"
</codesample>

<p>
Each <e>package dependency specification</e> is the full category and name of
a package. Dependency specifications are separated by arbitrary whitespace <d/>
convention is to have one specification per line for readability purposes.
When specifying names, the category part should be treated as mandatory.
</p>

</body>
</subsection>

<subsection>
<title>Version dependencies</title>
<body>

<p>
Sometimes a particular version of a package is needed. Where this is known, it
should be specified. A simple example:
</p>

<codesample lang="ebuild">
DEPEND="&gt;=dev-libs/openssl-0.9.7d"
</codesample>

<p>
This states that at least version 0.9.7d of <c>openssl</c> is required.
</p>
</body>

<subsubsection>
<title>Version specifiers</title>
<body>

<p>
Available version specifiers are:
</p>

<table>
  <tr>
    <th>Specifier</th>
    <th>Meaning</th>
  </tr>
  <tr>
    <ti><c>&gt;=app-misc/foo-1.23</c></ti>
    <ti>Version 1.23 or later is required.</ti>
  </tr>
  <tr>
    <ti><c>&gt;app-misc/foo-1.23</c></ti>
    <ti>A version strictly later than 1.23 is required.</ti>
  </tr>
  <tr>
    <ti><c>~app-misc/foo-1.23</c></ti>
    <ti>Version 1.23 (or any <c>1.23-r*</c>) is required.</ti>
  </tr>
  <tr>
    <ti><c>=app-misc/foo-1.23</c></ti>
    <ti>
      Exactly version 1.23 is required. If at all possible,
      use the <c>~</c> form to simplify revision bumps.
    </ti>
  </tr>
  <tr>
    <ti><c>&lt;=app-misc/foo-1.23</c></ti>
    <ti>Version 1.23 or older is required.</ti>
  </tr>
  <tr>
    <ti><c>&lt;app-misc/foo-1.23</c></ti>
    <ti>A version strictly before 1.23 is required.</ti>
  </tr>
</table>

</body>
</subsubsection>

<subsubsection>
<title>Ranged dependencies</title>
<body>

<p>
To specify "version 2.x (not 1.x or 3.x)" of a package, it is necessary to use
the asterisk postfix. This is most commonly seen in situations like:
</p>

<codesample lang="ebuild">
DEPEND="gtk? ( =x11-libs/gtk+-2* )"
</codesample>

<p>
Note that the equals sign is mandatory, and that there is no dot before the
asterisk. Also note that when selecting all versions in a specific
<c>SLOT</c>, <c>SLOT</c> dependencies should be used (see below).
</p>

</body>
</subsubsection>

<subsubsection>
<title>Blockers</title>
<body>

<p>
When two packages (package slots, versions) can not be installed
simultaneously, blockers can be used to expose such a conflict
to the package manager.
</p>

<p>
There are two kinds of blockers: <e>weak blockers</e> and <e>strong
blockers</e>.
</p>

<p>
A weak blocker is defined using the following syntax:
</p>

<codesample lang="ebuild">
RDEPEND="!app-misc/foo"
</codesample>

<p>
The package manager will try to resolve this conflict automatically.
The package blocked by a weak blocker can be uninstalled <e>after</e>
installing the package blocking it. However, it exempts the common
files from file collision checks. Weak blockers are usually used
to solve file collisions between packages and are meaningful only
in <c>RDEPEND</c>.
</p>

<p>
More specifically, installation of the newer package may overwrite any
colliding files that belong to the older package that is explicitly blocked.
When such file collisions occur, the colliding files cease to belong to the
older package, and they remain installed after the older package is eventually
uninstalled. The older package is uninstalled only after any newer blocking
packages have been merged on top of it.
</p>

<warning>
Weak blockers that are pure <c>DEPEND</c> <e>do not work correctly</e>.
While Portage seemingly queues the package for removal, it <e>does not</e>
exempt their contents from file collision checks. Always include your
weak blockers in <c>RDEPEND</c>!
</warning>

<p>
If it is strictly necessary to resolve the blocker before the package
is built (installed), a strong blocker must be used instead. In this case,
temporary simultaneous installation of the conflicting packages is not allowed.
Strong blockers are expressed using the following syntax:
</p>

<codesample lang="ebuild">
RDEPEND="!!app-misc/foo"
</codesample>

<p>
Strong blockers apply accordingly to the dependency type defining them.
Blockers defined in <c>RDEPEND</c> are enforced as long as the package
is installed (but do not prevent building binary packages). Blockers
defined purely in <c>DEPEND</c> are enforced only for building
the package from source, and may not apply once the package is installed
or when it is installed from a binary package.
</p>

<p>
The most common use for strong blockers is where another package simply
being installed causes a build failure. Strong blockers are not to be used
to prevent just file collisions.
</p>

<note>
If both weak and strong blockers match a given package, the strong blocker
takes precedence.
</note>

<p>
Specific versions can also be blocked:
</p>

<codesample lang="ebuild">
RDEPEND="!&lt;app-misc/foo-1.3"
</codesample>

<p>
Blockers can be optional based upon <c>USE</c> flags as per normal
dependencies.
</p>

<p>
Blockers added to older ebuilds should not be expected to be retroactive.  If
the user already has the ebuild installed, any changes to the ebuild should not
be expected to make any difference.  This means that you should add the
blockers to whichever ebuild is the newest (even if it means that logically it
would seem backwards).  For example, certain versions of Portage don't like
some versions of bash, but the blocker was put into bash because that was the
newer package that caused the issues.
</p>

</body>
</subsubsection>
</subsection>

<subsection>
<title>SLOT dependencies</title>
<body>

<p>
To depend on a specific <c>SLOT</c>, <c>:SLOT</c> should be appended to
the package name, where 'SLOT' is the <c>SLOT</c> of the package wanted:
</p>

<codesample lang="ebuild">
DEPEND="qt5? ( dev-qt/qtcore:5 )
	gtk? ( x11-libs/gtk+:2 )
</codesample>

<p>
To depend on a specific version or version-range within a SLOT we use:
</p>

<codesample lang="ebuild">
DEPEND="qt5? ( ~dev-qt/qtcore-5.15.2:5 )
	gtk? ( &gt;=x11-libs/gtk+-2.24.9:2 )
</codesample>
</body>

<subsubsection>
<title>Slot operators</title>
<body>

<p>
In <c>EAPI=5</c> and higher, you can use slot operators appended to the package
name to declare whether or not your package should be rebuilt after the versions
satisfying its runtime dependencies are updated to versions with a different slot
or <uri link="::general-concepts/slotting/#Sub-slots">sub-slot</uri>:
</p>

<ul>
  <li>
    <c>:=</c> means that any slot is acceptable. Additionally indicates that
    your package should be rebuilt if the version best matching the runtime
    dependency is updated to a version with a different slot or subslot.
  </li>
  <li>
    <c>:*</c> means that any slot is acceptable. Furthermore, this slot
    operator explicitly declares that changes in the slot or sub-slot can be
    ignored.
  </li>
  <li>
    <c>:SLOT=</c> means that only the 'SLOT' slot is acceptable. It otherwise
    behaves identically to the <c>:=</c> operator. That is, the package must be
    rebuilt if the sub-slot of the dependency changes.
  </li>
  <li>
    <c>:SLOT</c> means that only the 'SLOT' slot is acceptable, and that changes
    in the sub-slot can be ignored (like in previous EAPIs).
  </li>
  <li>
    <c>:SLOT/SUBSLOT</c> means a dependency on a specific slot and sub-slot pair,
    which can be useful for packages installing pre-built binaries that require a
    library with a particular soname version corresponding to the sub-slot.
  </li>
</ul>

<p>
For example:
</p>

<codesample lang="ebuild">
RDEPEND="media-libs/cogl:1.0=
	gnutls? ( &gt;=net-libs/gnutls-2.8:= )"
</codesample>

<p>
means that only the '1.0' slot is acceptable for <c>media-libs/cogl</c> and
that sub-slot changes of <c>media-libs/cogl</c> will cause a rebuild of the
dependent package. It furthermore means that every slot of
<c>net-libs/gnutls</c> is acceptable but any slot change is causing a rebuild.
</p>

<p>
The <c>:slot</c> dependency syntax continues to behave like in <c>EAPI=4</c> or
earlier, i.e. it indicates that only the specific slot value is acceptable and
that the package will not break when the currently installed version of the
dependency is replaced by a version with a different sub-slot.
</p>

<p>
For example:
</p>

<codesample lang="ebuild">
RDEPEND="dev-libs/foo:2=
    &gt;=dev-libs/bar-0.9:=
    media-gfx/baz:*
    x11-misc/wombat:0"
</codesample>

<p>
means that the package should be rebuilt when <c>foo:2</c> or
<c>&gt;=bar-0.9</c> are upgraded to versions with different subslots. On the
other hand, changes in slot or sub-slots of <c>baz</c> should be ignored, and
sub-slot changes of <c>wombat:0</c> should be ignored.
</p>

</body>
</subsubsection>
</subsection>

<subsection>
<title>USE-conditional dependencies</title>
<body>

<p>
To depend upon a certain package only if a given <c>USE</c> flag is set:
</p>

<codesample lang="ebuild">
DEPEND="perl? ( dev-lang/perl )
	ruby? ( &gt;=dev-lang/ruby-1.8 )
	python? ( dev-lang/python )"
</codesample>

<p>
It is also possible to depend upon a certain package if a given <c>USE</c> flag is
<e>not</e> set:
</p>

<codesample lang="ebuild">
RDEPEND="!crypt? ( net-misc/netkit-rsh )"
</codesample>

<p>
This should <b>not</b> be used for disabling a certain <c>USE</c> flag on a given
architecture. In order to do this, the architecture team should add the <c>USE</c>
flag to their <c>use.mask</c> file in the <c>profiles/arch</c>
directory of the Gentoo repository.
</p>

<p>
This can be nested:
</p>

<codesample lang="ebuild">
DEPEND="!build? (
	&gt;=sys-libs/ncurses-5.2-r2
	gcj? (
		&gt;=media-libs/libart_lgpl-2.1
		gtk? (
			x11-libs/libXt
			x11-libs/libX11
			x11-libs/libXtst
			x11-proto/xproto
			x11-proto/xextproto
			&gt;=x11-libs/gtk+-2.2
			x11-libs/pango
		)
	)
	nls? ( sys-devel/gettext )
)"
</codesample>

</body>
</subsection>

<subsection>
<title>Any of many dependencies</title>
<body>

<note>
To ease dependency resolution for Portage, it is recommended that you sort
the elements in <e>preferred</e> order first. See
<uri link="https://bugs.gentoo.org/489458">this bug</uri> for more context.
</note>

<p>
To depend on either <c>foo</c> or <c>bar</c>:
</p>

<codesample lang="ebuild">
DEPEND="|| ( app-misc/foo app-misc/bar )"
</codesample>

<p>
To depend on either <c>foo</c> or <c>bar</c> if the <c>baz</c> <c>USE</c> flag is set:
</p>

<codesample lang="ebuild">
DEPEND="baz? ( || ( app-misc/foo app-misc/bar ) )"
</codesample>
</body>

<subsubsection>
<title>Any of many versus USE</title>
<body>

<p>
Say <c>fnord</c> can be built against either <c>foo</c> or <c>bar</c>. Then a <c>USE</c>
flag is not necessary if and only if all of the following hold:
</p>

<ul>
  <li>
    <c>fnord</c> is merged on a system which has <c>foo</c> and not <c>bar</c> installed.
    <c>foo</c> is then unmerged, and <c>bar</c> is installed. <c>fnord</c> must continue to
    work correctly.
  </li>
  <li>
    A binary package of <c>fnord</c> made on a system with <c>foo</c> and not <c>bar</c>
    can be taken and installed on a system with <c>bar</c> and not <c>foo</c>.
  </li>
</ul>

</body>
</subsubsection>
</subsection>

<subsection>
<title>Built with USE dependencies</title>
<body>

<p>
Available specifiers are:
</p>

<table>
  <tr>
    <th>Specifier</th>
    <th>Meaning</th>
  </tr>
  <tr>
    <ti><c>app-misc/foo[bar]</c></ti>
    <ti>foo must have bar enabled.</ti>
  </tr>
  <tr>
    <ti><c>app-misc/foo[bar,baz]</c></ti>
    <ti>foo must have both bar and baz enabled.</ti>
  </tr>
  <tr>
    <ti><c>app-misc/foo[-bar,baz]</c></ti>
    <ti>foo must have bar disabled and baz enabled.</ti>
  </tr>
</table>

<p>
There are also shortcuts for conditional situations:
</p>

<table>
  <tr>
    <th>Compact form</th>
    <th>Equivalent expanded form</th>
  </tr>
  <tr>
    <ti><c>app-misc/foo[bar?]</c></ti>
    <ti><c>bar? ( app-misc/foo[bar] ) !bar? ( app-misc/foo )</c></ti>
  </tr>
  <tr>
    <ti><c>app-misc/foo[!bar?]</c></ti>
    <ti><c>bar? ( app-misc/foo ) !bar? ( app-misc/foo[-bar] )</c></ti>
  </tr>
  <tr>
    <ti><c>app-misc/foo[bar=]</c></ti>
    <ti><c>bar? ( app-misc/foo[bar] ) !bar? ( app-misc/foo[-bar] )</c></ti>
  </tr>
  <tr>
    <ti><c>app-misc/foo[!bar=]</c></ti>
    <ti><c>bar? ( app-misc/foo[-bar] ) !bar? ( app-misc/foo[bar] )</c></ti>
  </tr>
</table>
</body>

<subsubsection>
<title>Use dependency defaults</title>
<body>

<p>
If a dependency is introducing or removing a <c>USE</c> flag in a new package
version, a <c>(+)</c> or <c>(-)</c> may be added to the use-dependency
specification to define a default value in case the flag does not exist in the
target package. The <c>(+)</c> indicates that the missing flag is assumed to be
enabled, <c>(-)</c> the opposite.
</p>

<p>
For example, the following will treat all <c>boost</c> versions without the
<c>threads</c> flag as having it enabled, and all <c>gcc</c> versions without
the <c>openmp</c> as having it disabled:
</p>

<codesample lang="ebuild">
DEPEND="
	&gt;=dev-libs/boost-1.48[threads(+)]
	sys-devel/gcc[openmp(-)]"
</codesample>

</body>
</subsubsection>
</subsection>
</section>

<section>
<title>Tips for checking dependencies</title>
<body>

<p>
It is important to ensure that all the dependencies are complete for your
package:
</p>

<dl>
  <dt>Look at installed binaries/libraries</dt>
  <dd>
    Use a tool like <c>scanelf -n</c> (from app-misc/pax-utils) or
    <c>objdump -p</c> (from sys-devel/binutils) to list <c>DT_NEEDED</c>
    entries.
    app-portage/iwdevtools and portage's own <c>qa-unresolved-soname-deps</c>
    <b>FEATURE</b> can help finding these.
  </dd>
  <dt>Look in <c>configure.ac</c></dt>
  <dd>
    Look for checks for packages in here. Things to look out for are pkg-config
    checks or <c>AM_*</c> functions that check for a specific version.
  </dd>
  <dt>Look at included <c>.spec</c> files</dt>
  <dd>
    A good indication of dependencies is to look at the included <c>.spec</c>
    files for relevant deps. However, do not trust them to be the definitive
    complete list of dependencies.
  </dd>
  <dt>Look at the application/library website</dt>
  <dd>
    Check the application website for possible dependencies that they suggest
    are needed.
  </dd>
  <dt>Read the <c>README</c> and <c>INSTALL</c> for the package</dt>
  <dd>
    They usually also contain useful information about building and installing
    packages.
  </dd>
  <dt>
    Remember non-binary dependencies such as pkg-config, doc generation
    programs, etc. Such programs would usually belong in <c>BDEPEND</c>.
  </dt>
  <dd>
    Usually the build process requires some dependencies such as intltool,
    libtool, pkg-config, doxygen, scrollkeeper, gtk-doc, etc. Make sure those
    are clearly stated. Again, such dependencies usually belong in
    <c>BDEPEND</c>.
  </dd>
  <dt>Testing in chroots, containers and virtual machines</dt>
  <dd>
    A sure-way to find missing dependencies is to test your ebuild in a
    deprived environment. Chroots, containers, virtual machines and
    <c>dev-util/ebuildtester</c> can achieve this.
  </dd>
</dl>

</body>
</section>

<section>
<title>Implicit system dependency</title>
<body>

<p>
All packages have an implicit compile-time and runtime dependency upon the
entire <c>@system</c> set. It is therefore not necessary, nor advisable, to
specify dependencies upon toolchain packages like <c>gcc</c>, <c>libc</c> and
so on, except where specific versions or packages (for example, <c>glibc</c>
over <c>uclibc</c>) are required. Note that this rule also needs consideration
for packages like <c>flex</c>, <c>zlib</c> and <c>libtool</c>, which aren't in
the <c>@system</c> set for every profile. For example, the embedded profile
doesn't have <c>zlib</c> in <c>@system</c>, the <c>libtool</c> ABI might
change and break building order and <c>flex</c> might get removed from the
<c>@system</c> set in future.
</p>

<p>
However, packages which are included in the <c>@system</c> set, or are
dependencies of <c>@system</c> set packages, should generally include
a complete dependency list (excluding bootstrap packages). This makes
<c>emerge -e @system</c> possible when installing from a stage 1 or stage 2
tarball.
</p>

</body>
</section>

<section>
<title>Test dependencies</title>
<body>

<p>
Packages often have optional dependencies that are needed only when running
tests. These should be specified in DEPEND behind a USE flag. Often, the
'test' USE flag is used for this purpose.
</p>

<p>
Since testing will likely fail when test dependencies are not installed, the
test phase should be disabled in this case. This may be accomplished via USE
conditionals in the RESTRICT variable.
</p>

<p>
If other optional features must be enabled/disabled when testing, REQUIRED_USE
may be set to express this.
</p>

<codesample lang="ebuild">
# Define some USE flags
IUSE="debug test"

# Require debug support when tests are enabled
REQUIRED_USE="test? ( debug )"

# Disable test phase when test USE flag is disabled
RESTRICT="!test? ( test )"

# Running tests requires 'foo' to be installed
DEPEND="test? ( dev-util/foo )"
</codesample>

</body>
</section>

<section>
<title>Circular dependencies</title>
<body>

<p>
Circular dependencies occur if one or more of package's (possibly indirect)
dependencies depend on the package itself. This creates a dependency cycle where
each of the packages must technically be installed before the other.
For example, if package A depends on B, B depends on C and C depends on A, then
the package manager cannot install A before C, and C before A.
</p>

<p>
There are three kinds of circular dependencies:
</p>

<ol>
  <li>
    Circular dependencies that occur if only one of the packages strictly needs
    to be installed before the other. For example, <c>dev-python/certifi</c>
    strictly requires <c>dev-python/setuptools</c> to build but the latter
    package requires the former for some runtime functionality. As a result,
    <c>dev-python/certifi</c> can be installed later than the other package.
    <c>PDEPEND</c> is used to express this and automatically resolve
    the circular dependency.
  </li>

  <li>
    Circular dependencies that occur if the cycle applies only to some
    combination of USE flags on one of the packages. For example, running tests
    in <c>dev-python/setuptools</c> requires a number of packages which require
    <c>dev-python/setuptools</c> to be installed first. This kind of circular
    dependency can be resolved by the user by adjusting USE flags on one
    of the packages, e.g. by disabling tests on <c>dev-python/setuptools</c>,
    and reenabling them once the dependency is initially installed.
  </li>

  <li>
    Circular dependencies that cannot be resolved using the regular means.
    For example, <c>dev-util/cmake</c> used to depend
    on <c>dev-libs/jsoncpp</c>, while the latter package used the former
    to build. Resolving this kind of dependency usually requires bundling one
    of the dependencies conditionally, or providing an alternate bootstrap path.
  </li>
</ol>

</body>
</section>

<section>
<title>Indirect dependencies</title>
<body>

<p>
Always list each direct dependency that your package needs to build and run
correctly. Do not rely on dependency chains to meet the dependency
requirements. For example, a package needs <c>dep1</c> and <c>dep2</c>, but
<c>dep1</c> also depends on <c>dep2</c>. You might consider just adding
<c>dep1</c> since it currently pulls <c>dep2</c> too, but in the future,
<c>dep1</c> might drop <c>dep2</c> as a dependency, or make it conditional with
USE flags. This would then break building your ebuild.
</p>

</body>
</section>
</chapter>
</guide>