Adding a command to generate the env information for linking #8021
Conversation
Looks useful---I will review when I get the chance. |
So, an example of how one might use this. For instance, say I want to use brew's keg only libiconv for whatever reason. I could install it as per usual, then do: $ cd /path/to/my/project It will set: So now my include path should include libiconv from the keg as well as the right lib directory for linking. It would still be up to me to link against the library and deal with any issues when a keg is shadowing a built-in library. It should also be pretty easy to parse this output and append it to a Makefile. Anyway, just thought I would show a bit of the motivation for this command. I'll try to write a --help for it as well. |
ENV_VARIABLES = %w[ CC CXX LD CFLAGS CXXFLAGS CPPFLAGS LDFLAGS MAKEFLAGS | ||
MACOSX_DEPLOYMENT_TARGET PKG_CONFIG_PATH HOMEBREW_DEBUG | ||
HOMEBREW_VERBOSE HOMEBREW_USE_CLANG HOMEBREW_USE_GCC | ||
HOMEBREW_USE_LLVM HOMEBREW_SVN PATH CMAKE_LIBRARY_PATH ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The HOMEBREW_
environment variables aren't really useful in this context, no?
@jacknagel Good point, they really are not useful for this command. I just copied the whole list from the cmd/--env.rb file. I'll take those out. |
Probably needs to be squashed to a single commit for review |
Squashed the commits. |
Does |
When I run something like this:
This doesn't tell me anything about how to compile and link against the keg-only readline formula. The use case as I understood it was to provide an easy mechanism for having your source projects find the flags needed to compile and link against keg-only formulae outside of Homebrew. |
Perhaps we should modify |
I could work my changes into brew --env, should I make a new branch/pull request or should I just modify this one? |
Anything that goes into IMO an external command is the place to start with this, and the most useful things can be ported to |
@jacknagel Is there any reason we can't use the same output format? The only difference I see is the LDFLAGS, CPPFLAGS and output format. If we change the output format then we don't need any flag changes; |
|
Neat. Then I definitely think we just want support for @ashgti Just modify this pull request, thanks. As said you probably just need to add the |
@ashgti would be cool if you could do that! |
I squashed this into a simple extension of |
It displays |
@jacknagel how would I source the output of |
Further, the Something along the lines: ARGV.formulae.each do |f|
ENV.append "CPPFLAGS", "-I#{f.include}"
ENV.append "LDFLAGS", "-L#{f.lib}"
end |
|
Ok, thanks :-) |
I updated it to append instead of override LDFLAGS and CPPFLAGS |
I added a guard if formula.keg_only? and made it prepend the path instead of append, this way, if you say, for example, |
Great. Is prepending the action that is done when I add a keg-only formula, too? |
It only appends keg only formula, if its not keg only then just having /usr/local/include and /usr/local/lib is enough for you to find and link to the libraries. The path /usr/local is at the end of the list, here's a better example: $ brew --env readline sdl > /tmp/my-flags
$ cat /tmp/my-flags
export CC="/usr/bin/clang"
export CXX="/usr/bin/clang++"
export LD="/usr/bin/clang"
export CFLAGS="-Os -w -pipe -march=native -Qunused-arguments -mmacosx-version-min=10.7"
export CXXFLAGS="-Os -w -pipe -march=native -Qunused-arguments -mmacosx-version-min=10.7"
export CPPFLAGS="-I/usr/local/Cellar/readline/6.2.2/include -isystem /usr/local/include"
export LDFLAGS="-L/usr/local/Cellar/readline/6.2.2/lib -L/usr/local/lib"
export MACOSX_DEPLOYMENT_TARGET="10.7"
export MAKEFLAGS="-j8"
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig/:/usr/local/share/pkgconfig:" Here if you wanted to link your project against say readline (which is keg only) and sdl (which is not) it will give you this set of CPPFLAGS/LDFLAGS. Then, you can either export these flags or add them to a make file and things should hopefully work correctly. All of the SDL includes should be in /usr/local/include since its not keg-only. |
I just want to make sure that the content of the env flags are ordered the same way as homebrew uses internally, otherwise it may be bad for debugging linking errors etc.. |
In fact code should be refactored to ensure that they are the same, though that's perhaps a bigger piece of work. |
https://github.com/mxcl/homebrew/blob/master/Library/Homebrew/build.rb#L64 In the build.rb file ENV.prepend is used if its |
Then The other vars should be added too, I guess. And @adam is right, |
Extending `brew --env` to include formula include paths so you can easily find keg only formula from outside of brew.
The new commit looks good. For now, this is what we want to have. For the future, we want to refactor the code ... but until then... :-) |
brew --env sort of supports this now. But only for superenv. It wouldn't be hard to make it work for std-env. For superenv you can also do: brew sh And it will start a shell with all keg-only kegs set up in the environment for building. |
@mxcl - reject this? |
Rejecting as it's supported by |
Adding a command to generate the env information for linking for linking aginst a library. This is useful for
keg_only
formula and for generating the correct -I and -L information for any formula including its dependencies.Basically, if I have an external project that I don't want to put in homebrew but I would like to link against a keg_only formula, this script could help me generate the env variables needed to build my project.