1# -*-makefile-*- 2# Shared/java.make 3# 4# Makefile fragment with rules to compile and install java files, 5# with associated property files. 6# 7# Copyright (C) 2000, 2002, 2009 Free Software Foundation, Inc. 8# 9# Author: Nicola Pero <nicola.pero@meta-innovation.com> 10# 11# This file is part of the GNUstep Makefile Package. 12# 13# This library is free software; you can redistribute it and/or 14# modify it under the terms of the GNU General Public License 15# as published by the Free Software Foundation; either version 3 16# of the License, or (at your option) any later version. 17# 18# You should have received a copy of the GNU General Public 19# License along with this library; see the file COPYING. 20# If not, write to the Free Software Foundation, 21# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 22 23# 24# input variables: 25# 26# $(GNUSTEP_INSTANCE)_JAVA_FILES: The list of Java files to compile. 27# These are the files that will be batch-compiled unless 28# xxx_BATCH_COMPILE_JAVA_FILES is set to no, or unless they can't be 29# batch-compiled because each of them uses a different flag. 30# 31# JAVA_OBJ_FILES, JAVA_JNI_OBJ_FILES, SUBPROJECT_OBJ_FILES: the list 32# of object files (built by Instance/rules.make). These are the 33# files that will always be built. If some of the JAVA_OBJ_FILES are 34# not built from xxx_JAVA_FILES but from something else, they'll 35# still be compiled, but one by one - not batched with the 36# xxx_JAVA_FILES. 37# 38# $(GNUSTEP_INSTANCE)_JAVA_PROPERTIES_FILES : the list of .properties files 39# to install together with the .java files 40# 41# BATCH_COMPILE_JAVA_FILES: if this variable is set to 'no', batch compilation 42# of all Java files is disabled. 43# 44# $(GNUSTEP_INSTANCE)_BATCH_COMPILE_JAVA_FILES: if this variable is set to 'no', 45# batch compilation of xxx_JAVA_FILES is disabled and they are compiled one by one. 46# Else, it's enabled by default. 47 48# 49# GNUSTEP_SHARED_JAVA_INSTALLATION_DIR : the base directory where to 50# install the files. 51# 52 53# 54# public targets: 55# 56# shared-instance-java-all 57# shared-instance-java-install 58# shared-instance-java-uninstall 59# shared-instance-java-clean 60# 61 62.PHONY: \ 63shared-instance-java-all \ 64shared-instance-java-install \ 65shared-instance-java-install-dirs \ 66shared-instance-java-uninstall \ 67shared-instance-java-jar \ 68shared-instance-java-clean 69 70shared-instance-java-all: $(JAVA_OBJ_FILES) \ 71 $(JAVA_JNI_OBJ_FILES) \ 72 $(SUBPROJECT_OBJ_FILES) 73 74ifeq ($(strip $($(GNUSTEP_INSTANCE)_JAVA_JAR_NAME)),) 75 JAVA_JAR_FILE = $(subst .,-,$(GNUSTEP_INSTANCE)).jar 76else 77 JAVA_JAR_FILE = $($(GNUSTEP_INSTANCE)_JAVA_JAR_NAME).jar 78endif 79 80JAVA_MANIFEST_FILE = $($(GNUSTEP_INSTANCE)_JAVA_MANIFEST_FILE) 81ifeq ($(strip $(JAVA_MANIFEST_FILE)),) 82 JAVA_JAR_FLAGS = cf 83else 84 JAVA_JAR_FLAGS = cmf 85endif 86 87ifeq ($(strip $($(GNUSTEP_INSTANCE)_JAVA_INSTALL_AS_JAR)),yes) 88 JAVA_JAR_INSTALL_DEP = $(JAVA_JAR_FILE) 89else 90 JAVA_JAR_INSTALL_DEP = 91endif 92 93ifeq ($(strip $(as_jar)),yes) 94 JAVA_JAR_INSTALL_DEP = $(JAVA_JAR_FILE) 95else 96 ifeq ($(strip $(as_jar)),no) 97 JAVA_JAR_INSTALL_DEP = 98 endif 99endif 100 101 102# By default, we enable "batch compilation" of Java files. This means 103# that whenever make determines that a Java files needs recompilation, 104# the command that recompiles that files will actually recompile all 105# the files in the batch as well - causing make to then skip all 106# subsequent rebuilding - which is much more efficient. 107# 108# You can turn this off by setting 109# 110# xxx_BATCH_COMPILE_JAVA_FILES = no 111# 112# and this will cause all files to be always compiled one by one. 113ifeq ($(BATCH_COMPILE_JAVA_FILES),) 114 BATCH_COMPILE_JAVA_FILES = $($(GNUSTEP_INSTANCE)_BATCH_COMPILE_JAVA_FILES) 115endif 116 117# First set it to an empty string, which disables batch compilation. 118JAVA_FILES_TO_BATCH_COMPILE = 119 120ifneq ($(BATCH_COMPILE_JAVA_FILES), no) 121 # We can only batch compile the files if they all have the same flags. 122 # So, if any file has a non-empty xxx_FILE_FILTER_OUT_FLAGS or 123 # xxx_FILE_FLAGS set, we disable batch compilation. 124 # 125 # PS: Here it would be nicer if we could not disable it completely, 126 # but only batch compile the files that require no special flags. 127 128 ifeq ($(strip $(foreach f,$($(GNUSTEP_INSTANCE)_JAVA_FILES),$($(f)_FILE_FILTER_OUT_FLAGS))$(foreach f,$($(GNUSTEP_INSTANCE)_JAVA_FILES),$($(f)_FILE_FLAGS))),) 129 # OK - batch compilation is enabled, and all files have the same compilation flags, so turn it on :-) 130 # By default, batch compile all xxx_JAVA_FILES. 131 JAVA_FILES_TO_BATCH_COMPILE = $($(GNUSTEP_INSTANCE)_JAVA_FILES) 132 endif 133endif 134 135# Say that you have a Pisa.java source file. Here we install both 136# Pisa.class (the main class) and also, if they exist, all class files 137# with names beginning wih Pisa$ (such as Pisa$1$Nicola.class); these 138# files are generated for nested/inner classes, and must be installed 139# as well. The fact we need to install these files is the reason why 140# the following is more complicated than you would think at first 141# glance. 142 143# Build efficiently the list of possible inner/nested classes 144 145# We first build a list like in `Pisa[$]*.class Roma[$]*.class' by 146# taking the JAVA_OBJ_FILES and replacing .class with [$]*.class, then 147# we use wildcard to get the list of all files matching the pattern 148UNESCAPED_ADD_JAVA_OBJ_FILES = $(wildcard $(JAVA_OBJ_FILES:.class=[$$]*.class)) 149 150# Finally we need to escape the $s before passing the filenames to the 151# shell 152ADDITIONAL_JAVA_OBJ_FILES = $(subst $$,\$$,$(UNESCAPED_ADD_JAVA_OBJ_FILES)) 153 154JAVA_PROPERTIES_FILES = $($(GNUSTEP_INSTANCE)_JAVA_PROPERTIES_FILES) 155 156 157$(JAVA_JAR_FILE): $(JAVA_MANIFEST_FILE) \ 158 $(JAVA_OBJ_FILES) \ 159 $(ADDITIONAL_JAVA_OBJ_FILES) \ 160 $(JAVA_PROPERTIES_FILES) 161 $(ECHO_CREATING_JAR_FILE)$(JAR) $(JAVA_JAR_FLAGS) $(JAVA_MANIFEST_FILE) \ 162 $(JAVA_JAR_FILE) $(subst $$,\$$,$(filter-out $(JAVA_MANIFEST_FILE),$^));\ 163 $(END_ECHO) 164 165shared-instance-java-jar: $(JAVA_JAR_FILE) 166 167shared-instance-java-install: shared-instance-java-install-dirs $(JAVA_JAR_INSTALL_DEP) 168ifneq ($(strip $(JAVA_JAR_INSTALL_DEP)),) 169 $(ECHO_NOTHING) $(INSTALL_DATA) $(JAVA_JAR_INSTALL_DEP) $(JAVA_INSTALL_DIR)/$(JAVA_JAR_INSTALL_DEP) \ 170 $(END_ECHO) 171else 172ifneq ($(JAVA_OBJ_FILES),) 173 $(ECHO_INSTALLING_CLASS_FILES)for file in $(JAVA_OBJ_FILES) __done; do \ 174 if [ $$file != __done ]; then \ 175 $(INSTALL_DATA) $$file \ 176 $(GNUSTEP_SHARED_JAVA_INSTALLATION_DIR)/$$file ; \ 177 fi; \ 178 done$(END_ECHO) 179endif 180ifneq ($(ADDITIONAL_JAVA_OBJ_FILES),) 181 $(ECHO_INSTALLING_ADD_CLASS_FILES)for file in $(ADDITIONAL_JAVA_OBJ_FILES) __done; do \ 182 if [ $$file != __done ]; then \ 183 $(INSTALL_DATA) $$file \ 184 $(GNUSTEP_SHARED_JAVA_INSTALLATION_DIR)/$$file ; \ 185 fi; \ 186 done$(END_ECHO) 187endif 188ifneq ($(JAVA_PROPERTIES_FILES),) 189 $(ECHO_INSTALLING_PROPERTIES_FILES)for file in $(JAVA_PROPERTIES_FILES) __done; do \ 190 if [ $$file != __done ]; then \ 191 $(INSTALL_DATA) $$file \ 192 $(GNUSTEP_SHARED_JAVA_INSTALLATION_DIR)/$$file ; \ 193 fi; \ 194 done$(END_ECHO) 195endif 196endif 197shared-instance-java-install-dirs: $(GNUSTEP_SHARED_JAVA_INSTALLATION_DIR) 198ifneq ($(JAVA_OBJ_FILES),) 199 $(ECHO_NOTHING)$(MKINSTALLDIRS) \ 200 $(addprefix $(GNUSTEP_SHARED_JAVA_INSTALLATION_DIR)/,$(dir $(JAVA_OBJ_FILES)))$(END_ECHO) 201endif 202 203$(GNUSTEP_SHARED_JAVA_INSTALLATION_DIR): 204 $(ECHO_CREATING)$(MKINSTALLDIRS) $@$(END_ECHO) 205 206shared-instance-java-clean: 207 $(ECHO_NOTHING)rm -f $(JAVA_OBJ_FILES) \ 208 $(ADDITIONAL_JAVA_OBJ_FILES) \ 209 $(JAVA_JAR_FILE) \ 210 $(JAVA_JNI_OBJ_FILES)$(END_ECHO) 211 212shared-instance-java-uninstall: 213ifneq ($(strip $(JAVA_JAR_INSTALL_DEP)),) 214 $(ECHO_NOTHING) rm -f $(JAVA_INSTALL_DIR)/$(JAVA_JAR_INSTALL_DEP) \ 215 $(END_ECHO) 216else 217ifneq ($(JAVA_OBJ_FILES),) 218 $(ECHO_NOTHING)for file in $(JAVA_OBJ_FILES) __done; do \ 219 if [ $$file != __done ]; then \ 220 rm -f $(GNUSTEP_SHARED_JAVA_INSTALLATION_DIR)/$$file ; \ 221 fi; \ 222 done$(END_ECHO) 223endif 224ifneq ($(ADDITIONAL_JAVA_OBJ_FILES),) 225 $(ECHO_NOTHING)for file in $(ADDITIONAL_JAVA_OBJ_FILES) __done; do \ 226 if [ $$file != __done ]; then \ 227 rm -f $(GNUSTEP_SHARED_JAVA_INSTALLATION_DIR)/$$file ; \ 228 fi; \ 229 done$(END_ECHO) 230endif 231ifneq ($(JAVA_PROPERTIES_FILES),) 232 $(ECHO_NOTHING)for file in $(JAVA_PROPERTIES_FILES) __done; do \ 233 if [ $$file != __done ]; then \ 234 rm -f $(GNUSTEP_SHARED_JAVA_INSTALLATION_DIR)/$$file ; \ 235 fi; \ 236 done$(END_ECHO) 237endif 238endif 239