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