How can I describe alternative dependencies in a Homebrew formula? There are two different kinds I'm thinking of.<h3>1. Alternative packages</h3>
My formula can depend on package
Q, but it must have one of them. So, I want either
and I need at least one.<h3>2. Alternative flags for the same package</h3>
My formula requires another package
X for building, and it needs a package
X with one of two flags,
B. That is, I want either
depends_on 'X' => [:build, 'A']
depends_on 'X' => [:build, 'B']
and I need at least one.<h3>Example</h3>
A specific example of where these alternative dependencies would be useful is a formula depending on
gcc. There are multiple packages for
gcc4[3-9]), which could be supported by #1 above.
gcc has a flag
enable-all-languages which implies
enable-java, so if a formula that requires
gcj would use #2 to specify the alternative flags.
I recently discovered that it is possible to have dependencies conditionally determined by options. The general scheme is:<pre class="lang-ruby prettyprint-override">
option 'with-Q', 'Depend on Q instead of P' depends_on 'P' if !build.with?('Q') depends_on 'Q' if build.with?('Q')
This can also be used for one dependency with alternative flags. This example is taken from my <a href="https://github.com/spl/homebrew-pdftk/blob/956920b0ccc5cf65941c05d091d4d7cd967e2f32/pdftk.rb" rel="nofollow">
option 'with-java', 'Build gcc using --with-java instead of --with-all-languages' depends_on 'gcc' => ['with-all-languages'] if !build.with?('java') depends_on 'gcc' => ['with-java'] if build.with?('java')
This is not a perfect solution to dealing with alternative dependencies, but it is probably the only one that Homebrew will support.