Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative dependencies in a Homebrew formula (e.g. for use with gcc)

How can I describe alternative dependencies in a Homebrew formula? There are two different kinds I'm thinking of.

1. Alternative packages

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.

2. Alternative flags for the same package

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.

Example

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.

like image 658
Sean Leather Avatar asked Jan 14 '14 13:01

Sean Leather


1 Answers

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.

like image 58
Sean Leather Avatar answered Oct 20 '22 00:10

Sean Leather