#!/usr/bin/env ruby
require 'mkmf'

dir_config('IBM_DB2','/opt/IBM/db2/V8.1')

def crash(str)
  printf(" extconf failure: %s\n", str)
  exit 1
end

unless have_library('db2','SQLConnect')
  crash(<<EOL)
need db2.

        Install IBM DB2 Univeral Database or try passing one of the following
        options to extconf.rb:

        --with-IBM_DB2-dir=/path/to/db2
        --with-IBM_DB2-lib=/path/to/db2/lib
        --with-IBM_DB2-include=/path/to/db2/include
EOL
end

alias :libpathflag0 :libpathflag
def libpathflag(libpath)
  libpathflag0 + case Config::CONFIG["arch"]
    when /solaris2/
      libpath[0..-2].map {|path| " -R#{path}"}.join
    when /linux/
      libpath[0..-2].map {|path| " -Wl,-rpath,#{path}"}.join
    else
      ""
  end
end

create_makefile('ibm_db2')
