Class: OraConfIC

Inherits:
OraConf show all
Defined in:
ext/oci8/oraconf.rb

Overview

OraConf for Instant Client

Constant Summary

Constants included from MiniRegistry

MiniRegistry::ERROR_FILE_NOT_FOUND, MiniRegistry::ERROR_SUCCESS, MiniRegistry::HKEY_LOCAL_MACHINE, MiniRegistry::RegCloseKey, MiniRegistry::RegOpenKeyExA, MiniRegistry::RegQueryValueExA

Instance Attribute Summary

Attributes inherited from OraConf

#cc_is_gcc, #cflags, #libs, #version

Instance Method Summary collapse

Methods inherited from OraConf

get, ld_envs

Methods included from MiniRegistry

#get_local_registry, #get_reg_value

Constructor Details

#initialize(ic_dir) ⇒ OraConfIC

Returns a new instance of OraConfIC.



971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
# File 'ext/oci8/oraconf.rb', line 971

def initialize(ic_dir)
  init

  if ic_dir =~ /^\/usr\/lib(?:64)?\/oracle\/(\d+(?:\.\d+)*)\/client(64)?\/lib(?:64)?/
    # rpm package
    #   x86 rpms after 11.1.0.7.0:
    #    library: /usr/lib/oracle/X.X/client/lib/
    #    include: /usr/include/oracle/X.X/client/
    #
    #   x86_64 rpms after 11.1.0.7.0:
    #    library: /usr/lib/oracle/X.X/client64/lib/
    #    include: /usr/include/oracle/X.X/client64/
    #
    #   x86 rpms before 11.1.0.6.0:
    #    library: /usr/lib/oracle/X.X.X.X/client/lib/
    #    include: /usr/include/oracle/X.X.X.X/client/
    #
    #   x86_64 rpms before 11.1.0.6.0:
    #    library: /usr/lib/oracle/X.X.X.X/client64/lib/
    #    include: /usr/include/oracle/X.X.X.X/client64/
    #
    #   third-party x86_64 rpms(*1):
    #    library: /usr/lib64/oracle/X.X.X.X/client/lib/
    #          or /usr/lib64/oracle/X.X.X.X/client/lib64/
    #    include: /usr/include/oracle/X.X.X.X/client/
    #
    #   *1 These had been used before Oracle released official x86_64 rpms.
    #
    lib_dir = ic_dir
    inc_dir = "/usr/include/oracle/#{$1}/client#{$2}"
  else
    # zip package
    lib_dir = ic_dir
    inc_dir = "#{ic_dir}/sdk/include"
  end

  if RUBY_PLATFORM =~ /mswin32|cygwin|mingw32|bccwin32/ # when Windows
    unless File.exist?("#{ic_dir}/sdk/lib/msvc/oci.lib")
      raise <<EOS
Could not compile with Oracle instant client.
#{ic_dir}/sdk/lib/msvc/oci.lib could not be found.
EOS
      raise 'failed'
    end
    @cflags = " \"-I#{inc_dir}\""
    @cflags += " -D_int64=\"long long\"" if RUBY_PLATFORM =~ /cygwin/
    @libs = get_libs("#{ic_dir}/sdk")
    ld_path = nil
  else
    @cflags = " -I#{inc_dir}"
    # set ld_path and so_ext
    case RUBY_PLATFORM
    when /aix/
      ld_path = 'LIBPATH'
      so_ext = 'a'
    when /hppa.*-hpux/
      if @lp64
        ld_path = 'LD_LIBRARY_PATH'
      else
        ld_path = 'SHLIB_PATH'
      end
      so_ext = 'sl'
    when /darwin/
      ld_path = 'DYLD_LIBRARY_PATH'
      so_ext = 'dylib'
    else
      ld_path = 'LD_LIBRARY_PATH'
      so_ext = 'so'
    end
    # check Oracle client library.
    unless File.exist?("#{lib_dir}/libclntsh.#{so_ext}")
      files = Dir.glob("#{lib_dir}/libclntsh.#{so_ext}.*")
      if files.empty?
        raise <<EOS
Could not compile with Oracle instant client.
'#{lib_dir}/libclntsh.#{so_ext}' could not be found.
Did you install instantclient-basic?
EOS
      else
        file = File.basename(files.sort[-1])
        raise <<EOS
Could not compile with Oracle instant client.
#{lib_dir}/libclntsh.#{so_ext} could not be found.
You may need to make a symbolic link.
 cd #{lib_dir}
 ln -s #{file} libclntsh.#{so_ext}
EOS
      end
      raise 'failed'
    end
    @libs = " -L#{lib_dir} -lclntsh "
  end
  unless File.exist?("#{inc_dir}/oci.h")
        raise <<EOS
'#{inc_dir}/oci.h' does not exist.
Install 'Instant Client SDK'.
EOS
  end
  $CFLAGS += @cflags
  if try_link_oci()
    major = try_constant("OCI_MAJOR_VERSION", "oci.h")
    minor = try_constant("OCI_MINOR_VERSION", "oci.h")
    if major and minor
      @version = format('%d%d0', major, minor)
    else
      # 10.1.0 doesn't have OCI_MAJOR_VERSION and OCI_MINOR_VERSION in oci.h.
      @version = "1010"
    end
    return
  end

  if RUBY_PLATFORM =~ /darwin/
    is_intelmac = ([1].pack('s') == "\001\000")
    arch_ppc_error = false
    arch_i386_error = false
    open('mkmf.log', 'r') do |f|
      while line = f.gets
        # universal-darwin8.0 (Mac OS X 10.4?)
        if line.include? 'cputype (18, architecture ppc) does not match cputype (7)'
          # try to link an i386 library but the instant client is ppc.
          arch_i386_error = true
        end
        if line.include? 'cputype (7, architecture i386) does not match cputype (18)'
          # try to link a ppc library but the instant client is i386.
          arch_ppc_error = true
        end
        if line.include? '/libclntsh.dylib load command 8 unknown cmd field'
          raise <<EOS
Intel mac instant client is for Mac OS X 10.5.
It doesn't work on Mac OS X 10.4 or before.

You have three workarounds.
1. Compile ruby as ppc binary and use it with ppc instant client.
2. Use JRuby and JDBC
3. Use a third-party ODBC driver and ruby-odbc.
EOS
          # '
        end
        # universal-darwin9.0 (Mac OS X 10.5?)
        if line.include? 'Undefined symbols for architecture i386:'
          # try to link an i386 library but the instant client is ppc.
          arch_i386_error = true
        end
        if line.include? 'Undefined symbols for architecture ppc:'
          # try to link a ppc library but the instant client is i386.
          arch_ppc_error = true
        end

        if arch_i386_error
          if is_intelmac
            # intel mac and '-arch i386' error
            raise <<EOS
Could not compile with Oracle instant client.
Use intel mac instant client.
EOS
          else
            # ppc mac and '-arch i386' error
            raise <<EOS
Could not compile with Oracle instant client.
You may need to set a environment variable:
  RC_ARCHS=ppc
  export RC_ARCHS
If it does not fix the problem, delete all '-arch i386'
in '#{Config::CONFIG['archdir']}/rbconfig.rb'.
EOS
          end
        end

        if arch_ppc_error
          if is_intelmac
            # intel mac and '-arch ppc' error
            raise <<EOS
Could not compile with Oracle instant client.
You may need to set a environment variable:
  RC_ARCHS=i386
  export RC_ARCHS
If it does not fix the problem, delete all '-arch ppc'
in '#{Config::CONFIG['archdir']}/rbconfig.rb'.
EOS
          else
            # ppc mac and '-arch ppc' error
            raise <<EOS
Could not compile with Oracle instant client.
Use ppc instant client.
EOS
          end
        end
      end
    end
  end

  unless ld_path.nil?
    raise <<EOS
Could not compile with Oracle instant client.
You may need to set a environment variable:
  #{ld_path}=#{lib_dir}
  export #{ld_path}
EOS
  end
  raise 'failed'
end