xref: /aoo42x/main/solenv/gbuild/Jar.mk (revision b63233d8)
1###############################################################
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20###############################################################
21
22
23
24# if a jar prerequisite has changed, the ClassSet must be recompiled. How?
25
26# Jar class
27
28gb_Jar_JAVACOMMAND := $(JAVAINTERPRETER)
29gb_Jar_JARCOMMAND := jar
30
31# location of manifest file in workdir
32define gb_Jar_get_manifest_target
33$(call gb_JavaClassSet_get_classdir,$(call gb_Jar_get_classsetname,$(1)))/META-INF/MANIFEST.MF
34endef
35
36# creates classset and META-INF folders if they don't exist
37# adds manifest version, class path, solarversion and content from sources to manifest file
38# creates the target folder of the jar file if it doesn't exist
39# creates the jar file
40define gb_Jar__command
41	$(call gb_Helper_abbreviate_dirs_native,\
42	mkdir -p $(call gb_JavaClassSet_get_classdir,$(call gb_Jar_get_classsetname,$(1)))/META-INF && \
43	echo Manifest-Version: 1.0 > $(call gb_Jar_get_manifest_target,$(1)) && \
44	echo "Class-Path: $(JARCLASSPATH)" >> $(call gb_Jar_get_manifest_target,$(1)) && \
45	echo "Solar-Version: $(RSCREVISION)" >> $(call gb_Jar_get_manifest_target,$(1)) && \
46	cat $(MANIFEST) >> $(call gb_Jar_get_manifest_target,$(1)) && \
47	mkdir -p $(dir $(2)) && \
48	cd $(call gb_JavaClassSet_get_classdir,$(call gb_Jar_get_classsetname,$(1))) && $(gb_Jar_JARCOMMAND) cfm $(2) $(call gb_Jar_get_manifest_target,$(1)) META-INF $(PACKAGEROOTS) )
49endef
50
51# clean target reuses clean target of ClassSet
52$(call gb_Jar_get_clean_target,%) : $(call gb_JavaClassSet_get_clean_target,$(call gb_Jar_get_classsetname,%))
53	$(call gb_Output_announce,$*,$(false),JAR,3)
54	$(call gb_Helper_abbreviate_dirs,\
55		rm -f $(call gb_Jar_get_target,$*) $(call gb_Jar_get_outdir_target,$*))
56
57# the outdir target depends on the workdir target and is built by delivering the latter
58# the workdir target is created by cd'ing to the target directory and adding/updating the files
59
60# rule for creating the jar file using the command defined above
61$(call gb_Jar_get_target,%) : $(call gb_JavaClassSet_get_target,$(call gb_Jar_get_classsetname,%))
62	$(call gb_Jar__command,$*,$@,$*,$?)
63
64# resets scoped variables (see explanations where they are set)
65# creates a class set and a dependency to it
66# registers target and clean target
67# adds jar files to DeliverLogTarget
68# adds dependency for outdir target to workdir target (pattern rule for delivery is in Package.mk)
69define gb_Jar_Jar
70$(call gb_Jar_get_target,$(1)) : MANIFEST :=
71$(call gb_Jar_get_target,$(1)) : JARCLASSPATH :=
72$(call gb_Jar_get_target,$(1)) : PACKAGEROOTS :=
73$(call gb_JavaClassSet_JavaClassSet,$(call gb_Jar_get_classsetname,$(1)),$(2))
74$(call gb_JavaClassSet_set_classpath,$(call gb_Jar_get_classsetname,$(1)),$(value XCLASSPATH))
75$(eval $(call gb_Module_register_target,$(call gb_Jar_get_outdir_target,$(1)),$(call gb_Jar_get_clean_target,$(1))))
76$(call gb_Deliver_add_deliverable,$(call gb_Jar_get_outdir_target,$(1)),$(call gb_Jar_get_target,$(1)),$(1))
77$(call gb_Jar_get_outdir_target,$(1)) : $(call gb_Jar_get_target,$(1))
78
79endef
80
81# source files are forwarded to the ClassSet
82define gb_Jar_add_sourcefile
83$(call gb_JavaClassSet_add_sourcefile,$(call gb_Jar_get_classsetname,$(1)),$(2))
84endef
85
86# PACKAGEROOTS is the list of all root folders to pack into the jar (without META-INF as this is added automatically)
87define gb_Jar_set_packageroot
88$(call gb_Jar_get_target,$(1)) : PACKAGEROOTS := $(2)
89endef
90
91define gb_Jar_add_sourcefiles
92$(foreach sourcefile,$(2),$(call gb_Jar_add_sourcefile,$(1),$(sourcefile)))
93endef
94
95define gb_JarTest_set_classpath
96$(call gb_JavaClassSet_set_classpath,$(call gb_Jar_get_classsetname,$(1)),$(2))
97endef
98
99# JARCLASSPATH is the class path that is written to the manifest of the jar
100define gb_Jar_set_jarclasspath
101
102$(call gb_Jar_get_target,$(1)) : JARCLASSPATH := $(2)
103endef
104
105# provide a manifest template containing jar specific information to be written into the manifest
106# it will be appended to the standard content that is written in the build command explicitly
107# the jar file gets a dependency to the manifest template
108define gb_Jar_set_manifest
109$(call gb_Jar_get_target,$(1)) : MANIFEST := $(2)
110$(call gb_Jar_get_target,$(1)) : $(2)
111
112endef
113
114# remember: classpath is "inherited" to ClassSet
115define gb_Jar_add_jar
116$(call gb_JavaClassSet_add_jar,$(call gb_Jar_get_classsetname,$(1)),$(2))
117endef
118
119define gb_Jar_add_system_jar
120$(call gb_JavaClassSet_add_system_jar,$(call gb_Jar_get_classsetname,$(1)),$(2))
121endef
122
123# specify jars with imported modules
124define gb_Jar_add_jars
125$(call gb_JavaClassSet_add_jars,$(call gb_Jar_get_classsetname,$(1)),$(2))
126endef
127
128define gb_Jar_add_system_jars
129$(call gb_JavaClassSet_add_system_jars,$(call gb_Jar_get_classsetname,$(1)),$(2))
130endef
131
132define gb_Jar_use_external
133$(call gb_JavaClassSet_use_external,$(call gb_Jar_get_classsetname,$(1)),$(2))
134endef
135
136define gb_Jar_use_externals
137$(call gb_JavaClassSet_use_externals,$(call gb_Jar_get_classsetname,$(1)),$(2))
138endef
139
140# possible directories for jar files containing UNO services
141gb_Jar_COMPONENTPREFIXES := \
142    OOO:vnd.sun.star.expand:\dOOO_BASE_DIR/program/classes/ \
143    URE:vnd.sun.star.expand:\dURE_INTERNAL_JAVA_DIR/ \
144    INTERN:vnd.sun.star.expand:\dOOO_INBUILD_JAVA_DIR/
145
146# get component prefix from layer name ("OOO", "URE", "INTERN")
147gb_Jar__get_componentprefix = \
148    $(patsubst $(1):%,%,$(or \
149        $(filter $(1):%,$(gb_Jar_COMPONENTPREFIXES)), \
150        $(call gb_Output_error,no ComponentTarget native prefix for layer '$(1)')))
151
152# layer must be specified explicitly in this macro (different to libraries)
153define gb_Jar_set_componentfile
154$(call gb_ComponentTarget_ComponentTarget,$(2),$(call gb_Jar__get_componentprefix,$(3)),$(notdir $(call gb_Jar_get_target,$(1))))
155$(call gb_Jar_get_target,$(1)) : $(call gb_ComponentTarget_get_outdir_target,$(2))
156$(call gb_Jar_get_clean_target,$(1)) : $(call gb_ComponentTarget_get_clean_target,$(2))
157
158endef
159
160
161# vim: set noet sw=4 ts=4:
162