bdb/extconf.rb

196 lines
4.6 KiB
Ruby
Raw Normal View History

2006-02-14 03:56:36 +01:00
#!/usr/bin/env ruby
require 'getoptlong'
2006-02-14 03:56:36 +01:00
require 'mkmf'
target="bdb2"
2006-05-15 18:35:52 +02:00
$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(
2006-05-15 18:35:52 +02:00
[ "--va", GetoptLong::NO_ARGUMENT],
[ "-h","--help",GetoptLong::NO_ARGUMENT],
[ "--dbh", GetoptLong::REQUIRED_ARGUMENT]
)
opts.each do |opt,arg|
case opt
when '--va'
target="bdb2a"
2006-05-15 18:35:52 +02:00
when '-h','--help'
usage
exit
when '--dbh'
$dbh_location=arg
end
end
message "Target is #{target}\n"
2006-03-06 18:44:47 +01:00
if CONFIG['INSTALL'] =~ %r{./install-sh}
CONFIG.delete("INSTALL")
end
2006-02-14 03:56:36 +01:00
mj,mi,rv=RUBY_VERSION.split('.').collect {|s| s.to_i}
ri=(((mj*1000)+mi)*1000)+rv
if ri < 1008004
$stderr.puts("Version 1.8.4 minimum required")
exit(3)
end
inc_dir,lib_dir = dir_config(target,$dbh_location)
2006-02-14 03:56:36 +01:00
$stderr.puts("lib_dir=#{lib_dir} inc_dir=#{inc_dir}")
2006-05-15 18:35:52 +02:00
2006-02-14 03:56:36 +01:00
#case Config::CONFIG["arch"]
#when /solaris2/
# $DLDFLAGS ||= ""
# $DLDFLAGS += " -R#{lib_dir}"
#end
2006-05-15 18:35:52 +02:00
$libs << " -lpthread"
2006-12-12 17:13:20 +01:00
case Config::CONFIG["arch"]
when /solaris2/
$libs << " -lnsl"
end
2006-05-15 18:35:52 +02:00
2006-12-12 17:13:20 +01:00
versions=%w(db-4.4 db-4.3 db-4.2)
locations=%w(/usr/local/lib /opt/local/lib /usr/local/BerkeleyDB.4.3/lib /usr/local/BerkeleyDB.4.2/lib /opt/csw/bdb44/lib)
2006-02-14 03:56:36 +01:00
until versions.empty?
(lib_ok=find_library(this_version=versions.shift,'db_create',*locations)) && break
end
2006-05-15 18:35:52 +02:00
$maj,$min=0,0
if try_link0(<<SRC)
#include <db.h>
#include <stdio.h>
main() {
int maj,min;
db_version(&maj,&min,NULL);
printf("%d %d",maj,min);
}
SRC
xpopen("./conftest") do |f|
$maj,$min=f.gets.chomp.split.collect {|v| v.to_i}
end
rm_f("conftest*")
else
message("unable to compile against found DB library\n")
exit
2006-02-14 03:56:36 +01:00
end
2006-03-06 18:44:47 +01:00
2006-05-15 18:35:52 +02:00
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
2006-03-06 18:44:47 +01:00
end
2006-05-15 18:35:52 +02:00
# 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
2006-12-12 17:13:20 +01:00
/opt/csw/bdb44/include
2006-05-15 18:35:52 +02:00
)
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
2006-02-14 03:56:36 +01:00
2006-05-15 18:35:52 +02:00
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.
2006-02-14 03:56:36 +01:00
# Find db.h, not sure this will work everywhere, gcc is ok
2006-05-15 18:35:52 +02:00
src=create_tmpsrc("#include <db.h>")
2006-02-14 03:56:36 +01:00
cmd=cpp_command("-M")
r=`#{cmd}`
header_loc=r.split.collect {|k| k if k =~ %r{^/.*db.h} }.compact[0]
message("header is #{header_loc}\n")
2006-05-15 18:35:52 +02:00
inc="#include <db.h>"
2006-02-14 03:56:36 +01:00
n=0
message("Writing bdb_aux._c (defines), this takes a while\n")
2006-02-14 03:56:36 +01:00
defines=[]
2006-05-15 18:35:52 +02:00
File.open(File.join($db_inc,"db.h")) {|fd|
2006-02-14 03:56:36 +01:00
File.open("bdb_aux._c","w") {|hd|
hd.puts("/* This file automatically generated by extconf.rb */\n")
fd.each_line {|l|
if l =~ %r{^#define\s+(DBC?_\w*)\s+(\"?)} and macro_defined?($1,inc)
2006-03-06 18:44:47 +01:00
if $2 == '\"'
2006-02-14 03:56:36 +01:00
hd.print(%Q{ cs(mBdb,%s);\n}%[$1])
else
hd.print(%Q{ ci(mBdb,%s);\n}%[$1])
end
message(".")
n+=1
end
}
}
message("\nwrote #{n} defines\n")
2006-03-06 18:44:47 +01:00
} unless File.exist?("bdb_aux._c")
2006-02-14 03:56:36 +01:00
2006-03-06 18:44:47 +01:00
$defs << $INCFLAGS
2006-05-15 18:35:52 +02:00
if lib_ok
2006-03-06 18:44:47 +01:00
create_header
create_makefile(target)
2006-02-14 03:56:36 +01:00
else
$stderr.puts("cannot create Makefile")
end