100 lines
2.3 KiB
Ruby
100 lines
2.3 KiB
Ruby
#!/usr/bin/env ruby
|
|
require 'getoptlong'
|
|
require 'mkmf'
|
|
|
|
target="bdb2"
|
|
|
|
opts = GetoptLong.new(
|
|
[ "--va", GetoptLong::NO_ARGUMENT]
|
|
)
|
|
opts.each do |opt,arg|
|
|
case opt
|
|
when '--va'
|
|
target="bdb2a"
|
|
end
|
|
end
|
|
|
|
message "Target is #{target}\n"
|
|
|
|
if CONFIG['INSTALL'] =~ %r{./install-sh}
|
|
CONFIG.delete("INSTALL")
|
|
end
|
|
|
|
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)
|
|
|
|
$stderr.puts("lib_dir=#{lib_dir} inc_dir=#{inc_dir}")
|
|
|
|
#case Config::CONFIG["arch"]
|
|
#when /solaris2/
|
|
# $DLDFLAGS ||= ""
|
|
# $DLDFLAGS += " -R#{lib_dir}"
|
|
#end
|
|
|
|
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)
|
|
until versions.empty?
|
|
(lib_ok=find_library(this_version=versions.shift,'db_create',*locations)) && break
|
|
end
|
|
|
|
h_locations=%w(/usr/local/include /opt/local/include /usr/local/BerkeleyDB.4.2/include /usr/local/BerkeleyDB.4.3/include)
|
|
h_headers=%w(db4/db.h db.h)
|
|
until h_headers.empty?
|
|
(inc_ok=find_header(this_h=h_headers.shift,*h_locations)) && break
|
|
end
|
|
puts "db header is #{this_h} #{inc_ok} #$INCFLAGS"
|
|
|
|
if this_h == "db4/db.h"
|
|
$defs << "-DINC_DB4"
|
|
else
|
|
$defs << "-UINC_DB4"
|
|
end
|
|
|
|
puts "defs: "+$defs.inspect
|
|
|
|
# Find db.h, not sure this will work everywhere, gcc is ok
|
|
src=create_tmpsrc("#include <#{this_h}>")
|
|
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")
|
|
|
|
|
|
inc="#include <#{this_h}>"
|
|
n=0
|
|
message("Writing bdb_aux._c (defines), this takes a while\n")
|
|
defines=[]
|
|
File.open(header_loc) {|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+(\"?)} and macro_defined?($1,inc)
|
|
if $2 == '\"'
|
|
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")
|
|
} unless File.exist?("bdb_aux._c")
|
|
|
|
$defs << $INCFLAGS
|
|
|
|
if lib_ok and inc_ok
|
|
create_header
|
|
create_makefile(target)
|
|
else
|
|
$stderr.puts("cannot create Makefile")
|
|
end
|
|
|