@@ -49,6 +49,12 @@ def port_path
4949 "#{ target } /#{ RUBY_PLATFORM } "
5050 end
5151
52+ # Add "--prefix=/", to avoid our actual build install path compiled into the binary.
53+ # Instead use DESTDIR variable of make to set our install path.
54+ def configure_prefix
55+ "--prefix="
56+ end
57+
5258 def cook_and_activate
5359 checkpoint = File . join ( self . target , "#{ self . name } -#{ self . version } -#{ RUBY_PLATFORM } .installed" )
5460 unless File . exist? ( checkpoint )
@@ -70,13 +76,13 @@ def configure
7076 envs = [ ]
7177 envs << "CFLAGS=-DDSO_WIN32 -DOPENSSL_THREADS" if RUBY_PLATFORM =~ /mingw|mswin/
7278 envs << "CFLAGS=-fPIC -DOPENSSL_THREADS" if RUBY_PLATFORM =~ /linux|darwin/
73- execute ( 'configure' , [ 'env' , *envs , "./Configure" , openssl_platform , "threads" , "-static" , "CROSS_COMPILE=#{ host } -" , configure_prefix ] , altlog : "config.log" )
79+ execute ( 'configure' , [ 'env' , *envs , "./Configure" , openssl_platform , "threads" , "-static" , "CROSS_COMPILE=#{ host } -" , "--prefix=/" ] , altlog : "config.log" )
7480 end
7581 def compile
7682 execute ( 'compile' , "#{ make_cmd } build_libs" )
7783 end
7884 def install
79- execute ( 'install' , "#{ make_cmd } install_dev" )
85+ execute ( 'install' , "#{ make_cmd } install_dev DESTDIR= #{ path } " )
8086 end
8187 end
8288
@@ -104,6 +110,9 @@ def configure
104110 end
105111 super
106112 end
113+ def install
114+ execute ( 'install' , "#{ make_cmd } install DESTDIR=#{ path } " )
115+ end
107116 end
108117 # We specify -fcommon to get around duplicate definition errors in recent gcc.
109118 # See https://github.com/cockroachdb/cockroach/issues/49734
@@ -112,6 +121,7 @@ def configure
112121 recipe . configure_options << "--without-keyutils"
113122 recipe . configure_options << "--disable-nls"
114123 recipe . configure_options << "--disable-silent-rules"
124+ recipe . configure_options << "--disable-rpath"
115125 recipe . configure_options << "--without-system-verto"
116126 recipe . configure_options << "krb5_cv_attr_constructor_destructor=yes"
117127 recipe . configure_options << "ac_cv_func_regcomp=yes"
@@ -146,12 +156,13 @@ def configure_defaults
146156 '--without-zlib' ,
147157 '--without-icu' ,
148158 '--without-readline' ,
159+ '--disable-rpath' ,
149160 'ac_cv_search_gss_store_cred_into=' ,
150161 ]
151162 end
152163 def compile
153- execute 'compile include' , "#{ make_cmd } -C src/include install"
154- execute 'compile interfaces' , "#{ make_cmd } -C src/interfaces install"
164+ execute 'compile include' , "#{ make_cmd } -C src/include install DESTDIR= #{ path } "
165+ execute 'compile interfaces' , "#{ make_cmd } -C src/interfaces install DESTDIR= #{ path } "
155166 end
156167 def install
157168 end
@@ -169,15 +180,16 @@ def install
169180 # Use our own library name for libpq to avoid loading of system libpq by accident.
170181 FileUtils . ln_sf File . join ( postgresql_recipe . port_path , "lib/#{ libpq_orig } " ) ,
171182 File . join ( postgresql_recipe . port_path , "lib/#{ libpq_rubypg } " )
183+ # Link to libpq_rubypg in our ports directory without adding it as rpath (like dir_config does)
184+ $CFLAGS << " -I#{ postgresql_recipe . path } /include"
185+ $LDFLAGS << " -L#{ postgresql_recipe . path } /lib"
172186 # Avoid dependency to external libgcc.dll on x86-mingw32
173187 $LDFLAGS << " -static-libgcc" if RUBY_PLATFORM =~ /mingw|mswin/
174188 # Avoid: "libpq.so: undefined reference to `dlopen'" in cross-ruby-2.7.8
175189 $LDFLAGS << " -Wl,--no-as-needed" if RUBY_PLATFORM !~ /aarch64|arm64|darwin/
176190 # Find libpq in the ports directory coming from lib/3.x
177191 # It is shared between all compiled ruby versions.
178192 $LDFLAGS << " '-Wl,-rpath=$$ORIGIN/../../ports/#{ gem_platform } /lib'" if RUBY_PLATFORM =~ /linux/
179- # Don't use pg_config for cross build, but --with-pg-* path options
180- dir_config ( 'pg' , "#{ postgresql_recipe . path } /include" , "#{ postgresql_recipe . path } /lib" )
181193
182194 $defs. push ( "-DPG_IS_BINARY_GEM" )
183195else
0 commit comments