@@ -66,15 +66,24 @@ def configure_packaged_libraries
6666 end
6767 recipe . activate
6868
69- ENV [ "PKG_CONFIG_ALLOW_SYSTEM_CFLAGS" ] = "t" # on macos, pkg-config will not return --cflags without this
70- pcfile = File . join ( recipe . path , "lib" , "pkgconfig" , "sqlite3.pc" )
71- if pkg_config ( pcfile )
72- # see https://bugs.ruby-lang.org/issues/18490
73- libs = xpopen ( [ "pkg-config" , "--libs" , "--static" , pcfile ] , err : [ :child , :out ] , &:read )
74- libs . split . each { |lib | append_ldflags ( lib ) } if $?. success?
75- else
76- abort ( "\n Could not configure the build properly. Please install either the `pkg-config` utility or the `pkg-config` rubygem.\n \n " )
69+ # on macos, pkg-config will not return --cflags without this
70+ ENV [ "PKG_CONFIG_ALLOW_SYSTEM_CFLAGS" ] = "t"
71+
72+ lib_path = File . join ( recipe . path , "lib" )
73+ pcfile = File . join ( lib_path , "pkgconfig" , "sqlite3.pc" )
74+ abort_pkg_config ( "pkg_config" ) unless pkg_config ( pcfile )
75+
76+ # see https://bugs.ruby-lang.org/issues/18490
77+ flags = xpopen ( [ "pkg-config" , "--libs" , "--static" , pcfile ] , err : [ :child , :out ] , &:read )
78+ abort_pkg_config ( "xpopen" ) unless $?. success?
79+ flags = flags . split
80+
81+ # see https://github.com/flavorjones/mini_portile/issues/118
82+ "-L#{ lib_path } " . tap do |lib_path_flag |
83+ flags . prepend ( lib_path_flag ) unless flags . include? ( lib_path_flag )
7784 end
85+
86+ flags . each { |flag | append_ldflags ( flag ) }
7887 end
7988 end
8089
@@ -140,6 +149,10 @@ def abort_could_not_find(missing)
140149 abort ( "\n Could not find #{ missing } .\n Please visit https://github.com/sparklemotion/sqlite3-ruby for installation instructions.\n \n " )
141150 end
142151
152+ def abort_pkg_config ( id )
153+ abort ( "\n Could not configure the build properly (#{ id } ). Please install either the `pkg-config` utility or the `pkg-config` rubygem.\n \n " )
154+ end
155+
143156 def cross_build?
144157 enable_config ( "cross-build" )
145158 end
0 commit comments