7

Suppose I have a node module which is essentially a wrapper around some standard C library using autotools. So the library by itself would be installed using ./configure and make and perhaps make install. The wrapper code is just a few files, and can be handled by gyp. But how can I handle the dependency? How can I instruct gyp that I want to build the autotooled library before I compile my code? Or is that not possible because autotools can't be expected to run on Windows? If I can't run configure, is there some gyp way to do similar things, in particular to detect which functions are availabel and which are not?

MvG
  • 51,562
  • 13
  • 126
  • 251

2 Answers2

6

With gyp actions and 'target_type': none it might look like this:

   {
        'target_name': 'FTGL',
        'type': 'none',
        'dependencies': ['FreeType'],
        'actions': [
            {
                'action_name': 'build_ftgl',
                'message': 'Building FTGL...',
                'inputs': ['ftgl/src/FTGL/ftgl.h'],
                'outputs': ['ftgl/src/.libs/libftgl.a'],
                'action': ['eval', 'cd ftgl && ./configure --with-pic && make -C src'],
            },
        ],
  }

Note: using eval in the action allows to run multiple commands

Bernardo Ramos
  • 2,789
  • 23
  • 21
pmed
  • 1,456
  • 8
  • 11
3

You can execute arbitrary commands within gyp using command line expansion. However as you noted, this isn't reliable if you want to be cross-platform.

Typically if you want it to be cross-platform, you will need to "gyp-ify" your dependency. This means creating a separate gyp file that is included as a dependency gyp in your main binding.gyp. This can take some time because you have to list all of the source files that are to be compiled and you have to also add any necessary library-specific compilation flags (e.g. if a library makes use of compile-time defines like -Dfoo).

You might also consider making the dependency dynamic instead of bundling the source for the library you're wrapping and just dynamically linking with the library. This is much easier since you don't have to "gyp-ify" the library and you just have to add a few things like libraries: ['-lfoo'] to your binding.gyp.

mscdex
  • 93,083
  • 13
  • 170
  • 135