1require 'mkmf'
2
3if RbConfig::CONFIG['GCC'] == 'yes'
4  flag = " -fno-defer-pop"
5  if have_macro("__clang__")
6    $LDFLAGS << flag if try_ldflags(flag)
7  else
8    $CFLAGS << flag
9  end
10  $CFLAGS << " -fno-omit-frame-pointer"
11end
12
13$INSTALLFILES = [
14  ["dl.h", "$(HDRDIR)"],
15]
16
17check = true
18if( have_header("dlfcn.h") )
19  have_library("dl")
20  check &&= have_func("dlopen")
21  check &&= have_func("dlclose")
22  check &&= have_func("dlsym")
23  have_func("dlerror")
24elsif( have_header("windows.h") )
25  check &&= have_func("LoadLibrary")
26  check &&= have_func("FreeLibrary")
27  check &&= have_func("GetProcAddress")
28else
29  check = false
30end
31
32if check
33  config = File.read(RbConfig.expand(File.join($arch_hdrdir, "ruby/config.h")))
34  types = {"SIZE_T"=>"SSIZE_T", "PTRDIFF_T"=>nil, "INTPTR_T"=>nil}
35  types.each do |type, signed|
36    if /^\#define\s+SIZEOF_#{type}\s+(SIZEOF_(.+)|\d+)/ =~ config
37      if size = $2 and size != 'VOIDP'
38        size = types.fetch(size) {size}
39        $defs << format("-DDLTYPE_%s=DLTYPE_%s", signed||type, size)
40      end
41      if signed
42        check_signedness(type.downcase, "stddef.h")
43      end
44    end
45  end
46  $defs << %[-DRUBY_VERSION=\\"#{RUBY_VERSION}\\"]
47  create_makefile("dl")
48end
49