A brew formula is a Ruby (.rb
) file that contains the compile options inside. Homebrew's brew install|reinstall
allows specifying a URL instead of a formula name, so compile flags can be added to an online copy of the formula and hosted on a service like gist.github.com.
Here's an example ruby file that has an overridden compile option.
def install
args = std_cmake_args
# OVERRIDE: Force cmake to use debug flags
args << "-DCMAKE_BUILD_TYPE=Debug"
system "cmake", ".", *args
end
std_cmake_args
, defined in Homebrew's interneal formula.rb
is a variable internal to all Homebrew cmake
formula and provides sane defaults to each cmake
build prior to adding additional arguments.
This example uses cmake
, each project will have its own compiler tools and thus potentially different technique(s) for adding compile flags. For example, to tell cmake
to use Debug flags, it's args << "-DCMAKE_BUILD_TYPE=Debug"
Once these changes have been made to the .rb
file and hosted online, you can reinstall the package with the new options using the --build-from-source
command line option.
brew reinstall --build-from-source https://<path to formula>.rb
WARNING: If using gist.github.com
, note that the "Raw" version is the URL that you want. If not, it'll try to install the HTML (e.g. code preview) of the page, which won't work. :)
WARNING: Remember, this will reinstall the specified package in the Homebrew directory with debug flags, so the old "release" or "optimized" build will not longer be available. So please remember to reinstall the non-debug version using the standard brew install
technique once troubleshooting has been completed or else you'll have a debug version of a library on your computer until it's manually updated. :)