extconf: try harder for gcc atomics in i386-configured systems
[raindrops.git] / ext / raindrops / extconf.rb
blobf012808166c4d06999d7e79a44dbfd70ee0ab7e0
1 require 'mkmf'
3 dir_config('atomic_ops')
4 have_func('mmap', 'sys/mman.h') or abort 'mmap() not found'
5 have_func('munmap', 'sys/mman.h') or abort 'munmap() not found'
7 $CPPFLAGS += " -D_GNU_SOURCE "
8 have_func('mremap', 'sys/mman.h')
10 $CPPFLAGS += " -D_BSD_SOURCE "
11 have_func("getpagesize", "unistd.h")
12 have_func('rb_thread_blocking_region')
13 have_func('rb_thread_io_blocking_region')
15 checking_for "GCC 4+ atomic builtins" do
16   # we test CMPXCHG anyways even though we don't need it to filter out
17   # ancient i386-only targets without CMPXCHG
18   src = <<SRC
19 int main(int argc, char * const argv[]) {
20         unsigned long i = 0;
21         __sync_lock_test_and_set(&i, 0);
22         __sync_lock_test_and_set(&i, 1);
23         __sync_bool_compare_and_swap(&i, 0, 1);
24         __sync_add_and_fetch(&i, argc);
25         __sync_sub_and_fetch(&i, argc);
26         return 0;
28 SRC
30   if try_link(src)
31     $defs.push(format("-DHAVE_GCC_ATOMIC_BUILTINS"))
32     true
33   else
34     # some compilers still target 386 by default, but we need at least 486
35     # to run atomic builtins.
36     prev_cflags = $CFLAGS
37     $CFLAGS += " -march=i486 "
38     if try_link(src)
39       $defs.push(format("-DHAVE_GCC_ATOMIC_BUILTINS"))
40       true
41     else
42       prev_cflags = $CFLAGS
43       false
44     end
45   end
46 end or have_header('atomic_ops.h') or abort <<-SRC
48 libatomic_ops is required if GCC 4+ is not used.
49 See http://www.hpl.hp.com/research/linux/atomic_ops/
51 Users of Debian-based distros may run:
53   apt-get install libatomic-ops-dev
54 SRC
55 create_makefile('raindrops_ext')