Skip to content
This repository

removed circular requires #63

Closed
wants to merge 10 commits into from

2 participants

Justin Freitag Nathan Rajlich
Justin Freitag

I've gone through lib and test to remove the circular requires that center around ffi.js. My reason for doing this was to get the code (including libffi) working as a native module.

Nathan Rajlich
Collaborator

Cool thanks, I've been meaning to do that. Looks mostly good, except you're changing the public api a lot, which is bad and unnecessary. I'll address some of them inline, but also, all the changes to test should be reverted, since that also should only test the public API.

My reason for doing this was to get the code (including libffi) working as a native module.

What does that mean exactly? node-ffi is a native module so I'm confused.

lib/types.js
@@ -7,41 +7,6 @@ var bindings = require('./bindings')
1
Nathan Rajlich Collaborator
TooTallNate added a note

Why did you change the name of this file? It's the entry point to the module as described in the package.json, so with it renamed the entry point is missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/types.js
@@ -7,41 +7,6 @@ var bindings = require('./bindings')
7 7 var ffi = exports
8 8
9 9 /**
10   - * The extension to use on libraries.
11   - * i.e. libm -> libm.so on linux
12   - */
13   -
14   -Object.defineProperty(ffi, 'LIB_EXT', {
1
Nathan Rajlich Collaborator
TooTallNate added a note

LIB_EXT is public api and shouldn't be removed. If Library is the only thing in node-ffi using it, then it can be defined there, and re-exported in ffi.js if you want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/types.js
((20 lines not shown))
26   - }[process.platform]
27   -})
28   -
29   -/**
30   - * Export some of the properties from the "bindings" file.
31   - */
32   -
33   -;['HAS_OBJC', 'FFI_TYPES',
34   -, 'FFI_OK', 'FFI_BAD_TYPEDEF', 'FFI_BAD_ABI'
35   -, 'FFI_DEFAULT_ABI', 'FFI_LAST_ABI', 'FFI_SYSV', 'FFI_UNIX64', 'FFI_WIN64'
36   -, 'FFI_STDCALL', 'FFI_THISCALL', 'FFI_FASTCALL', 'FFI_MS_CDECL'].forEach(function (prop) {
37   - if (!bindings.hasOwnProperty(prop)) {
38   - return debug('skipping exporting of non-existant property: %s', prop)
39   - }
40   - var desc = Object.getOwnPropertyDescriptor(bindings, prop)
41   - Object.defineProperty(ffi, prop, desc)
1
Nathan Rajlich Collaborator
TooTallNate added a note

Same with these - public API; shouldn't be removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
lib/types.js
@@ -127,17 +92,6 @@ ffi.ffiType = function ffiType (type) {
127 92 return rtn
128 93 }
129 94
130   -
131   -// Include our other modules
132   -ffi.CIF = require('./cif')
133   -ffi.CIF_var = require('./cif_var')
134   -ffi.ForeignFunction = require('./foreign_function')
135   -ffi.VariadicForeignFunction = require('./foreign_function_var')
136   -ffi.DynamicLibrary = require('./dynamic_library')
137   -ffi.Library = require('./library')
138   -ffi.Callback = require('./callback')
139   -ffi.errno = require('./errno')
1
Nathan Rajlich Collaborator
TooTallNate added a note

Same with all of these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
test/library.js
@@ -3,8 +3,16 @@ var expect = require('expect.js')
3 3 , assert = require('assert')
4 4 , ref = require('ref')
5 5 , Struct = require('ref-struct')
6   - , ffi = require('../')
7   - , Library = ffi.Library
  6 + , Library = require('../lib/library')
  7 + , LIB_EXT = {
1
Nathan Rajlich Collaborator
TooTallNate added a note

This is exactly why LIB_EXT is public api in the first place ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
test/callback.js
... ... @@ -1,7 +1,8 @@
1 1
1
Nathan Rajlich Collaborator
TooTallNate added a note

So all of these test changes should be reverted please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Justin Freitag

by 'native module' I meant 'core native', adding libffi as a dependency on core -- its part of a personal project. i'll have a go at restoring the public interface now (essentially ffi.js) and revert the tests.

Justin Freitag

restored the public api and reverted tests.

lib/library.js
((10 lines not shown))
3 9 , debug = require('debug')('ffi:Library')
4   - , EXT = ffi.LIB_EXT
5   - , RTLD_NOW = ffi.DynamicLibrary.FLAGS.RTLD_NOW
  10 + , RTLD_NOW = DynamicLibrary.FLAGS.RTLD_NOW
  11 + , EXT = {
1
Nathan Rajlich Collaborator
TooTallNate added a note

Instead of defining this twice (here and in ffi.js), export it here as Library.EXT = EXT, and then re-export it in ffi.js as ffi.LIB_EXT = ffi.Library.EXT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Nathan Rajlich TooTallNate commented on the diff
lib/type.js
... ... @@ -0,0 +1,53 @@
1
Nathan Rajlich Collaborator
TooTallNate added a note

I like this new addition! Though you dropped the comments from ffi.js (minor I know)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Nathan Rajlich
Collaborator

Very good man a couple more things and then it looks great. Also, what's with that test/.callback.js.swp file?

Justin Freitag

my bad, I wrongly assumed there was a friendly .gitignore file in the repo. it's cleaned up now together with the duplicate LIB_EXT definitions and type.js comments

Nathan Rajlich TooTallNate closed this pull request from a commit
Justin Freitag justinfreitag lib: removed circular module references
Closes #63.

Squashed commit of the following:

commit 58ffa8c
Author: Justin Freitag <justin.freitag@gmail.com>
Date:   Wed Jun 27 15:38:35 2012 +1000

    re-added comments

commit ca43c9d
Author: Justin Freitag <justin.freitag@gmail.com>
Date:   Wed Jun 27 15:34:25 2012 +1000

    removed vim swap file

commit acd10dd
Author: Justin Freitag <justin.freitag@gmail.com>
Date:   Wed Jun 27 15:31:49 2012 +1000

    removed duplicate LIB_EXT definition

commit 21094ff
Author: Justin Freitag <justin.freitag@gmail.com>
Date:   Wed Jun 27 15:08:57 2012 +1000

    changes

commit 078008a
Author: Justin Freitag <justin.freitag@gmail.com>
Date:   Wed Jun 27 15:07:44 2012 +1000

    restored public api

commit 765a7ac
Author: Justin Freitag <justin.freitag@gmail.com>
Date:   Wed Jun 27 14:47:21 2012 +1000

    changes

commit bb43242
Author: Justin Freitag <justin.freitag@gmail.com>
Date:   Wed Jun 27 14:45:57 2012 +1000

    changes

commit 466c543
Author: Justin Freitag <justin.freitag@gmail.com>
Date:   Wed Jun 27 13:01:13 2012 +1000

    removed circular module references
0a556e9
Nathan Rajlich
Collaborator

Thanks @justinfreitag, merged in 0a556e9.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
22 .gitignore
... ... @@ -1,16 +1,6 @@
1   -.lock-wscript
2   -*.dylib
3   -*.so
4   -*.o
5   -*.lo
6   -*.Makefile
7   -*.target.gyp.mk
8   -build
9   -out
10   -Release
11   -Debug
12   -node_modules
13   -Makefile.gyp
14   -gyp-*-tool
15   -.dirstamp
16   -npm-debug.log
  1 +*.log
  2 +~*
  3 +.*
  4 +node_modules/
  5 +build/
  6 +
3  lib/_foreign_function.js
... ... @@ -1,6 +1,5 @@
1 1
2   -var ffi = require('./ffi')
3   - , assert = require('assert')
  2 +var assert = require('assert')
4 3 , debug = require('debug')('ffi:_ForeignFunction')
5 4 , ref = require('ref')
6 5 , bindings = require('./bindings')
4 lib/callback.js
... ... @@ -1,5 +1,5 @@
1 1
2   -var ffi = require('./ffi')
  2 +var CIF = require('./cif')
3 3 , assert = require('assert')
4 4 , ref = require('ref')
5 5 , debug = require('debug')('ffi:Callback')
@@ -31,7 +31,7 @@ function Callback (retType, types, abi, func) {
31 31 types = types.map(ref.coerceType)
32 32
33 33 // create the `ffi_cif *` instance
34   - var cif = ffi.CIF(retType, types, abi)
  34 + var cif = CIF(retType, types, abi)
35 35 var argc = types.length
36 36
37 37 return _Callback(cif, retType.size, argc, function (retval, params) {
6 lib/cif.js
... ... @@ -1,5 +1,5 @@
1 1
2   -var ffi = require('./ffi')
  2 +var Type = require('./type').Type
3 3 , assert = require('assert')
4 4 , debug = require('debug')('ffi:cif')
5 5 , ref = require('ref')
@@ -30,11 +30,11 @@ function CIF (rtype, types, abi) {
30 30
31 31 var numArgs = types.length
32 32 var _argtypesptr = new Buffer(numArgs * POINTER_SIZE)
33   - var _rtypeptr = ffi.ffiType(rtype)
  33 + var _rtypeptr = Type(rtype)
34 34
35 35 for (var i = 0; i < numArgs; i++) {
36 36 var type = types[i]
37   - var ffiType = ffi.ffiType(type)
  37 + var ffiType = Type(type)
38 38
39 39 _argtypesptr.writePointer(ffiType, i * POINTER_SIZE)
40 40 }
6 lib/cif_var.js
... ... @@ -1,5 +1,5 @@
1 1
2   -var ffi = require('./ffi')
  2 +var Type = require('./type').Type
3 3 , assert = require('assert')
4 4 , debug = require('debug')('ffi:cif_var')
5 5 , ref = require('ref')
@@ -31,10 +31,10 @@ function CIF_var (rtype, types, numFixedArgs, abi) {
31 31
32 32 var numTotalArgs = types.length
33 33 var _argtypesptr = new Buffer(numTotalArgs * POINTER_SIZE)
34   - var _rtypeptr = ffi.ffiType(rtype)
  34 + var _rtypeptr = Type(rtype)
35 35
36 36 for (var i = 0; i < numTotalArgs; i++) {
37   - var ffiType = ffi.ffiType(types[i])
  37 + var ffiType = Type(types[i])
38 38 _argtypesptr.writePointer(ffiType, i * POINTER_SIZE)
39 39 }
40 40
10 lib/dynamic_library.js
... ... @@ -1,4 +1,4 @@
1   -var ffi = require('./ffi')
  1 +var ForeignFunction = require('./foreign_function')
2 2 , assert = require('assert')
3 3 , debug = require('debug')('ffi:DynamicLibrary')
4 4 , bindings = require('./bindings')
@@ -9,10 +9,10 @@ var int = ref.types.int
9 9 , charPtr = ref.refType(ref.types.char)
10 10 , voidPtr = ref.refType(ref.types.void)
11 11
12   -var dlopen = ffi.ForeignFunction(bindings.StaticFunctions.dlopen, voidPtr, [ charPtr, int ])
13   - , dlclose = ffi.ForeignFunction(bindings.StaticFunctions.dlclose, int, [ voidPtr ])
14   - , dlsym = ffi.ForeignFunction(bindings.StaticFunctions.dlsym, voidPtr, [ voidPtr, charPtr ])
15   - , dlerror = ffi.ForeignFunction(bindings.StaticFunctions.dlerror, charPtr, [ ])
  12 +var dlopen = ForeignFunction(bindings.StaticFunctions.dlopen, voidPtr, [ charPtr, int ])
  13 + , dlclose = ForeignFunction(bindings.StaticFunctions.dlclose, int, [ voidPtr ])
  14 + , dlsym = ForeignFunction(bindings.StaticFunctions.dlsym, voidPtr, [ voidPtr, charPtr ])
  15 + , dlerror = ForeignFunction(bindings.StaticFunctions.dlerror, charPtr, [ ])
16 16
17 17 /**
18 18 * `DynamicLibrary` loads and fetches function pointers for dynamic libraries
13 lib/errno.js
@@ -6,20 +6,21 @@
6 6 * On Windows it's a method execution called `_errno`.
7 7 */
8 8
9   -var ffi = require('./ffi')
  9 +var DynamicLibrary = require('./dynamic_library')
  10 + , ForeignFunction = require('./foreign_function')
10 11 , ref = require('ref')
11 12 , errnoPtr = null
12 13 , int = ref.types.int
13 14 , intPtr = ref.refType(int)
14 15
15 16 if (process.platform == 'darwin' || process.platform == 'mac') {
16   - var __error = ffi.DynamicLibrary().get('__error')
17   - errnoPtr = ffi.ForeignFunction(__error, intPtr, [])
  17 + var __error = DynamicLibrary().get('__error')
  18 + errnoPtr = ForeignFunction(__error, intPtr, [])
18 19 } else if (process.platform == 'win32') {
19   - var _errno = ffi.DynamicLibrary('msvcrt.dll').get('_errno')
20   - errnoPtr = ffi.ForeignFunction(_errno, intPtr, [])
  20 + var _errno = DynamicLibrary('msvcrt.dll').get('_errno')
  21 + errnoPtr = ForeignFunction(_errno, intPtr, [])
21 22 } else { // linux, sunos, etc.
22   - var errnoGlobal = ffi.DynamicLibrary().get('errno').reinterpret(int.size)
  23 + var errnoGlobal = DynamicLibrary().get('errno').reinterpret(int.size)
23 24 errnoPtr = function () { return errnoGlobal }
24 25 // set the errno type
25 26 errnoGlobal.type = int
102 lib/ffi.js
... ... @@ -1,30 +1,8 @@
1   -
2 1 var ref = require('ref')
3 2 var assert = require('assert')
4 3 var debug = require('debug')('ffi:ffi')
5 4 var Struct = require('ref-struct')
6 5 var bindings = require('./bindings')
7   -var ffi = exports
8   -
9   -/**
10   - * The extension to use on libraries.
11   - * i.e. libm -> libm.so on linux
12   - */
13   -
14   -Object.defineProperty(ffi, 'LIB_EXT', {
15   - configurable: true
16   - , enumerable: true
17   - , writable: false
18   - , value: {
19   - 'linux': '.so'
20   - , 'linux2': '.so'
21   - , 'sunos': '.so'
22   - , 'solaris':'.so'
23   - , 'darwin': '.dylib'
24   - , 'mac': '.dylib'
25   - , 'win32': '.dll'
26   - }[process.platform]
27   -})
28 6
29 7 /**
30 8 * Export some of the properties from the "bindings" file.
@@ -38,7 +16,7 @@ Object.defineProperty(ffi, 'LIB_EXT', {
38 16 return debug('skipping exporting of non-existant property: %s', prop)
39 17 }
40 18 var desc = Object.getOwnPropertyDescriptor(bindings, prop)
41   - Object.defineProperty(ffi, prop, desc)
  19 + Object.defineProperty(exports, prop, desc)
42 20 })
43 21
44 22 /**
@@ -82,72 +60,18 @@ switch (ref.sizeof.long) {
82 60 * Alias the "ref" types onto ffi's exports, for convenience...
83 61 */
84 62
85   -ffi.types = ref.types
86   -
87   -
88   -/**
89   - * Returns a `ffi_type *` Buffer appropriate for the given "type".
90   - */
91   -
92   -ffi.ffiType = function ffiType (type) {
93   - debug('ffiType()', type.name || type)
94   - type = ref.coerceType(type)
95   - assert(type.indirection >= 1, 'invalid "type" given: ' + (type.name || type))
96   - var rtn
97   - if (type.indirection === 1) {
98   - rtn = type.ffi_type
99   - } else {
100   - rtn = bindings.FFI_TYPES.pointer
101   - }
102   -
103   - if (!rtn && type.fields) {
104   - // got a "ref-struct" type
105   - // need to create the `ffi_type` instance manually
106   - debug('creating an `ffi_type` for given "ref-struct" type')
107   - var props = type.fields
108   - , propNames = Object.keys(props)
109   - , numProps = propNames.length
110   - var t = new ffi.FFI_TYPE
111   - t.size = 0
112   - t.alignment = 0
113   - t.type = 13 // FFI_TYPE_STRUCT
114   - var elementsSize = ref.sizeof.pointer * (numProps + 1) // +1 because of the NULL terminator
115   - var elements = t.elements = new Buffer(elementsSize)
116   - for (var i = 0; i < numProps; i++) {
117   - var prop = props[propNames[i]]
118   - elements.writePointer(ffi.ffiType(prop.type), i * ref.sizeof.pointer)
119   - }
120   - // final NULL pointer to terminate the Array
121   - elements.writePointer(ref.NULL, i * ref.sizeof.pointer)
122   - // also set the `ffi_type` property to that it's cached for next time
123   - rtn = type.ffi_type = t.ref()
124   - }
125   - assert(rtn, 'Could not determine the `ffi_type` instance for type: ' + (type.name || type))
126   - debug('returning `ffi_type`', rtn.name)
127   - return rtn
128   -}
129   -
  63 +exports.types = ref.types
130 64
131 65 // Include our other modules
132   -ffi.CIF = require('./cif')
133   -ffi.CIF_var = require('./cif_var')
134   -ffi.ForeignFunction = require('./foreign_function')
135   -ffi.VariadicForeignFunction = require('./foreign_function_var')
136   -ffi.DynamicLibrary = require('./dynamic_library')
137   -ffi.Library = require('./library')
138   -ffi.Callback = require('./callback')
139   -ffi.errno = require('./errno')
140   -
141   -/**
142   - * Define the `ffi_type` struct (see deps/libffi/include/ffi.h) for use in JS.
143   - * This struct type is used internally to define custom struct rtn/arg types.
144   - */
  66 +exports.CIF = require('./cif')
  67 +exports.CIF_var = require('./cif_var')
  68 +exports.ForeignFunction = require('./foreign_function')
  69 +exports.VariadicForeignFunction = require('./foreign_function_var')
  70 +exports.DynamicLibrary = require('./dynamic_library')
  71 +exports.Library = require('./library').Library
  72 +exports.LIB_EXT = require('./library').LIB_EXT
  73 +exports.Callback = require('./callback')
  74 +exports.errno = require('./errno')
  75 +exports.ffiType = require('./type').Type
  76 +exports.FFI_TYPE = require('./type').FFI_TYPE
145 77
146   -ffi.FFI_TYPE = Struct()
147   -ffi.FFI_TYPE.defineProperty('size', ref.types.size_t)
148   -ffi.FFI_TYPE.defineProperty('alignment', ref.types.ushort)
149   -ffi.FFI_TYPE.defineProperty('type', ref.types.ushort)
150   -// this last prop is a C Array of `ffi_type *` elements, so this is `ffi_type **`
151   -var ffi_type_ptr_array = ref.refType(ref.refType(ffi.FFI_TYPE))
152   -ffi.FFI_TYPE.defineProperty('elements', ffi_type_ptr_array)
153   -assert.equal(bindings.FFI_TYPE_SIZE, ffi.FFI_TYPE.size)
4 lib/foreign_function.js
... ... @@ -1,5 +1,5 @@
1 1
2   -var ffi = require('./ffi')
  2 +var CIF = require('./cif')
3 3 , _ForeignFunction = require('./_foreign_function')
4 4 , debug = require('debug')('ffi:ForeignFunction')
5 5 , assert = require('assert')
@@ -26,7 +26,7 @@ function ForeignFunction (funcPtr, returnType, argTypes, abi) {
26 26 argTypes = argTypes.map(ref.coerceType)
27 27
28 28 // create the `ffi_cif *` instance
29   - var cif = ffi.CIF(returnType, argTypes, abi)
  29 + var cif = CIF(returnType, argTypes, abi)
30 30
31 31 // create and return the JS proxy function
32 32 return _ForeignFunction(cif, funcPtr, returnType, argTypes)
11 lib/foreign_function_var.js
... ... @@ -1,5 +1,6 @@
1 1
2   -var ffi = require('./ffi')
  2 +var CIF_var = require('./cif_var')
  3 + , Type = require('./type').Type
3 4 , _ForeignFunction = require('./_foreign_function')
4 5 , assert = require('assert')
5 6 , debug = require('debug')('ffi:VariadicForeignFunction')
@@ -36,7 +37,7 @@ function VariadicForeignFunction (funcPtr, returnType, fixedArgTypes, abi) {
36 37
37 38 // get the names of the fixed arg types
38 39 var fixedKey = fixedArgTypes.map(function (type) {
39   - var ffi_type = ffi.ffiType(type)
  40 + var ffi_type = Type(type)
40 41 assert(ffi_type.name)
41 42 return ffi_type.name
42 43 })
@@ -55,14 +56,14 @@ function VariadicForeignFunction (funcPtr, returnType, fixedArgTypes, abi) {
55 56 var type = ref.coerceType(arguments[i])
56 57 argTypes.push(type)
57 58
58   - var ffi_type = ffi.ffiType(type)
  59 + var ffi_type = Type(type)
59 60 assert(ffi_type.name)
60 61 key.push(ffi_type.name)
61 62 }
62 63
63 64 // now figure out the return type
64 65 var rtnType = ref.coerceType(variadic_function_generator.returnType)
65   - var rtnName = ffi.ffiType(rtnType).name
  66 + var rtnName = Type(rtnType).name
66 67 assert(rtnName)
67 68
68 69 // first let's generate the key and see if we got a cache-hit
@@ -74,7 +75,7 @@ function VariadicForeignFunction (funcPtr, returnType, fixedArgTypes, abi) {
74 75 } else {
75 76 // create the `ffi_cif *` instance
76 77 debug('creating the variadic ffi_cif instance for key:', key)
77   - var cif = ffi.CIF_var(returnType, argTypes, numFixedArgs, abi)
  78 + var cif = CIF_var(returnType, argTypes, numFixedArgs, abi)
78 79 func = cache[key] = _ForeignFunction(cif, funcPtr, rtnType, argTypes)
79 80 }
80 81 return func
46 lib/library.js
... ... @@ -1,24 +1,49 @@
  1 +/**
  2 + * The extension to use on libraries.
  3 + * i.e. libm -> libm.so on linux
  4 + */
1 5
2   -var ffi = require('./ffi')
  6 +var DynamicLibrary = require('./dynamic_library')
  7 + , ForeignFunction = require('./foreign_function')
  8 + , VariadicForeignFunction = require('./foreign_function_var')
3 9 , debug = require('debug')('ffi:Library')
4   - , EXT = ffi.LIB_EXT
5   - , RTLD_NOW = ffi.DynamicLibrary.FLAGS.RTLD_NOW
  10 + , RTLD_NOW = DynamicLibrary.FLAGS.RTLD_NOW
  11 +
  12 +/**
  13 + * The extension to use on libraries.
  14 + * i.e. libm -> libm.so on linux
  15 + */
  16 +
  17 +Object.defineProperty(exports, 'LIB_EXT', {
  18 + configurable: true
  19 + , enumerable: true
  20 + , writable: false
  21 + , value: {
  22 + 'linux': '.so'
  23 + , 'linux2': '.so'
  24 + , 'sunos': '.so'
  25 + , 'solaris':'.so'
  26 + , 'darwin': '.dylib'
  27 + , 'mac': '.dylib'
  28 + , 'win32': '.dll'
  29 + }[process.platform]
  30 +})
6 31
7 32 /**
8 33 * Provides a friendly abstraction/API on-top of DynamicLibrary and
9 34 * ForeignFunction.
10 35 */
11 36
12   -function Library (libfile, funcs) {
  37 +exports.Library = function Library (libfile, funcs) {
13 38 debug('creating Library object for', libfile)
14 39
15   - if (libfile && libfile.indexOf(EXT) === -1) {
16   - debug('appending library extension to library name', EXT)
17   - libfile += EXT
  40 + if (libfile && libfile.indexOf(exports.LIB_EXT) === -1) {
  41 + debug('appending library extension to library name', exports.LIB_EXT)
  42 + libfile += exports.LIB_EXT
18 43 }
19 44
20 45 var lib = {}
21   - var dl = new ffi.DynamicLibrary(libfile || null, RTLD_NOW)
  46 + var dl = new DynamicLibrary(libfile || null, RTLD_NOW)
22 47
23 48 Object.keys(funcs || {}).forEach(function (func) {
24 49 debug('defining function', func)
@@ -39,13 +64,12 @@ function Library (libfile, funcs) {
39 64 , varargs = fopts && fopts.varargs
40 65
41 66 if (varargs) {
42   - lib[func] = ffi.VariadicForeignFunction(fptr, resultType, paramTypes, abi)
  67 + lib[func] = VariadicForeignFunction(fptr, resultType, paramTypes, abi)
43 68 } else {
44   - var ff = ffi.ForeignFunction(fptr, resultType, paramTypes, abi)
  69 + var ff = ForeignFunction(fptr, resultType, paramTypes, abi)
45 70 lib[func] = async ? ff.async : ff
46 71 }
47 72 })
48 73
49 74 return lib
50 75 }
51   -module.exports = Library
62 lib/type.js
... ... @@ -0,0 +1,62 @@
  1 +var ref = require('ref')
  2 +var assert = require('assert')
  3 +var debug = require('debug')('ffi:types')
  4 +var Struct = require('ref-struct')
  5 +var bindings = require('./bindings')
  6 +
  7 +/**
  8 + * Define the `ffi_type` struct (see deps/libffi/include/ffi.h) for use in JS.
  9 + * This struct type is used internally to define custom struct rtn/arg types.
  10 + */
  11 +
  12 +exports.FFI_TYPE = FFI_TYPE = Struct()
  13 +FFI_TYPE.defineProperty('size', ref.types.size_t)
  14 +FFI_TYPE.defineProperty('alignment', ref.types.ushort)
  15 +FFI_TYPE.defineProperty('type', ref.types.ushort)
  16 +// this last prop is a C Array of `ffi_type *` elements, so this is `ffi_type **`
  17 +var ffi_type_ptr_array = ref.refType(ref.refType(FFI_TYPE))
  18 +FFI_TYPE.defineProperty('elements', ffi_type_ptr_array)
  19 +assert.equal(bindings.FFI_TYPE_SIZE, FFI_TYPE.size)
  20 +
  21 +/**
  22 + * Returns a `ffi_type *` Buffer appropriate for the given "type".
  23 + */
  24 +
  25 +exports.Type = function Type (type) {
  26 + debug('Type()', type.name || type)
  27 + type = ref.coerceType(type)
  28 + assert(type.indirection >= 1, 'invalid "type" given: ' + (type.name || type))
  29 + var rtn
  30 + if (type.indirection === 1) {
  31 + rtn = type.ffi_type
  32 + } else {
  33 + rtn = bindings.FFI_TYPES.pointer
  34 + }
  35 +
  36 + if (!rtn && type.fields) {
  37 + // got a "ref-struct" type
  38 + // need to create the `ffi_type` instance manually
  39 + debug('creating an `ffi_type` for given "ref-struct" type')
  40 + var props = type.fields
  41 + , propNames = Object.keys(props)
  42 + , numProps = propNames.length
  43 + var t = new FFI_TYPE
  44 + t.size = 0
  45 + t.alignment = 0
  46 + t.type = 13 // FFI_TYPE_STRUCT
  47 + var elementsSize = ref.sizeof.pointer * (numProps + 1) // +1 because of the NULL terminator
  48 + var elements = t.elements = new Buffer(elementsSize)
  49 + for (var i = 0; i < numProps; i++) {
  50 + var prop = props[propNames[i]]
  51 + elements.writePointer(Type(prop.type), i * ref.sizeof.pointer)
  52 + }
  53 + // final NULL pointer to terminate the Array
  54 + elements.writePointer(ref.NULL, i * ref.sizeof.pointer)
  55 + // also set the `ffi_type` property to that it's cached for next time
  56 + rtn = type.ffi_type = t.ref()
  57 + }
  58 + assert(rtn, 'Could not determine the `ffi_type` instance for type: ' + (type.name || type))
  59 + debug('returning `ffi_type`', rtn.name)
  60 + return rtn
  61 +}
  62 +
344 test/build/Makefile
... ... @@ -0,0 +1,344 @@
  1 +# We borrow heavily from the kernel build setup, though we are simpler since
  2 +# we don't have Kconfig tweaking settings on us.
  3 +
  4 +# The implicit make rules have it looking for RCS files, among other things.
  5 +# We instead explicitly write all the rules we care about.
  6 +# It's even quicker (saves ~200ms) to pass -r on the command line.
  7 +MAKEFLAGS=-r
  8 +
  9 +# The source directory tree.
  10 +srcdir := ..
  11 +abs_srcdir := $(abspath $(srcdir))
  12 +
  13 +# The name of the builddir.
  14 +builddir_name ?= .
  15 +
  16 +# The V=1 flag on command line makes us verbosely print command lines.
  17 +ifdef V
  18 + quiet=
  19 +else
  20 + quiet=quiet_
  21 +endif
  22 +
  23 +# Specify BUILDTYPE=Release on the command line for a release build.
  24 +BUILDTYPE ?= Release
  25 +
  26 +# Directory all our build output goes into.
  27 +# Note that this must be two directories beneath src/ for unit tests to pass,
  28 +# as they reach into the src/ directory for data with relative paths.
  29 +builddir ?= $(builddir_name)/$(BUILDTYPE)
  30 +abs_builddir := $(abspath $(builddir))
  31 +depsdir := $(builddir)/.deps
  32 +
  33 +# Object output directory.
  34 +obj := $(builddir)/obj
  35 +abs_obj := $(abspath $(obj))
  36 +
  37 +# We build up a list of every single one of the targets so we can slurp in the
  38 +# generated dependency rule Makefiles in one pass.
  39 +all_deps :=
  40 +
  41 +
  42 +
  43 +# C++ apps need to be linked with g++.
  44 +#
  45 +# Note: flock is used to seralize linking. Linking is a memory-intensive
  46 +# process so running parallel links can often lead to thrashing. To disable
  47 +# the serialization, override LINK via an envrionment variable as follows:
  48 +#
  49 +# export LINK=g++
  50 +#
  51 +# This will allow make to invoke N linker processes as specified in -jN.
  52 +LINK ?= flock $(builddir)/linker.lock $(CXX)
  53 +
  54 +CC.target ?= $(CC)
  55 +CFLAGS.target ?= $(CFLAGS)
  56 +CXX.target ?= $(CXX)
  57 +CXXFLAGS.target ?= $(CXXFLAGS)
  58 +LINK.target ?= $(LINK)
  59 +LDFLAGS.target ?= $(LDFLAGS)
  60 +AR.target ?= $(AR)
  61 +ARFLAGS.target ?= crsT
  62 +
  63 +# N.B.: the logic of which commands to run should match the computation done
  64 +# in gyp's make.py where ARFLAGS.host etc. is computed.
  65 +# TODO(evan): move all cross-compilation logic to gyp-time so we don't need
  66 +# to replicate this environment fallback in make as well.
  67 +CC.host ?= gcc
  68 +CFLAGS.host ?=
  69 +CXX.host ?= g++
  70 +CXXFLAGS.host ?=
  71 +LINK.host ?= g++
  72 +LDFLAGS.host ?=
  73 +AR.host ?= ar
  74 +ARFLAGS.host := crsT
  75 +
  76 +# Define a dir function that can handle spaces.
  77 +# http://www.gnu.org/software/make/manual/make.html#Syntax-of-Functions
  78 +# "leading spaces cannot appear in the text of the first argument as written.
  79 +# These characters can be put into the argument value by variable substitution."
  80 +empty :=
  81 +space := $(empty) $(empty)
  82 +
  83 +# http://stackoverflow.com/questions/1189781/using-make-dir-or-notdir-on-a-path-with-spaces
  84 +replace_spaces = $(subst $(space),?,$1)
  85 +unreplace_spaces = $(subst ?,$(space),$1)
  86 +dirx = $(call unreplace_spaces,$(dir $(call replace_spaces,$1)))
  87 +
  88 +# Flags to make gcc output dependency info. Note that you need to be
  89 +# careful here to use the flags that ccache and distcc can understand.
  90 +# We write to a dep file on the side first and then rename at the end
  91 +# so we can't end up with a broken dep file.
  92 +depfile = $(depsdir)/$(call replace_spaces,$@).d
  93 +DEPFLAGS = -MMD -MF $(depfile).raw
  94 +
  95 +# We have to fixup the deps output in a few ways.
  96 +# (1) the file output should mention the proper .o file.
  97 +# ccache or distcc lose the path to the target, so we convert a rule of
  98 +# the form:
  99 +# foobar.o: DEP1 DEP2
  100 +# into
  101 +# path/to/foobar.o: DEP1 DEP2
  102 +# (2) we want missing files not to cause us to fail to build.
  103 +# We want to rewrite
  104 +# foobar.o: DEP1 DEP2 \
  105 +# DEP3
  106 +# to
  107 +# DEP1:
  108 +# DEP2:
  109 +# DEP3:
  110 +# so if the files are missing, they're just considered phony rules.
  111 +# We have to do some pretty insane escaping to get those backslashes
  112 +# and dollar signs past make, the shell, and sed at the same time.
  113 +# Doesn't work with spaces, but that's fine: .d files have spaces in
  114 +# their names replaced with other characters.
  115 +define fixup_dep
  116 +# The depfile may not exist if the input file didn't have any #includes.
  117 +touch $(depfile).raw
  118 +# Fixup path as in (1).
  119 +sed -e "s|^$(notdir $@)|$@|" $(depfile).raw >> $(depfile)
  120 +# Add extra rules as in (2).
  121 +# We remove slashes and replace spaces with new lines;
  122 +# remove blank lines;
  123 +# delete the first line and append a colon to the remaining lines.
  124 +sed -e 's|\\||' -e 'y| |\n|' $(depfile).raw |\
  125 + grep -v '^$$' |\
  126 + sed -e 1d -e 's|$$|:|' \
  127 + >> $(depfile)
  128 +rm $(depfile).raw
  129 +endef
  130 +
  131 +# Command definitions:
  132 +# - cmd_foo is the actual command to run;
  133 +# - quiet_cmd_foo is the brief-output summary of the command.
  134 +
  135 +quiet_cmd_cc = CC($(TOOLSET)) $@
  136 +cmd_cc = $(CC.$(TOOLSET)) $(GYP_CFLAGS) $(DEPFLAGS) $(CFLAGS.$(TOOLSET)) -c -o $@ $<
  137 +
  138 +quiet_cmd_cxx = CXX($(TOOLSET)) $@
  139 +cmd_cxx = $(CXX.$(TOOLSET)) $(GYP_CXXFLAGS) $(DEPFLAGS) $(CXXFLAGS.$(TOOLSET)) -c -o $@ $<
  140 +
  141 +quiet_cmd_touch = TOUCH $@
  142 +cmd_touch = touch $@
  143 +
  144 +quiet_cmd_copy = COPY $@
  145 +# send stderr to /dev/null to ignore messages when linking directories.
  146 +cmd_copy = ln -f "$<" "$@" 2>/dev/null || (rm -rf "$@" && cp -af "$<" "$@")
  147 +
  148 +quiet_cmd_alink = AR($(TOOLSET)) $@
  149 +cmd_alink = rm -f $@ && $(AR.$(TOOLSET)) $(ARFLAGS.$(TOOLSET)) $@ $(filter %.o,$^)
  150 +
  151 +# Due to circular dependencies between libraries :(, we wrap the
  152 +# special "figure out circular dependencies" flags around the entire
  153 +# input list during linking.
  154 +quiet_cmd_link = LINK($(TOOLSET)) $@
  155 +cmd_link = $(LINK.$(TOOLSET)) $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -o $@ -Wl,--start-group $(LD_INPUTS) -Wl,--end-group $(LIBS)
  156 +
  157 +# We support two kinds of shared objects (.so):
  158 +# 1) shared_library, which is just bundling together many dependent libraries
  159 +# into a link line.
  160 +# 2) loadable_module, which is generating a module intended for dlopen().
  161 +#
  162 +# They differ only slightly:
  163 +# In the former case, we want to package all dependent code into the .so.
  164 +# In the latter case, we want to package just the API exposed by the
  165 +# outermost module.
  166 +# This means shared_library uses --whole-archive, while loadable_module doesn't.
  167 +# (Note that --whole-archive is incompatible with the --start-group used in
  168 +# normal linking.)
  169 +
  170 +# Other shared-object link notes:
  171 +# - Set SONAME to the library filename so our binaries don't reference
  172 +# the local, absolute paths used on the link command-line.
  173 +quiet_cmd_solink = SOLINK($(TOOLSET)) $@
  174 +cmd_solink = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--whole-archive $(LD_INPUTS) -Wl,--no-whole-archive $(LIBS)
  175 +
  176 +quiet_cmd_solink_module = SOLINK_MODULE($(TOOLSET)) $@
  177 +cmd_solink_module = $(LINK.$(TOOLSET)) -shared $(GYP_LDFLAGS) $(LDFLAGS.$(TOOLSET)) -Wl,-soname=$(@F) -o $@ -Wl,--start-group $(filter-out FORCE_DO_CMD, $^) -Wl,--end-group $(LIBS)
  178 +
  179 +
  180 +# Define an escape_quotes function to escape single quotes.
  181 +# This allows us to handle quotes properly as long as we always use
  182 +# use single quotes and escape_quotes.
  183 +escape_quotes = $(subst ','\'',$(1))
  184 +# This comment is here just to include a ' to unconfuse syntax highlighting.
  185 +# Define an escape_vars function to escape '$' variable syntax.
  186 +# This allows us to read/write command lines with shell variables (e.g.
  187 +# $LD_LIBRARY_PATH), without triggering make substitution.
  188 +escape_vars = $(subst $$,$$$$,$(1))
  189 +# Helper that expands to a shell command to echo a string exactly as it is in
  190 +# make. This uses printf instead of echo because printf's behaviour with respect
  191 +# to escape sequences is more portable than echo's across different shells
  192 +# (e.g., dash, bash).
  193 +exact_echo = printf '%s\n' '$(call escape_quotes,$(1))'
  194 +
  195 +# Helper to compare the command we're about to run against the command
  196 +# we logged the last time we ran the command. Produces an empty
  197 +# string (false) when the commands match.
  198 +# Tricky point: Make has no string-equality test function.
  199 +# The kernel uses the following, but it seems like it would have false
  200 +# positives, where one string reordered its arguments.
  201 +# arg_check = $(strip $(filter-out $(cmd_$(1)), $(cmd_$@)) \
  202 +# $(filter-out $(cmd_$@), $(cmd_$(1))))
  203 +# We instead substitute each for the empty string into the other, and
  204 +# say they're equal if both substitutions produce the empty string.
  205 +# .d files contain ? instead of spaces, take that into account.
  206 +command_changed = $(or $(subst $(cmd_$(1)),,$(cmd_$(call replace_spaces,$@))),\
  207 + $(subst $(cmd_$(call replace_spaces,$@)),,$(cmd_$(1))))
  208 +
  209 +# Helper that is non-empty when a prerequisite changes.
  210 +# Normally make does this implicitly, but we force rules to always run
  211 +# so we can check their command lines.
  212 +# $? -- new prerequisites
  213 +# $| -- order-only dependencies
  214 +prereq_changed = $(filter-out FORCE_DO_CMD,$(filter-out $|,$?))
  215 +
  216 +# Helper that executes all postbuilds, and deletes the output file when done
  217 +# if any of the postbuilds failed.
  218 +define do_postbuilds
  219 + @E=0;\
  220 + for p in $(POSTBUILDS); do\
  221 + eval $$p;\
  222 + F=$$?;\
  223 + if [ $$F -ne 0 ]; then\
  224 + E=$$F;\
  225 + fi;\
  226 + done;\
  227 + if [ $$E -ne 0 ]; then\
  228 + rm -rf "$@";\
  229 + exit $$E;\
  230 + fi
  231 +endef
  232 +
  233 +# do_cmd: run a command via the above cmd_foo names, if necessary.
  234 +# Should always run for a given target to handle command-line changes.
  235 +# Second argument, if non-zero, makes it do asm/C/C++ dependency munging.
  236 +# Third argument, if non-zero, makes it do POSTBUILDS processing.
  237 +# Note: We intentionally do NOT call dirx for depfile, since it contains ? for
  238 +# spaces already and dirx strips the ? characters.
  239 +define do_cmd
  240 +$(if $(or $(command_changed),$(prereq_changed)),
  241 + @$(call exact_echo, $($(quiet)cmd_$(1)))
  242 + @mkdir -p "$(call dirx,$@)" "$(dir $(depfile))"
  243 + $(if $(findstring flock,$(word 1,$(cmd_$1))),
  244 + @$(cmd_$(1))
  245 + @echo " $(quiet_cmd_$(1)): Finished",
  246 + @$(cmd_$(1))
  247 + )
  248 + @$(call exact_echo,$(call escape_vars,cmd_$(call replace_spaces,$@) := $(cmd_$(1)))) > $(depfile)
  249 + @$(if $(2),$(fixup_dep))
  250 + $(if $(and $(3), $(POSTBUILDS)),
  251 + $(call do_postbuilds)
  252 + )
  253 +)
  254 +endef
  255 +
  256 +# Declare the "all" target first so it is the default,
  257 +# even though we don't have the deps yet.
  258 +.PHONY: all
  259 +all:
  260 +
  261 +# Use FORCE_DO_CMD to force a target to run. Should be coupled with
  262 +# do_cmd.
  263 +.PHONY: FORCE_DO_CMD
  264 +FORCE_DO_CMD:
  265 +
  266 +TOOLSET := target
  267 +# Suffix rules, putting all outputs into $(obj).
  268 +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.c FORCE_DO_CMD
  269 + @$(call do_cmd,cc,1)
  270 +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD
  271 + @$(call do_cmd,cxx,1)
  272 +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cpp FORCE_DO_CMD
  273 + @$(call do_cmd,cxx,1)
  274 +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.cxx FORCE_DO_CMD
  275 + @$(call do_cmd,cxx,1)
  276 +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.S FORCE_DO_CMD
  277 + @$(call do_cmd,cc,1)
  278 +$(obj).$(TOOLSET)/%.o: $(srcdir)/%.s FORCE_DO_CMD
  279 + @$(call do_cmd,cc,1)
  280 +
  281 +# Try building from generated source, too.
  282 +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.c FORCE_DO_CMD
  283 + @$(call do_cmd,cc,1)
  284 +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD
  285 + @$(call do_cmd,cxx,1)
  286 +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cpp FORCE_DO_CMD
  287 + @$(call do_cmd,cxx,1)
  288 +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.cxx FORCE_DO_CMD
  289 + @$(call do_cmd,cxx,1)
  290 +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.S FORCE_DO_CMD
  291 + @$(call do_cmd,cc,1)
  292 +$(obj).$(TOOLSET)/%.o: $(obj).$(TOOLSET)/%.s FORCE_DO_CMD
  293 + @$(call do_cmd,cc,1)
  294 +
  295 +$(obj).$(TOOLSET)/%.o: $(obj)/%.c FORCE_DO_CMD
  296 + @$(call do_cmd,cc,1)
  297 +$(obj).$(TOOLSET)/%.o: $(obj)/%.cc FORCE_DO_CMD
  298 + @$(call do_cmd,cxx,1)
  299 +$(obj).$(TOOLSET)/%.o: $(obj)/%.cpp FORCE_DO_CMD
  300 + @$(call do_cmd,cxx,1)
  301 +$(obj).$(TOOLSET)/%.o: $(obj)/%.cxx FORCE_DO_CMD
  302 + @$(call do_cmd,cxx,1)
  303 +$(obj).$(TOOLSET)/%.o: $(obj)/%.S FORCE_DO_CMD
  304 + @$(call do_cmd,cc,1)
  305 +$(obj).$(TOOLSET)/%.o: $(obj)/%.s FORCE_DO_CMD
  306 + @$(call do_cmd,cc,1)
  307 +
  308 +
  309 +ifeq ($(strip $(foreach prefix,$(NO_LOAD),\
  310 + $(findstring $(join ^,$(prefix)),\
  311 + $(join ^,ffi_tests.target.mk)))),)
  312 + include ffi_tests.target.mk
  313 +endif
  314 +
  315 +quiet_cmd_regen_makefile = ACTION Regenerating $@
  316 +cmd_regen_makefile = /home/justin/.node-gyp/0.8.0/tools/gyp_addon -fmake --ignore-environment "--toplevel-dir=." -I/home/justin/dev/node-ffi/test/build/config.gypi -I/home/justin/.node-gyp/0.8.0/tools/addon.gypi -I/home/justin/.node-gyp/0.8.0/common.gypi "--depth=." "-Goutput_dir=." "--generator-output=build" "-Dlibrary=shared_library" "-Dvisibility=default" "-Dnode_root_dir=/home/justin/.node-gyp/0.8.0" "-Dmodule_root_dir=/home/justin/dev/node-ffi/test" binding.gyp
  317 +Makefile: $(srcdir)/../../../.node-gyp/0.8.0/common.gypi $(srcdir)/../../../.node-gyp/0.8.0/tools/addon.gypi $(srcdir)/build/config.gypi $(srcdir)/binding.gyp
  318 + $(call do_cmd,regen_makefile)
  319 +
  320 +# "all" is a concatenation of the "all" targets from all the included
  321 +# sub-makefiles. This is just here to clarify.
  322 +all:
  323 +
  324 +# Add in dependency-tracking rules. $(all_deps) is the list of every single
  325 +# target in our tree. Only consider the ones with .d (dependency) info:
  326 +d_files := $(wildcard $(foreach f,$(all_deps),$(depsdir)/$(f).d))
  327 +ifneq ($(d_files),)
  328 + # Rather than include each individual .d file, concatenate them into a
  329 + # single file which make is able to load faster. We split this into
  330 + # commands that take 512 files at a time to avoid overflowing the
  331 + # command line.
  332 + $(shell cat $(wordlist 1,512,$(d_files)) > $(depsdir)/all.deps)
  333 +
  334 + ifneq ($(word 513,$(d_files)),)
  335 + $(error Found unprocessed dependency files (gyp didn't generate enough rules!))
  336 + endif
  337 +
  338 + # make looks for ways to re-generate included makefiles, but in our case, we
  339 + # don't have a direct way. Explicitly telling make that it has nothing to do
  340 + # for them makes it go faster.
  341 + $(depsdir)/all.deps: ;
  342 +
  343 + include $(depsdir)/all.deps
  344 +endif
BIN  test/build/Release/ffi_tests.node
Binary file not shown
0  test/build/Release/linker.lock
No changes.
BIN  test/build/Release/obj.target/ffi_tests.node
Binary file not shown
BIN  test/build/Release/obj.target/ffi_tests/ffi_tests.o
Binary file not shown
6 test/build/binding.Makefile
... ... @@ -0,0 +1,6 @@
  1 +# This file is generated by gyp; do not edit.
  2 +
  3 +export builddir_name ?= build/./.
  4 +.PHONY: all
  5 +all:
  6 + $(MAKE) ffi_tests
27 test/build/config.gypi
... ... @@ -0,0 +1,27 @@
  1 +# Do not edit. File was generated by node-gyp's "configure" step
  2 +{
  3 + "target_defaults": {
  4 + "cflags": [],
  5 + "default_configuration": "Release",
  6 + "defines": [],
  7 + "include_dirs": [],
  8 + "libraries": []
  9 + },
  10 + "variables": {
  11 + "host_arch": "x64",
  12 + "node_install_npm": "true",
  13 + "node_install_waf": "true",
  14 + "node_prefix": "/home/justin/.nvm/v0.8.0",
  15 + "node_shared_openssl": "false",
  16 + "node_shared_v8": "false",
  17 + "node_shared_zlib": "false",
  18 + "node_use_dtrace": "false",
  19 + "node_use_etw": "false",
  20 + "node_use_openssl": "true",
  21 + "strict_aliasing": "true",
  22 + "target_arch": "x64",
  23 + "v8_use_snapshot": "true",
  24 + "nodedir": "/home/justin/.node-gyp/0.8.0",
  25 + "copy_dev_lib": "true"
  26 + }
  27 +}
112 test/build/ffi_tests.target.mk
... ... @@ -0,0 +1,112 @@
  1 +# This file is generated by gyp; do not edit.
  2 +
  3 +TOOLSET := target
  4 +TARGET := ffi_tests
  5 +DEFS_Debug := '-D_LARGEFILE_SOURCE' \
  6 + '-D_FILE_OFFSET_BITS=64' \
  7 + '-DDEBUG' \
  8 + '-D_DEBUG'
  9 +
  10 +# Flags passed to all source files.
  11 +CFLAGS_Debug := -fPIC \
  12 + -Wall \
  13 + -pthread \
  14 + -m64 \
  15 + -g \
  16 + -O0
  17 +
  18 +# Flags passed to only C files.
  19 +CFLAGS_C_Debug :=
  20 +
  21 +# Flags passed to only C++ files.
  22 +CFLAGS_CC_Debug := -fno-rtti \
  23 + -fno-exceptions
  24 +
  25 +INCS_Debug := -I/home/justin/.node-gyp/0.8.0/src \
  26 + -I/home/justin/.node-gyp/0.8.0/deps/uv/include \
  27 + -I/home/justin/.node-gyp/0.8.0/deps/v8/include
  28 +
  29 +DEFS_Release := '-D_LARGEFILE_SOURCE' \
  30 + '-D_FILE_OFFSET_BITS=64'
  31 +
  32 +# Flags passed to all source files.
  33 +CFLAGS_Release := -fPIC \
  34 + -Wall \
  35 + -pthread \
  36 + -m64 \
  37 + -O3 \
  38 + -fdata-sections \
  39 + -ffunction-sections
  40 +
  41 +# Flags passed to only C files.
  42 +CFLAGS_C_Release :=
  43 +
  44 +# Flags passed to only C++ files.
  45 +CFLAGS_CC_Release := -fno-rtti \
  46 + -fno-exceptions
  47 +
  48 +INCS_Release := -I/home/justin/.node-gyp/0.8.0/src \
  49 + -I/home/justin/.node-gyp/0.8.0/deps/uv/include \
  50 + -I/home/justin/.node-gyp/0.8.0/deps/v8/include
  51 +
  52 +OBJS := $(obj).target/$(TARGET)/ffi_tests.o
  53 +
  54 +# Add to the list of files we specially track dependencies for.
  55 +all_deps += $(OBJS)
  56 +
  57 +# CFLAGS et al overrides must be target-local.
  58 +# See "Target-specific Variable Values" in the GNU Make manual.
  59 +$(OBJS): TOOLSET := $(TOOLSET)
  60 +$(OBJS): GYP_CFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_C_$(BUILDTYPE))
  61 +$(OBJS): GYP_CXXFLAGS := $(DEFS_$(BUILDTYPE)) $(INCS_$(BUILDTYPE)) $(CFLAGS_$(BUILDTYPE)) $(CFLAGS_CC_$(BUILDTYPE))
  62 +
  63 +# Suffix rules, putting all outputs into $(obj).
  64 +
  65 +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(srcdir)/%.cc FORCE_DO_CMD
  66 + @$(call do_cmd,cxx,1)
  67 +
  68 +# Try building from generated source, too.
  69 +
  70 +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj).$(TOOLSET)/%.cc FORCE_DO_CMD
  71 + @$(call do_cmd,cxx,1)
  72 +
  73 +$(obj).$(TOOLSET)/$(TARGET)/%.o: $(obj)/%.cc FORCE_DO_CMD
  74 + @$(call do_cmd,cxx,1)
  75 +
  76 +# End of this set of suffix rules
  77 +### Rules for final target.
  78 +LDFLAGS_Debug := -pthread \
  79 + -m64 \
  80 + -rdynamic
  81 +
  82 +LDFLAGS_Release := -pthread \
  83 + -m64 \
  84 + -rdynamic
  85 +
  86 +LIBS :=
  87 +
  88 +$(obj).target/ffi_tests.node: GYP_LDFLAGS := $(LDFLAGS_$(BUILDTYPE))
  89 +$(obj).target/ffi_tests.node: LIBS := $(LIBS)
  90 +$(obj).target/ffi_tests.node: TOOLSET := $(TOOLSET)
  91 +$(obj).target/ffi_tests.node: $(OBJS) FORCE_DO_CMD
  92 + $(call do_cmd,solink_module)
  93 +
  94 +all_deps += $(obj).target/ffi_tests.node
  95 +# Add target alias
  96 +.PHONY: ffi_tests
  97 +ffi_tests: $(builddir)/ffi_tests.node
  98 +
  99 +# Copy this to the executable output path.
  100 +$(builddir)/ffi_tests.node: TOOLSET := $(TOOLSET)
  101 +$(builddir)/ffi_tests.node: $(obj).target/ffi_tests.node FORCE_DO_CMD
  102 + $(call do_cmd,copy)
  103 +
  104 +all_deps += $(builddir)/ffi_tests.node
  105 +# Short alias for building this executable.
  106 +.PHONY: ffi_tests.node
  107 +ffi_tests.node: $(obj).target/ffi_tests.node $(builddir)/ffi_tests.node
  108 +
  109 +# Add executable to "all" target.
  110 +.PHONY: all
  111 +all: $(builddir)/ffi_tests.node
  112 +

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.