2008-12-28 03:12:49 +01:00
|
|
|
#!/usr/bin/env ruby
|
|
|
|
require 'mkmf'
|
|
|
|
|
2010-03-28 17:09:09 +02:00
|
|
|
%w[/usr/local /usr / /usr/local/db* /usr/local/BerkeleyDB*].each do |pdir|
|
|
|
|
Dir[pdir].each do |dir|
|
|
|
|
dir_config('db', "#{dir}/include", "#{dir}/lib")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
%w(db-4.9 db-4.8 db-4.7 db-4.6 db-4.5 db-4.4 db-4.3 db-4.2).each do |ver|
|
|
|
|
have_library ver, 'db_version', 'db.h'
|
2008-12-28 03:12:49 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create_header
|
|
|
|
if File.exist?("bdb_aux._c")
|
|
|
|
message("Not writing bdb_aux._c (defines), already exists\n")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
message("Writing bdb_aux._c (defines), this takes a while\n")
|
|
|
|
db_header = $CPPFLAGS.split.select { |f| f =~ /^-I/ }.map { |e|
|
|
|
|
f = File.join(e[2..-1], 'db.h')
|
|
|
|
File.exists?(f) ? f : nil
|
|
|
|
}.select { |e| e }.first
|
2010-03-28 17:09:09 +02:00
|
|
|
|
2008-12-28 03:12:49 +01:00
|
|
|
n=0
|
|
|
|
defines=[]
|
|
|
|
File.open(db_header) {|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,"#include <db.h>")
|
|
|
|
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.strip}, guessing UINT"
|
|
|
|
hd.print(%Q{cu(mBdb,%s);\n}%[name])
|
|
|
|
end
|
|
|
|
n+=1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
}
|
|
|
|
message("\nwrote #{n} defines\n")
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2010-03-28 17:09:09 +02:00
|
|
|
#if lib_ok
|
2008-12-28 03:12:49 +01:00
|
|
|
create_header
|
|
|
|
create_makefile('bdb')
|
2010-03-28 17:09:09 +02:00
|
|
|
#else
|
|
|
|
# $stderr.puts("cannot create Makefile")
|
|
|
|
# exit 1
|
|
|
|
#end
|