Initial commit
[yaffs-website] / node_modules / node-gyp / README.md
1 node-gyp
2 =========
3 ### Node.js native addon build tool
4
5 `node-gyp` is a cross-platform command-line tool written in Node.js for compiling
6 native addon modules for Node.js.  It bundles the [gyp](https://code.google.com/p/gyp/)
7 project used by the Chromium team and takes away the pain of dealing with the
8 various differences in build platforms. It is the replacement to the `node-waf`
9 program which is removed for node `v0.8`. If you have a native addon for node that
10 still has a `wscript` file, then you should definitely add a `binding.gyp` file
11 to support the latest versions of node.
12
13 Multiple target versions of node are supported (i.e. `0.8`, ..., `4`, `5`, `6`,
14 etc.), regardless of what version of node is actually installed on your system
15 (`node-gyp` downloads the necessary development files or headers for the target version).
16
17 #### Features:
18
19  * Easy to use, consistent interface
20  * Same commands to build your module on every platform
21  * Supports multiple target versions of Node
22
23
24 Installation
25 ------------
26
27 You can install with `npm`:
28
29 ``` bash
30 $ npm install -g node-gyp
31 ```
32
33 You will also need to install:
34
35   * On Unix:
36     * `python` (`v2.7` recommended, `v3.x.x` is __*not*__ supported)
37     * `make`
38     * A proper C/C++ compiler toolchain, like [GCC](https://gcc.gnu.org)
39   * On Mac OS X:
40     * `python` (`v2.7` recommended, `v3.x.x` is __*not*__ supported) (already installed on Mac OS X)
41     * [Xcode](https://developer.apple.com/xcode/download/)
42       * You also need to install the `Command Line Tools` via Xcode. You can find this under the menu `Xcode -> Preferences -> Downloads`
43       * This step will install `gcc` and the related toolchain containing `make`
44   * On Windows:
45     * Option 1: Install all the required tools and configurations using Microsoft's [windows-build-tools](https://github.com/felixrieseberg/windows-build-tools) using `npm install --global --production windows-build-tools` from an elevated PowerShell or CMD.exe (run as Administrator).
46     * Option 2: Install tools and configuration manually:
47       * Visual C++ Build Environment:
48         * Option 1: Install [Visual C++ Build Tools](http://landinghub.visualstudio.com/visual-cpp-build-tools) using the **Default Install** option.
49
50         * Option 2: Install [Visual Studio 2015](https://www.visualstudio.com/products/visual-studio-community-vs) (or modify an existing installation) and select *Common Tools for Visual C++* during setup. This also works with the free Community and Express for Desktop editions.
51
52         > :bulb: [Windows Vista / 7 only] requires [.NET Framework 4.5.1](http://www.microsoft.com/en-us/download/details.aspx?id=40773)
53
54       * Install [Python 2.7](https://www.python.org/downloads/) (`v3.x.x` is not supported), and run `npm config set python python2.7` (or see below for further instructions on specifying the proper Python version and path.)
55       * Launch cmd, `npm config set msvs_version 2015`
56
57     If the above steps didn't work for you, please visit [Microsoft's Node.js Guidelines for Windows](https://github.com/Microsoft/nodejs-guidelines/blob/master/windows-environment.md#compiling-native-addon-modules) for additional tips.
58
59 If you have multiple Python versions installed, you can identify which Python
60 version `node-gyp` uses by setting the '--python' variable:
61
62 ``` bash
63 $ node-gyp --python /path/to/python2.7
64 ```
65
66 If `node-gyp` is called by way of `npm` *and* you have multiple versions of
67 Python installed, then you can set `npm`'s 'python' config key to the appropriate
68 value:
69
70 ``` bash
71 $ npm config set python /path/to/executable/python2.7
72 ```
73
74 Note that OS X is just a flavour of Unix and so needs `python`, `make`, and C/C++.
75 An easy way to obtain these is to install XCode from Apple,
76 and then use it to install the command line tools (under Preferences -> Downloads).
77
78 How to Use
79 ----------
80
81 To compile your native addon, first go to its root directory:
82
83 ``` bash
84 $ cd my_node_addon
85 ```
86
87 The next step is to generate the appropriate project build files for the current
88 platform. Use `configure` for that:
89
90 ``` bash
91 $ node-gyp configure
92 ```
93
94 __Note__: The `configure` step looks for the `binding.gyp` file in the current
95 directory to process. See below for instructions on creating the `binding.gyp` file.
96
97 Now you will have either a `Makefile` (on Unix platforms) or a `vcxproj` file
98 (on Windows) in the `build/` directory. Next invoke the `build` command:
99
100 ``` bash
101 $ node-gyp build
102 ```
103
104 Now you have your compiled `.node` bindings file! The compiled bindings end up
105 in `build/Debug/` or `build/Release/`, depending on the build mode. At this point
106 you can require the `.node` file with Node and run your tests!
107
108 __Note:__ To create a _Debug_ build of the bindings file, pass the `--debug` (or
109 `-d`) switch when running either the `configure`, `build` or `rebuild` command.
110
111
112 The "binding.gyp" file
113 ----------------------
114
115 Previously when node had `node-waf` you had to write a `wscript` file. The
116 replacement for that is the `binding.gyp` file, which describes the configuration
117 to build your module in a JSON-like format. This file gets placed in the root of
118 your package, alongside the `package.json` file.
119
120 A barebones `gyp` file appropriate for building a node addon looks like:
121
122 ``` python
123 {
124   "targets": [
125     {
126       "target_name": "binding",
127       "sources": [ "src/binding.cc" ]
128     }
129   ]
130 }
131 ```
132
133 Some additional resources for addons and writing `gyp` files:
134
135  * ["Going Native" a nodeschool.io tutorial](http://nodeschool.io/#goingnative)
136  * ["Hello World" node addon example](https://github.com/nodejs/node/tree/master/test/addons/hello-world)
137  * [gyp user documentation](https://gyp.gsrc.io/docs/UserDocumentation.md)
138  * [gyp input format reference](https://gyp.gsrc.io/docs/InputFormatReference.md)
139  * [*"binding.gyp" files out in the wild* wiki page](https://github.com/nodejs/node-gyp/wiki/%22binding.gyp%22-files-out-in-the-wild)
140
141
142 Commands
143 --------
144
145 `node-gyp` responds to the following commands:
146
147 | **Command**   | **Description**
148 |:--------------|:---------------------------------------------------------------
149 | `help`        | Shows the help dialog
150 | `build`       | Invokes `make`/`msbuild.exe` and builds the native addon
151 | `clean`       | Removes the `build` directory if it exists
152 | `configure`   | Generates project build files for the current platform
153 | `rebuild`     | Runs `clean`, `configure` and `build` all in a row
154 | `install`     | Installs node header files for the given version
155 | `list`        | Lists the currently installed node header versions
156 | `remove`      | Removes the node header files for the given version
157
158
159 Command Options
160 --------
161
162 `node-gyp` accepts the following command options:
163
164 | **Command**                       | **Description**
165 |:----------------------------------|:------------------------------------------
166 | `-j n`, `--jobs n`                | Run make in parallel
167 | `--target=v6.2.1`                 | Node version to build for (default=process.version)
168 | `--silly`, `--loglevel=silly`     | Log all progress to console
169 | `--verbose`, `--loglevel=verbose` | Log most progress to console
170 | `--silent`, `--loglevel=silent`   | Don't log anything to console
171 | `debug`, `--debug`                | Make Debug build (default=Release)
172 | `--release`, `--no-debug`         | Make Release build
173 | `-C $dir`, `--directory=$dir`     | Run command in different directory
174 | `--make=$make`                    | Override make command (e.g. gmake)
175 | `--thin=yes`                      | Enable thin static libraries
176 | `--arch=$arch`                    | Set target architecture (e.g. ia32)
177 | `--tarball=$path`                 | Get headers from a local tarball
178 | `--devdir=$path`                  | SDK download directory (default=~/.node-gyp)
179 | `--ensure`                        | Don't reinstall headers if already present
180 | `--dist-url=$url`                 | Download header tarball from custom URL
181 | `--proxy=$url`                    | Set HTTP proxy for downloading header tarball
182 | `--cafile=$cafile`                | Override default CA chain (to download tarball)
183 | `--nodedir=$path`                 | Set the path to the node binary
184 | `--python=$path`                  | Set path to the python (2) binary
185 | `--msvs_version=$version`         | Set Visual Studio version (win)
186 | `--solution=$solution`            | Set Visual Studio Solution version (win)
187
188
189 License
190 -------
191
192 (The MIT License)
193
194 Copyright (c) 2012 Nathan Rajlich <nathan@tootallnate.net>
195
196 Permission is hereby granted, free of charge, to any person obtaining
197 a copy of this software and associated documentation files (the
198 'Software'), to deal in the Software without restriction, including
199 without limitation the rights to use, copy, modify, merge, publish,
200 distribute, sublicense, and/or sell copies of the Software, and to
201 permit persons to whom the Software is furnished to do so, subject to
202 the following conditions:
203
204 The above copyright notice and this permission notice shall be
205 included in all copies or substantial portions of the Software.
206
207 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
208 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
209 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
210 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
211 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
212 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
213 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
214
215
216 [python-v2.7.10]: https://www.python.org/downloads/release/python-2710/
217 [msvc2013]: https://www.microsoft.com/en-gb/download/details.aspx?id=44914
218 [win7sdk]: https://www.microsoft.com/en-us/download/details.aspx?id=8279
219 [compiler update for the Windows SDK 7.1]: https://www.microsoft.com/en-us/download/details.aspx?id=4422