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_Helper_abbreviate_dirs
,\
58 mkdir
-p
$(call gb_Jar_get_workdir
,$(1))/META-INF
&& \
59 echo Manifest-Version
: 1.0 > $(call gb_Jar_get_manifest_target
,$(1)) && \
60 $(if
$(JARCLASSPATH
),$(SRCDIR
)/solenv
/bin
/write_classpath.sh
"$(call gb_Jar_get_manifest_target,$(1))" $(strip $(JARCLASSPATH
)) &&) \
61 echo
"Solar-Version: $(LIBO_VERSION_MAJOR).$(LIBO_VERSION_MINOR).$(LIBO_VERSION_MICRO).$(LIBO_VERSION_PATCH)" >> $(call gb_Jar_get_manifest_target
,$(1)) && \
62 $(if
$(MANIFEST
),cat
$(MANIFEST
) >> $(call gb_Jar_get_manifest_target
,$(1)) &&) \
63 mkdir
-p
$(dir $(2)) && cd
$(call gb_Jar_get_workdir
,$(1)) && \
64 $(gb_Jar_JARCOMMAND
) cfm
$(2) $(call gb_Jar_get_manifest_target
,$(1)) \
65 META-INF
$(PACKAGEROOTS
) $(PACKAGEFILES
) \
66 $(foreach root
,$(PACKAGEDIRS
),&& cd
$(dir $(root
)) && $(gb_Jar_JARCOMMAND
) uf
$(2) $(notdir $(root
))) \
67 ||
(rm -f
$(2); false
) )
70 # clean target reuses clean target of ClassSet
71 .PHONY
: $(call gb_Jar_get_clean_target
,%)
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
,$*))
77 # the workdir target is created by cd'ing to the target directory and adding/updating the files
79 # rule for creating the jar file using the command defined above
80 $(WORKDIR
)/Jar
/%.jar
:
81 $(call gb_Output_announce
,$*,$(true
),JAR
,3)
82 $(call gb_Trace_StartRange
,$*,JAR
)
83 $(call gb_Jar__command
,$*,$@
)
84 $(call gb_Trace_EndRange
,$*,JAR
)
86 # call gb_Jar__make_installed_rule,jar
87 define gb_Jar__make_installed_rule
88 $(call gb_Jar_get_target
,$(1)) :
89 $$(call gb_Jar__command
,$(1),$(call gb_Jar_get_target
,$(1)))
93 # resets scoped variables (see explanations where they are set)
94 # creates a class set and a dependency to it
95 # registers target and clean target
96 # adds jar files to DeliverLogTarget
97 # call gb_Jar_Jar,jarname,java9modulename
99 ifeq (,$$(findstring $(1),$$(gb_Jar_KNOWN
)))
100 $$(eval
$$(call gb_Output_info
,Currently known jars are
: $(sort $(gb_Jar_KNOWN
)),ALL
))
101 $$(eval
$$(call gb_Output_error
,Jar
$(1) must be registered in Repository.mk or RepositoryExternal.mk
))
103 $(call gb_Jar_get_target
,$(1)) : MANIFEST
:=
104 $(call gb_Jar_get_target
,$(1)) : JARCLASSPATH
:=
105 $(call gb_Jar_get_target
,$(1)) : PACKAGEROOTS
:=
106 $(call gb_Jar_get_target
,$(1)) : PACKAGEDIRS
:=
107 $(call gb_Jar_get_target
,$(1)) : PACKAGEFILES
:=
108 $(call gb_Jar_get_target
,$(1)) : \
109 $(call gb_JavaClassSet_get_target
,$(call gb_Jar_get_classsetname
,$(1)))
110 $(call gb_JavaClassSet_JavaClassSet
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
111 $(eval
$(call gb_Module_register_target
,$(call gb_Jar_get_target
,$(1)),$(call gb_Jar_get_clean_target
,$(1))))
112 $(call gb_Helper_make_userfriendly_targets
,$(1),Jar
,$(call gb_Jar_get_target
,$(1)))
114 # installed jars need a rule to build!
115 $(if
$(findstring $(INSTDIR
),$(call gb_Jar_get_target
,$(1))),$(call gb_Jar__make_installed_rule
,$(1)))
119 # source files are forwarded to the ClassSet
120 define gb_Jar_add_sourcefile
121 $(call gb_JavaClassSet_add_sourcefile
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
125 define gb_Jar_add_sourcefile_java9
126 $(call gb_JavaClassSet_add_sourcefile_java9
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
131 # 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)
132 define gb_Jar_set_packageroot
133 $(call gb_Jar_get_target
,$(1)) : PACKAGEROOTS
:= $(2)
137 # PACKAGEDIRS is the list of additional root directories to pack into the jar
138 define gb_Jar_add_packagedir
139 $(call gb_Jar_get_target
,$(1)) : PACKAGEDIRS
+= $(2)
143 define gb_Jar_add_packagedirs
144 $(foreach packagedir
,$(2),$(call gb_Jar_add_packagedir
,$(1),$(packagedir
)))
148 # PACKAGEFILES is the list of all root files to pack into the jar
149 define gb_Jar_add_packagefile
150 $(call gb_Jar_get_target
,$(1)) : PACKAGEFILES
+= $(2)
151 $(call gb_Jar_get_target
,$(1)) : $(call gb_Jar_get_workdir
,$(1))/$(strip $(2))
152 $(call gb_Jar_get_workdir
,$(1))/$(strip $(2)) : $(3) $(call gb_JavaClassSet_get_target
,$(call gb_Jar_get_classsetname
,$(1)))
158 # gb_Jar_add_packagefiles jar target-dir file(s)
159 define gb_Jar_add_packagefiles
160 $(foreach file
,$(3),$(call gb_Jar_add_packagefile
,$(1),$(if
$(strip $(2)),$(strip $(2))/)$(notdir $(file
)),$(file
)))
164 define gb_Jar_add_sourcefiles
165 $(foreach sourcefile
,$(2),$(call gb_Jar_add_sourcefile
,$(1),$(sourcefile
)))
169 define gb_Jar_add_sourcefiles_java9
170 $(foreach sourcefile
,$(2),$(call gb_Jar_add_sourcefile_java9
,$(1),$(sourcefile
)))
174 define gb_Jar_add_generated_sourcefile
175 $(call gb_JavaClassSet_add_generated_sourcefile
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
179 define gb_Jar_add_generated_sourcefiles
180 $(foreach sourcefile
,$(2),$(call gb_Jar_add_generated_sourcefile
,$(1),$(sourcefile
)))
184 # JARCLASSPATH is the class path that is written to the manifest of the jar
185 define gb_Jar_add_manifest_classpath
186 $(call gb_Jar_get_target
,$(1)) : JARCLASSPATH
+= $(2)
190 # provide a manifest template containing jar specific information to be written into the manifest
191 # it will be appended to the standard content that is written in the build command explicitly
192 # the jar file gets a dependency to the manifest template
193 define gb_Jar_set_manifest
194 $(call gb_Jar_get_target
,$(1)) : MANIFEST
:= $(2)
195 $(call gb_Jar_get_target
,$(1)) : $(2)
199 # URE jars are not added to manifest classpath:
200 gb_Jar_default_jars
:= $(gb_Jar_URE
)
202 # remember: classpath is "inherited" to ClassSet
203 define gb_Jar_use_jar
204 $(call gb_JavaClassSet_use_jar
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
205 $(if
$(filter-out $(gb_Jar_default_jars
),$(2)),\
206 $(call gb_Jar_add_manifest_classpath
,$(1),$(2).jar
))
210 define gb_Jar_use_system_jar
211 $(call gb_JavaClassSet_use_system_jar
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
212 $(call gb_Jar_add_manifest_classpath
,$(1),$(call gb_Helper_make_url
,$(2)))
216 # call gb_Jar_use_external_jar,jar,externaljarfullpath,manifestentry
217 define gb_Jar_use_external_jar
218 $(if
$(3),,$(call gb_Output_error
,gb_Jar_use_external_jar
: manifest entry missing
))
219 $(call gb_JavaClassSet_use_system_jar
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
220 $(call gb_Jar_add_manifest_classpath
,$(1),$(3))
224 # specify jars with imported modules
225 define gb_Jar_use_jars
226 $(foreach jar
,$(2),$(call gb_Jar_use_jar
,$(1),$(jar
)))
230 define gb_Jar_use_system_jars
231 $(foreach jar
,$(2),$(call gb_Jar_use_system_jar
,$(1),$(jar
)))
235 # this forwards to functions that must be defined in RepositoryExternal.mk.
236 # $(eval $(call gb_Jar_use_external,jar,external))
237 define gb_Jar_use_external
238 $(if
$(value gb_Jar__use_
$(2)),\
239 $(call gb_Jar__use_
$(2),$(1)),\
240 $(error gb_Jar_use_external
: unknown external
: $(2)))
244 define gb_Jar_use_externals
245 $(foreach external
,$(2),$(call gb_Jar_use_external
,$(1),$(external
)))
249 define gb_Jar_use_customtarget
250 $(call gb_JavaClassSet_use_customtarget
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
254 define gb_Jar_use_customtargets
255 $(foreach customtarget
,$(2),$(call gb_Jar_use_customtarget
,$(1),$(customtarget
)))
259 # Add a dependency on an ExternalProject.
261 # call gb_Jar_use_external_project,jar,externalproject
262 define gb_Jar_use_external_project
263 $(call gb_JavaClassSet_use_external_project
,$(call gb_Jar_get_classsetname
,$(1)),$(2))
266 # possible directories for jar files containing UNO services
267 gb_Jar_COMPONENTPREFIXES
:= \
268 OOO
:vnd.sun.star.expand
:\dLO_JAVA_DIR
/ \
269 URE
:vnd.sun.star.expand
:\dURE_INTERNAL_JAVA_DIR
/ \
271 NONE
:$(call gb_Helper_make_url
,$(WORKDIR
)/Jar
/) \
273 # get component prefix from layer name ("OOO", "URE", "OXT", "NONE")
274 gb_Jar__get_componentprefix
= \
275 $(patsubst $(1):%,%,$(or \
276 $(filter $(1):%,$(gb_Jar_COMPONENTPREFIXES
)), \
277 $(call gb_Output_error
,no ComponentTarget native
prefix for layer
'$(1)')))
279 # layer must be specified explicitly in this macro (different to libraries)
280 define gb_Jar_set_componentfile
281 $(call gb_ComponentTarget_ComponentTarget
,$(2),$(call gb_Jar__get_componentprefix
,$(3)),$(notdir $(call gb_Jar_get_target
,$(1))),$(4))
282 $(call gb_Jar_get_target
,$(1)) : $(call gb_ComponentTarget_get_target
,$(2))
283 $(call gb_Jar_get_clean_target
,$(1)) : $(call gb_ComponentTarget_get_clean_target
,$(2))
287 # vim: set noet sw=4 ts=4: