Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Xcode-only: Clean up compiler flags. Use CPATH.

- When using CPATH, we only need -isysroot and not the other -I spam.
- LDFLAGS use -isysroot instead of -L
  Turns out that the linker also understands the
  -isysroot flag which behaves more natural (in the
  sense: "like the internal defaults `/usr/lib` etc.)
  than adding `-L$(SDKROOT).
  Especially for duplicates, the linker first searches
  through all `-L` dirs and then looks at the sysroot
  or internal defaults. This is what we want.
- Pkg-config needs CC with CFLAGS passed to configure.

Closes #14351.

Signed-off-by: Jack Nagel <jacknagel@gmail.com>
  • Loading branch information...
commit 17469d7ad648754462ee3348bae1e496c831a52f 1 parent 0afd719
@samueljohn samueljohn authored jacknagel committed
Showing with 21 additions and 26 deletions.
  1. +11 −4 Library/Formula/pkg-config.rb
  2. +10 −22 Library/Homebrew/extend/ENV.rb
View
15 Library/Formula/pkg-config.rb
@@ -21,10 +21,17 @@ def install
/usr/local/lib/pkgconfig
/usr/lib/pkgconfig
].uniq
- system "./configure", "--disable-debug",
- "--prefix=#{prefix}",
- "--with-pc-path=#{paths*':'}",
- "--with-internal-glib"
+
+ args = %W[
+ --disable-debug
+ --prefix=#{prefix}
+ --with-pc-path=#{paths*':'}
+ --with-internal-glib
+ ]
+ args << "CC=#{ENV.cc} #{ENV.cflags}" unless MacOS::CLT.installed?
+
+ system "./configure", *args
+
system "make"
system "make check"
system "make install"
View
32 Library/Homebrew/extend/ENV.rb
@@ -238,19 +238,14 @@ def remove_macosxsdk v=MacOS.version
v = v.to_s
remove_from_cflags(/ ?-mmacosx-version-min=10\.\d/)
self['MACOSX_DEPLOYMENT_TARGET'] = nil
- remove 'CPPFLAGS', "-isystem #{HOMEBREW_PREFIX}/include"
+ self['CPATH'] = nil
remove 'LDFLAGS', "-L#{HOMEBREW_PREFIX}/lib"
sdk = MacOS.sdk_path(v)
unless sdk.nil? or MacOS::CLT.installed?
self['SDKROOT'] = nil
- remove 'CPPFLAGS', "-isysroot #{sdk}"
- remove 'CPPFLAGS', "-isystem #{sdk}/usr/include"
- remove 'CPPFLAGS', "-I#{sdk}/usr/include"
- remove_from_cflags "-isystem #{sdk}/usr/include"
remove_from_cflags "-isysroot #{sdk}"
- remove_from_cflags "-I#{sdk}/usr/include"
- remove 'LDFLAGS', "-L#{sdk}/usr/lib"
- remove 'LDFLAGS', "-I#{sdk}/usr/include"
+ remove 'CPPFLAGS', "-isysroot #{sdk}"
+ remove 'LDFLAGS', "-isysroot #{sdk}"
if HOMEBREW_PREFIX.to_s == '/usr/local'
self['CMAKE_PREFIX_PATH'] = nil
else
@@ -268,26 +263,19 @@ def macosxsdk v=MacOS.version
v = v.to_s
append_to_cflags("-mmacosx-version-min=#{v}")
self['MACOSX_DEPLOYMENT_TARGET'] = v
- append 'CPPFLAGS', "-isystem #{HOMEBREW_PREFIX}/include"
+ self['CPATH'] = "#{HOMEBREW_PREFIX}/include"
prepend 'LDFLAGS', "-L#{HOMEBREW_PREFIX}/lib"
sdk = MacOS.sdk_path(v)
unless sdk.nil? or MacOS::CLT.installed?
# Extra setup to support Xcode 4.3+ without CLT.
self['SDKROOT'] = sdk
- # Teach the preprocessor and compiler (some don't respect CPPFLAGS)
- # where system includes are:
- append 'CPPFLAGS', "-isysroot #{sdk}"
+ # Tell clang/gcc where system include's are:
+ append 'CPATH', "#{sdk}/usr/include", ":"
+ # The -isysroot is needed, too, because of the Frameworks
append_to_cflags "-isysroot #{sdk}"
- append 'CPPFLAGS', "-isystem #{sdk}/usr/include"
- # Suggested by mxcl (https://github.com/mxcl/homebrew/pull/10510#issuecomment-4187996):
- append_to_cflags "-isystem #{sdk}/usr/include"
- # Some software needs this (e.g. python shows error: /usr/include/zlib.h: No such file or directory)
- append 'CPPFLAGS', "-I#{sdk}/usr/include"
- # And finally the "normal" things one expects for the CFLAGS and LDFLAGS:
- append_to_cflags "-I#{sdk}/usr/include"
- append 'LDFLAGS', "-L#{sdk}/usr/lib"
- # Believe it or not, sometimes only the LDFLAGS are used :/
- append 'LDFLAGS', "-I#{sdk}/usr/include"
+ append 'CPPFLAGS', "-isysroot #{sdk}"
+ # And the linker needs to find sdk/usr/lib
+ append 'LDFLAGS', "-isysroot #{sdk}"
# Needed to build cmake itself and perhaps some cmake projects:
append 'CMAKE_PREFIX_PATH', "#{sdk}/usr", ':'
append 'CMAKE_FRAMEWORK_PATH', "#{sdk}/System/Library/Frameworks", ':'
Please sign in to comment.
Something went wrong with that request. Please try again.