ext: enable C extension under Ruby 2.0.0
[clogger.git] / ext / clogger_ext / extconf.rb
blob99f7debd21e1b40dc8713bddc3a6894edaa20676
1 begin
2   require 'mkmf'
3   $CPPFLAGS += " -D_BSD_SOURCE=1 "
5   have_header('ruby.h') or raise "ruby.h header not found!"
7   if have_header('fcntl.h')
8     have_macro('F_GETFL', %w(fcntl.h))
9     have_macro('O_NONBLOCK', %w(unistd.h fcntl.h))
10   end
12   $CPPFLAGS += '-D_POSIX_C_SOURCE=200112L'
13   unless have_macro('CLOCK_MONOTONIC', 'time.h')
14     have_func('CLOCK_MONOTONIC', 'time.h')
15   end
16   have_type('clockid_t', 'time.h')
17   have_func('clock_gettime', 'time.h')
18   have_func('localtime_r', 'time.h') or raise "localtime_r needed"
19   have_func('gmtime_r', 'time.h') or raise "gmtime_r needed"
20   have_struct_member('struct tm', 'tm_gmtoff', 'time.h')
21   have_func('rb_str_set_len', 'ruby.h')
22   have_func('rb_thread_blocking_region', 'ruby.h')
23   have_func('rb_thread_io_blocking_region', 'ruby.h')
24   create_makefile('clogger_ext')
25 rescue Object => err
26   warn "E: #{err.inspect}"
27   warn "Skipping C extension, pure Ruby version will be used instead"
29   # generate a dummy Makefile to fool rubygems installer
30   targets = %w(all static clean distclean realclean
31                install install-so install-rb install-rb-default
32                pre-install-rb pre-install-rb-default
33                site-install site-install-so site-install-rb)
34   File.open(File.dirname(__FILE__) << "/Makefile", "wb") do |fp|
35     fp.puts targets.join(' ') << ":"
36     fp.puts "\techo >&2 extension disabled"
37   end
38 end