bdb/extconf.rb

100 lines
2.3 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"
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"
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)
2006-02-14 03:56:36 +01:00
$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
2006-03-06 18:44:47 +01:00
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
2006-02-14 03:56:36 +01:00
# 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")
2006-02-14 03:56:36 +01:00
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)
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-02-14 03:56:36 +01:00
if lib_ok and inc_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