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