revise installing a license file
[platform/upstream/nodejs.git] / deps / npm / 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`, `0.9`, `0.10`, ..., `1.0`,
14 etc.), regardless of what version of node is actually installed on your system
15 (`node-gyp` downloads the necessary development files 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     * Python ([`v2.7.10`][python-v2.7.10] recommended, `v3.x.x` is __*not*__ supported)
46       * Make sure that you have a PYTHON environment variable, and it is set to drive:\path\to\python.exe not to a folder
47     * Windows XP/Vista/7:
48       * Microsoft Visual Studio C++ 2013 ([Express][msvc2013] version works well)
49         * If the install fails, try uninstalling any C++ 2010 x64&x86 Redistributable that you have installed first
50         * If you get errors that the 64-bit compilers are not installed you may also need the [compiler update for the Windows SDK 7.1]
51     * Windows 7/8:
52       * Microsoft Visual Studio C++ 2013 for Windows Desktop ([Express][msvc2013] version works well)
53     * Windows 10:
54         * Install the latest version of npm (3.3.6 at the time of writing)
55         * Install Python 2.7 from https://www.python.org/download/releases/2.7/ and make sure its on the System Path
56         * Install Visual Studio Community 2015 Edition. (Custom Install, Select Visual C++ during the installation)
57         * Set the environment variable GYP_MSVS_VERSION=2015
58         * Run the command prompt as Administrator
59         * $ npm install (--msvs_version=2015) <-- Shouldn't be needed if you have set GYP_MSVS_VERSION env
60         * If the above steps have not worked or you are unsure please visit http://www.serverpals.com/blog/building-using-node-gyp-with-visual-studio-express-2015-on-windows-10-pro-x64 for a full walkthrough
61     * All Windows Versions
62       * For 64-bit builds of node and native modules you will _**also**_ need the [Windows 7 64-bit SDK][win7sdk]
63       * You may need to run one of the following commands if your build complains about WindowsSDKDir not being set, and you are sure you have already installed the SDK:
64
65 ```
66 call "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\Setenv.cmd" /Release /x86
67 call "C:\Program Files\Microsoft SDKs\Windows\v7.1\bin\Setenv.cmd" /Release /x64
68 ```
69
70 If you have multiple Python versions installed, you can identify which Python
71 version `node-gyp` uses by setting the '--python' variable:
72
73 ``` bash
74 $ node-gyp --python /path/to/python2.7
75 ```
76
77 If `node-gyp` is called by way of `npm` *and* you have multiple versions of
78 Python installed, then you can set `npm`'s 'python' config key to the appropriate
79 value:
80
81 ``` bash
82 $ npm config set python /path/to/executable/python2.7
83 ```
84
85 Note that OS X is just a flavour of Unix and so needs `python`, `make`, and C/C++.
86 An easy way to obtain these is to install XCode from Apple,
87 and then use it to install the command line tools (under Preferences -> Downloads).
88
89 How to Use
90 ----------
91
92 To compile your native addon, first go to its root directory:
93
94 ``` bash
95 $ cd my_node_addon
96 ```
97
98 The next step is to generate the appropriate project build files for the current
99 platform. Use `configure` for that:
100
101 ``` bash
102 $ node-gyp configure
103 ```
104
105 __Note__: The `configure` step looks for the `binding.gyp` file in the current
106 directory to process. See below for instructions on creating the `binding.gyp` file.
107
108 Now you will have either a `Makefile` (on Unix platforms) or a `vcxproj` file
109 (on Windows) in the `build/` directory. Next invoke the `build` command:
110
111 ``` bash
112 $ node-gyp build
113 ```
114
115 Now you have your compiled `.node` bindings file! The compiled bindings end up
116 in `build/Debug/` or `build/Release/`, depending on the build mode. At this point
117 you can require the `.node` file with Node and run your tests!
118
119 __Note:__ To create a _Debug_ build of the bindings file, pass the `--debug` (or
120 `-d`) switch when running either the `configure`, `build` or `rebuild` command.
121
122
123 The "binding.gyp" file
124 ----------------------
125
126 Previously when node had `node-waf` you had to write a `wscript` file. The
127 replacement for that is the `binding.gyp` file, which describes the configuration
128 to build your module in a JSON-like format. This file gets placed in the root of
129 your package, alongside the `package.json` file.
130
131 A barebones `gyp` file appropriate for building a node addon looks like:
132
133 ``` python
134 {
135   "targets": [
136     {
137       "target_name": "binding",
138       "sources": [ "src/binding.cc" ]
139     }
140   ]
141 }
142 ```
143
144 Some additional resources for addons and writing `gyp` files:
145
146  * ["Going Native" a nodeschool.io tutorial](http://nodeschool.io/#goingnative)
147  * ["Hello World" node addon example](https://github.com/nodejs/node/tree/master/test/addons/hello-world)
148  * [gyp user documentation](https://gyp.gsrc.io/docs/UserDocumentation.md)
149  * [gyp input format reference](https://gyp.gsrc.io/docs/InputFormatReference.md)
150  * [*"binding.gyp" files out in the wild* wiki page](https://github.com/nodejs/node-gyp/wiki/%22binding.gyp%22-files-out-in-the-wild)
151
152
153 Commands
154 --------
155
156 `node-gyp` responds to the following commands:
157
158 | **Command**   | **Description**
159 |:--------------|:---------------------------------------------------------------
160 | `build`       | Invokes `make`/`msbuild.exe` and builds the native addon
161 | `clean`       | Removes the `build` directory if it exists
162 | `configure`   | Generates project build files for the current platform
163 | `rebuild`     | Runs `clean`, `configure` and `build` all in a row
164 | `install`     | Installs node development header files for the given version
165 | `list`        | Lists the currently installed node development file versions
166 | `remove`      | Removes the node development header files for the given version
167
168
169 License
170 -------
171
172 (The MIT License)
173
174 Copyright (c) 2012 Nathan Rajlich &lt;nathan@tootallnate.net&gt;
175
176 Permission is hereby granted, free of charge, to any person obtaining
177 a copy of this software and associated documentation files (the
178 'Software'), to deal in the Software without restriction, including
179 without limitation the rights to use, copy, modify, merge, publish,
180 distribute, sublicense, and/or sell copies of the Software, and to
181 permit persons to whom the Software is furnished to do so, subject to
182 the following conditions:
183
184 The above copyright notice and this permission notice shall be
185 included in all copies or substantial portions of the Software.
186
187 THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
188 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
189 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
190 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
191 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
192 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
193 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
194
195
196 [python-v2.7.10]: https://www.python.org/downloads/release/python-2710/
197 [msvc2013]: https://www.microsoft.com/en-gb/download/details.aspx?id=44914
198 [win7sdk]: https://www.microsoft.com/en-us/download/details.aspx?id=8279
199 [compiler update for the Windows SDK 7.1]: https://www.microsoft.com/en-us/download/details.aspx?id=4422