bdb/extconf.rb

70 lines
1.7 KiB
Ruby
Raw Normal View History

2006-02-14 03:56:36 +01:00
#!/usr/bin/env ruby
require 'mkmf'
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('bdb2')
$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
# 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")
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")
if lib_ok and inc_ok
create_makefile('bdb2')
else
$stderr.puts("cannot create Makefile")
end