Bump for 3.6-28
[LibreOffice.git] / solenv / gbuild / Jar.mk
blobb85681b4dcb5e8ce8e33a06aaf1a3c56e4a9cd16
1 # -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
2 #*************************************************************************
4 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 #
6 # Copyright 2000, 2011 Oracle and/or its affiliates.
8 # OpenOffice.org - a multi-platform office productivity suite
10 # This file is part of OpenOffice.org.
12 # OpenOffice.org is free software: you can redistribute it and/or modify
13 # it under the terms of the GNU Lesser General Public License version 3
14 # only, as published by the Free Software Foundation.
16 # OpenOffice.org is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU Lesser General Public License version 3 for more details
20 # (a copy is included in the LICENSE file that accompanied this code).
22 # You should have received a copy of the GNU Lesser General Public License
23 # version 3 along with OpenOffice.org. If not, see
24 # <http://www.openoffice.org/license.html>
25 # for a copy of the LGPLv3 License.
27 #*************************************************************************
29 # if a jar prerequisite has changed, the ClassSet must be recompiled. How?
31 # Jar class
33 gb_Jar_JAVACOMMAND := $(JAVAINTERPRETER)
34 gb_Jar_JARCOMMAND := jar
36 # location of files going to be packed into .jar file
37 define gb_Jar_get_workdir
38 $(call gb_JavaClassSet_get_classdir,$(call gb_Jar_get_classsetname,$(1)))
39 endef
41 # location of manifest file in workdir
42 define gb_Jar_get_manifest_target
43 $(call gb_Jar_get_workdir,$(1))/META-INF/MANIFEST.MF
44 endef
46 # creates classset and META-INF folders if they don't exist
47 # adds manifest version, class path, solarversion and content from sources to manifest file
48 # creates the target folder of the jar file if it doesn't exist
49 # creates the jar file
50 # jar program does not remove the target in case of error, so rm it manually
51 # XXX: PACKAGEDIRS need special treatment, because sometimes we need to
52 # add into the jar another class hierarchy created outside of our class
53 # set (e.g., by javamaker). Because jar does not allow two same root dirs
54 # when creating the archive, we work around this deficiency by creating
55 # the archive with the main class hierarchy and then updating it from
56 # the other one(s), which seems to work .-)
57 define gb_Jar__command
58 $(call gb_Output_announce,$*,$(true),JAR,3)
59 $(call gb_Helper_abbreviate_dirs,\
60 mkdir -p $(call gb_Jar_get_workdir,$(1))/META-INF && \
61 echo Manifest-Version: 1.0 > $(call gb_Jar_get_manifest_target,$(1)) && \
62 $(if $(JARCLASSPATH),echo "Class-Path: $(strip $(JARCLASSPATH))" >> $(call gb_Jar_get_manifest_target,$(1)) &&) \
63 echo "Solar-Version: $(RSCREVISION)" >> $(call gb_Jar_get_manifest_target,$(1)) && \
64 cat $(if $(MANIFEST),$(MANIFEST),$(gb_Helper_MISCDUMMY)) >> $(call gb_Jar_get_manifest_target,$(1)) && \
65 mkdir -p $(dir $(2)) && cd $(call gb_Jar_get_workdir,$(1)) && \
66 $(gb_Jar_JARCOMMAND) cfm $(2) $(call gb_Jar_get_manifest_target,$(1)) \
67 META-INF $(PACKAGEROOTS) $(PACKAGEFILES) \
68 $(foreach root,$(PACKAGEDIRS),&& cd $(dir $(root)) && $(gb_Jar_JARCOMMAND) uf $(2) $(notdir $(root))) \
69 || (rm $(2); false) )
70 endef
72 # clean target reuses clean target of ClassSet
73 $(call gb_Jar_get_clean_target,%) : $(call gb_JavaClassSet_get_clean_target,$(call gb_Jar_get_classsetname,%))
74 $(call gb_Output_announce,$*,$(false),JAR,3)
75 $(call gb_Helper_abbreviate_dirs,\
76 rm -f $(call gb_Jar_get_target,$*) $(call gb_Jar_get_outdir_target,$*))
78 # the outdir target depends on the workdir target and is built by delivering the latter
79 # the workdir target is created by cd'ing to the target directory and adding/updating the files
81 # rule for creating the jar file using the command defined above
82 $(call gb_Jar_get_target,%) : $(call gb_JavaClassSet_get_target,$(call gb_Jar_get_classsetname,%))
83 $(call gb_Jar__command,$*,$@,$*,$?)
85 # resets scoped variables (see explanations where they are set)
86 # creates a class set and a dependency to it
87 # registers target and clean target
88 # adds jar files to DeliverLogTarget
89 # adds dependency for outdir target to workdir target (pattern rule for delivery is in Package.mk)
90 define gb_Jar_Jar
91 $(call gb_Jar_get_target,$(1)) : MANIFEST :=
92 $(call gb_Jar_get_target,$(1)) : JARCLASSPATH :=
93 $(call gb_Jar_get_target,$(1)) : PACKAGEROOTS :=
94 $(call gb_Jar_get_target,$(1)) : PACKAGEDIRS :=
95 $(call gb_Jar_get_target,$(1)) : PACKAGEFILES :=
96 $(call gb_JavaClassSet_JavaClassSet,$(call gb_Jar_get_classsetname,$(1)))
97 $(call gb_JavaClassSet_set_classpath,$(call gb_Jar_get_classsetname,$(1)),$(value XCLASSPATH))
98 $(eval $(call gb_Module_register_target,$(call gb_Jar_get_outdir_target,$(1)),$(call gb_Jar_get_clean_target,$(1))))
99 $(call gb_Deliver_add_deliverable,$(call gb_Jar_get_outdir_target,$(1)),$(call gb_Jar_get_target,$(1)),$(1))
100 $(call gb_Jar_get_outdir_target,$(1)) : $(call gb_Jar_get_target,$(1))
102 endef
104 # source files are forwarded to the ClassSet
105 define gb_Jar_add_sourcefile
106 $(call gb_JavaClassSet_add_sourcefile,$(call gb_Jar_get_classsetname,$(1)),$(2))
108 endef
110 # PACKAGEROOTS is the list of all root folders created by the JavaClassSet to pack into the jar (without META-INF as this is added automatically)
111 define gb_Jar_set_packageroot
112 $(call gb_Jar_get_target,$(1)) : PACKAGEROOTS := $(2)
114 endef
116 # PACKAGEDIRS is the list of additional root directories to pack into the jar
117 define gb_Jar_add_packagedir
118 $(call gb_Jar_get_target,$(1)) : PACKAGEDIRS += $(2)
120 endef
122 define gb_Jar_add_packagedirs
123 $(foreach packagedir,$(2),$(call gb_Jar_add_packagedir,$(1),$(packagedir)))
125 endef
127 # PACKAGEFILES is the list of all root files to pack into the jar
128 define gb_Jar_add_packagefile
129 $(call gb_Jar_get_target,$(1)) : PACKAGEFILES += $(2)
130 $(call gb_Jar_get_target,$(1)) : $(call gb_Jar_get_workdir,$(1))/$(strip $(2))
131 $(call gb_Jar_get_workdir,$(1))/$(strip $(2)) : $(3) $(call gb_JavaClassSet_get_target,$(call gb_Jar_get_classsetname,$(1)))
132 mkdir -p $$(dir $$@)
133 cp -rf $(3) $$@
135 endef
137 # gb_Jar_add_packagefiles jar target-dir file(s)
138 define gb_Jar_add_packagefiles
139 $(foreach file,$(3),$(call gb_Jar_add_packagefile,$(1),$(if $(strip $(2)),$(strip $(2))/)$(notdir $(file)),$(file)))
141 endef
143 define gb_Jar_add_sourcefiles
144 $(foreach sourcefile,$(2),$(call gb_Jar_add_sourcefile,$(1),$(sourcefile)))
146 endef
148 define gb_Jar_add_generated_sourcefile
149 $(call gb_JavaClassSet_add_generated_sourcefile,$(call gb_Jar_get_classsetname,$(1)),$(2))
151 endef
153 define gb_Jar_add_generated_sourcefiles
154 $(foreach sourcefile,$(2),$(call gb_Jar_add_generated_sourcefile,$(1),$(sourcefile)))
156 endef
158 define gb_JarTest_set_classpath
159 $(call gb_JavaClassSet_set_classpath,$(call gb_Jar_get_classsetname,$(1)),$(2))
161 endef
163 # JARCLASSPATH is the class path that is written to the manifest of the jar
164 define gb_Jar_set_jarclasspath
165 $(call gb_Jar_get_target,$(1)) : JARCLASSPATH := $(2)
167 endef
169 # provide a manifest template containing jar specific information to be written into the manifest
170 # it will be appended to the standard content that is written in the build command explicitly
171 # the jar file gets a dependency to the manifest template
172 define gb_Jar_set_manifest
173 $(call gb_Jar_get_target,$(1)) : MANIFEST := $(2)
174 $(call gb_Jar_get_target,$(1)) : $(2)
176 endef
178 define gb_Jar_add_jar
179 $$(call gb_Output_error,\
180 gb_Jar_add_jar: use gb_Jar_use_jar instead.)
181 endef
183 # remember: classpath is "inherited" to ClassSet
184 define gb_Jar_use_jar
185 $(call gb_JavaClassSet_use_jar,$(call gb_Jar_get_classsetname,$(1)),$(2))
187 endef
189 define gb_Jar_add_system_jar
190 $$(call gb_Output_error,\
191 gb_Jar_add_system_jar: use gb_Jar_use_system_jar instead.)
192 endef
194 define gb_Jar_use_system_jar
195 $(call gb_JavaClassSet_use_system_jar,$(call gb_Jar_get_classsetname,$(1)),$(2))
197 endef
199 define gb_Jar_add_jars
200 $$(call gb_Output_error,\
201 gb_Jar_add_jars: use gb_Jar_use_jars instead.)
202 endef
204 # specify jars with imported modules
205 define gb_Jar_use_jars
206 $(call gb_JavaClassSet_use_jars,$(call gb_Jar_get_classsetname,$(1)),$(2))
208 endef
210 define gb_Jar_add_system_jars
211 $$(call gb_Output_error,\
212 gb_Jar_add_system_jars: use gb_Jar_use_system_jars instead.)
213 endef
215 define gb_Jar_use_system_jars
216 $(call gb_JavaClassSet_use_system_jars,$(call gb_Jar_get_classsetname,$(1)),$(2))
218 endef
220 define gb_Jar_use_external
221 $(call gb_JavaClassSet_use_external,$(call gb_Jar_get_classsetname,$(1)),$(2))
223 endef
225 define gb_Jar_use_externals
226 $(call gb_JavaClassSet_use_externals,$(call gb_Jar_get_classsetname,$(1)),$(2))
228 endef
230 define gb_Jar_add_customtarget_dependency
231 $$(call gb_Output_error,\
232 gb_Jar_add_customtarget_dependency: use gb_Jar_use_customtarget instead.)
233 endef
235 define gb_Jar_use_customtarget
236 $(call gb_JavaClassSet_use_customtarget,$(call gb_Jar_get_classsetname,$(1)),$(2))
238 endef
240 define gb_Jar_add_customtarget_dependencies
241 $$(call gb_Output_error,\
242 gb_Jar_add_customtarget_dependencies: use gb_Jar_use_customtargets instead.)
243 endef
245 define gb_Jar_use_customtargets
246 $(foreach customtarget,$(2),$(call gb_Jar_use_customtarget,$(1),$(customtarget)))
248 endef
250 # possible directories for jar files containing UNO services
251 gb_Jar_COMPONENTPREFIXES := \
252 OOO:vnd.sun.star.expand:\dLO_JAVA_DIR/ \
253 URE:vnd.sun.star.expand:\dURE_INTERNAL_JAVA_DIR/ \
254 OXT:./ \
256 # get component prefix from layer name ("OOO", "URE", "OXT", "INTERN")
257 gb_Jar__get_componentprefix = \
258 $(patsubst $(1):%,%,$(or \
259 $(filter $(1):%,$(gb_Jar_COMPONENTPREFIXES)), \
260 $(call gb_Output_error,no ComponentTarget native prefix for layer '$(1)')))
262 # layer must be specified explicitly in this macro (different to libraries)
263 define gb_Jar_set_componentfile
264 $(call gb_ComponentTarget_ComponentTarget,$(2),$(call gb_Jar__get_componentprefix,$(3)),$(notdir $(call gb_Jar_get_target,$(1))))
265 $(call gb_Jar_get_target,$(1)) : \
266 $(call gb_ComponentTarget_get_outdir_target,$(2))
267 $(call gb_Jar_get_clean_target,$(1)) : $(call gb_ComponentTarget_get_clean_target,$(2))
269 endef
271 # vim: set noet sw=4 ts=4: