I'm using node-gyp to build a native Node.js add-on written in C++ on Linux.
The add-on is dependent on another shared library. This library is not currently built with gyp, it just has a makefile.
If I build the shared library first, then build my add-on specifying a value for 'libraries' in the main target in my binding.gyp file, everything works fine.
However, what I would like to do is build the shared library from source from within the node-gyp process, by invoking make on the shared library's makefile. I tried adding a dependent target using the 'action' property to the add-on's binding.gyp and making the main target dependent on it:
{
"target_name": "other_library",
"type": "none",
"actions": [
{
"action_name": "build_other_library",
"inputs": [],
"outputs": [ "/path/to/build/output/libother.so" ],
"action": [ "make", "-C", "/path/to/makefile" ]
}
]
}
This doesn't completely work. It is finding the other makefile and make is being launched (I can see this happening with --verbose set), but the makefile is not executing properly.
It seems that GNU make's implicit build rules are being suppressed when the makefile for the shared library runs. This means that .cc and .cpp files are not being compiled to .o files.
I realise that node-gyp is itself generating a set of makefiles for the add-on from the targets in the binding.gyp, and the the shared library's makefile is being spawned from one of these.
Is it inheriting the make settings from node-gyp, including the suppression of built-in rules?
Is there a way around it? (Other than adding explicit build rules to the shared library's makefile)?
(I've tried replacing make with $(MAKE), it made no difference).
EDIT:
Running GNU make on the shared library with -d specified from the shell (i.e. outside node-gyp), the search for an implicit rule for a typical source file looks like this:
Considering target file `code.o'.
File `code.o' does not exist.
Looking for an implicit rule for `code.o'.
Trying pattern rule with stem `code'.
Trying implicit prerequisite `code.c'.
Trying pattern rule with stem `code'.
Trying implicit prerequisite `code.cc'.
Trying pattern rule with stem `code'.
Trying implicit prerequisite `code.C'.
Trying pattern rule with stem `code'.
Trying implicit prerequisite `code.cpp'.
Found prerequisite `code.cpp' as VPATH `../Common/code.cpp'
Found an implicit rule for `code.o'.
Adding -d to the invocation from within the action block in the node-gyp dependent target, the same source file gets this:
Considering target file `code.o'.
File `code.o' does not exist.
Looking for an implicit rule for `code.o'.
No implicit rule found for `code.o'.
So it does look like implicit build rules are being suppressed (?)