123 lines
2.9 KiB
Ruby
123 lines
2.9 KiB
Ruby
#!/usr/bin/env ruby
|
|
require 'mkmf'
|
|
|
|
$distcleanfiles=["bdb_aux._c"]
|
|
dir_config('db')
|
|
|
|
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
|
|
|
|
versions=%w(db-4.6 db-4.5 db-4.4 db-4.3 db-4.2)
|
|
until versions.empty?
|
|
(lib_ok=find_library(this_version=versions.shift,'db_create')) && break
|
|
end
|
|
|
|
$stderr.puts(this_version)
|
|
|
|
$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
|
|
libpath=`ldd conftest`.split.find {|e| e =~ %r{/.+#{this_version}} }
|
|
$stderr.puts("library path #{libpath}")
|
|
rm_f("conftest*")
|
|
else
|
|
message("unable to compile against found DB library\n")
|
|
exit
|
|
end
|
|
|
|
message("Found DB version #{$maj}.#{$min} in #{libpath}\n")
|
|
|
|
# lets find its header now
|
|
incpath=libpath
|
|
while incpath!= "/"
|
|
incpath=File.dirname(incpath)
|
|
i=File.join(incpath,"include","db.h")
|
|
if File.exist?(i)
|
|
incpath=i ; break
|
|
end
|
|
end
|
|
|
|
if incpath=="/"
|
|
message("unable to find db.h")
|
|
exit
|
|
end
|
|
incpath=File.dirname(incpath)
|
|
|
|
message("Found db.h in #{incpath}\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
|
|
|
|
exit unless check_header(incpath)
|
|
|
|
inc="#include <db.h>"
|
|
n=0
|
|
message("Writing bdb_aux._c (defines), this takes a while\n")
|
|
defines=[]
|
|
File.open(File.join($db_inc,"db.h")) {|fd|
|
|
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+([^\/]*)\s*(.*?)(\/\*.*)?$}
|
|
name = $1
|
|
value = $2
|
|
if macro_defined?(name,inc)
|
|
case value
|
|
when /^"/
|
|
hd.print(%Q{ cs(mBdb,%s);\n}%[name])
|
|
when /^\(?(0x|\d)/
|
|
hd.print(%Q{ cu(mBdb,%s);\n}%[name])
|
|
when /^\(?-/
|
|
hd.print(%Q{ ci(mBdb,%s);\n}%[name])
|
|
else
|
|
$stderr.puts "don't know how to handle #{name} #{value}, guessing UINT"
|
|
hd.print(%Q{ cu(mBdb,%s);\n}%[name])
|
|
end
|
|
n+=1
|
|
end
|
|
end
|
|
}
|
|
}
|
|
message("\nwrote #{n} defines\n")
|
|
} unless File.exist?("bdb_aux._c")
|
|
|
|
$defs << $INCFLAGS
|
|
|
|
if lib_ok
|
|
create_header
|
|
create_makefile('bdb2')
|
|
else
|
|
$stderr.puts("cannot create Makefile")
|
|
end
|