1246149Ssjg#
2246149Ssjg# RCSid:
3246149Ssjg#	$Id: java.mk,v 1.14 2007/11/22 08:16:25 sjg Exp $
4246149Ssjg
5246149Ssjg#	@(#) Copyright (c) 1998-2001, Simon J. Gerraty
6246149Ssjg#
7246149Ssjg#	This file is provided in the hope that it will
8246149Ssjg#	be of use.  There is absolutely NO WARRANTY.
9246149Ssjg#	Permission to copy, redistribute or otherwise
10246149Ssjg#	use this file is hereby granted provided that 
11246149Ssjg#	the above copyright notice and this notice are
12246149Ssjg#	left intact. 
13246149Ssjg#      
14246149Ssjg#	Please send copies of changes and bug-fixes to:
15246149Ssjg#	sjg@crufty.net
16246149Ssjg#
17246149Ssjg
18246149Ssjg.if !target(__${.PARSEFILE}__)
19246149Ssjg__${.PARSEFILE}__:
20246149Ssjg
21246149Ssjg.include <init.mk>
22246149Ssjg
23246149SsjgCLASSPATH?=.
24246149Ssjg
25246149Ssjg.if defined(PROG)
26246149SsjgSRCS?=	${PROG:.class=.java}
27246149Ssjg.endif
28246149Ssjg.if !defined(SRCS) || empty(SRCS)
29246149SsjgSRCS!=cd ${.CURDIR} && echo *.java
30246149Ssjg.endif
31246149Ssjg.SUFFIXES:	.class .java
32246149Ssjg
33246149SsjgCLEANFILES+= *.class
34246149Ssjg
35246149SsjgJAVAC?=   javac
36246149SsjgJAVADOC?= javadoc
37246149Ssjg
38246149Ssjg.if !target(docs)
39246149Ssjgdocs:
40246149Ssjg	${JAVADOC} ${JAVADOC_FLAGS} ${SRCS}
41246149Ssjg.endif
42246149Ssjg
43246149Ssjg.if defined(JAVADESTDIR) && !empty(JAVADESTDIR)
44246149SsjgJAVASRCDIR?=${JAVADESTDIR:H}/src
45246149Ssjg__classdest:=${JAVADESTDIR}${.CURDIR:S,${JAVASRCDIR},,}/
46246149SsjgCLASSPATH:=${CLASSPATH}:${JAVADESTDIR}
47246149SsjgJAVAC_FLAGS+= -d ${JAVADESTDIR}
48246149Ssjg.else
49246149Ssjg__classdest=
50246149Ssjg.endif
51246149Ssjg
52246149SsjgJAVAC_FLAGS+= ${JAVAC_DBG}
53246149Ssjg
54246149Ssjg.if defined(MAKE_VERSION) && !defined(NO_CLASSES_COOKIE)
55246149Ssjg# java works best by compiling a bunch of classes at once.
56246149Ssjg# this lot does that but needs a recent netbsd make or 
57246149Ssjg# or its portable cousin bmake.
58246149Ssjg.for __s in ${SRCS}
59246149Ssjg__c:= ${__classdest}${__s:.java=.class}
60246149Ssjg.if !target(${__c})
61246149Ssjg# We need to do something to force __c's parent to be made.
62246149Ssjg${__c}:	${__s}
63246149Ssjg	@rm -f ${.TARGET}
64246149Ssjg.endif
65246149SsjgSRCS_${__c}=${__s}
66246149Ssjg__classes:= ${__classes} ${__c}
67246149Ssjg.endfor
68246149Ssjg__classes_cookie=${__classdest}.classes.done
69246149SsjgCLEANFILES+= ${__classes} ${__classes_cookie}
70246149Ssjg
71246149Ssjg${__classes_cookie}:	${__classes}
72246149Ssjg	CLASSPATH=${CLASSPATH} ${JAVAC} ${JAVAC_FLAGS} ${.OODATE:@c@${SRCS_$c}@}
73246149Ssjg	@touch ${.TARGET}
74246149Ssjg
75246149Ssjgall:	${__classes_cookie}
76246149Ssjg
77246149Ssjg.else
78246149Ssjg# this will work with other BSD make's
79246149Ssjg.for __s in ${SRCS}
80246149Ssjg__c:= ${__classdest}${__s:.java=.class}
81246149Ssjg${__c}:	${__s}
82246149Ssjg	CLASSPATH=${CLASSPATH} ${JAVAC} ${JAVAC_FLAGS} ${.OODATE}
83246149Ssjg.endfor
84246149Ssjg
85246149Ssjgall:	${SRCS:%.java=${__classdest}%.class}
86246149Ssjg
87246149Ssjg.endif
88246149Ssjg
89246149Ssjg.if !target(cleanjava)
90246149Ssjgcleanjava:
91246149Ssjg	rm -f [Ee]rrs mklog core *.core ${PROG} ${CLEANFILES}
92246149Ssjg
93246149Ssjgclean: cleanjava
94246149Ssjgcleandir: cleanjava
95246149Ssjg.endif
96246149Ssjg
97246149Ssjg.endif
98