35400

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

Question:

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 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.

<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, 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.

<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 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.

Answer1:

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">pdftk formula</a>:

<pre class="lang-ruby prettyprint-override">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.

Recommend

  • Why do I get IPC delays on 20% busy machine
  • How to test Rate this app functionality before submitting to app store
  • Changing UITableViewCell's width constraint's constant value for each instance
  • Spring Cloud: default redirecting from Gateway to UI
  • C function always returns zero to Objective C
  • Java Regex Finding digits in a String
  • Get all the values from excel file by using linqtoexcel
  • Mocking OpenXML with Moq
  • How do you close TCP connections gracefully without exceptions?
  • Select Checkbox !== Select Row Table
  • Plugin with id Android not found
  • How to populate a Mutation for a different Cassandra table in a trigger
  • How to upload an Image onto localhost server whilst path is stored in mysql database?
  • Fixing corrupt encoding (with Python)
  • How to create wsdl from xsd
  • Different sized images (with the same name) in one drawable folder
  • Git for windows has stopped working
  • Use 2D Text into 3D scenes in JavaFX results in blurry texts
  • How do you run a synchronous timer in C#?
  • I need a PHP mySQL Login script that directs user to specific URL based on username and password
  • Separating definition/instantiation of template classes without 'extern'
  • Google Spreadsheet Script to Blink a range of Cells
  • Why is ordered choice in pyparsing failing for my use case?
  • Neo4j…how to get a visual representation of my data?
  • how to snap two objects in runtime in unity?
  • Another “Cannot make static reference…” Question
  • read part of h5 dataset python
  • Debug `Unexpected end of JSON input Error` on content script
  • Update cell query for Excel ADO from Delphi
  • Why my AngularJS async test in Jasmine 1.3.x is not working?
  • How to call different template for different category archive page in woocommerce
  • customize soft keyboard key preview
  • Why does Rails 3 think xE2x80x89 means â x80 x89
  • Using Service Component Runtime
  • How to use FirstOrDefault inside Include
  • PHP Permalinks.. how to change?
  • media foundation H264 decoder not working properly
  • Running R's aov() mixed effects model from Python using rpy2
  • How to mutate multiple variables without repeating codes?
  • Access to a Matlab gui from the web