require 'mkmf'
require 'ftools'

dir_config("msql")

if MSQLDIR = with_config("msql-dir")
  SITE_MM = MSQLDIR + "/makegen/site.mm"
  if FileTest::exist? SITE_MM
    fp   = File.open SITE_MM
    site = File.open ('site.h', 'w')
    fp.each do |line|
      if /(INST_DIR|TARGET)\s*=\s*(.*)/ =~ line
        site.write "#define #{$1} \"#{$2}\"\n"
      end
    end
    site.write "#define SERVER_VERSION \"unknown\"\n"
  else
    File.copy 'site.h.in', 'site.h'
  end
end

if have_header("msql.h")
  have_library("msql", "msqlGetHostInfo")
  create_makefile("msql")
end
