xref: /unit/auto/modules/java (revision 1938:418e225f58e4)
1
2# Copyright (C) NGINX, Inc.
3
4
5shift
6
7NXT_JAVA_HOME=${JAVA_HOME-}
8NXT_JAR_REPO=https://repo1.maven.org/maven2/
9NXT_JAR_LOCAL_REPO=$HOME/.m2/repository/
10
11for nxt_option; do
12
13    case "$nxt_option" in
14        -*=*) value=`echo "$nxt_option" | sed -e 's/[-_a-zA-Z0-9]*=//'`     ;;
15           *) value="" ;;
16    esac
17
18    case "$nxt_option" in
19
20        --module=*)     NXT_JAVA_MODULE="$value"                              ;;
21        --home=*)       NXT_JAVA_HOME="$value"                                ;;
22        --lib-path=*)   NXT_JAVA_LIB_PATH="$value"                            ;;
23        --repo=*)       NXT_JAR_REPO="$value"                                 ;;
24        --local-repo=*) NXT_JAR_LOCAL_REPO="$value"                           ;;
25        --sha512=*)     NXT_SHA512_TOOL="$value"                              ;;
26        --jars=*)       NXT_JARS="$value"                                     ;;
27
28        --help)
29            cat << END
30
31    --module=NAME         set unit Java module name
32    --home=DIR            set Java home directory
33    --lib-path=DIRECTORY  set directory path to libjvm.so library
34    --repo=URL            set Maven remote repository URL
35                          default: "$NXT_JAR_REPO"
36    --local-repo=DIR      set local repository directory
37                          default: "$NXT_JAR_LOCAL_REPO"
38    --sha512=SHA512       set command for SHA512 check
39    --jars=DIR            set jars install/search directory
40
41END
42            exit 0
43        ;;
44
45        *)
46            echo
47            echo $0: error: invalid Java option \"$nxt_option\"
48            echo
49            exit 1
50        ;;
51    esac
52
53done
54
55
56if [ ! -f $NXT_AUTOCONF_DATA ]; then
57   echo
58   echo Please run common $0 before configuring module \"$nxt_module\".
59   echo
60   exit 1
61fi
62
63. $NXT_AUTOCONF_DATA
64
65
66NXT_JARS=${NXT_JARS=$NXT_MODULES}
67NXT_JAVA_MODULE=${NXT_JAVA_MODULE=java}
68NXT_JAVA_LIB_PATH=${NXT_JAVA_LIB_PATH=}
69
70$echo "configuring Java module"
71$echo "configuring Java module ..." >> $NXT_AUTOCONF_ERR
72
73if [ -n "${NXT_JAVA_HOME}" ]; then
74    $echo "using java.home ${NXT_JAVA_HOME}"
75    $echo "using java.home ${NXT_JAVA_HOME}" >> $NXT_AUTOCONF_ERR
76
77    if [ ! -d "${NXT_JAVA_HOME}" ]; then
78        $echo
79        $echo $0: error: Java home directory not found.
80        $echo
81        exit 1
82    fi
83
84    NXT_JAVA="${NXT_JAVA_HOME}/bin/java"
85
86else
87    $echo -n "checking for java executable ..."
88    $echo "checking for java executable ..." >> $NXT_AUTOCONF_ERR
89
90    NXT_JAVA=`which java || :`
91    if [ -z "$NXT_JAVA" -o ! -x "$NXT_JAVA" ]; then
92        $echo " not found"
93        $echo
94        $echo $0: error: java executable not found.
95        $echo
96        exit 1
97    fi
98
99    $echo " found $NXT_JAVA"
100    $echo "found $NXT_JAVA" >> $NXT_AUTOCONF_ERR
101
102    "$NXT_JAVA" -version
103
104    $echo -n "checking java.home ..."
105    $echo "checking java.home ..." >> $NXT_AUTOCONF_ERR
106
107    NXT_JAVA_HOME=`$NXT_JAVA -XshowSettings 2>&1 | grep -F -e java.home | sed -e 's/^.*= //'`
108    if [ -z "$NXT_JAVA_HOME" ]; then
109        $echo " not found"
110        $echo
111        $echo $0: error: java.home not found.
112        $echo
113        exit 1
114    fi
115
116    $echo " $NXT_JAVA_HOME"
117    $echo "got java.home $NXT_JAVA_HOME" >> $NXT_AUTOCONF_ERR
118
119    if [ ! -x "${NXT_JAVA_HOME}/bin/javac" ]; then
120        NXT_JAVA_HOME_=${NXT_JAVA_HOME%/jre}
121        if [ -x "${NXT_JAVA_HOME_}/bin/javac" ]; then
122            $echo "adjust java.home $NXT_JAVA_HOME_"
123            $echo "adjust java.home $NXT_JAVA_HOME_" >> $NXT_AUTOCONF_ERR
124
125            NXT_JAVA_HOME="$NXT_JAVA_HOME_"
126        fi
127    fi
128fi
129
130NXT_JAVAC="${NXT_JAVA_HOME}/bin/javac"
131
132if [ ! -x "$NXT_JAVAC" ]; then
133    $echo
134    $echo $0: error: javac not found.
135    $echo
136    exit 1
137fi
138
139NXT_JAVA_INCLUDE="-I${NXT_JAVA_HOME}/include"
140
141case "$NXT_SYSTEM" in
142    Linux)
143        NXT_JAVA_INCLUDE="${NXT_JAVA_INCLUDE} -I${NXT_JAVA_HOME}/include/linux"
144        ;;
145    Darwin)
146        NXT_JAVA_INCLUDE="${NXT_JAVA_INCLUDE} -I${NXT_JAVA_HOME}/include/darwin"
147        ;;
148    FreeBSD)
149        NXT_JAVA_INCLUDE="${NXT_JAVA_INCLUDE} -I${NXT_JAVA_HOME}/include/freebsd"
150        ;;
151esac
152
153if [ -z "$NXT_JAVA_LIB_PATH" ]; then
154    $echo -n "checking library path ..."
155    $echo "checking library path ..." >> $NXT_AUTOCONF_ERR
156
157    if [ ! -x "$NXT_JAVA" ]; then
158        $echo " not found"
159        $echo
160        $echo $0: error: java executable not found.
161        $echo
162        exit 1
163    fi
164
165    NXT_JAVA_LIB_PATH=`$NXT_JAVA -XshowSettings 2>&1 | grep -F -e sun.boot.library.path | sed -e 's/^.*= //'`
166
167    if [ -z "$NXT_JAVA_LIB_PATH" ]; then
168        $echo " not found"
169        $echo
170        $echo $0: error: library path not found.
171        $echo
172        exit 1
173    fi
174
175    $echo " $NXT_JAVA_LIB_PATH"
176    $echo "got library path $NXT_JAVA_LIB_PATH" >> $NXT_AUTOCONF_ERR
177fi
178
179NXT_JAVA_LIB_SERVER_PATH="${NXT_JAVA_LIB_PATH}/server"
180
181NXT_JAVA_LDFLAGS="-L${NXT_JAVA_LIB_SERVER_PATH} -Wl,-rpath,${NXT_JAVA_LIB_SERVER_PATH} -ljvm"
182
183
184nxt_found=no
185
186nxt_feature="JNI"
187nxt_feature_name=""
188nxt_feature_run=no
189nxt_feature_incs="${NXT_JAVA_INCLUDE}"
190nxt_feature_libs="${NXT_JAVA_LDFLAGS}"
191nxt_feature_test="
192    #include <jni.h>
193
194    int main() {
195        JNI_CreateJavaVM(NULL, NULL, NULL);
196        return 0;
197    }"
198
199. auto/feature
200
201
202if [ $nxt_found = no ]; then
203    $echo
204    $echo $0: error: no JNI found.
205    $echo
206    exit 1;
207fi
208
209NXT_JAVA_VERSION=`$NXT_JAVAC -version 2>&1`
210NXT_JAVA_VERSION=${NXT_JAVA_VERSION#javac }
211NXT_JAVA_INCLUDE="$NXT_JAVA_INCLUDE -I$NXT_BUILD_DIR/$NXT_JAVA_MODULE -DNXT_JAVA_VERSION=$NXT_JAVA_VERSION"
212
213if grep ^$NXT_JAVA_MODULE: $NXT_MAKEFILE 2>&1 > /dev/null; then
214    $echo
215    $echo $0: error: duplicate \"$NXT_JAVA_MODULE\" module configured.
216    $echo
217    exit 1;
218fi
219
220. ./version
221
222NXT_UNIT_JAR=nginx-unit-jsc-${NXT_JAVA_MODULE}-$NXT_VERSION.jar
223NXT_WS_API_JAR=websocket-api-${NXT_JAVA_MODULE}-$NXT_VERSION.jar
224
225NXT_JAVA_BUILD_CP=$NXT_BUILD_DIR/$NXT_JAVA_MODULE
226NXT_JAVA_INSTALL_JARS=
227NXT_JAVA_UNINSTALL_JARS=
228
229NXT_JAVA_JARS=$NXT_BUILD_DIR/$NXT_JAVA_MODULE/nxt_jars.h
230mkdir -p $NXT_BUILD_DIR/$NXT_JAVA_MODULE
231
232cat << END > $NXT_JAVA_JARS
233#ifndef _NXT_JAVA_JARS_INCLUDED_
234#define _NXT_JAVA_JARS_INCLUDED_
235
236#define NXT_JARS "$NXT_JARS"
237
238static const char *nxt_java_system_jars[] = {
239END
240
241NXT_TOMCAT_VERSION=9.0.52
242
243NXT_JAR_VERSION=$NXT_TOMCAT_VERSION
244
245NXT_JAR_NAME=tomcat-servlet-api
246NXT_JAR_NAMESPACE=org/apache/tomcat/
247. auto/modules/java_get_jar
248
249NXT_JAR_NAME=tomcat-el-api
250. auto/modules/java_get_jar
251
252NXT_JAR_NAME=tomcat-jsp-api
253. auto/modules/java_get_jar
254
255NXT_JAR_NAME=tomcat-jasper
256. auto/modules/java_get_jar
257
258NXT_JAR_NAME=tomcat-jasper-el
259. auto/modules/java_get_jar
260
261NXT_JAR_NAME=tomcat-juli
262. auto/modules/java_get_jar
263
264NXT_JAR_NAME=tomcat-api
265. auto/modules/java_get_jar
266
267NXT_JAR_NAME=tomcat-util-scan
268. auto/modules/java_get_jar
269
270NXT_JAR_NAME=tomcat-util
271. auto/modules/java_get_jar
272
273NXT_JAR_NAME=ecj
274NXT_JAR_VERSION=3.26.0
275NXT_JAR_NAMESPACE=org/eclipse/jdt/
276. auto/modules/java_get_jar
277
278cat << END >> $NXT_JAVA_JARS
279    "$NXT_WS_API_JAR",
280    NULL
281};
282
283static const char *nxt_java_unit_jars[] = {
284    "$NXT_UNIT_JAR",
285END
286
287NXT_JAR_VERSION=9.4.43.v20210629
288NXT_JAR_NAMESPACE=org/eclipse/jetty/
289
290NXT_JAR_NAME=jetty-util
291. auto/modules/java_get_jar
292
293NXT_JAR_NAME=jetty-server
294. auto/modules/java_get_jar
295
296NXT_JAR_NAME=jetty-http
297. auto/modules/java_get_jar
298
299NXT_JAR_NAME=classgraph
300NXT_JAR_VERSION=4.8.112
301NXT_JAR_NAMESPACE=io/github/classgraph/
302. auto/modules/java_get_jar
303
304cat << END >> $NXT_JAVA_JARS
305    NULL
306};
307
308#endif /* _NXT_JAVA_JARS_INCLUDED_ */
309END
310
311NXT_JAVA_LIBJVM="$NXT_JAVA_LIB_SERVER_PATH/libjvm.so"
312
313if [ "$NXT_SYSTEM" = "Darwin" ]; then
314NXT_JAVA_LIBC_DIR="/usr/lib"
315else
316NXT_JAVA_LIBC_DIR=`ldd "$NXT_JAVA_LIBJVM" | grep -F libc. | cut -d' ' -f3`
317NXT_JAVA_LIBC_DIR=`dirname $NXT_JAVA_LIBC_DIR`
318fi
319
320
321NXT_JAVA_MOUNTS_HEADER=nxt_${NXT_JAVA_MODULE}_mounts.h
322
323cat << END > $NXT_BUILD_DIR/$NXT_JAVA_MOUNTS_HEADER
324#ifndef _NXT_JAVA_MOUNTS_H_INCLUDED_
325#define _NXT_JAVA_MOUNTS_H_INCLUDED_
326
327
328static const nxt_fs_mount_t  nxt_java_mounts[] = {
329    {(u_char *) "$NXT_JAVA_LIBC_DIR", (u_char *) "$NXT_JAVA_LIBC_DIR",
330     NXT_FS_BIND, (u_char *) "bind", 0, NULL, 1, 1},
331    {(u_char *) "$NXT_JAVA_HOME", (u_char *) "$NXT_JAVA_HOME",
332     NXT_FS_BIND, (u_char *) "bind", 0, NULL, 1, 1},
333};
334
335
336#endif /* _NXT_JAVA_MOUNTS_H_INCLUDED_ */
337END
338
339$echo " + Java module: ${NXT_JAVA_MODULE}.unit.so"
340
341. auto/cc/deps
342
343$echo >> $NXT_MAKEFILE
344
345NXT_JAVA_MODULE_SRCS=" \
346    src/nxt_java.c \
347    src/java/nxt_jni.c \
348    src/java/nxt_jni_Context.c \
349    src/java/nxt_jni_HeaderNamesEnumeration.c \
350    src/java/nxt_jni_HeadersEnumeration.c \
351    src/java/nxt_jni_InputStream.c \
352    src/java/nxt_jni_OutputStream.c \
353    src/java/nxt_jni_Request.c \
354    src/java/nxt_jni_Response.c \
355    src/java/nxt_jni_Thread.c \
356    src/java/nxt_jni_URLClassLoader.c \
357"
358
359# The Java module object files.
360
361nxt_objs=$NXT_BUILD_DIR/src/nxt_unit.o
362
363for nxt_src in $NXT_JAVA_MODULE_SRCS; do
364
365    nxt_obj=${nxt_src%.c}-$NXT_JAVA_MODULE.o
366    nxt_dep=${nxt_src%.c}-$NXT_JAVA_MODULE.dep
367    nxt_dep_flags=`nxt_gen_dep_flags`
368    nxt_dep_post=`nxt_gen_dep_post`
369    nxt_objs="$nxt_objs $NXT_BUILD_DIR/$nxt_obj"
370
371    cat << END >> $NXT_MAKEFILE
372
373$NXT_BUILD_DIR/$nxt_obj: $nxt_src $NXT_VERSION_H
374	mkdir -p $NXT_BUILD_DIR/src/java
375	\$(CC) -c \$(CFLAGS) -DNXT_JAVA_MOUNTS_H=\"$NXT_JAVA_MOUNTS_HEADER\" \\
376           \$(NXT_INCS) $NXT_JAVA_INCLUDE \\
377	$nxt_dep_flags \\
378	-o $NXT_BUILD_DIR/$nxt_obj $nxt_src
379	$nxt_dep_post
380
381-include $NXT_BUILD_DIR/$nxt_dep
382
383END
384
385done
386
387NXT_JAVA_SRCS=" \
388    src/java/nginx/unit/Context.java \
389    src/java/nginx/unit/DynamicDispatcherRequest.java \
390    src/java/nginx/unit/DynamicPathRequest.java \
391    src/java/nginx/unit/ForwardRequestWrapper.java \
392    src/java/nginx/unit/HeaderNamesEnumeration.java \
393    src/java/nginx/unit/HeadersEnumeration.java \
394    src/java/nginx/unit/IncludeRequestWrapper.java \
395    src/java/nginx/unit/IncludeResponseWrapper.java \
396    src/java/nginx/unit/InitParams.java \
397    src/java/nginx/unit/InputStream.java \
398    src/java/nginx/unit/JspPropertyGroup.java \
399    src/java/nginx/unit/OutputStream.java \
400    src/java/nginx/unit/Request.java \
401    src/java/nginx/unit/RequestAttrProxy.java \
402    src/java/nginx/unit/Response.java \
403    src/java/nginx/unit/Session.java \
404    src/java/nginx/unit/SessionAttrProxy.java \
405    src/java/nginx/unit/Taglib.java \
406    src/java/nginx/unit/UnitSessionCookieConfig.java \
407    src/java/nginx/unit/websocket/AsyncChannelGroupUtil.java \
408    src/java/nginx/unit/websocket/AsyncChannelWrapper.java \
409    src/java/nginx/unit/websocket/AsyncChannelWrapperNonSecure.java \
410    src/java/nginx/unit/websocket/AsyncChannelWrapperSecure.java \
411    src/java/nginx/unit/websocket/AuthenticationException.java \
412    src/java/nginx/unit/websocket/Authenticator.java \
413    src/java/nginx/unit/websocket/AuthenticatorFactory.java \
414    src/java/nginx/unit/websocket/BackgroundProcess.java \
415    src/java/nginx/unit/websocket/BackgroundProcessManager.java \
416    src/java/nginx/unit/websocket/BasicAuthenticator.java \
417    src/java/nginx/unit/websocket/Constants.java \
418    src/java/nginx/unit/websocket/DecoderEntry.java \
419    src/java/nginx/unit/websocket/DigestAuthenticator.java \
420    src/java/nginx/unit/websocket/FutureToSendHandler.java \
421    src/java/nginx/unit/websocket/MessageHandlerResult.java \
422    src/java/nginx/unit/websocket/MessageHandlerResultType.java \
423    src/java/nginx/unit/websocket/MessagePart.java \
424    src/java/nginx/unit/websocket/PerMessageDeflate.java \
425    src/java/nginx/unit/websocket/ReadBufferOverflowException.java \
426    src/java/nginx/unit/websocket/Transformation.java \
427    src/java/nginx/unit/websocket/TransformationFactory.java \
428    src/java/nginx/unit/websocket/TransformationResult.java \
429    src/java/nginx/unit/websocket/Util.java \
430    src/java/nginx/unit/websocket/WrappedMessageHandler.java \
431    src/java/nginx/unit/websocket/WsContainerProvider.java \
432    src/java/nginx/unit/websocket/WsExtension.java \
433    src/java/nginx/unit/websocket/WsExtensionParameter.java \
434    src/java/nginx/unit/websocket/WsFrameBase.java \
435    src/java/nginx/unit/websocket/WsFrameClient.java \
436    src/java/nginx/unit/websocket/WsHandshakeResponse.java \
437    src/java/nginx/unit/websocket/WsIOException.java \
438    src/java/nginx/unit/websocket/WsPongMessage.java \
439    src/java/nginx/unit/websocket/WsRemoteEndpointAsync.java \
440    src/java/nginx/unit/websocket/WsRemoteEndpointBase.java \
441    src/java/nginx/unit/websocket/WsRemoteEndpointBasic.java \
442    src/java/nginx/unit/websocket/WsRemoteEndpointImplBase.java \
443    src/java/nginx/unit/websocket/WsRemoteEndpointImplClient.java \
444    src/java/nginx/unit/websocket/WsSession.java \
445    src/java/nginx/unit/websocket/WsWebSocketContainer.java \
446    src/java/nginx/unit/websocket/pojo/Constants.java \
447    src/java/nginx/unit/websocket/pojo/PojoEndpointBase.java \
448    src/java/nginx/unit/websocket/pojo/PojoEndpointClient.java \
449    src/java/nginx/unit/websocket/pojo/PojoEndpointServer.java \
450    src/java/nginx/unit/websocket/pojo/PojoMessageHandlerBase.java \
451    src/java/nginx/unit/websocket/pojo/PojoMessageHandlerPartialBase.java \
452    src/java/nginx/unit/websocket/pojo/PojoMessageHandlerPartialBinary.java \
453    src/java/nginx/unit/websocket/pojo/PojoMessageHandlerPartialText.java \
454    src/java/nginx/unit/websocket/pojo/PojoMessageHandlerWholeBase.java \
455    src/java/nginx/unit/websocket/pojo/PojoMessageHandlerWholeBinary.java \
456    src/java/nginx/unit/websocket/pojo/PojoMessageHandlerWholePong.java \
457    src/java/nginx/unit/websocket/pojo/PojoMessageHandlerWholeText.java \
458    src/java/nginx/unit/websocket/pojo/PojoMethodMapping.java \
459    src/java/nginx/unit/websocket/pojo/PojoPathParam.java \
460    src/java/nginx/unit/websocket/pojo/package-info.java \
461    src/java/nginx/unit/websocket/server/Constants.java \
462    src/java/nginx/unit/websocket/server/DefaultServerEndpointConfigurator.java \
463    src/java/nginx/unit/websocket/server/UpgradeUtil.java \
464    src/java/nginx/unit/websocket/server/UriTemplate.java \
465    src/java/nginx/unit/websocket/server/WsContextListener.java \
466    src/java/nginx/unit/websocket/server/WsFilter.java \
467    src/java/nginx/unit/websocket/server/WsHandshakeRequest.java \
468    src/java/nginx/unit/websocket/server/WsHttpUpgradeHandler.java \
469    src/java/nginx/unit/websocket/server/WsMappingResult.java \
470    src/java/nginx/unit/websocket/server/WsPerSessionServerEndpointConfig.java \
471    src/java/nginx/unit/websocket/server/WsRemoteEndpointImplServer.java \
472    src/java/nginx/unit/websocket/server/WsSci.java \
473    src/java/nginx/unit/websocket/server/WsServerContainer.java \
474    src/java/nginx/unit/websocket/server/WsSessionListener.java \
475    src/java/nginx/unit/websocket/server/WsWriteTimeout.java \
476    src/java/nginx/unit/websocket/server/package-info.java \
477"
478
479NXT_JAVA_WS_API_SRCS=" \
480    src/java/javax/websocket/ClientEndpoint.java \
481    src/java/javax/websocket/ClientEndpointConfig.java \
482    src/java/javax/websocket/CloseReason.java \
483    src/java/javax/websocket/ContainerProvider.java \
484    src/java/javax/websocket/DecodeException.java \
485    src/java/javax/websocket/Decoder.java \
486    src/java/javax/websocket/DefaultClientEndpointConfig.java \
487    src/java/javax/websocket/DeploymentException.java \
488    src/java/javax/websocket/EncodeException.java \
489    src/java/javax/websocket/Encoder.java \
490    src/java/javax/websocket/Endpoint.java \
491    src/java/javax/websocket/EndpointConfig.java \
492    src/java/javax/websocket/Extension.java \
493    src/java/javax/websocket/HandshakeResponse.java \
494    src/java/javax/websocket/MessageHandler.java \
495    src/java/javax/websocket/OnClose.java \
496    src/java/javax/websocket/OnError.java \
497    src/java/javax/websocket/OnMessage.java \
498    src/java/javax/websocket/OnOpen.java \
499    src/java/javax/websocket/PongMessage.java \
500    src/java/javax/websocket/RemoteEndpoint.java \
501    src/java/javax/websocket/SendHandler.java \
502    src/java/javax/websocket/SendResult.java \
503    src/java/javax/websocket/Session.java \
504    src/java/javax/websocket/SessionException.java \
505    src/java/javax/websocket/WebSocketContainer.java \
506    src/java/javax/websocket/server/DefaultServerEndpointConfig.java \
507    src/java/javax/websocket/server/HandshakeRequest.java \
508    src/java/javax/websocket/server/PathParam.java \
509    src/java/javax/websocket/server/ServerApplicationConfig.java \
510    src/java/javax/websocket/server/ServerContainer.java \
511    src/java/javax/websocket/server/ServerEndpoint.java \
512    src/java/javax/websocket/server/ServerEndpointConfig.java \
513"
514
515cat << END >> $NXT_MAKEFILE
516
517.PHONY: ${NXT_JAVA_MODULE}
518.PHONY: ${NXT_JAVA_MODULE}-install
519.PHONY: ${NXT_JAVA_MODULE}-uninstall
520
521all: ${NXT_JAVA_MODULE}
522
523${NXT_JAVA_MODULE}: $NXT_BUILD_DIR/${NXT_JAVA_MODULE}.unit.so \
524    $NXT_BUILD_DIR/$NXT_UNIT_JAR \
525    $NXT_BUILD_DIR/$NXT_WS_API_JAR
526
527$NXT_BUILD_DIR/${NXT_JAVA_MODULE}.unit.so: $nxt_objs
528	\$(NXT_MODULE_LINK) -o $NXT_BUILD_DIR/${NXT_JAVA_MODULE}.unit.so \\
529	$nxt_objs $NXT_JAVA_LDFLAGS $NXT_LD_OPT
530
531
532install: ${NXT_JAVA_MODULE}-install
533
534${NXT_JAVA_MODULE}-install: $NXT_BUILD_DIR/${NXT_JAVA_MODULE}.unit.so \\
535    $NXT_BUILD_DIR/$NXT_UNIT_JAR \\
536    $NXT_BUILD_DIR/$NXT_WS_API_JAR \\
537    java-shared-install
538	install -d \$(DESTDIR)$NXT_MODULES
539	install -p $NXT_BUILD_DIR/${NXT_JAVA_MODULE}.unit.so \\
540		\$(DESTDIR)$NXT_MODULES/
541	install -d \$(DESTDIR)$NXT_JARS
542	install -p -m 0644 $NXT_BUILD_DIR/$NXT_UNIT_JAR \$(DESTDIR)$NXT_JARS/
543	install -p -m 0644 $NXT_BUILD_DIR/$NXT_WS_API_JAR \$(DESTDIR)$NXT_JARS/
544
545
546uninstall: ${NXT_JAVA_MODULE}-uninstall
547
548${NXT_JAVA_MODULE}-uninstall: java-shared-uninstall
549	rm -f \$(DESTDIR)$NXT_MODULES/${NXT_JAVA_MODULE}.unit.so
550	@rmdir -p \$(DESTDIR)$NXT_MODULES 2>/dev/null || true
551	rm -f \$(DESTDIR)$NXT_JARS/$NXT_UNIT_JAR
552	rm -f \$(DESTDIR)$NXT_JARS/$NXT_WS_API_JAR
553	@rmdir -p \$(DESTDIR)$NXT_JARS 2>/dev/null || true
554
555END
556
557if ! grep ^$NXT_BUILD_DIR/$NXT_UNIT_JAR: $NXT_MAKEFILE 2>&1 > /dev/null; then
558
559    cat << END >> $NXT_MAKEFILE
560
561NXT_JAVA_SRCS = $NXT_JAVA_SRCS
562
563$NXT_BUILD_DIR/$NXT_JAVA_MODULE/.nginx.unit.classes: \$(NXT_JAVA_SRCS) \\
564    $NXT_BUILD_DIR/$NXT_WS_API_JAR
565	rm -rf $NXT_BUILD_DIR/$NXT_JAVA_MODULE/nginx/unit
566	$NXT_JAVAC -d $NXT_BUILD_DIR/$NXT_JAVA_MODULE \\
567		-cp $NXT_JAVA_BUILD_CP:$NXT_BUILD_DIR/$NXT_WS_API_JAR \\
568		\$(NXT_JAVA_SRCS)
569	touch \$@
570
571$NXT_BUILD_DIR/$NXT_JAVA_MODULE/META-INF/LICENSE: LICENSE
572	mkdir -p $NXT_BUILD_DIR/$NXT_JAVA_MODULE/META-INF
573	cp -p LICENSE \$@
574
575$NXT_BUILD_DIR/$NXT_JAVA_MODULE/META-INF/NOTICE: NOTICE
576	mkdir -p $NXT_BUILD_DIR/$NXT_JAVA_MODULE/META-INF
577	cp -p NOTICE \$@
578
579$NXT_BUILD_DIR/$NXT_UNIT_JAR: \\
580    $NXT_BUILD_DIR/$NXT_JAVA_MODULE/.nginx.unit.classes \\
581    $NXT_BUILD_DIR/$NXT_JAVA_MODULE/META-INF/LICENSE \\
582    $NXT_BUILD_DIR/$NXT_JAVA_MODULE/META-INF/NOTICE
583	$NXT_JAVA_HOME/bin/jar c -C $NXT_BUILD_DIR/$NXT_JAVA_MODULE META-INF \\
584		-C $NXT_BUILD_DIR/$NXT_JAVA_MODULE nginx/unit > \$@
585
586NXT_JAVA_WS_API_SRCS = $NXT_JAVA_WS_API_SRCS
587
588$NXT_BUILD_DIR/$NXT_JAVA_MODULE/.javax.websocket.classes: \$(NXT_JAVA_WS_API_SRCS)
589	rm -rf $NXT_BUILD_DIR/$NXT_JAVA_MODULE/javax/websocket
590	$NXT_JAVAC -d $NXT_BUILD_DIR/$NXT_JAVA_MODULE -cp $NXT_JAVA_BUILD_CP \\
591		\$(NXT_JAVA_WS_API_SRCS)
592	touch \$@
593
594$NXT_BUILD_DIR/$NXT_WS_API_JAR: \\
595    $NXT_BUILD_DIR/$NXT_JAVA_MODULE/.javax.websocket.classes \\
596    $NXT_BUILD_DIR/$NXT_JAVA_MODULE/META-INF/LICENSE \\
597    $NXT_BUILD_DIR/$NXT_JAVA_MODULE/META-INF/NOTICE
598	$NXT_JAVA_HOME/bin/jar c -C $NXT_BUILD_DIR/$NXT_JAVA_MODULE META-INF \\
599		-C $NXT_BUILD_DIR/$NXT_JAVA_MODULE javax/websocket > \$@
600
601END
602
603NXT_PROPS="\
604    nginx/unit/websocket/LocalStrings.properties \
605    nginx/unit/websocket/pojo/LocalStrings.properties \
606    nginx/unit/websocket/server/LocalStrings.properties \
607"
608
609for nxt_prop in $NXT_PROPS ; do
610
611    cat << END >> $NXT_MAKEFILE
612$NXT_BUILD_DIR/$NXT_JAVA_MODULE/$nxt_prop: src/java/$nxt_prop \\
613    $NXT_BUILD_DIR/$NXT_JAVA_MODULE/.nginx.unit.classes
614	cp src/java/$nxt_prop \$@
615
616$NXT_BUILD_DIR/$NXT_UNIT_JAR: $NXT_BUILD_DIR/$NXT_JAVA_MODULE/$nxt_prop
617
618END
619
620done
621
622fi
623
624if ! grep ^java-shared-install: $NXT_MAKEFILE 2>&1 > /dev/null; then
625
626    cat << END >> $NXT_MAKEFILE
627
628.PHONY: java-shared-install
629.PHONY: java-shared-uninstall
630
631java-shared-install: $NXT_JAVA_INSTALL_JARS
632	install -d \$(DESTDIR)$NXT_JARS
633	install -p -m 0644 $NXT_JAVA_INSTALL_JARS \$(DESTDIR)$NXT_JARS/
634
635java-shared-uninstall:
636	rm -f $NXT_JAVA_UNINSTALL_JARS
637	@rmdir -p \$(DESTDIR)$NXT_JARS 2>/dev/null || true
638
639END
640
641fi
642