expand automagic configuration

This commit is contained in:
danj 2006-05-15 16:35:52 +00:00
parent 347f639922
commit fd336dd767
2 changed files with 109 additions and 23 deletions

5
bdb.h
View file

@ -5,12 +5,7 @@
#include <ruby.h> #include <ruby.h>
#include <version.h> #include <version.h>
#include <extconf.h> #include <extconf.h>
#ifdef INC_DB4
#include <db4/db.h>
#else
#include <db.h> #include <db.h>
#endif
#define NOTXN NULL #define NOTXN NULL

View file

@ -4,13 +4,44 @@ require 'mkmf'
target="bdb2" target="bdb2"
$distcleanfiles=["bdb_aux._c"]
def usage
$stderr.puts "
Options:
--va build an alternate output bdb2a, use this to avoid overwriting a
previous bdb2 library, since R0.3 the interfaces are not
compatible due to the addition of transaction parameters to many
calls. Note the impact on indicating the include, below.
If you have not used bdb2 before, you need not use this argument.
-h,--help this
--dbh {dir for db.h}
If we cannot find the right db.h automatically, use this to
indicate where to look. Do not use --with... because we need
to find the file itself to extract all the DB defines.
"
end
opts = GetoptLong.new( opts = GetoptLong.new(
[ "--va", GetoptLong::NO_ARGUMENT] [ "--va", GetoptLong::NO_ARGUMENT],
[ "-h","--help",GetoptLong::NO_ARGUMENT],
[ "--dbh", GetoptLong::REQUIRED_ARGUMENT]
) )
opts.each do |opt,arg| opts.each do |opt,arg|
case opt case opt
when '--va' when '--va'
target="bdb2a" target="bdb2a"
when '-h','--help'
usage
exit
when '--dbh'
$dbh_location=arg
end end
end end
@ -31,46 +62,106 @@ inc_dir,lib_dir = dir_config(target)
$stderr.puts("lib_dir=#{lib_dir} inc_dir=#{inc_dir}") $stderr.puts("lib_dir=#{lib_dir} inc_dir=#{inc_dir}")
#case Config::CONFIG["arch"] #case Config::CONFIG["arch"]
#when /solaris2/ #when /solaris2/
# $DLDFLAGS ||= "" # $DLDFLAGS ||= ""
# $DLDFLAGS += " -R#{lib_dir}" # $DLDFLAGS += " -R#{lib_dir}"
#end #end
$libs << " -lpthread"
versions=%w(db-4.3 db-4.2) versions=%w(db-4.3 db-4.2)
locations=%w(/usr/local/lib /opt/local/lib /usr/local/BerkeleyDB.4.2/lib /usr/local/BerkeleyDB.4.3/lib) locations=%w(/usr/local/lib /opt/local/lib /usr/local/BerkeleyDB.4.3/lib /usr/local/BerkeleyDB.4.2/lib)
until versions.empty? until versions.empty?
(lib_ok=find_library(this_version=versions.shift,'db_create',*locations)) && break (lib_ok=find_library(this_version=versions.shift,'db_create',*locations)) && break
end end
h_locations=%w(/usr/local/include /opt/local/include /usr/local/BerkeleyDB.4.2/include /usr/local/BerkeleyDB.4.3/include) $maj,$min=0,0
h_headers=%w(db4/db.h db.h) if try_link0(<<SRC)
until h_headers.empty? #include <db.h>
(inc_ok=find_header(this_h=h_headers.shift,*h_locations)) && break #include <stdio.h>
end main() {
puts "db header is #{this_h} #{inc_ok} #$INCFLAGS" int maj,min;
db_version(&maj,&min,NULL);
if this_h == "db4/db.h" printf("%d %d",maj,min);
$defs << "-DINC_DB4" }
SRC
xpopen("./conftest") do |f|
$maj,$min=f.gets.chomp.split.collect {|v| v.to_i}
end
rm_f("conftest*")
else else
$defs << "-UINC_DB4" message("unable to compile against found DB library\n")
exit
end end
puts "defs: "+$defs.inspect message("Found DB version #{$maj}.#{$min}\n")
def check_header dir
opt=if dir; "-I#{dir}".quote; else nil; end
hmaj=hmin=nil
if try_cpp(cpp_include("db.h"),opt)
if (hmaj=try_constant("DB_VERSION_MAJOR","db.h",opt)) and
(hmin=try_constant("DB_VERSION_MINOR","db.h",opt)) and
hmaj.to_i == $maj and hmin.to_i == $min
message("Found matching db.h with #{opt}\n")
$INCFLAGS << " " << opt
$db_inc=dir
return true
else
if hmaj
message("found a db.h, but wrong version (lib) #{$maj}.#{$min} != (db.h) #{hmaj}.#{hmin}\n")
end
end
end
false
end
# All systems seem to have a default db.h, so this is more selective
h_test_locations=%w(
/usr/local/include
/opt/local/include
/usr/local
)
h_test_locations.unshift($dbh_location) if $dbh_location
message("Header test locations are #{h_test_locations.inspect}\n")
found=false
$db_inc=nil
# Find possible headers first:
require 'find'
Find.find(*h_test_locations) do |p1|
if FileTest.directory?(p1)
Find.prune if File.basename(p1)[0] == ?.
else
if File.basename(p1) == 'db.h'
break if found=check_header(File.dirname(p1))
end
end
end
unless found
usage
message("\nUnable to find db.h to match library (#{maj}.#{min})\n")
exit 4
end
# This is an alternate way of find headers, by makedepend
# support of gcc. It is not as necessary as we could just use
# the above result, but it is another check.
# Find db.h, not sure this will work everywhere, gcc is ok # Find db.h, not sure this will work everywhere, gcc is ok
src=create_tmpsrc("#include <#{this_h}>") src=create_tmpsrc("#include <db.h>")
cmd=cpp_command("-M") cmd=cpp_command("-M")
r=`#{cmd}` r=`#{cmd}`
header_loc=r.split.collect {|k| k if k =~ %r{^/.*db.h} }.compact[0] header_loc=r.split.collect {|k| k if k =~ %r{^/.*db.h} }.compact[0]
message("header is #{header_loc}\n") message("header is #{header_loc}\n")
inc="#include <db.h>"
inc="#include <#{this_h}>"
n=0 n=0
message("Writing bdb_aux._c (defines), this takes a while\n") message("Writing bdb_aux._c (defines), this takes a while\n")
defines=[] defines=[]
File.open(header_loc) {|fd| File.open(File.join($db_inc,"db.h")) {|fd|
File.open("bdb_aux._c","w") {|hd| File.open("bdb_aux._c","w") {|hd|
hd.puts("/* This file automatically generated by extconf.rb */\n") hd.puts("/* This file automatically generated by extconf.rb */\n")
fd.each_line {|l| fd.each_line {|l|
@ -90,7 +181,7 @@ File.open(header_loc) {|fd|
$defs << $INCFLAGS $defs << $INCFLAGS
if lib_ok and inc_ok if lib_ok
create_header create_header
create_makefile(target) create_makefile(target)
else else