use clock_gettime for time resolution
[clogger.git] / ext / clogger_ext / extconf.rb
blob60c46a720678637132523113c0a4f0e7736ba20c
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   unless have_macro('CLOCK_MONOTONIC', 'time.h', '-D_POSIX_C_SOURCE=200112L')
17     $CPPFLAGS += '-D_POSIX_SOURCE_200112L'
18     have_func('CLOCK_MONOTONIC', 'time.h')
19   end
20   have_func('localtime_r', 'time.h') or raise "localtime_r needed"
21   have_func('gmtime_r', 'time.h') or raise "gmtime_r needed"
22   have_func('rb_str_set_len', 'ruby.h')
23   dir_config('clogger_ext')
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