1 # -*- Mode: makefile-gmake; tab-width: 4; indent-tabs-mode: t -*-
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 # This file incorporates work covered by the following license notice:
11 # Licensed to the Apache Software Foundation (ASF) under one or more
12 # contributor license agreements. See the NOTICE file distributed
13 # with this work for additional information regarding copyright
14 # ownership. The ASF licenses this file to you under the Apache
15 # License, Version 2.0 (the "License"); you may not use this file
16 # except in compliance with the License. You may obtain a copy of
17 # the License at http://www.apache.org/licenses/LICENSE-2.0 .
22 gb_Jar_JAVACOMMAND
:= $(JAVAINTERPRETER
)
23 gb_Jar_JARCOMMAND
:= jar
25 gb_Jar_LAYER_DIRS
:= \
29 # location of files going to be packed into .jar file
30 define gb_Jar_get_workdir
31 $(call gb_JavaClassSet_get_classdir
,$(call gb_Jar_get_classsetname
,$(1)))
34 # location of manifest file in workdir
35 define gb_Jar_get_manifest_target
36 $(call gb_Jar_get_workdir
,$(1))/META-INF
/MANIFEST.MF
39 gb_Jar_get_packagename
= Jar
/$(1)
41 gb_Jar__get_layer
= $(strip $(foreach group
,$(gb_Jar_VALIDGROUPS
),$(if
$(filter $(1),$(gb_Jar_
$(group
))),$(group
))))
42 gb_Jar__get_dir_for_layer
= $(patsubst $(1):%,%,$(filter $(1):%,$(gb_Jar_LAYER_DIRS
)))
43 gb_Jar__get_instdir
= $(call gb_Jar__get_dir_for_layer
,$(call gb_Jar__get_layer
,$(1)))
45 # creates classset and META-INF folders if they don't exist
46 # adds manifest version, class path, solarversion and content from sources to manifest file
47 # creates the target folder of the jar file if it doesn't exist
48 # creates the jar file
49 # jar program does not remove the target in case of error, so rm it manually
50 # XXX: PACKAGEDIRS need special treatment, because sometimes we need to
51 # add into the jar another class hierarchy created outside of our class
52 # set (e.g., by javamaker). Because jar does not allow two same root dirs
53 # when creating the archive, we work around this deficiency by creating
54 # the archive with the main class hierarchy and then updating it from
55 # the other one(s), which seems to work .-)
56 define gb_Jar__command
57 $(call gb_Output_announce
,$*,$(true
),JAR
,3)
58 $(call gb_Helper_abbreviate_dirs
,\
59 mkdir
-p
$(call gb_Jar_get_workdir
,$(1))/META-INF
&& \
60 echo Manifest-Version
: 1.0 > $(call gb_Jar_get_manifest_target
,$(1)) && \
61 $(if
$(JARCLASSPATH
),echo
"Class-Path: $(strip $(JARCLASSPATH))" >> $(call gb_Jar_get_manifest_target
,$(1)) &&) \
62 echo
"Solar-Version: $(LIBO_VERSION_MAJOR).$(LIBO_VERSION_MINOR).$(LIBO_VERSION_MICRO).$(LIBO_VERSION_PATCH)" >> $(call gb_Jar_get_manifest_target
,$(1)) && \
63 $(if
$(MANIFEST
),cat
$(MANIFEST
) >> $(call gb_Jar_get_manifest_target
,$(1)) &&) \
64 mkdir
-p
$(dir $(2)) && cd
$(call gb_Jar_get_workdir
,$(1)) && \
65 $(gb_Jar_JARCOMMAND
) cfm
$(2) $(call gb_Jar_get_manifest_target
,$(1)) \
66 META-INF
$(PACKAGEROOTS
) $(PACKAGEFILES
) \
67 $(foreach root
,$(PACKAGEDIRS
),&& cd
$(dir $(root
)) && $(gb_Jar_JARCOMMAND
) uf
$(2) $(notdir $(root
))) \
71 # clean target reuses clean target of ClassSet
72 $(call gb_Jar_get_clean_target
,%) : $(call gb_JavaClassSet_get_clean_target
,$(call gb_Jar_get_classsetname
,%))
73 $(call gb_Output_announce
,$*,$(false
),JAR
,3)
74 $(call gb_Helper_abbreviate_dirs
,\
75 rm -f
$(call gb_Jar_get_target
,$*) $(call gb_Jar_get_outdir_target
,$*))
77 # the outdir target depends on the workdir target and is built by delivering the latter
78 # the workdir target is created by cd'ing to the target directory and adding/updating the files
80 # rule for creating the jar file using the command defined above
81 $(call gb_Jar_get_target
,%) : $(call gb_JavaClassSet_get_target
,$(call gb_Jar_get_classsetname
,%))
82 $(call gb_Jar__command
,$*,$@
,$*,$?
)
84 # resets scoped variables (see explanations where they are set)
85 # creates a class set and a dependency to it
86 # registers target and clean target
87 # adds jar files to DeliverLogTarget
88 # adds dependency for outdir target to workdir target (pattern rule for delivery is in Package.mk)
90 ifeq (,$$(findstring $(1),$$(gb_Jar_KNOWN
)))
91 $$(eval
$$(call gb_Output_info
,Currently known jars are
: $(sort $(gb_Jar_KNOWN
)),ALL
))
92 $$(eval
$$(call gb_Output_error
,Jar
$(1) must be registered in Repository.mk
))
94 $(call gb_Jar_get_target
,$(1)) : MANIFEST
:=
95 $(call gb_Jar_get_target
,$(1)) : JARCLASSPATH
:=
96 $(call gb_Jar_get_target
,$(1)) : PACKAGEROOTS
:=
97 $(call gb_Jar_get_target
,$(1)) : PACKAGEDIRS
:=
98 $(call gb_Jar_get_target
,$(1)) : PACKAGEFILES
:=
99 $(call gb_JavaClassSet_JavaClassSet
,$(call gb_Jar_get_classsetname
,$(1)))
100 $(eval
$(call gb_Module_register_target
,$(call gb_Jar_get_outdir_target
,$(1)),$(call gb_Jar_get_clean_target
,$(1))))
101 $(call gb_Helper_make_userfriendly_targets
,$(1),Jar
,$(call gb_Jar_get_outdir_target
,$(1)))
102 $(call gb_Deliver_add_deliverable
,$(call gb_Jar_get_outdir_target
,$(1)),$(call gb_Jar_get_target
,$(1)),$(1))
103 $(call gb_Jar_get_outdir_target
,$(1)) : $(call gb_Jar_get_target
,$(1))
104 $(call gb_Jar_get_outdir_target
,$(1)) :|
$(dir $(call gb_Jar_get_outdir_target
,$(1))).
dir
106 ifneq ($(gb_RUNNABLE_INSTDIR
),)
107 $(if
$(filter OOO URE
,$(call gb_Jar__get_layer
,$(1))),\
108 $(call gb_Jar__Jar_package
,$(1),$(call gb_Jar_get_packagename
,$(1)),$(notdir $(call gb_Jar_get_target
,$(1)))) \
114 # gb_Jar__Jar_package jar package filename
115 define gb_Jar__Jar_package
116 $(call gb_Package_Package_internal
,$(2),$(WORKDIR
)/Jar
)
117 $(call gb_Package_set_outdir
,$(2),$(INSTDIR
))
118 $(call gb_Package_add_file
,$(2),$(call gb_Jar__get_instdir
,$(1))/$(3),$(3))
120 $(call gb_Package_get_target
,$(2)) : $(call gb_Jar_get_target
,$(1))
121 $(call gb_Jar_get_outdir_target
,$(1)) : $(call gb_Package_get_target
,$(2))
122 $(call gb_Jar_get_clean_target
,$(1)) : $(call gb_Package_get_clean_target
,$(2))
126 # source files are forwarded to the ClassSet
127 define gb_Jar_add_sourcefile
128 $(call gb_JavaClassSet_add_sourcefile
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
132 # 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)
133 define gb_Jar_set_packageroot
134 $(call gb_Jar_get_target
,$(1)) : PACKAGEROOTS
:= $(2)
138 # PACKAGEDIRS is the list of additional root directories to pack into the jar
139 define gb_Jar_add_packagedir
140 $(call gb_Jar_get_target
,$(1)) : PACKAGEDIRS
+= $(2)
144 define gb_Jar_add_packagedirs
145 $(foreach packagedir
,$(2),$(call gb_Jar_add_packagedir
,$(1),$(packagedir
)))
149 # PACKAGEFILES is the list of all root files to pack into the jar
150 define gb_Jar_add_packagefile
151 $(call gb_Jar_get_target
,$(1)) : PACKAGEFILES
+= $(2)
152 $(call gb_Jar_get_target
,$(1)) : $(call gb_Jar_get_workdir
,$(1))/$(strip $(2))
153 $(call gb_Jar_get_workdir
,$(1))/$(strip $(2)) : $(3) $(call gb_JavaClassSet_get_target
,$(call gb_Jar_get_classsetname
,$(1)))
159 # gb_Jar_add_packagefiles jar target-dir file(s)
160 define gb_Jar_add_packagefiles
161 $(foreach file
,$(3),$(call gb_Jar_add_packagefile
,$(1),$(if
$(strip $(2)),$(strip $(2))/)$(notdir $(file
)),$(file
)))
165 define gb_Jar_add_sourcefiles
166 $(foreach sourcefile
,$(2),$(call gb_Jar_add_sourcefile
,$(1),$(sourcefile
)))
170 define gb_Jar_add_generated_sourcefile
171 $(call gb_JavaClassSet_add_generated_sourcefile
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
175 define gb_Jar_add_generated_sourcefiles
176 $(foreach sourcefile
,$(2),$(call gb_Jar_add_generated_sourcefile
,$(1),$(sourcefile
)))
180 define gb_JarTest_set_classpath
181 $$(call gb_Output_error
,\
182 gb_JarTest_set_classpath
: use gb_JavaClassSet_add_classpath instead.
)
185 # JARCLASSPATH is the class path that is written to the manifest of the jar
186 define gb_Jar_set_jarclasspath
187 $$(call gb_Output_error
,\
188 gb_Jar_set_jarclasspath
: use gb_Jar_add_manifest_classpath instead.
)
192 define gb_Jar_add_manifest_classpath
193 $(call gb_Jar_get_target
,$(1)) : JARCLASSPATH
+= $(2)
197 # provide a manifest template containing jar specific information to be written into the manifest
198 # it will be appended to the standard content that is written in the build command explicitly
199 # the jar file gets a dependency to the manifest template
200 define gb_Jar_set_manifest
201 $(call gb_Jar_get_target
,$(1)) : MANIFEST
:= $(2)
202 $(call gb_Jar_get_target
,$(1)) : $(2)
206 define gb_Jar_add_jar
207 $$(call gb_Output_error
,\
208 gb_Jar_add_jar
: use gb_Jar_use_jar instead.
)
211 # URE jars are not added to manifest classpath; and neither is unoil.jar, which
212 # is available at runtime via URE_MORE_JAVA_TYPES:
213 gb_Jar_default_jars
:= $(gb_Jar_URE
) unoil
215 # remember: classpath is "inherited" to ClassSet
216 define gb_Jar_use_jar
217 $(call gb_JavaClassSet_use_jar
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
218 $(if
$(filter-out $(gb_Jar_default_jars
),$(2)),\
219 $(call gb_Jar_add_manifest_classpath
,$(1),$(2).jar
))
223 define gb_Jar_add_system_jar
224 $$(call gb_Output_error
,\
225 gb_Jar_add_system_jar
: use gb_Jar_use_system_jar instead.
)
228 define gb_Jar_use_system_jar
229 $(call gb_JavaClassSet_use_system_jar
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
230 $(call gb_Jar_add_manifest_classpath
,$(1),$(call gb_Helper_make_url
,$(2)))
234 define gb_Jar_add_jars
235 $$(call gb_Output_error
,\
236 gb_Jar_add_jars
: use gb_Jar_use_jars instead.
)
239 # specify jars with imported modules
240 define gb_Jar_use_jars
241 $(foreach jar
,$(2),$(call gb_Jar_use_jar
,$(1),$(jar
)))
245 define gb_Jar_add_system_jars
246 $$(call gb_Output_error
,\
247 gb_Jar_add_system_jars
: use gb_Jar_use_system_jars instead.
)
250 define gb_Jar_use_system_jars
251 $(foreach jar
,$(2),$(call gb_Jar_use_system_jar
,$(1),$(jar
)))
255 # this forwards to functions that must be defined in RepositoryExternal.mk.
256 # $(eval $(call gb_Jar_use_external,jar,external))
257 define gb_Jar_use_external
258 $(if
$(value gb_Jar__use_
$(2)),\
259 $(call gb_Jar__use_
$(2),$(1)),\
260 $(error gb_Jar_use_external
: unknown external
: $(2)))
264 define gb_Jar_use_externals
265 $(foreach external
,$(2),$(call gb_Jar_use_external
,$(1),$(external
)))
269 define gb_Jar_add_customtarget_dependency
270 $$(call gb_Output_error
,\
271 gb_Jar_add_customtarget_dependency
: use gb_Jar_use_customtarget instead.
)
274 define gb_Jar_use_customtarget
275 $(call gb_JavaClassSet_use_customtarget
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
279 define gb_Jar_add_customtarget_dependencies
280 $$(call gb_Output_error
,\
281 gb_Jar_add_customtarget_dependencies
: use gb_Jar_use_customtargets instead.
)
284 define gb_Jar_use_customtargets
285 $(foreach customtarget
,$(2),$(call gb_Jar_use_customtarget
,$(1),$(customtarget
)))
289 # possible directories for jar files containing UNO services
290 gb_Jar_COMPONENTPREFIXES
:= \
291 OOO
:vnd.sun.star.expand
:\dLO_JAVA_DIR
/ \
292 URE
:vnd.sun.star.expand
:\dURE_INTERNAL_JAVA_DIR
/ \
295 # get component prefix from layer name ("OOO", "URE", "OXT", "INTERN")
296 gb_Jar__get_componentprefix
= \
297 $(patsubst $(1):%,%,$(or \
298 $(filter $(1):%,$(gb_Jar_COMPONENTPREFIXES
)), \
299 $(call gb_Output_error
,no ComponentTarget native
prefix for layer
'$(1)')))
301 # layer must be specified explicitly in this macro (different to libraries)
302 define gb_Jar_set_componentfile
303 $(call gb_ComponentTarget_ComponentTarget
,$(2),$(call gb_Jar__get_componentprefix
,$(3)),$(notdir $(call gb_Jar_get_target
,$(1))))
304 $(call gb_Jar_get_target
,$(1)) : \
305 $(call gb_ComponentTarget_get_outdir_target
,$(2))
306 $(call gb_Jar_get_clean_target
,$(1)) : $(call gb_ComponentTarget_get_clean_target
,$(2))
310 # vim: set noet sw=4 ts=4: