ext/dbm/extconf.rb


DEFINITIONS

This source file includes following functions.


   1  require 'mkmf'
   2  
   3  dir_config("dbm")
   4  
   5  dblib = with_config("dbm-type", nil)
   6  
   7  $dbm_conf_headers = {
   8    "db" => ["db.h"],
   9    "db1" => ["db1/ndbm.h", "db1.h", "ndbm.h"],
  10    "db2" => ["db2/db.h", "db2.h", "db.h"],
  11    "dbm" => ["ndbm.h"],
  12    "gdbm" => ["gdbm-ndbm.h", "ndbm.h"],
  13  }
  14  
  15  def db_check(db)
  16    $dbm_conf_db_prefix = ""
  17    $dbm_conf_have_gdbm = false
  18    hsearch = ""
  19  
  20    case db
  21    when /^db2?$/
  22      $dbm_conf_db_prefix = "__db_n"
  23      hsearch = "-DDB_DBM_HSEARCH "
  24    when "gdbm"
  25      $dbm_conf_have_gdbm = true
  26    end
  27  
  28    if have_func(db_prefix("dbm_open")) || have_library(db, db_prefix("dbm_open"))
  29      for hdr in $dbm_conf_headers.fetch(db, ["ndbm.h"])
  30        if have_header(hdr.dup)
  31          $CFLAGS += " " + hsearch + "-DDBM_HDR='<"+hdr+">'"
  32          return true
  33        end
  34      end
  35    end
  36    return false
  37  end
  38  
  39  def db_prefix(func)
  40    $dbm_conf_db_prefix+func
  41  end
  42  
  43  if dblib
  44    db_check(dblib)
  45  else
  46    for dblib in %w(db db2 db1 dbm gdbm)
  47      db_check(dblib) and break
  48    end
  49  end
  50  
  51  have_header("cdefs.h") 
  52  have_header("sys/cdefs.h") 
  53  if /DBM_HDR/ =~ $CFLAGS and have_func(db_prefix("dbm_open"))
  54    have_func(db_prefix("dbm_clearerr")) unless $dbm_conf_have_gdbm
  55    create_makefile("dbm")
  56  end