ffi 0.3.5 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of ffi might be problematic. Click here for more details.

Files changed (59) hide show
  1. data/README.rdoc +51 -1
  2. data/Rakefile +34 -26
  3. data/ext/ffi_c/AbstractMemory.c +73 -70
  4. data/ext/ffi_c/AbstractMemory.h +8 -4
  5. data/ext/ffi_c/AutoPointer.c +8 -9
  6. data/ext/ffi_c/AutoPointer.h +2 -2
  7. data/ext/ffi_c/Buffer.c +19 -20
  8. data/ext/ffi_c/Callback.c +85 -33
  9. data/ext/ffi_c/Callback.h +11 -5
  10. data/ext/ffi_c/{NativeLibrary.c → DynamicLibrary.c} +83 -16
  11. data/ext/ffi_c/{NativeLibrary.h → DynamicLibrary.h} +1 -1
  12. data/ext/ffi_c/Invoker.c +148 -192
  13. data/ext/ffi_c/LastError.c +135 -0
  14. data/ext/ffi_c/LastError.h +18 -0
  15. data/ext/ffi_c/MemoryPointer.c +26 -19
  16. data/ext/ffi_c/MemoryPointer.h +3 -3
  17. data/ext/ffi_c/NullPointer.c +49 -47
  18. data/ext/ffi_c/Platform.c +9 -10
  19. data/ext/ffi_c/Platform.h +1 -1
  20. data/ext/ffi_c/Pointer.c +52 -21
  21. data/ext/ffi_c/Pointer.h +8 -6
  22. data/ext/ffi_c/Struct.c +70 -61
  23. data/ext/ffi_c/Struct.h +2 -2
  24. data/ext/ffi_c/Type.c +230 -0
  25. data/ext/ffi_c/Type.h +28 -0
  26. data/ext/ffi_c/Types.c +47 -6
  27. data/ext/ffi_c/Types.h +8 -2
  28. data/ext/ffi_c/endian.h +40 -0
  29. data/ext/ffi_c/extconf.rb +6 -5
  30. data/ext/ffi_c/ffi.c +20 -43
  31. data/ext/ffi_c/libffi.bsd.mk +34 -0
  32. data/ext/ffi_c/libffi.darwin.mk +30 -10
  33. data/ext/ffi_c/libffi.gnu.mk +29 -0
  34. data/ext/ffi_c/libffi.mk +4 -2
  35. data/ext/ffi_c/rbffi.h +6 -8
  36. data/lib/ffi.rb +10 -1
  37. data/lib/ffi/autopointer.rb +1 -1
  38. data/lib/ffi/enum.rb +78 -0
  39. data/lib/ffi/ffi.rb +5 -6
  40. data/lib/ffi/io.rb +15 -1
  41. data/lib/ffi/library.rb +78 -17
  42. data/lib/ffi/pointer.rb +2 -2
  43. data/lib/ffi/struct.rb +68 -14
  44. data/lib/ffi/types.rb +6 -3
  45. data/lib/ffi/variadic.rb +2 -2
  46. data/spec/ffi/bool_spec.rb +24 -0
  47. data/spec/ffi/callback_spec.rb +217 -17
  48. data/spec/ffi/enum_spec.rb +164 -0
  49. data/spec/ffi/managed_struct_spec.rb +6 -1
  50. data/spec/ffi/number_spec.rb +30 -0
  51. data/spec/ffi/pointer_spec.rb +33 -8
  52. data/spec/ffi/rbx/memory_pointer_spec.rb +0 -6
  53. data/spec/ffi/spec_helper.rb +5 -1
  54. data/spec/ffi/string_spec.rb +65 -4
  55. data/spec/ffi/struct_callback_spec.rb +41 -0
  56. data/spec/ffi/struct_initialize_spec.rb +30 -0
  57. data/spec/ffi/struct_spec.rb +19 -20
  58. metadata +29 -52
  59. data/ext/ffi_c/ffi.mk +0 -23
@@ -0,0 +1,28 @@
1
+ #ifndef _TYPE_H
2
+ #define _TYPE_H
3
+
4
+ #include <ruby.h>
5
+ #include <ffi.h>
6
+
7
+ #ifdef __cplusplus
8
+ extern "C" {
9
+ #endif
10
+
11
+
12
+ typedef struct Type_ {
13
+ NativeType nativeType;
14
+ ffi_type* ffiType;
15
+ int size;
16
+ int alignment;
17
+ } Type;
18
+
19
+ extern VALUE rbffi_TypeClass;
20
+ extern int rbffi_Type_GetIntValue(VALUE type);
21
+
22
+
23
+ #ifdef __cplusplus
24
+ }
25
+ #endif
26
+
27
+ #endif /* _TYPE_H */
28
+
@@ -1,9 +1,13 @@
1
1
  #include <ruby.h>
2
2
  #include "Pointer.h"
3
+ #include "rbffi.h"
4
+ #include "Callback.h"
3
5
  #include "Types.h"
4
6
 
7
+ static ID id_find = 0;
8
+
5
9
  ffi_type*
6
- rb_FFI_NativeTypeToFFI(NativeType type)
10
+ rbffi_NativeType_ToFFI(NativeType type)
7
11
  {
8
12
  switch (type) {
9
13
  case NATIVE_VOID:
@@ -16,7 +20,9 @@ rb_FFI_NativeTypeToFFI(NativeType type)
16
20
  return &ffi_type_sint16;
17
21
  case NATIVE_UINT16:
18
22
  return &ffi_type_uint16;
23
+ case NATIVE_BOOL:
19
24
  case NATIVE_INT32:
25
+ case NATIVE_ENUM:
20
26
  return &ffi_type_sint32;
21
27
  case NATIVE_UINT32:
22
28
  return &ffi_type_uint32;
@@ -34,6 +40,7 @@ rb_FFI_NativeTypeToFFI(NativeType type)
34
40
  case NATIVE_BUFFER_IN:
35
41
  case NATIVE_BUFFER_OUT:
36
42
  case NATIVE_BUFFER_INOUT:
43
+ case NATIVE_CALLBACK:
37
44
  return &ffi_type_pointer;
38
45
  default:
39
46
  return NULL;
@@ -41,9 +48,9 @@ rb_FFI_NativeTypeToFFI(NativeType type)
41
48
  }
42
49
 
43
50
  VALUE
44
- rb_FFI_NativeValueToRuby(NativeType type, const void* ptr)
51
+ rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr, VALUE enums)
45
52
  {
46
- switch (type) {
53
+ switch (type->nativeType) {
47
54
  case NATIVE_VOID:
48
55
  return Qnil;
49
56
  case NATIVE_INT8:
@@ -67,11 +74,45 @@ rb_FFI_NativeValueToRuby(NativeType type, const void* ptr)
67
74
  case NATIVE_FLOAT64:
68
75
  return rb_float_new(*(double *) ptr);
69
76
  case NATIVE_STRING:
70
- return rb_tainted_str_new2(*(char **) ptr);
77
+ return (*(char **)ptr) ? rb_tainted_str_new2(*(char **) ptr) : Qnil;
71
78
  case NATIVE_POINTER:
72
- return rb_FFI_Pointer_new(*(void **) ptr);
79
+ return rbffi_Pointer_NewInstance(*(void **) ptr);
80
+ case NATIVE_BOOL:
81
+ return ((int) *(ffi_arg *) ptr) ? Qtrue : Qfalse;
82
+ case NATIVE_ENUM:
83
+ {
84
+ VALUE enum_obj = rb_funcall(enums, id_find, 1, rbType);
85
+ if (enum_obj == Qnil) {
86
+ VALUE s = rb_inspect(rbType);
87
+ rb_raise(rb_eRuntimeError, "Unknown enumeration: %s", StringValueCStr(s));
88
+ }
89
+ return rb_funcall(enum_obj, id_find, 1, INT2NUM((unsigned int) *(ffi_arg *) ptr));
90
+ }
91
+ case NATIVE_CALLBACK: {
92
+ CallbackInfo* cbInfo;
93
+ VALUE argv[6];
94
+ VALUE funcptr = rbffi_Pointer_NewInstance(*(void **) ptr);
95
+
96
+ Data_Get_Struct(rbType, CallbackInfo, cbInfo);
97
+ argv[0] = funcptr;
98
+ argv[1] = cbInfo->rbParameterTypes;
99
+ argv[2] = ID2SYM(rb_intern("cb")); // just shove a dummy value
100
+ argv[3] = cbInfo->rbReturnType;
101
+ argv[4] = rb_str_new2("default");
102
+ argv[5] = Qnil;
103
+
104
+ return rb_class_new_instance(6, argv, rbffi_InvokerClass);
105
+ }
106
+
73
107
  default:
74
- rb_raise(rb_eRuntimeError, "Unknown type: %d", type);
108
+ rb_raise(rb_eRuntimeError, "Unknown type: %d", type->nativeType);
75
109
  return Qnil;
76
110
  }
77
111
  }
112
+
113
+ void
114
+ rbffi_Types_Init(VALUE moduleFFI)
115
+ {
116
+ id_find = rb_intern("find");
117
+ }
118
+
@@ -25,6 +25,7 @@ typedef enum {
25
25
  NATIVE_BUFFER_OUT,
26
26
  NATIVE_BUFFER_INOUT,
27
27
  NATIVE_CHAR_ARRAY,
28
+ NATIVE_BOOL,
28
29
 
29
30
  /**
30
31
  * An immutable string. Nul terminated, but only copies in to the native function
@@ -34,11 +35,16 @@ typedef enum {
34
35
  NATIVE_RBXSTRING,
35
36
  /** The function takes a variable number of arguments */
36
37
  NATIVE_VARARGS,
38
+ /** A typedef-ed enum */
39
+ NATIVE_ENUM,
37
40
  } NativeType;
38
41
 
39
42
  #include <ffi.h>
40
- extern ffi_type* rb_FFI_NativeTypeToFFI(NativeType type);
41
- VALUE rb_FFI_NativeValueToRuby(NativeType type, const void* ptr);
43
+ #include "Type.h"
44
+
45
+ extern ffi_type* rbffi_NativeType_ToFFI(NativeType type);
46
+ VALUE rbffi_NativeValue_ToRuby(Type* type, VALUE rbType, const void* ptr, VALUE enums);
47
+ void rbffi_Types_Init(VALUE moduleFFI);
42
48
 
43
49
  #ifdef __cplusplus
44
50
  }
@@ -0,0 +1,40 @@
1
+ #ifndef JFFI_ENDIAN_H
2
+ #define JFFI_ENDIAN_H
3
+
4
+ #include <sys/param.h>
5
+ #include <sys/types.h>
6
+
7
+ #ifdef __linux__
8
+ # include_next <endian.h>
9
+ #endif
10
+
11
+ #ifdef __sun
12
+ # include <sys/byteorder.h>
13
+ # define LITTLE_ENDIAN 1234
14
+ # define BIG_ENDIAN 4321
15
+ # if defined(_BIG_ENDIAN)
16
+ # define BYTE_ORDER BIG_ENDIAN
17
+ # elif defined(_LITTLE_ENDIAN)
18
+ # define BYTE_ORDER LITTLE_ENDIAN
19
+ # else
20
+ # error "Cannot determine endian-ness"
21
+ # endif
22
+ #endif
23
+
24
+ #if defined(_AIX) && !defined(BYTE_ORDER)
25
+ # define LITTLE_ENDIAN 1234
26
+ # define BIG_ENDIAN 4321
27
+ # if defined(__BIG_ENDIAN__)
28
+ # define BYTE_ORDER BIG_ENDIAN
29
+ # elif defined(__LITTLE_ENDIAN__)
30
+ # define BYTE_ORDER LITTLE_ENDIAN
31
+ # else
32
+ # error "Cannot determine endian-ness"
33
+ # endif
34
+ #endif
35
+
36
+ #if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN)
37
+ # error "Cannot determine the endian-ness of this platform"
38
+ #endif
39
+
40
+ #endif /* JFFI_ENDIAN_H */
@@ -16,15 +16,16 @@ $defs << "-DHAVE_EXTCONF_H" if $defs.empty? # needed so create_header works
16
16
  create_makefile("ffi_c")
17
17
  create_header("extconf.h")
18
18
  File.open("Makefile", "a") do |mf|
19
- mf.puts "CPPFLAGS += -Werror -Wunused -Wformat"
19
+ mf.puts "CPPFLAGS += -Werror -Wunused -Wformat -Wimplicit -Wreturn-type"
20
20
  unless libffi_ok
21
- mf.puts "include $(srcdir)/ffi.mk"
22
21
  mf.puts "LIBFFI_HOST=--host=#{Config::CONFIG['host_alias']}" if Config::CONFIG.has_key?("host_alias")
23
22
  mf.puts "FFI_MMAP_EXEC=-DFFI_MMAP_EXEC_WRIT=#{Config::CONFIG['host_os'] =~ /win/ ? 0 : 1}"
24
- if Config::CONFIG['host_os'] =~ /darwin/
25
- mf.puts "include $(srcdir)/libffi.darwin.mk"
23
+ if Config::CONFIG['host_os'].downcase =~ /darwin/
24
+ mf.puts "include ${srcdir}/libffi.darwin.mk"
25
+ elsif Config::CONFIG['host_os'].downcase =~ /bsd/
26
+ mf.puts '.include "${srcdir}/libffi.bsd.mk"'
26
27
  else
27
- mf.puts "include $(srcdir)/libffi.mk"
28
+ mf.puts "include ${srcdir}/libffi.mk"
28
29
  end
29
30
  end
30
31
  end
@@ -10,20 +10,21 @@
10
10
  #include "MemoryPointer.h"
11
11
  #include "AutoPointer.h"
12
12
  #include "Struct.h"
13
- #include "NativeLibrary.h"
13
+ #include "Callback.h"
14
+ #include "DynamicLibrary.h"
14
15
  #include "Platform.h"
15
16
  #include "Types.h"
17
+ #include "LastError.h"
16
18
 
17
19
 
18
20
  void Init_ffi_c();
19
21
 
20
22
  static VALUE moduleFFI = Qnil;
21
- static VALUE moduleNativeType = Qnil;
22
23
  static VALUE typeMap = Qnil, sizeMap = Qnil;
23
24
  static ID type_size_id = 0, size_id;
24
25
 
25
26
  int
26
- rb_FFI_type_size(VALUE type)
27
+ rbffi_type_size(VALUE type)
27
28
  {
28
29
  int t = TYPE(type);
29
30
  if (t == T_FIXNUM || t == T_BIGNUM) {
@@ -40,7 +41,7 @@ rb_FFI_type_size(VALUE type)
40
41
  }
41
42
  }
42
43
  // Not found - call up to the ruby version to resolve
43
- return NUM2INT(rb_funcall2(moduleFFI, rb_intern("type_size"), 1, &type));
44
+ return NUM2INT(rb_funcall2(moduleFFI, type_size_id, 1, &type));
44
45
  } else {
45
46
  return NUM2INT(rb_funcall2(type, size_id, 0, NULL));
46
47
  }
@@ -50,50 +51,26 @@ void
50
51
  Init_ffi_c() {
51
52
  moduleFFI = rb_define_module("FFI");
52
53
  rb_global_variable(&moduleFFI);
53
- moduleNativeType = rb_define_module_under(moduleFFI, "NativeType");
54
54
  rb_define_const(moduleFFI, "TypeDefs", typeMap = rb_hash_new());
55
55
  rb_define_const(moduleFFI, "SizeTypes", sizeMap = rb_hash_new());
56
56
  rb_global_variable(&typeMap);
57
57
  rb_global_variable(&sizeMap);
58
58
  type_size_id = rb_intern("type_size");
59
59
  size_id = rb_intern("size");
60
-
61
- rb_define_const(moduleNativeType, "VOID", INT2FIX(NATIVE_VOID));
62
- rb_define_const(moduleNativeType, "INT8", INT2FIX(NATIVE_INT8));
63
- rb_define_const(moduleNativeType, "UINT8", INT2FIX(NATIVE_UINT8));
64
- rb_define_const(moduleNativeType, "INT16", INT2FIX(NATIVE_INT16));
65
- rb_define_const(moduleNativeType, "UINT16", INT2FIX(NATIVE_UINT16));
66
- rb_define_const(moduleNativeType, "INT32", INT2FIX(NATIVE_INT32));
67
- rb_define_const(moduleNativeType, "UINT32", INT2FIX(NATIVE_UINT32));
68
- rb_define_const(moduleNativeType, "INT64", INT2FIX(NATIVE_INT64));
69
- rb_define_const(moduleNativeType, "UINT64", INT2FIX(NATIVE_UINT64));
70
- rb_define_const(moduleNativeType, "FLOAT32", INT2FIX(NATIVE_FLOAT32));
71
- rb_define_const(moduleNativeType, "FLOAT64", INT2FIX(NATIVE_FLOAT64));
72
- rb_define_const(moduleNativeType, "POINTER", INT2FIX(NATIVE_POINTER));
73
- rb_define_const(moduleNativeType, "STRING", INT2FIX(NATIVE_STRING));
74
- rb_define_const(moduleNativeType, "RBXSTRING", INT2FIX(NATIVE_RBXSTRING));
75
- rb_define_const(moduleNativeType, "CHAR_ARRAY", INT2FIX(NATIVE_CHAR_ARRAY));
76
- rb_define_const(moduleNativeType, "BUFFER_IN", INT2FIX(NATIVE_BUFFER_IN));
77
- rb_define_const(moduleNativeType, "BUFFER_OUT", INT2FIX(NATIVE_BUFFER_OUT));
78
- rb_define_const(moduleNativeType, "BUFFER_INOUT", INT2FIX(NATIVE_BUFFER_INOUT));
79
- rb_define_const(moduleNativeType, "VARARGS", INT2FIX(NATIVE_VARARGS));
80
- if (sizeof(long) == 4) {
81
- rb_define_const(moduleNativeType, "LONG", INT2FIX(NATIVE_INT32));
82
- rb_define_const(moduleNativeType, "ULONG", INT2FIX(NATIVE_UINT32));
83
- } else {
84
- rb_define_const(moduleNativeType, "LONG", INT2FIX(NATIVE_INT64));
85
- rb_define_const(moduleNativeType, "ULONG", INT2FIX(NATIVE_UINT64));
86
- }
87
- rb_FFI_Platform_Init();
88
- rb_FFI_AbstractMemory_Init();
89
- rb_FFI_Pointer_Init();
90
- rb_FFI_AutoPointer_Init();
91
- rb_FFI_NullPointer_Init();
92
- rb_FFI_MemoryPointer_Init();
93
- rb_FFI_Buffer_Init();
94
- rb_FFI_Callback_Init();
95
- rb_FFI_Struct_Init();
96
- rb_FFI_NativeLibrary_Init();
97
- rb_FFI_Invoker_Init();
60
+
61
+ rbffi_Type_Init(moduleFFI);
62
+ rbffi_LastError_Init(moduleFFI);
63
+ rbffi_Platform_Init(moduleFFI);
64
+ rbffi_AbstractMemory_Init(moduleFFI);
65
+ rbffi_Pointer_Init(moduleFFI);
66
+ rbffi_AutoPointer_Init(moduleFFI);
67
+ rbffi_NullPointer_Init(moduleFFI);
68
+ rbffi_MemoryPointer_Init(moduleFFI);
69
+ rbffi_Buffer_Init(moduleFFI);
70
+ rbffi_Callback_Init(moduleFFI);
71
+ rbffi_Struct_Init(moduleFFI);
72
+ rbffi_DynamicLibrary_Init(moduleFFI);
73
+ rbffi_Invoker_Init(moduleFFI);
74
+ rbffi_Types_Init(moduleFFI);
98
75
  }
99
76
 
@@ -0,0 +1,34 @@
1
+ # -*- makefile -*-
2
+ #
3
+ # Makefile for BSD systems
4
+ #
5
+
6
+ INCFLAGS += -I${LIBFFI_BUILD_DIR}/include
7
+ LOCAL_LIBS += ${LIBFFI} -lpthread
8
+
9
+ LIBFFI_CFLAGS = ${FFI_MMAP_EXEC} -pthread
10
+ LIBFFI_BUILD_DIR = ${.CURDIR}/libffi
11
+
12
+ .if "${srcdir}" == "."
13
+ LIBFFI_SRC_DIR := ${.CURDIR}/libffi
14
+ .else
15
+ LIBFFI_SRC_DIR := ${srcdir}/libffi
16
+ .endif
17
+
18
+
19
+ LIBFFI = ${LIBFFI_BUILD_DIR}/.libs/libffi_convenience.a
20
+ LIBFFI_CONFIGURE = ${LIBFFI_SRC_DIR}/configure --disable-static \
21
+ --with-pic=yes --disable-dependency-tracking
22
+
23
+ $(OBJS): ${LIBFFI}
24
+
25
+ $(LIBFFI):
26
+ @mkdir -p ${LIBFFI_BUILD_DIR}
27
+ @if [ ! -f ${LIBFFI_BUILD_DIR}/Makefile ]; then \
28
+ echo "Configuring libffi"; \
29
+ cd ${LIBFFI_BUILD_DIR} && \
30
+ /usr/bin/env CC="${CC}" LD="${LD}" CFLAGS="${LIBFFI_CFLAGS}" \
31
+ /bin/sh ${LIBFFI_CONFIGURE} ${LIBFFI_HOST} > /dev/null; \
32
+ fi
33
+ @cd ${LIBFFI_BUILD_DIR} && ${MAKE}
34
+
@@ -1,32 +1,52 @@
1
1
  # -*- makefile -*-
2
- ARCHES :=
2
+
3
+ include ${srcdir}/libffi.gnu.mk
4
+
3
5
  CCACHE := $(shell type -p ccache)
6
+ BUILD_DIR := $(shell pwd)
7
+
8
+ INCFLAGS += -I${BUILD_DIR}
9
+
10
+ # Work out which arches we need to compile the lib for
11
+ ARCHES :=
4
12
  ifneq ($(findstring -arch ppc,$(CFLAGS)),)
5
13
  ARCHES += ppc
6
14
  endif
15
+
7
16
  ifneq ($(findstring -arch i386,$(CFLAGS)),)
8
17
  ARCHES += i386
9
18
  endif
19
+
10
20
  ifneq ($(findstring -arch x86_64,$(CFLAGS)),)
11
21
  ARCHES += x86_64
12
22
  endif
13
- ifeq ($(ARCHES),)
14
- ARCHES = $(shell arch)
15
- endif
16
23
 
24
+ ifeq ($(strip $(ARCHES)),)
25
+ # Just build the one (default) architecture
26
+ $(LIBFFI):
27
+ @mkdir -p $(LIBFFI_BUILD_DIR)
28
+ @if [ ! -f $(LIBFFI_BUILD_DIR)/Makefile ]; then \
29
+ echo "Configuring libffi"; \
30
+ cd $(LIBFFI_BUILD_DIR) && \
31
+ /usr/bin/env CC="$(CC)" LD="$(LD)" CFLAGS="$(LIBFFI_CFLAGS)" \
32
+ /bin/sh $(LIBFFI_CONFIGURE) $(LIBFFI_HOST) > /dev/null; \
33
+ fi
34
+ cd $(LIBFFI_BUILD_DIR) && $(MAKE)
35
+
36
+ else
37
+ # Build a fat binary and assemble
17
38
  build_ffi = \
18
39
  mkdir -p $(BUILD_DIR)/libffi-$(1); \
19
40
  (if [ ! -f $(BUILD_DIR)/libffi-$(1)/Makefile ]; then \
20
41
  echo "Configuring libffi for $(1)"; \
21
42
  cd $(BUILD_DIR)/libffi-$(1) && \
22
- env CC="$(CCACHE) $(CC)" CFLAGS="-arch $(1) $(FFI_CFLAGS)" LDFLAGS="-arch $(1)" \
23
- $(FFI_CONFIGURE) --host=$(1)-apple-darwin > /dev/null; \
43
+ env CC="$(CCACHE) $(CC)" CFLAGS="-arch $(1) $(LIBFFI_CFLAGS)" LDFLAGS="-arch $(1)" \
44
+ $(LIBFFI_CONFIGURE) --host=$(1)-apple-darwin > /dev/null; \
24
45
  fi); \
25
46
  env MACOSX_DEPLOYMENT_TARGET=10.4 $(MAKE) -C $(BUILD_DIR)/libffi-$(1)
26
-
47
+
27
48
  $(LIBFFI):
28
- @for arch in $(ARCHES); do $(call build_ffi,$$arch);done
29
-
49
+ @for arch in $(ARCHES); do $(call build_ffi,$$arch);done
30
50
  # Assemble into a FAT (i386, ppc) library
31
51
  @mkdir -p $(BUILD_DIR)/libffi/.libs
32
52
  env MACOSX_DEPLOYMENT_TARGET=10.4 /usr/bin/libtool -static -o $@ \
@@ -51,5 +71,5 @@ $(LIBFFI):
51
71
  printf "#include \"libffi-ppc/include/ffitarget.h\"\n";\
52
72
  printf "#endif\n";\
53
73
  ) > $(LIBFFI_BUILD_DIR)/include/ffitarget.h
54
-
55
74
 
75
+ endif
@@ -0,0 +1,29 @@
1
+ # -*- makefile -*-
2
+ #
3
+ # Common definitions for all systems that use GNU make
4
+ #
5
+
6
+
7
+ # Tack the extra deps onto the autogenerated variables
8
+ INCFLAGS += -I$(LIBFFI_BUILD_DIR)/include
9
+ LOCAL_LIBS += $(LIBFFI)
10
+ BUILD_DIR = $(shell pwd)
11
+ LIBFFI_CFLAGS = $(FFI_MMAP_EXEC)
12
+ LIBFFI_BUILD_DIR = $(BUILD_DIR)/libffi
13
+
14
+ ifeq ($(srcdir),.)
15
+ LIBFFI_SRC_DIR := $(shell pwd)/libffi
16
+ else
17
+ LIBFFI_SRC_DIR := $(srcdir)/libffi
18
+ endif
19
+
20
+ LIBFFI = $(LIBFFI_BUILD_DIR)/.libs/libffi_convenience.a
21
+ LIBFFI_CONFIGURE = $(LIBFFI_SRC_DIR)/configure --disable-static \
22
+ --with-pic=yes --disable-dependency-tracking
23
+
24
+ $(OBJS): $(LIBFFI)
25
+
26
+ #
27
+ # libffi.mk or libffi.darwin.mk contains rules for building the actual library
28
+ #
29
+
@@ -1,11 +1,13 @@
1
1
  # -*- makefile -*-
2
2
 
3
+ include ${srcdir}/libffi.gnu.mk
4
+
3
5
  $(LIBFFI):
4
6
  @mkdir -p $(LIBFFI_BUILD_DIR)
5
7
  @if [ ! -f $(LIBFFI_BUILD_DIR)/Makefile ]; then \
6
8
  echo "Configuring libffi"; \
7
9
  cd $(LIBFFI_BUILD_DIR) && \
8
- /usr/bin/env CC="$(CC)" LD="$(LD)" CFLAGS="$(FFI_CFLAGS)" \
9
- /bin/sh $(FFI_CONFIGURE) $(LIBFFI_HOST) > /dev/null; \
10
+ /usr/bin/env CC="$(CC)" LD="$(LD)" CFLAGS="$(LIBFFI_CFLAGS)" \
11
+ /bin/sh $(LIBFFI_CONFIGURE) $(LIBFFI_HOST) > /dev/null; \
10
12
  fi
11
13
  cd $(LIBFFI_BUILD_DIR) && $(MAKE)