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_JARCOMMAND
:= jar
24 gb_Jar_LAYER_DIRS
:= \
25 URE
:$(INSTROOT
)/$(LIBO_URE_SHARE_JAVA_FOLDER
) \
26 OOO
:$(INSTROOT
)/$(LIBO_SHARE_JAVA_FOLDER
) \
31 # location of files going to be packed into .jar file
32 define gb_Jar_get_workdir
33 $(call gb_JavaClassSet_get_classdir
,$(call gb_Jar_get_classsetname
,$(1)))
36 # location of manifest file in workdir
37 define gb_Jar_get_manifest_target
38 $(call gb_Jar_get_workdir
,$(1))/META-INF
/MANIFEST.MF
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_install_target
= $(call gb_Jar__get_dir_for_layer
,$(call gb_Jar__get_layer
,$(1)))/$(1).jar
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
,$(1),$(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
),$(SRCDIR
)/solenv
/bin
/write_classpath.sh
"$(call gb_Jar_get_manifest_target,$(1))" $(strip $(JARCLASSPATH
)) &&) \
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 .PHONY
: $(call gb_Jar_get_clean_target
,%)
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
,$*))
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 $(WORKDIR
)/Jar
/%.jar
:
82 $(call gb_Jar__command
,$*,$@
)
84 # call gb_Jar__make_installed_rule,jar
85 define gb_Jar__make_installed_rule
86 $(call gb_Jar_get_target
,$(1)) :
87 $$(call gb_Jar__command
,$(1),$(call gb_Jar_get_target
,$(1)))
91 # resets scoped variables (see explanations where they are set)
92 # creates a class set and a dependency to it
93 # registers target and clean target
94 # adds jar files to DeliverLogTarget
96 ifeq (,$$(findstring $(1),$$(gb_Jar_KNOWN
)))
97 $$(eval
$$(call gb_Output_info
,Currently known jars are
: $(sort $(gb_Jar_KNOWN
)),ALL
))
98 $$(eval
$$(call gb_Output_error
,Jar
$(1) must be registered in Repository.mk or RepositoryExternal.mk
))
100 $(call gb_Jar_get_target
,$(1)) : MANIFEST
:=
101 $(call gb_Jar_get_target
,$(1)) : JARCLASSPATH
:=
102 $(call gb_Jar_get_target
,$(1)) : PACKAGEROOTS
:=
103 $(call gb_Jar_get_target
,$(1)) : PACKAGEDIRS
:=
104 $(call gb_Jar_get_target
,$(1)) : PACKAGEFILES
:=
105 $(call gb_Jar_get_target
,$(1)) : \
106 $(call gb_JavaClassSet_get_target
,$(call gb_Jar_get_classsetname
,$(1)))
107 $(call gb_JavaClassSet_JavaClassSet
,$(call gb_Jar_get_classsetname
,$(1)))
108 $(eval
$(call gb_Module_register_target
,Jar_
$(1),$(call gb_Jar_get_target
,$(1)),$(call gb_Jar_get_clean_target
,$(1))))
109 $(call gb_Helper_make_userfriendly_targets
,$(1),Jar
,$(call gb_Jar_get_target
,$(1)))
111 # installed jars need a rule to build!
112 $(if
$(findstring $(INSTDIR
),$(call gb_Jar_get_target
,$(1))),$(call gb_Jar__make_installed_rule
,$(1)))
116 # source files are forwarded to the ClassSet
117 define gb_Jar_add_sourcefile
118 $(call gb_JavaClassSet_add_sourcefile
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
122 # 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)
123 define gb_Jar_set_packageroot
124 $(call gb_Jar_get_target
,$(1)) : PACKAGEROOTS
:= $(2)
128 # PACKAGEDIRS is the list of additional root directories to pack into the jar
129 define gb_Jar_add_packagedir
130 $(call gb_Jar_get_target
,$(1)) : PACKAGEDIRS
+= $(2)
134 define gb_Jar_add_packagedirs
135 $(foreach packagedir
,$(2),$(call gb_Jar_add_packagedir
,$(1),$(packagedir
)))
139 # PACKAGEFILES is the list of all root files to pack into the jar
140 define gb_Jar_add_packagefile
141 $(call gb_Jar_get_target
,$(1)) : PACKAGEFILES
+= $(2)
142 $(call gb_Jar_get_target
,$(1)) : $(call gb_Jar_get_workdir
,$(1))/$(strip $(2))
143 $(call gb_Jar_get_workdir
,$(1))/$(strip $(2)) : $(3) $(call gb_JavaClassSet_get_target
,$(call gb_Jar_get_classsetname
,$(1)))
149 # gb_Jar_add_packagefiles jar target-dir file(s)
150 define gb_Jar_add_packagefiles
151 $(foreach file
,$(3),$(call gb_Jar_add_packagefile
,$(1),$(if
$(strip $(2)),$(strip $(2))/)$(notdir $(file
)),$(file
)))
155 define gb_Jar_add_sourcefiles
156 $(foreach sourcefile
,$(2),$(call gb_Jar_add_sourcefile
,$(1),$(sourcefile
)))
160 define gb_Jar_add_generated_sourcefile
161 $(call gb_JavaClassSet_add_generated_sourcefile
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
165 define gb_Jar_add_generated_sourcefiles
166 $(foreach sourcefile
,$(2),$(call gb_Jar_add_generated_sourcefile
,$(1),$(sourcefile
)))
170 # JARCLASSPATH is the class path that is written to the manifest of the jar
171 define gb_Jar_add_manifest_classpath
172 $(call gb_Jar_get_target
,$(1)) : JARCLASSPATH
+= $(2)
176 # provide a manifest template containing jar specific information to be written into the manifest
177 # it will be appended to the standard content that is written in the build command explicitly
178 # the jar file gets a dependency to the manifest template
179 define gb_Jar_set_manifest
180 $(call gb_Jar_get_target
,$(1)) : MANIFEST
:= $(2)
181 $(call gb_Jar_get_target
,$(1)) : $(2)
185 # URE jars are not added to manifest classpath; and neither is unoil.jar, which
186 # is available at runtime via URE_MORE_JAVA_TYPES:
187 gb_Jar_default_jars
:= $(gb_Jar_URE
) unoil
189 # remember: classpath is "inherited" to ClassSet
190 define gb_Jar_use_jar
191 $(call gb_JavaClassSet_use_jar
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
192 $(if
$(filter-out $(gb_Jar_default_jars
),$(2)),\
193 $(call gb_Jar_add_manifest_classpath
,$(1),$(2).jar
))
197 define gb_Jar_use_system_jar
198 $(call gb_JavaClassSet_use_system_jar
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
199 $(call gb_Jar_add_manifest_classpath
,$(1),$(call gb_Helper_make_url
,$(2)))
203 # call gb_Jar_use_external_jar,jar,externaljarfullpath,manifestentry
204 define gb_Jar_use_external_jar
205 $(if
$(3),,$(call gb_Output_error
,gb_Jar_use_external_jar
: manifest entry missing
))
206 $(call gb_JavaClassSet_use_system_jar
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
207 $(call gb_Jar_add_manifest_classpath
,$(1),$(3))
211 # specify jars with imported modules
212 define gb_Jar_use_jars
213 $(foreach jar
,$(2),$(call gb_Jar_use_jar
,$(1),$(jar
)))
217 define gb_Jar_use_system_jars
218 $(foreach jar
,$(2),$(call gb_Jar_use_system_jar
,$(1),$(jar
)))
222 # this forwards to functions that must be defined in RepositoryExternal.mk.
223 # $(eval $(call gb_Jar_use_external,jar,external))
224 define gb_Jar_use_external
225 $(if
$(value gb_Jar__use_
$(2)),\
226 $(call gb_Jar__use_
$(2),$(1)),\
227 $(error gb_Jar_use_external
: unknown external
: $(2)))
231 define gb_Jar_use_externals
232 $(foreach external
,$(2),$(call gb_Jar_use_external
,$(1),$(external
)))
236 define gb_Jar_use_customtarget
237 $(call gb_JavaClassSet_use_customtarget
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
241 define gb_Jar_use_customtargets
242 $(foreach customtarget
,$(2),$(call gb_Jar_use_customtarget
,$(1),$(customtarget
)))
246 # Add a dependency on an ExternalProject.
248 # call gb_Jar_use_external_project,jar,externalproject
249 define gb_Jar_use_external_project
250 $(call gb_JavaClassSet_use_external_project
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
253 # possible directories for jar files containing UNO services
254 gb_Jar_COMPONENTPREFIXES
:= \
255 OOO
:vnd.sun.star.expand
:\dLO_JAVA_DIR
/ \
256 URE
:vnd.sun.star.expand
:\dURE_INTERNAL_JAVA_DIR
/ \
258 NONE
:$(call gb_Helper_make_url
,$(WORKDIR
)/Jar
/) \
260 # get component prefix from layer name ("OOO", "URE", "OXT", "NONE")
261 gb_Jar__get_componentprefix
= \
262 $(patsubst $(1):%,%,$(or \
263 $(filter $(1):%,$(gb_Jar_COMPONENTPREFIXES
)), \
264 $(call gb_Output_error
,no ComponentTarget native
prefix for layer
'$(1)')))
266 # layer must be specified explicitly in this macro (different to libraries)
267 define gb_Jar_set_componentfile
268 $(call gb_ComponentTarget_ComponentTarget
,$(2),$(call gb_Jar__get_componentprefix
,$(3)),$(notdir $(call gb_Jar_get_target
,$(1))))
269 $(call gb_Jar_get_target
,$(1)) : $(call gb_ComponentTarget_get_target
,$(2))
270 $(call gb_Jar_get_clean_target
,$(1)) : $(call gb_ComponentTarget_get_clean_target
,$(2))
274 # vim: set noet sw=4 ts=4: