03ecd2dec2d7027cd1f3ed98b13102376dddcdf8
[clogger.git] / ext / clogger_ext / extconf.rb
blob03ecd2dec2d7027cd1f3ed98b13102376dddcdf8
1 begin
2   require 'mkmf'
4   # XXX let me know if this works for you...
5   if ! defined?(RUBY_VERSION) || RUBY_VERSION !~ /\A1\.[89]\./
6     raise "Invalid RUBY_VERSION for C extension"
7   end
9   have_header('ruby.h') or raise "ruby.h header not found!"
11   if have_header('fcntl.h')
12     have_macro('F_GETFL', %w(fcntl.h))
13     have_macro('O_NONBLOCK', %w(unistd.h fcntl.h))
14   end
16   $CPPFLAGS += '-D_POSIX_C_SOURCE=200112L'
17   unless have_macro('CLOCK_MONOTONIC', 'time.h')
18     have_func('CLOCK_MONOTONIC', 'time.h')
19   end
20   have_type('clockid_t', 'time.h')
21   have_func('clock_gettime', 'time.h')
22   have_func('localtime_r', 'time.h') or raise "localtime_r needed"
23   have_func('gmtime_r', 'time.h') or raise "gmtime_r needed"
24   have_func('rb_str_set_len', 'ruby.h')
25   have_func('rb_thread_blocking_region', 'ruby.h')
26   have_func('rb_thread_io_blocking_region', 'ruby.h')
27   create_makefile('clogger_ext')
28 rescue Object => err
29   warn "E: #{err.inspect}"
30   warn "Skipping C extension, pure Ruby version will be used instead"
32   # generate a dummy Makefile to fool rubygems installer
33   targets = %w(all static clean distclean realclean
34                install install-so install-rb install-rb-default
35                pre-install-rb pre-install-rb-default
36                site-install site-install-so site-install-rb)
37   File.open(File.dirname(__FILE__) << "/Makefile", "wb") do |fp|
38     fp.puts targets.join(' ') << ":"
39     fp.puts "\techo >&2 extension disabled"
40   end
41 end