xref: /unit/auto/modules/nodejs (revision 2651:fa2780144e8f)
1802Salexander.borisov@nginx.com
2802Salexander.borisov@nginx.com# Copyright (C) NGINX, Inc.
3802Salexander.borisov@nginx.com
4802Salexander.borisov@nginx.com
5802Salexander.borisov@nginx.comshift
6802Salexander.borisov@nginx.com
7802Salexander.borisov@nginx.comfor nxt_option; do
8802Salexander.borisov@nginx.com
9802Salexander.borisov@nginx.com    case "$nxt_option" in
10802Salexander.borisov@nginx.com        -*=*) value=`echo "$nxt_option" | sed -e 's/[-_a-zA-Z0-9]*=//'`     ;;
11802Salexander.borisov@nginx.com           *) value=""                                                      ;;
12802Salexander.borisov@nginx.com    esac
13802Salexander.borisov@nginx.com
14802Salexander.borisov@nginx.com    case "$nxt_option" in
15802Salexander.borisov@nginx.com        --node=*)       NXT_NODE="$value"                                   ;;
16802Salexander.borisov@nginx.com        --npm=*)        NXT_NPM="$value"                                    ;;
17802Salexander.borisov@nginx.com        --node-gyp=*)   NXT_NODE_GYP="$value"                               ;;
18838Svbart@nginx.com        --local=*)      NXT_NODE_LOCAL="$value"                             ;;
19802Salexander.borisov@nginx.com
20802Salexander.borisov@nginx.com        --help)
21802Salexander.borisov@nginx.com            cat << END
22802Salexander.borisov@nginx.com
23837Svbart@nginx.com    --node=FILE        set node executable
24837Svbart@nginx.com    --npm=FILE         set npm executable
25837Svbart@nginx.com    --node-gyp=FILE    set node-gyp executable
26838Svbart@nginx.com    --local=DIRECTORY  set directory path for local installation
27802Salexander.borisov@nginx.com
28802Salexander.borisov@nginx.comEND
29802Salexander.borisov@nginx.com            exit 0
30802Salexander.borisov@nginx.com        ;;
31802Salexander.borisov@nginx.com
32802Salexander.borisov@nginx.com        *)
33802Salexander.borisov@nginx.com            echo
34802Salexander.borisov@nginx.com            echo $0: error: invalid Node option \"$nxt_option\"
35802Salexander.borisov@nginx.com            echo
36802Salexander.borisov@nginx.com            exit 1
37802Salexander.borisov@nginx.com        ;;
38802Salexander.borisov@nginx.com
39802Salexander.borisov@nginx.com    esac
40802Salexander.borisov@nginx.com
41802Salexander.borisov@nginx.comdone
42802Salexander.borisov@nginx.com
43802Salexander.borisov@nginx.com
44802Salexander.borisov@nginx.comif [ ! -f $NXT_AUTOCONF_DATA ]; then
45802Salexander.borisov@nginx.com   echo
46802Salexander.borisov@nginx.com   echo Please run common $0 before configuring module \"$nxt_module\".
47802Salexander.borisov@nginx.com   echo
48802Salexander.borisov@nginx.com   exit 1
49802Salexander.borisov@nginx.comfi
50802Salexander.borisov@nginx.com
51802Salexander.borisov@nginx.com. $NXT_AUTOCONF_DATA
52802Salexander.borisov@nginx.com
53802Salexander.borisov@nginx.com
54802Salexander.borisov@nginx.comNXT_NODE=${NXT_NODE=node}
55802Salexander.borisov@nginx.comNXT_NPM=${NXT_NPM=npm}
56802Salexander.borisov@nginx.comNXT_NODE_GYP=${NXT_NODE_GYP=node-gyp}
57838Svbart@nginx.comNXT_NODE_LOCAL=${NXT_NODE_LOCAL=}
58802Salexander.borisov@nginx.com
59837Svbart@nginx.com
60837Svbart@nginx.com$echo "configuring nodejs module"
61837Svbart@nginx.com$echo "configuring nodejs module..." >> $NXT_AUTOCONF_ERR
62837Svbart@nginx.com
63802Salexander.borisov@nginx.com$echo -n "checking for node ..."
64802Salexander.borisov@nginx.com$echo "checking for node ..." >> $NXT_AUTOCONF_ERR
65802Salexander.borisov@nginx.com
66802Salexander.borisov@nginx.comif /bin/sh -c "${NXT_NODE} -v" >> $NXT_AUTOCONF_ERR 2>&1; then
67802Salexander.borisov@nginx.com    $echo " found"
68802Salexander.borisov@nginx.com
69802Salexander.borisov@nginx.com    NXT_NODE_VERSION="`${NXT_NODE} -v`"
70802Salexander.borisov@nginx.com    $echo " + node version ${NXT_NODE_VERSION}"
71802Salexander.borisov@nginx.com
72802Salexander.borisov@nginx.comelse
73802Salexander.borisov@nginx.com    $echo " not found"
74802Salexander.borisov@nginx.com    $echo
75802Salexander.borisov@nginx.com    $echo $0: error: no Node found.
76802Salexander.borisov@nginx.com    $echo
77802Salexander.borisov@nginx.com    exit 1;
78802Salexander.borisov@nginx.comfi
79802Salexander.borisov@nginx.com
80837Svbart@nginx.com
81802Salexander.borisov@nginx.com$echo -n "checking for npm ..."
82802Salexander.borisov@nginx.com$echo "checking for npm ..." >> $NXT_AUTOCONF_ERR
83802Salexander.borisov@nginx.com
84802Salexander.borisov@nginx.comif /bin/sh -c "${NXT_NPM} -v" >> $NXT_AUTOCONF_ERR 2>&1; then
85802Salexander.borisov@nginx.com    $echo " found"
86802Salexander.borisov@nginx.com
87802Salexander.borisov@nginx.com    NXT_NPM_VERSION="`${NXT_NPM} -v`"
88802Salexander.borisov@nginx.com    $echo " + npm version ${NXT_NPM_VERSION}"
89802Salexander.borisov@nginx.com
90802Salexander.borisov@nginx.comelse
91802Salexander.borisov@nginx.com    $echo " not found"
92802Salexander.borisov@nginx.com    $echo
93802Salexander.borisov@nginx.com    $echo $0: error: no npm found.
94802Salexander.borisov@nginx.com    $echo
95802Salexander.borisov@nginx.com    exit 1;
96802Salexander.borisov@nginx.comfi
97802Salexander.borisov@nginx.com
98837Svbart@nginx.com
99802Salexander.borisov@nginx.com$echo -n "checking for node-gyp ..."
100802Salexander.borisov@nginx.com$echo "checking for node-gyp ..." >> $NXT_AUTOCONF_ERR
101802Salexander.borisov@nginx.com
102802Salexander.borisov@nginx.comif /bin/sh -c "${NXT_NODE_GYP} -v" >> $NXT_AUTOCONF_ERR 2>&1; then
103802Salexander.borisov@nginx.com    $echo " found"
104802Salexander.borisov@nginx.com
105802Salexander.borisov@nginx.com    NXT_NODE_GYP_VERSION="`${NXT_NODE_GYP} -v`"
106802Salexander.borisov@nginx.com    $echo " + node-gyp version ${NXT_NODE_GYP_VERSION}"
107802Salexander.borisov@nginx.com
108802Salexander.borisov@nginx.comelse
109802Salexander.borisov@nginx.com    $echo " not found"
110802Salexander.borisov@nginx.com    $echo
111802Salexander.borisov@nginx.com    $echo $0: error: no node-gyp found.
112802Salexander.borisov@nginx.com    $echo
113802Salexander.borisov@nginx.com    exit 1;
114802Salexander.borisov@nginx.comfi
115802Salexander.borisov@nginx.com
116802Salexander.borisov@nginx.comif grep ^$NXT_NODE: $NXT_MAKEFILE 2>&1 > /dev/null; then
117802Salexander.borisov@nginx.com    $echo
118802Salexander.borisov@nginx.com    $echo $0: error: duplicate \"$NXT_NODE\" package configured.
119802Salexander.borisov@nginx.com    $echo
120802Salexander.borisov@nginx.com    exit 1;
121802Salexander.borisov@nginx.comfi
122802Salexander.borisov@nginx.com
123837Svbart@nginx.com
124802Salexander.borisov@nginx.comNXT_NODE_TMP=${NXT_BUILD_DIR}/src/${NXT_NODE}/unit-http
1251830Smax.romanov@nginx.comNXT_NODE_TMP_G=${NXT_BUILD_DIR}/src/${NXT_NODE}/unit-http-g
126*2651Sa.clayton@nginx.comNXT_NODE_TARBALL=${NXT_BUILD_DIR}/src/${NXT_NODE}-unit-http.tar.gz
127*2651Sa.clayton@nginx.comNXT_NODE_TARBALL_G=${NXT_BUILD_DIR}/src/${NXT_NODE}-unit-http-g.tar.gz
1281830Smax.romanov@nginx.comNXT_NODE_VERSION_FILE=${NXT_BUILD_DIR}/src/${NXT_NODE}/version.h
1291830Smax.romanov@nginx.comNXT_NODE_PACKAGE_FILE=${NXT_BUILD_DIR}/src/${NXT_NODE}/package.json
130877Salexander.borisov@nginx.comNXT_NODE_EXPORTS="export UNIT_SRC_PATH=${PWD}/src \
131877Salexander.borisov@nginx.com    && export UNIT_BUILD_PATH=${PWD}/${NXT_BUILD_DIR} \
1322397Salx@nginx.com    && export UNIT_LIB_STATIC_PATH=${PWD}/${NXT_BUILD_DIR}/lib/libunit.a"
133802Salexander.borisov@nginx.com
134838Svbart@nginx.comif [ -n "$NXT_NODE_LOCAL" ]; then
135838Svbart@nginx.com    NXT_NODE_INSTALL=local-install
136838Svbart@nginx.comelse
137838Svbart@nginx.com    NXT_NODE_INSTALL=install
138838Svbart@nginx.comfi
139838Svbart@nginx.com
140802Salexander.borisov@nginx.comcat << END >> $NXT_MAKEFILE
141802Salexander.borisov@nginx.com
142802Salexander.borisov@nginx.com.PHONY: ${NXT_NODE}
143802Salexander.borisov@nginx.com.PHONY: ${NXT_NODE}-copy
1441830Smax.romanov@nginx.com.PHONY: ${NXT_NODE}-copy-g
145802Salexander.borisov@nginx.com.PHONY: ${NXT_NODE}-install
146802Salexander.borisov@nginx.com.PHONY: ${NXT_NODE}-uninstall
147838Svbart@nginx.com.PHONY: ${NXT_NODE}-local-check
148837Svbart@nginx.com.PHONY: ${NXT_NODE}-local-install
149837Svbart@nginx.com.PHONY: ${NXT_NODE}-build
150837Svbart@nginx.com.PHONY: ${NXT_NODE}-publish
151802Salexander.borisov@nginx.com
1522397Salx@nginx.com${NXT_NODE}: ${NXT_NODE}-copy $NXT_BUILD_DIR/lib/$NXT_LIB_UNIT_STATIC
153802Salexander.borisov@nginx.com	${NXT_NODE_EXPORTS} && \\
154802Salexander.borisov@nginx.com	cd ${NXT_NODE_TMP} && ${NXT_NODE_GYP} configure build clean
155802Salexander.borisov@nginx.com
1561830Smax.romanov@nginx.com${NXT_NODE}-copy: ${NXT_NODE_VERSION_FILE} ${NXT_NODE_PACKAGE_FILE}
1571830Smax.romanov@nginx.com	mkdir -p ${NXT_NODE_TMP}
1581830Smax.romanov@nginx.com	cp -rp src/nodejs/unit-http/* ${NXT_NODE_TMP}/
1591830Smax.romanov@nginx.com	cp -p ${NXT_NODE_VERSION_FILE} ${NXT_NODE_PACKAGE_FILE} ${NXT_NODE_TMP}/
1601898Smax.romanov@nginx.com	rm -f ${NXT_NODE_TMP}/binding_pub.gyp
1611830Smax.romanov@nginx.com
1621830Smax.romanov@nginx.com${NXT_NODE}-copy-g: ${NXT_NODE_VERSION_FILE} ${NXT_NODE_PACKAGE_FILE}
1631830Smax.romanov@nginx.com	mkdir -p ${NXT_NODE_TMP_G}
1641830Smax.romanov@nginx.com	cp -rp src/nodejs/unit-http/* ${NXT_NODE_TMP_G}/
1651830Smax.romanov@nginx.com	cp -p ${NXT_NODE_VERSION_FILE} ${NXT_NODE_PACKAGE_FILE} ${NXT_NODE_TMP_G}/
1661830Smax.romanov@nginx.com	mv ${NXT_NODE_TMP_G}/binding_pub.gyp ${NXT_NODE_TMP_G}/binding.gyp
167878Salexander.borisov@nginx.com
168953Salexander.borisov@nginx.com${NXT_NODE_VERSION_FILE}: ${NXT_VERSION_H}
1691830Smax.romanov@nginx.com	mkdir -p ${NXT_BUILD_DIR}/src/${NXT_NODE}
170953Salexander.borisov@nginx.com	$echo '#define NXT_NODE_VERNUM \$(NXT_VERNUM)' > $NXT_NODE_VERSION_FILE
171802Salexander.borisov@nginx.com
1721830Smax.romanov@nginx.com${NXT_NODE_PACKAGE_FILE}: ${NXT_VERSION_H} src/nodejs/unit-http/package.json
1731830Smax.romanov@nginx.com	mkdir -p ${NXT_BUILD_DIR}/src/${NXT_NODE}
1741831Svbart@nginx.com	sed -e "s|%%VERSION%%|\$(NXT_VERSION)|" \
1751830Smax.romanov@nginx.com		src/nodejs/unit-http/package.json > ${NXT_NODE_PACKAGE_FILE}
1761830Smax.romanov@nginx.com
177802Salexander.borisov@nginx.com${NXT_NODE_TARBALL}: ${NXT_NODE}-copy
1781898Smax.romanov@nginx.com	cd ${NXT_NODE_TMP} && npm pack
1791898Smax.romanov@nginx.com	mv ${NXT_NODE_TMP}/unit-http-\$(NXT_VERSION).tgz ${NXT_NODE_TARBALL}
180802Salexander.borisov@nginx.com
1811830Smax.romanov@nginx.com${NXT_NODE_TARBALL_G}: ${NXT_NODE}-copy-g
1821898Smax.romanov@nginx.com	cd ${NXT_NODE_TMP_G} && npm pack
1831898Smax.romanov@nginx.com	mv ${NXT_NODE_TMP_G}/unit-http-\$(NXT_VERSION).tgz ${NXT_NODE_TARBALL_G}
1841830Smax.romanov@nginx.com
185837Svbart@nginx.com
186838Svbart@nginx.cominstall: ${NXT_NODE}-$NXT_NODE_INSTALL
187838Svbart@nginx.com
1881830Smax.romanov@nginx.com${NXT_NODE}-install: ${NXT_NODE_TARBALL_G} libunit-install
1891830Smax.romanov@nginx.com	${NXT_NPM} install -g --unsafe-perm ${PWD}/${NXT_NODE_TARBALL_G}
190837Svbart@nginx.com
191837Svbart@nginx.com${NXT_NODE}-uninstall:
192837Svbart@nginx.com	${NXT_NPM} uninstall -g unit-http
193802Salexander.borisov@nginx.com
194838Svbart@nginx.com${NXT_NODE}-local-check:
195838Svbart@nginx.com	@test -n "\$(DESTDIR)$NXT_NODE_LOCAL" \\
196838Svbart@nginx.com	|| (echo; \\
197838Svbart@nginx.com	    echo "error: to make ${NXT_NODE}-local-install you need either"; \\
198838Svbart@nginx.com	    echo "    to configure --local option"; \\
199838Svbart@nginx.com	    echo "    or to set DESTDIR environment variable."; \\
200838Svbart@nginx.com	    echo; \\
201838Svbart@nginx.com	    exit 1)
202838Svbart@nginx.com
203838Svbart@nginx.com${NXT_NODE}-local-install: ${NXT_NODE_TARBALL} ${NXT_NODE}-local-check \
2042397Salx@nginx.com    $NXT_BUILD_DIR/lib/$NXT_LIB_UNIT_STATIC
205802Salexander.borisov@nginx.com	${NXT_NODE_EXPORTS} && \\
206838Svbart@nginx.com	mkdir -p \$(DESTDIR)${NXT_NODE_LOCAL} && \\
207838Svbart@nginx.com	cd \$(DESTDIR)${NXT_NODE_LOCAL} && \\
208838Svbart@nginx.com	${NXT_NPM} install ${PWD}/${NXT_NODE_TARBALL}
209802Salexander.borisov@nginx.com
210837Svbart@nginx.com
211802Salexander.borisov@nginx.com${NXT_NODE}-build: ${NXT_NODE}
212802Salexander.borisov@nginx.com
213802Salexander.borisov@nginx.com${NXT_NODE}-publish: ${NXT_NODE}
214802Salexander.borisov@nginx.com	cd ${NXT_NODE_TMP} && ${NXT_NPM} publish
215802Salexander.borisov@nginx.com
216802Salexander.borisov@nginx.comEND
217