Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #154 from terceiro/portability

GNU (non i386/amd64 linux) portability patches
  • Loading branch information...
commit 58a80280acdb61f1bb070d2f173ef4745d2879b5 2 parents f1d93c8 + 83bb40c
Wayne Meissner authored
2  Rakefile
@@ -64,7 +64,7 @@ OS = case Config::CONFIG['host_os'].downcase
64 64
65 65 CC=ENV['CC'] || Config::CONFIG['CC'] || "gcc"
66 66
67   -GMAKE = Config::CONFIG['host_os'].downcase =~ /bsd|solaris/ ? "gmake" : "make"
  67 +GMAKE = system('which gmake >/dev/null') && 'gmake' || 'make'
68 68
69 69 LIBTEST = "build/libtest.#{LIBEXT}"
70 70 BUILD_DIR = "build"
6 ext/ffi_c/Platform.c
@@ -26,6 +26,9 @@
26 26 #include <ctype.h>
27 27 #include "endian.h"
28 28 #include "Platform.h"
  29 +#if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
  30 + #include <gnu/lib-names.h>
  31 +#endif
29 32
30 33 static VALUE PlatformModule = Qnil;
31 34
@@ -93,6 +96,9 @@ rbffi_Platform_Init(VALUE moduleFFI)
93 96 rb_define_const(PlatformModule, "LITTLE_ENDIAN", INT2FIX(LITTLE_ENDIAN));
94 97 rb_define_const(PlatformModule, "BIG_ENDIAN", INT2FIX(BIG_ENDIAN));
95 98 rb_define_const(PlatformModule, "CPU", rb_str_new2(CPU));
  99 +#if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
  100 + rb_define_const(PlatformModule, "GNU_LIBC", rb_str_new2(LIBC_SO));
  101 +#endif
96 102 export_primitive_types(PlatformModule);
97 103 }
98 104
2  ext/ffi_c/endian.h
@@ -4,7 +4,7 @@
4 4 #include <sys/param.h>
5 5 #include <sys/types.h>
6 6
7   -#if defined(__linux__) || defined(__CYGWIN__)
  7 +#if defined(__linux__) || defined(__CYGWIN__) || defined(__GNU__) || defined(__GLIBC__)
8 8 # include_next <endian.h>
9 9 #endif
10 10
11 lib/ffi/platform.rb
@@ -25,8 +25,8 @@ class PlatformError < LoadError; end
25 25
26 26 module Platform
27 27 OS = case RbConfig::CONFIG['host_os'].downcase
28   - when /linux/
29   - "linux"
  28 + when /gnu/
  29 + "gnu"
30 30 when /darwin/
31 31 "darwin"
32 32 when /freebsd/
@@ -58,7 +58,8 @@ def self.is_os(os)
58 58 end
59 59
60 60 NAME = "#{ARCH}-#{OS}"
61   - IS_LINUX = is_os("linux")
  61 + IS_GNU = is_os("gnu")
  62 + IS_LINUX = IS_GNU
62 63 IS_MAC = is_os("darwin")
63 64 IS_FREEBSD = is_os("freebsd")
64 65 IS_OPENBSD = is_os("openbsd")
@@ -85,8 +86,8 @@ def self.is_os(os)
85 86
86 87 LIBC = if IS_WINDOWS
87 88 "msvcrt.dll"
88   - elsif IS_LINUX
89   - "libc.so.6"
  89 + elsif IS_GNU
  90 + GNU_LIBC
90 91 else
91 92 "#{LIBPREFIX}c.#{LIBSUFFIX}"
92 93 end
15 libtest/GNUmakefile
@@ -9,8 +9,6 @@ ifeq ($(CPU),)
9 9 CPU := $(shell uname -m | sed -e 's/i[345678]86/i386/')
10 10 endif
11 11
12   -MODEL = 32 # Default to 32bit compiles
13   -
14 12 PLATFORM = $(CPU)-$(OS)
15 13
16 14 ifeq ($(OS), sunos)
@@ -96,6 +94,10 @@ ifneq ($(findstring bsd, $(OS)),)
96 94 LDFLAGS += -pthread
97 95 endif
98 96
  97 +ifeq ($(CPU), i386)
  98 + MODEL = 32
  99 +endif
  100 +
99 101 ifeq ($(CPU), sparcv9)
100 102 MODEL = 64
101 103 endif
@@ -116,12 +118,17 @@ ifeq ($(CPU), powerpc64)
116 118 MODEL = 64
117 119 endif
118 120
  121 +MODELFLAG =
  122 +ifneq ($(MODEL),)
  123 + MODELFLAG = -m$(MODEL)
  124 +endif
  125 +
119 126 # On platforms (linux, solaris) that support both 32bit and 64bit, force building for one or the other
120 127 ifneq ($(or $(findstring linux, $(OS)), $(findstring solaris, $(OS))),)
121 128 # Change the CC/LD instead of CFLAGS/LDFLAGS, incase other things in the flags
122 129 # makes the libffi build choke
123   - CC += -m$(MODEL)
124   - LD += -m$(MODEL)
  130 + CC += $(MODELFLAG)
  131 + LD += $(MODELFLAG)
125 132 endif
126 133
127 134 LIBTEST = $(BUILD_DIR)/$(LIBNAME)

0 comments on commit 58a8028

Please sign in to comment.
Something went wrong with that request. Please try again.