How can I describe alternative dependencies in a Homebrew formula? There are two different kinds I'm thinking of.
My formula can depend on package P
or Q
, but it must have one of them. So, I want either
depends_on 'P'
or
depends_on 'Q'
and I need at least one.
My formula requires another package X
for building, and it needs a package X
with one of two flags, A
and B
. That is, I want either
depends_on 'X' => [:build, 'A']
or
depends_on 'X' => [:build, 'B']
and I need at least one.
A specific example of where these alternative dependencies would be useful is a formula depending on gcc
. There are multiple packages for gcc
(e.g. 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:
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 pdftk
formula:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With