Add files from parent branch HEAD:
[pkgsrc.git] / mk / java-env.mk
1 # $NetBSD: java-env.mk,v 1.10 2007/08/02 18:04:48 jlam Exp $
2 #
3 # This Makefile fragment handles Java wrappers and is meant to be included
4 # by packages that provide a Java build-time and/or run-time environment.
5 #
6 # The following variables can be defined in package Makefiles to tune the
7 # behavior of this file:
8 #
9 #       JAVA_CLASSPATH  Classpath that will be prepended on all invocations
10 #                       to this implementation.  Optional.
11 #
12 #       JAVA_LD_LIBRARY_PATH
13 #                       Value to prepend to LD_LIBRARY_PATH before running
14 #                       the real command.  Optional; use *only* if necessary.
15 #
16 #       JAVA_HOME       Path to the directory holding the Java implementation.
17 #                       Required.
18 #
19 #       JAVA_NAME       Base name of the Java implementation.  This will be
20 #                       used as part of wrappers' names.  Required.
21 #
22 #       JAVA_UNLIMIT    List of resources to be unlimited at runtime.
23 #                       Can include any of cmdsize, datasize and stacksize.
24 #                       Optional.
25 #
26 #       JAVA_WRAPPERS   List of wrappers to be created under ${PREFIX}/bin,
27 #                       pointing to binaries under ${JAVA_HOME}/bin.  The
28 #                       names must match files in the later directory.
29 #                       Required (if empty, the inclusion of this file is
30 #                       useless).
31 #
32
33 .if !defined(JAVA_ENV_MK)
34 JAVA_ENV_MK=            # defined
35
36 JAVA_NAME?=             # undefined
37 JAVA_HOME?=             # undefined
38 JAVA_CLASSPATH?=        # empty
39 JAVA_LD_LIBRARY_PATH?=  # empty
40 JAVA_UNLIMIT?=          # empty
41 JAVA_WRAPPERS?=         # empty
42
43 .include "../../mk/bsd.prefs.mk"
44
45 .if !empty(JAVA_WRAPPERS)
46 INSTALLATION_DIRS+=     bin
47
48 ALTERNATIVES_SRC=       ${WRKDIR}/.ALTERNATIVES
49 ${WRKDIR}/.ALTERNATIVES:
50 .  for w in ${JAVA_WRAPPERS}
51         @${ECHO} 'bin/${w} ${PREFIX}/bin/${JAVA_NAME}-${w}' \
52                 >>${WRKDIR}/.ALTERNATIVES
53 .  endfor
54
55 .  for w in ${JAVA_WRAPPERS}
56
57 JAVA_WRAPPER_BIN.${w}?= ${JAVA_HOME}/bin/${w}
58
59 post-build:             ${WRKDIR}/${w}
60
61 .PHONY:                 install-java-wrapper-${w}
62 post-install:           install-java-wrapper-${w}
63
64 .    if !target(${WRKDIR}/${w})
65 ${WRKDIR}/${w}:
66         @${ECHO} 'Generating ${w} wrapper...'
67         @${ECHO} '#! ${SH}' >${WRKDIR}/${w}
68         @${ECHO} 'PATH=${JAVA_HOME}/bin:$${PATH}; export PATH' >>${WRKDIR}/${w}
69         @${ECHO} 'JAVA_HOME=${JAVA_HOME}; export JAVA_HOME' >>${WRKDIR}/${w}
70         @${ECHO} 'JVM_HOME=${JAVA_HOME}; export JVM_HOME' >>${WRKDIR}/${w}
71 .      if !empty(JAVA_CLASSPATH)
72         @${ECHO} 'CLASSPATH=${JAVA_CLASSPATH}:$${CLASSPATH}; export CLASSPATH' \
73                 >>${WRKDIR}/${w}
74 .      endif
75 .      if !empty(JAVA_LD_LIBRARY_PATH)
76         @${ECHO} 'LD_LIBRARY_PATH=${JAVA_LD_LIBRARY_PATH}$${LD_LIBRARY_PATH:+:}$${LD_LIBRARY_PATH}; export LD_LIBRARY_PATH' \
77                 >>${WRKDIR}/${w}
78 .      endif
79 .      for f in ${JAVA_UNLIMIT}
80         @${ECHO} '${ULIMIT_CMD_${f}}' >>${WRKDIR}/${w}
81 .      endfor
82 .      undef f
83         @${ECHO} '${JAVA_WRAPPER_BIN.${w}} "$$@"' >>${WRKDIR}/${w}
84 .    endif
85
86 install-java-wrapper-${w}:
87         ${INSTALL_SCRIPT} ${WRKDIR}/${w} ${DESTDIR}${PREFIX}/bin/${JAVA_NAME}-${w}
88
89 .  endfor
90 .  undef w
91 .endif
92
93 # Handle the ${PREFIX}/java shared directory automatically.
94 REQD_DIRS+=             ${PREFIX}/java
95 PRINT_PLIST_AWK+=       /^@dirrm java$$/ { next; }
96
97 PLIST_SUBST+=           JAVA_HOME=${JAVA_HOME:Q}
98 FILES_SUBST+=           JAVA_HOME=${JAVA_HOME:Q}
99
100 .endif  # JAVA_ENV_MK