I am debugging a Homebrew formula that is failing due to build variables being clobbered:
clang++ called with: -mmacosx-version-min=10.7 -arch i386 -Weverything -O3 -std=c++11 -stdlib=libc++ -lc++ objects/foo.o objects/bar.o -o ../bin/foo_i386
superenv removed: -arch i386 -Weverything -O3
superenv added: -pipe -w -Os -march=native -isystem/usr/local/include -isystem/usr/include/libxml2 -isystem/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers -L/usr/local/lib -L/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries -Wl,-headerpad_max_install_names
superenv executed: clang++ -pipe -w -Os -march=native -mmacosx-version-min=10.7 -std=c++11 -stdlib=libc++ -lc++ objects/foo.o objects/bar.o -o ../bin/foo_i386 -isystem/usr/local/include -isystem/usr/include/libxml2 -isystem/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers -L/usr/local/lib -L/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries -Wl,-headerpad_max_install_names
I would like to preserve the flags that are removed by superenv, removing their replacements (which are added by superenv).
I do want to specify architecture and optimization level, and I don't need to compile in links to XML or OpenGL libraries to a command-line app that does not process XML and does not have a graphical interface or renders a three-dimensional layout.
Here's my formula's install
block:
def install
ENV.deparallelize
system 'make all'
system 'make install'
end
Are there any changes to Ruby environment variables I can make in the install
block of a Homebrew formula to prevent original flags from getting clobbered (as well as keep out unnecessary modifications)?
What will not work
This formula will be shared with others. The formula needs to be self-contained, as far as what settings it enables. I do not want to have to reconfigure and recompile the main Homebrew package manager to preserve flags, as this will require the end user to have to do the same customization to their Homebrew installation.
Add this line to your formula:
env :std
This tells Homebrew to install the formula without superenv by default. (This can always be overridden by giving the --env=superenv
option to brew install
.)
I found the following modifications helped create a working formula, in terms of addressing the specific issues outlined in my question:
class Foo < Formula
env :std
...
def install
ENV.O3
ENV.deparallelize
ENV.delete('CFLAGS')
ENV.delete('CXXFLAGS')
system 'make', 'all'
system 'make', 'install'
end
end
Adding env :std
wasn't enough — Homebrew kept adding architecture and other flags and linking options that broke the build process. Deleting the CFLAGS
and CXXFLAGS
changes helped.
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