ffi 0.6.3 → 0.6.4
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.
- data/README.md +109 -0
- data/Rakefile +84 -56
- data/ext/ffi_c/Ffi_c.iml +12 -0
- data/ext/ffi_c/StructLayout.c +2 -1
- data/ffi.gemspec +18 -0
- data/gen/log +1 -0
- data/lib/Lib.iml +21 -0
- data/lib/ffi/platform.rb +5 -3
- data/libtest/Benchmark.c +73 -0
- data/libtest/BoolTest.c +52 -0
- data/libtest/BufferTest.c +52 -0
- data/libtest/ClosureTest.c +173 -0
- data/libtest/EnumTest.c +55 -0
- data/libtest/FunctionTest.c +50 -0
- data/libtest/GNUmakefile +141 -0
- data/libtest/GlobalVariable.c +56 -0
- data/libtest/LastErrorTest.c +41 -0
- data/libtest/NumberTest.c +145 -0
- data/libtest/PointerTest.c +84 -0
- data/libtest/ReferenceTest.c +44 -0
- data/libtest/StringTest.c +55 -0
- data/libtest/StructTest.c +247 -0
- data/libtest/UnionTest.c +64 -0
- data/libtest/VariadicTest.c +57 -0
- data/spec/ffi/Ffi.iml +12 -0
- metadata +137 -106
- data/README.rdoc +0 -69
- data/tasks/ann.rake +0 -80
- data/tasks/extension.rake +0 -25
- data/tasks/gem.rake +0 -200
- data/tasks/git.rake +0 -41
- data/tasks/notes.rake +0 -27
- data/tasks/post_load.rake +0 -34
- data/tasks/rdoc.rake +0 -50
- data/tasks/rubyforge.rake +0 -55
- data/tasks/setup.rb +0 -300
- data/tasks/spec.rake +0 -54
- data/tasks/svn.rake +0 -47
- data/tasks/test.rake +0 -40
data/libtest/BoolTest.c
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2009 Aman Gupta. All rights reserved.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions are met:
|
6
|
+
*
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
* list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
* Neither the name of the project nor the names of its contributors
|
13
|
+
* may be used to endorse or promote products derived from this software
|
14
|
+
* without specific prior written permission.
|
15
|
+
*
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
20
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
#include <stdbool.h>
|
29
|
+
|
30
|
+
bool
|
31
|
+
bool_return_true()
|
32
|
+
{
|
33
|
+
return true;
|
34
|
+
}
|
35
|
+
|
36
|
+
bool
|
37
|
+
bool_return_false()
|
38
|
+
{
|
39
|
+
return false;
|
40
|
+
}
|
41
|
+
|
42
|
+
bool
|
43
|
+
bool_return_val(bool value)
|
44
|
+
{
|
45
|
+
return value;
|
46
|
+
}
|
47
|
+
|
48
|
+
bool
|
49
|
+
bool_reverse_val(bool value)
|
50
|
+
{
|
51
|
+
return value ? false : true;
|
52
|
+
}
|
@@ -0,0 +1,52 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2007 Wayne Meissner
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions are met:
|
6
|
+
*
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
* list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
* Neither the name of the project nor the names of its contributors
|
13
|
+
* may be used to endorse or promote products derived from this software
|
14
|
+
* without specific prior written permission.
|
15
|
+
*
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
20
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
|
29
|
+
#define MEMSET(buf, value, size) do { \
|
30
|
+
int i; for (i = 0; i < size; ++i) buf[i] = value; \
|
31
|
+
} while(0)
|
32
|
+
#define MEMCPY(dst, src, size) do { \
|
33
|
+
int i; for (i = 0; i < size; ++i) dst[i] = src[i]; \
|
34
|
+
} while(0)
|
35
|
+
|
36
|
+
#define FILL(JTYPE, CTYPE) \
|
37
|
+
void fill##JTYPE##Buffer(CTYPE* buf, CTYPE value, int size) { MEMSET(buf, value, size); }
|
38
|
+
|
39
|
+
#define COPY(JTYPE, CTYPE) \
|
40
|
+
void copy##JTYPE##Buffer(CTYPE* dst, CTYPE* src, int size) { MEMCPY(dst, src, size); }
|
41
|
+
|
42
|
+
#define FUNC(JTYPE, CTYPE) \
|
43
|
+
FILL(JTYPE, CTYPE); \
|
44
|
+
COPY(JTYPE, CTYPE)
|
45
|
+
|
46
|
+
FUNC(Byte, char);
|
47
|
+
FUNC(Short, short);
|
48
|
+
FUNC(Int, int);
|
49
|
+
FUNC(Long, long long);
|
50
|
+
FUNC(Float, float);
|
51
|
+
FUNC(Double, double);
|
52
|
+
|
@@ -0,0 +1,173 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions are met:
|
6
|
+
*
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
* list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
* Neither the name of the project nor the names of its contributors
|
13
|
+
* may be used to endorse or promote products derived from this software
|
14
|
+
* without specific prior written permission.
|
15
|
+
*
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
20
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
#include <stdlib.h>
|
29
|
+
#include <stdbool.h>
|
30
|
+
|
31
|
+
#define R(T, rtype) rtype testClosureVr##T(rtype (*closure)(void)) { \
|
32
|
+
return closure != NULL ? (*closure)() : (rtype) 0; \
|
33
|
+
}
|
34
|
+
|
35
|
+
#define P(T, ptype) void testClosure##T##rV(void (*closure)(ptype), ptype a1) { \
|
36
|
+
if (closure != NULL) (*closure)(a1); \
|
37
|
+
}
|
38
|
+
|
39
|
+
void testClosureVrV(void (*closure)(void))
|
40
|
+
{
|
41
|
+
(*closure)();
|
42
|
+
}
|
43
|
+
|
44
|
+
R(Z, bool);
|
45
|
+
R(B, char);
|
46
|
+
R(S, short);
|
47
|
+
R(I, int);
|
48
|
+
R(L, long);
|
49
|
+
R(J, long long);
|
50
|
+
R(LL, long long);
|
51
|
+
R(F, float);
|
52
|
+
R(D, double);
|
53
|
+
R(P, const void*);
|
54
|
+
|
55
|
+
|
56
|
+
P(Z, bool);
|
57
|
+
P(B, char);
|
58
|
+
P(S, short);
|
59
|
+
P(I, int);
|
60
|
+
P(L, long);
|
61
|
+
P(J, long long);
|
62
|
+
P(LL, long long);
|
63
|
+
P(F, float);
|
64
|
+
P(D, double);
|
65
|
+
P(P, const void*);
|
66
|
+
P(UL, unsigned long);
|
67
|
+
|
68
|
+
void testOptionalClosureBrV(void (*closure)(char), char a1)
|
69
|
+
{
|
70
|
+
if (closure) {
|
71
|
+
(*closure)(a1);
|
72
|
+
}
|
73
|
+
}
|
74
|
+
|
75
|
+
struct s8f32s32 {
|
76
|
+
char s8;
|
77
|
+
float f32;
|
78
|
+
int s32;
|
79
|
+
};
|
80
|
+
|
81
|
+
// Takes a struct argument
|
82
|
+
void testClosureTrV(void (*closure)(struct s8f32s32 s), struct s8f32s32* s)
|
83
|
+
{
|
84
|
+
(*closure)(*s);
|
85
|
+
}
|
86
|
+
|
87
|
+
// Returns a struct value
|
88
|
+
struct s8f32s32 testClosureVrT(struct s8f32s32 (*closure)())
|
89
|
+
{
|
90
|
+
return (*closure)();
|
91
|
+
}
|
92
|
+
|
93
|
+
typedef int (*returnTypeClosure_t)(int) ;
|
94
|
+
typedef returnTypeClosure_t (*lookupClosure_t)();
|
95
|
+
|
96
|
+
int testReturnsClosure(lookupClosure_t lookup, int val)
|
97
|
+
{
|
98
|
+
returnTypeClosure_t func = lookup ? (*lookup)() : NULL;
|
99
|
+
return func ? (*func)(val) : 0;
|
100
|
+
}
|
101
|
+
|
102
|
+
static int multiplyByTwo(int value)
|
103
|
+
{
|
104
|
+
return value * 2;
|
105
|
+
}
|
106
|
+
|
107
|
+
returnTypeClosure_t testReturnsFunctionPointer()
|
108
|
+
{
|
109
|
+
return multiplyByTwo;
|
110
|
+
}
|
111
|
+
|
112
|
+
typedef int (*argumentClosure_t)(int);
|
113
|
+
typedef int (*withArgumentClosure_t)(argumentClosure_t, int);
|
114
|
+
|
115
|
+
int testArgumentClosure(withArgumentClosure_t closure_with, argumentClosure_t closure_arg, int val)
|
116
|
+
{
|
117
|
+
return (*closure_with)(closure_arg, val);
|
118
|
+
}
|
119
|
+
|
120
|
+
|
121
|
+
//
|
122
|
+
// These macros produce functions of the form:
|
123
|
+
// testClosureBIrV(void (*closure)(char, int), char a1, int a2) {}
|
124
|
+
//
|
125
|
+
#define C2_(J1, J2, N1, N2) \
|
126
|
+
void testClosure##J1##J2##rV(void (*closure)(N1, N2), N1 a1, N2 a2) \
|
127
|
+
{ \
|
128
|
+
if (closure != NULL) (*closure)(a1, a2); \
|
129
|
+
}
|
130
|
+
|
131
|
+
#define C2(J, N) \
|
132
|
+
C2_(B, J, char, N) \
|
133
|
+
C2_(S, J, short, N) \
|
134
|
+
C2_(I, J, int, N) \
|
135
|
+
C2_(LL, J, long long, N) \
|
136
|
+
C2_(F, J, float, N) \
|
137
|
+
C2_(D, J, double, N) \
|
138
|
+
|
139
|
+
|
140
|
+
C2(B, char);
|
141
|
+
C2(S, short);
|
142
|
+
C2(I, int);
|
143
|
+
C2(LL, long long);
|
144
|
+
C2(F, float);
|
145
|
+
C2(D, double);
|
146
|
+
|
147
|
+
#define C3_(J1, J2, J3, N1, N2, N3) \
|
148
|
+
void testClosure##J1##J2##J3##rV(void (*closure)(N1, N2, N3), N1 a1, N2 a2, N3 a3) \
|
149
|
+
{ \
|
150
|
+
(*closure)(a1, a2, a3); \
|
151
|
+
}
|
152
|
+
|
153
|
+
|
154
|
+
#define C3(J, N) \
|
155
|
+
C3_(B, J, B, char, N, char) \
|
156
|
+
C3_(S, J, S, short, N, short) \
|
157
|
+
C3_(I, J, I, int, N, int) \
|
158
|
+
C3_(LL, J, LL, long long, N, long long) \
|
159
|
+
C3_(F, J, F, float, N, float) \
|
160
|
+
C3_(D, J, D, double, N, double) \
|
161
|
+
|
162
|
+
C3(B, char);
|
163
|
+
C3(S, short);
|
164
|
+
C3(I, int);
|
165
|
+
C3(LL, long long);
|
166
|
+
C3(F, float);
|
167
|
+
C3(D, double);
|
168
|
+
C3_(B, S, I, char, short, int);
|
169
|
+
C3_(B, S, LL, char, short, long long);
|
170
|
+
C3_(LL, S, B, long long, short, char);
|
171
|
+
C3_(LL, B, S, long long, char, short);
|
172
|
+
|
173
|
+
|
data/libtest/EnumTest.c
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2007 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions are met:
|
6
|
+
*
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
* list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
* Neither the name of the project nor the names of its contributors
|
13
|
+
* may be used to endorse or promote products derived from this software
|
14
|
+
* without specific prior written permission.
|
15
|
+
*
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
20
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
int test_untagged_enum(int val) {
|
29
|
+
return val;
|
30
|
+
}
|
31
|
+
|
32
|
+
int test_untagged_typedef_enum(int val) {
|
33
|
+
return val;
|
34
|
+
}
|
35
|
+
|
36
|
+
typedef enum {c1, c2, c3, c4} enum_type1;
|
37
|
+
enum_type1 test_tagged_typedef_enum1(enum_type1 val) {
|
38
|
+
return val;
|
39
|
+
}
|
40
|
+
|
41
|
+
typedef enum {c5 = 42, c6, c7, c8} enum_type2;
|
42
|
+
enum_type2 test_tagged_typedef_enum2(enum_type2 val) {
|
43
|
+
return val;
|
44
|
+
}
|
45
|
+
|
46
|
+
typedef enum {c9 = 42, c10, c11 = 4242, c12} enum_type3;
|
47
|
+
enum_type3 test_tagged_typedef_enum3(enum_type3 val) {
|
48
|
+
return val;
|
49
|
+
}
|
50
|
+
|
51
|
+
typedef enum {c13 = 42, c14 = 4242, c15 = 424242, c16 = 42424242} enum_type4;
|
52
|
+
enum_type4 test_tagged_typedef_enum4(enum_type4 val) {
|
53
|
+
return val;
|
54
|
+
}
|
55
|
+
|
@@ -0,0 +1,50 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2009 Wayne Meissner. All rights reserved.
|
3
|
+
*
|
4
|
+
* Redistribution and use in source and binary forms, with or without
|
5
|
+
* modification, are permitted provided that the following conditions are met:
|
6
|
+
*
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this
|
8
|
+
* list of conditions and the following disclaimer.
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice
|
10
|
+
* this list of conditions and the following disclaimer in the documentation
|
11
|
+
* and/or other materials provided with the distribution.
|
12
|
+
* Neither the name of the project nor the names of its contributors
|
13
|
+
* may be used to endorse or promote products derived from this software
|
14
|
+
* without specific prior written permission.
|
15
|
+
*
|
16
|
+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
17
|
+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
18
|
+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
19
|
+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
|
20
|
+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
21
|
+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
22
|
+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
23
|
+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
24
|
+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
25
|
+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
26
|
+
*/
|
27
|
+
|
28
|
+
#include <unistd.h>
|
29
|
+
|
30
|
+
#ifdef __WIN32__
|
31
|
+
#include <windows.h>
|
32
|
+
#define sleep(x) Sleep(x)
|
33
|
+
#endif
|
34
|
+
|
35
|
+
int testAdd(int a, int b)
|
36
|
+
{
|
37
|
+
return a + b;
|
38
|
+
};
|
39
|
+
|
40
|
+
int testFunctionAdd(int a, int b, int (*f)(int, int))
|
41
|
+
{
|
42
|
+
return f(a, b);
|
43
|
+
};
|
44
|
+
|
45
|
+
void testBlocking(int seconds) {
|
46
|
+
sleep(seconds);
|
47
|
+
};
|
48
|
+
|
49
|
+
|
50
|
+
|
data/libtest/GNUmakefile
ADDED
@@ -0,0 +1,141 @@
|
|
1
|
+
# -*- makefile -*-
|
2
|
+
|
3
|
+
ifeq ($(OS),)
|
4
|
+
BUILD_OS := $(shell uname -s | tr '[:upper:]' '[:lower:]')
|
5
|
+
OS := $(BUILD_OS)
|
6
|
+
endif
|
7
|
+
|
8
|
+
ifeq ($(CPU),)
|
9
|
+
CPU := $(shell uname -m | sed -e 's/i[345678]86/i386/')
|
10
|
+
endif
|
11
|
+
|
12
|
+
MODEL = 32 # Default to 32bit compiles
|
13
|
+
|
14
|
+
PLATFORM = $(CPU)-$(OS)
|
15
|
+
|
16
|
+
ifeq ($(OS), sunos)
|
17
|
+
OS = solaris
|
18
|
+
endif
|
19
|
+
|
20
|
+
SRC_DIR = libtest
|
21
|
+
BUILD_DIR ?= build
|
22
|
+
TEST_BUILD_DIR = $(BUILD_DIR)/libtest
|
23
|
+
# Set defaults to unix (linux/solaris/bsd)
|
24
|
+
PREFIX = lib
|
25
|
+
LIBEXT ?= so
|
26
|
+
LIBNAME = $(PREFIX)test.$(LIBEXT)
|
27
|
+
|
28
|
+
export MACOSX_DEPLOYMENT_TARGET=10.4
|
29
|
+
|
30
|
+
CCACHE := $(strip $(realpath $(shell which ccache 2> /dev/null)))
|
31
|
+
|
32
|
+
TEST_SRCS = $(wildcard $(SRC_DIR)/*.c)
|
33
|
+
TEST_OBJS := $(patsubst $(SRC_DIR)/%.c, $(TEST_BUILD_DIR)/%.o, $(TEST_SRCS))
|
34
|
+
|
35
|
+
#
|
36
|
+
# Compiler/linker flags from:
|
37
|
+
# http://weblogs.java.net/blog/kellyohair/archive/2006/01/compilation_of_1.html
|
38
|
+
JFLAGS = -fno-omit-frame-pointer -fno-strict-aliasing
|
39
|
+
OFLAGS = -O2 $(JFLAGS)
|
40
|
+
WFLAGS = -W -Werror -Wall -Wno-unused -Wno-parentheses
|
41
|
+
PICFLAGS = -fPIC
|
42
|
+
SOFLAGS = -shared -mimpure-text -Wl,-O1
|
43
|
+
LDFLAGS += $(SOFLAGS)
|
44
|
+
|
45
|
+
IFLAGS = -I"$(BUILD_DIR)"
|
46
|
+
CFLAGS = $(OFLAGS) $(WFLAGS) $(IFLAGS) $(PICFLAGS) -D_REENTRANT
|
47
|
+
|
48
|
+
ifneq ($(strip $(findstring $(OS), win32, mingw, cygwin)),)
|
49
|
+
# For cygwin => win32-native builds, strip out cygwin deps
|
50
|
+
ifneq ($(findstring cygwin, $(BUILD_OS)),)
|
51
|
+
CC += -mno-cygwin -mwin32
|
52
|
+
LDFLAGS += -mno-cygwin -Wl,--add-stdcall-alias
|
53
|
+
endif
|
54
|
+
PICFLAGS=
|
55
|
+
LIBEXT=dll
|
56
|
+
CC = gcc
|
57
|
+
endif
|
58
|
+
|
59
|
+
ifeq ($(OS), darwin)
|
60
|
+
ARCHFLAGS = -arch ppc
|
61
|
+
ifneq ($(findstring $(CPU),i386 x86_64),)
|
62
|
+
ARCHFLAGS += -arch i386 -arch x86_64
|
63
|
+
endif
|
64
|
+
CFLAGS += $(ARCHFLAGS) -DTARGET_RT_MAC_CFM=0
|
65
|
+
CFLAGS += -fno-common
|
66
|
+
MACSDK = /Developer/SDKs/MacOSX10.4u.sdk
|
67
|
+
LDFLAGS = $(ARCHFLAGS) -dynamiclib -Wl,-syslibroot,$(MACSDK) -mmacosx-version-min=10.4
|
68
|
+
# link against the universal libraries on ppc machines
|
69
|
+
LDFLAGS += -L$(MACSDK)/usr/lib
|
70
|
+
LIBEXT = dylib
|
71
|
+
FFI_CFLAGS += -isysroot $(MACSDK)
|
72
|
+
PICFLAGS =
|
73
|
+
SOFLAGS =
|
74
|
+
endif
|
75
|
+
|
76
|
+
ifeq ($(OS), linux)
|
77
|
+
SOFLAGS += -Wl,-soname,$(LIBNAME)
|
78
|
+
endif
|
79
|
+
|
80
|
+
ifeq ($(OS), solaris)
|
81
|
+
CC = /usr/sfw/bin/gcc -std=c99
|
82
|
+
LD = /usr/ccs/bin/ld
|
83
|
+
SOFLAGS = -shared -static-libgcc
|
84
|
+
endif
|
85
|
+
|
86
|
+
ifeq ($(OS), aix)
|
87
|
+
LIBEXT = a
|
88
|
+
SOFLAGS = -shared -static-libgcc
|
89
|
+
PICFLAGS += -pthread
|
90
|
+
endif
|
91
|
+
|
92
|
+
ifneq ($(findstring bsd, $(OS)),)
|
93
|
+
SOFLAGS = -shared -static-libgcc
|
94
|
+
CFLAGS += -pthread
|
95
|
+
LDFLAGS += -pthread
|
96
|
+
endif
|
97
|
+
|
98
|
+
ifeq ($(CPU), sparcv9)
|
99
|
+
MODEL = 64
|
100
|
+
endif
|
101
|
+
|
102
|
+
ifeq ($(CPU), amd64)
|
103
|
+
MODEL = 64
|
104
|
+
endif
|
105
|
+
|
106
|
+
ifeq ($(CPU), x86_64)
|
107
|
+
MODEL = 64
|
108
|
+
endif
|
109
|
+
|
110
|
+
ifeq ($(CPU), ppc64)
|
111
|
+
MODEL = 64
|
112
|
+
endif
|
113
|
+
|
114
|
+
ifeq ($(CPU), powerpc64)
|
115
|
+
MODEL = 64
|
116
|
+
endif
|
117
|
+
|
118
|
+
# On platforms (linux, solaris) that support both 32bit and 64bit, force building for one or the other
|
119
|
+
ifneq ($(or $(findstring linux, $(OS)), $(findstring solaris, $(OS))),)
|
120
|
+
# Change the CC/LD instead of CFLAGS/LDFLAGS, incase other things in the flags
|
121
|
+
# makes the libffi build choke
|
122
|
+
CC += -m$(MODEL)
|
123
|
+
LD += -m$(MODEL)
|
124
|
+
endif
|
125
|
+
|
126
|
+
LIBTEST = $(BUILD_DIR)/$(LIBNAME)
|
127
|
+
|
128
|
+
all: $(LIBTEST)
|
129
|
+
|
130
|
+
$(TEST_BUILD_DIR)/%.o : $(SRC_DIR)/%.c
|
131
|
+
@mkdir -p $(@D)
|
132
|
+
$(CCACHE) $(CC) $(CFLAGS) -c $< -o $@
|
133
|
+
|
134
|
+
$(LIBTEST): $(TEST_OBJS)
|
135
|
+
$(CC) -o $@ $(LDFLAGS) $(TEST_OBJS) -lm
|
136
|
+
|
137
|
+
clean::
|
138
|
+
# nothing to do - ant will delete the build dir
|
139
|
+
|
140
|
+
debug::
|
141
|
+
@echo "SRCS=$(TEST_SRCS)"
|