xref: /freebsd/contrib/bmake/mk/java.mk (revision a0b9e2e854027e6ff61fb075a1309dbc71c42b54)
1#
2# RCSid:
3#	$Id: java.mk,v 1.15 2020/08/19 17:51:53 sjg Exp $
4
5#	@(#) Copyright (c) 1998-2001, Simon J. Gerraty
6#
7#	This file is provided in the hope that it will
8#	be of use.  There is absolutely NO WARRANTY.
9#	Permission to copy, redistribute or otherwise
10#	use this file is hereby granted provided that
11#	the above copyright notice and this notice are
12#	left intact.
13#
14#	Please send copies of changes and bug-fixes to:
15#	sjg@crufty.net
16#
17
18.if !target(__${.PARSEFILE}__)
19__${.PARSEFILE}__:
20
21.include <init.mk>
22
23CLASSPATH?=.
24
25.if defined(PROG)
26SRCS?=	${PROG:.class=.java}
27.endif
28.if !defined(SRCS) || empty(SRCS)
29SRCS!=cd ${.CURDIR} && echo *.java
30.endif
31.SUFFIXES:	.class .java
32
33CLEANFILES+= *.class
34
35JAVAC?=   javac
36JAVADOC?= javadoc
37
38.if !target(docs)
39docs:
40	${JAVADOC} ${JAVADOC_FLAGS} ${SRCS}
41.endif
42
43.if defined(JAVADESTDIR) && !empty(JAVADESTDIR)
44JAVASRCDIR?=${JAVADESTDIR:H}/src
45__classdest:=${JAVADESTDIR}${.CURDIR:S,${JAVASRCDIR},,}/
46CLASSPATH:=${CLASSPATH}:${JAVADESTDIR}
47JAVAC_FLAGS+= -d ${JAVADESTDIR}
48.else
49__classdest=
50.endif
51
52JAVAC_FLAGS+= ${JAVAC_DBG}
53
54.if defined(MAKE_VERSION) && !defined(NO_CLASSES_COOKIE)
55# java works best by compiling a bunch of classes at once.
56# this lot does that but needs a recent netbsd make or
57# or its portable cousin bmake.
58.for __s in ${SRCS}
59__c:= ${__classdest}${__s:.java=.class}
60.if !target(${__c})
61# We need to do something to force __c's parent to be made.
62${__c}:	${__s}
63	@rm -f ${.TARGET}
64.endif
65SRCS_${__c}=${__s}
66__classes:= ${__classes} ${__c}
67.endfor
68__classes_cookie=${__classdest}.classes.done
69CLEANFILES+= ${__classes} ${__classes_cookie}
70
71${__classes_cookie}:	${__classes}
72	CLASSPATH=${CLASSPATH} ${JAVAC} ${JAVAC_FLAGS} ${.OODATE:@c@${SRCS_$c}@}
73	@touch ${.TARGET}
74
75all:	${__classes_cookie}
76
77.else
78# this will work with other BSD make's
79.for __s in ${SRCS}
80__c:= ${__classdest}${__s:.java=.class}
81${__c}:	${__s}
82	CLASSPATH=${CLASSPATH} ${JAVAC} ${JAVAC_FLAGS} ${.OODATE}
83.endfor
84
85all:	${SRCS:%.java=${__classdest}%.class}
86
87.endif
88
89.if !target(cleanjava)
90cleanjava:
91	rm -f [Ee]rrs mklog core *.core ${PROG} ${CLEANFILES}
92
93clean: cleanjava
94cleandir: cleanjava
95.endif
96
97.endif
98