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#  The Contents of this file are made available subject to the terms of
25#  the BSD license.
26#
27#  Copyright 2000, 2010 Oracle and/or its affiliates.
28#  All rights reserved.
29#
30#  Redistribution and use in source and binary forms, with or without
31#  modification, are permitted provided that the following conditions
32#  are met:
33#  1. Redistributions of source code must retain the above copyright
34#     notice, this list of conditions and the following disclaimer.
35#  2. Redistributions in binary form must reproduce the above copyright
36#     notice, this list of conditions and the following disclaimer in the
37#     documentation and/or other materials provided with the distribution.
38#  3. Neither the name of Sun Microsystems, Inc. nor the names of its
39#     contributors may be used to endorse or promote products derived
40#     from this software without specific prior written permission.
41#
42#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43#  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44#  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
45#  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
46#  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
47#  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
48#  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
49#  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
50#  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
51#  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
52#  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53#
54#**************************************************************************
55
56# Builds the Charts examples of the Developers Guide.
57
58PRJ=../../..
59SETTINGS=$(PRJ)/settings
60
61include $(SETTINGS)/settings.mk
62include $(SETTINGS)/std.mk
63include $(SETTINGS)/dk.mk
64
65# Define non-platform/compiler specific settings
66SAMPLE_NAME=DevGuideChartExample
67SAMPLE_CLASS_OUT = $(OUT_CLASS)/$(SAMPLE_NAME)
68SAMPLE_GEN_OUT = $(OUT_MISC)/$(SAMPLE_NAME)
69
70APP1_NAME=ChartInCalc
71APP1_JAR=$(SAMPLE_CLASS_OUT)/$(APP1_NAME).jar
72APP2_NAME=ChartInDraw
73APP2_JAR=$(SAMPLE_CLASS_OUT)/$(APP2_NAME).jar
74APP3_NAME=ChartInWriter
75APP3_JAR=$(SAMPLE_CLASS_OUT)/$(APP3_NAME).jar
76APP4_NAME=ListenAtCalcRangeInDraw
77APP4_JAR=$(SAMPLE_CLASS_OUT)/$(APP4_NAME).jar
78APP5_NAME=SelectionChangeListener
79APP5_JAR=$(SAMPLE_CLASS_OUT)/$(APP5_NAME).jar
80
81COMP_NAME=JavaSampleChartAddIn
82COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
83COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
84COMP_JAR_NAME = $(COMP_NAME).uno.jar
85COMP_JAR = $(SAMPLE_CLASS_OUT)/$(COMP_JAR_NAME)
86COMP_MANIFESTFILE = $(SAMPLE_CLASS_OUT)/$(COMP_NAME).uno.Manifest
87COMP_UNOPKG_MANIFEST = $(SAMPLE_CLASS_OUT)/$(COMP_NAME)/META-INF/manifest.xml
88COMP_REGISTERFLAG = $(SAMPLE_GEN_OUT)/devguide_$(COMP_NAME)_register_component.flag
89COMP_COMPONENTS=$(COMP_NAME).components
90
91COMPJAVAFILES  = \
92	   JavaSampleChartAddIn.java
93
94APP_JAVAFILES  = \
95	   Helper.java \
96	   CalcHelper.java \
97	   ChartHelper.java
98
99COMPCLASSFILES= $(patsubst %.java,$(SAMPLE_CLASS_OUT)/%.class,$(COMPJAVAFILES))
100
101APP_CLASSFILES= $(patsubst %.java,$(SAMPLE_CLASS_OUT)/%.class,$(APP_JAVAFILES))
102APP_CLASSNAMES= $(patsubst %.java,%.class,$(APP_JAVAFILES))
103
104$(COMP_NAME)_CLASSFILES = $(COMP_NAME).class
105
106SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
107		$(PATH_SEPARATOR)$(SAMPLE_CLASS_OUT))
108
109
110# Targets
111.PHONY: ALL
112ALL : $(SAMPLE_NAME)
113
114include $(SETTINGS)/stdtarget.mk
115
116$(SAMPLE_CLASS_OUT)/%.Manifest :
117	-$(MKDIR) $(subst /,$(PS),$(@D))
118	@echo RegistrationClassName: $(basename $(basename $(@F)))> $@
119
120# rule for client/example application class files, explicit dependencies to common
121# java files which are used in all examples.
122$(SAMPLE_CLASS_OUT)/%.class : %.java $(APP_JAVAFILES)
123	-$(MKDIR) $(subst /,$(PS),$(@D))
124	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(SAMPLE_CLASS_OUT) $< $(APP_JAVAFILES)
125
126$(COMPCLASSFILES) : $(JAVAFILES)
127	-$(MKDIR) $(subst /,$(PS),$(@D))
128	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(SAMPLE_CLASS_OUT) $(COMPJAVAFILES)
129
130# rule for client/example application manifest file
131$(SAMPLE_CLASS_OUT)/%.mf :
132	-$(MKDIR) $(subst /,$(PS),$(@D))
133	@echo Main-Class: com.sun.star.lib.loader.Loader> $@
134	$(ECHOLINE)>> $@
135	@echo Name: com/sun/star/lib/loader/Loader.class>> $@
136	@echo Application-Class: $*>> $@
137
138# rule for client/example application jar file
139$(SAMPLE_CLASS_OUT)/%.jar : $(SAMPLE_CLASS_OUT)/%.mf $(SAMPLE_CLASS_OUT)/%.class
140	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
141	-$(MKDIR) $(subst /,$(PS),$(@D))
142	+cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) cvfm $(@F) $*.mf $**.class $(APP_CLASSNAMES)
143
144	+$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
145
146# rule for component jar file
147$(COMP_JAR) : $(COMP_MANIFESTFILE) $(COMPCLASSFILES)
148	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
149	-$(MKDIR) $(subst /,$(PS),$(@D))
150	cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
151
152# rule for component package manifest
153$(SAMPLE_CLASS_OUT)/%/manifest.xml :
154	-$(MKDIR) $(subst /,$(PS),$(@D))
155	@echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
156	@echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
157	@echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
158	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components$(QM)">> $@
159	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(COMP_COMPONENTS)$(QM)"/$(CSEP)>> $@
160	@echo $(OSEP)/manifest:manifest$(CSEP) >> $@
161
162# rule for component pacakge file
163$(COMP_PACKAGE) : $(COMP_JAR) $(COMP_UNOPKG_MANIFEST) $(COMP_COMPONENTS)
164	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
165	-$(MKDIR) $(subst /,$(PS),$(@D))
166	$(SDK_ZIP) $@ $(COMP_COMPONENTS)
167	cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) ../../bin/$(@F) -u $(<F)
168	cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) ../../../bin/$(@F) -u META-INF/manifest.xml
169
170$(COMP_REGISTERFLAG) : $(COMP_PACKAGE)
171ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
172	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
173	-$(MKDIR) $(subst /,$(PS),$(@D))
174	$(DEPLOYTOOL) $(COMP_PACKAGE_URL)
175	@echo flagged > $(subst /,$(PS),$@)
176else
177	@echo --------------------------------------------------------------------------------
178	@echo  If you want to install your component automatically, please set the environment
179	@echo  variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
180	@echo  possible if no office instance is running.
181	@echo --------------------------------------------------------------------------------
182endif
183
184$(APP1_JAR) : $(SAMPLE_CLASS_OUT)/$(APP1_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP1_NAME).class
185$(APP2_JAR) : $(SAMPLE_CLASS_OUT)/$(APP2_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP2_NAME).class
186$(APP3_JAR) : $(SAMPLE_CLASS_OUT)/$(APP3_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP3_NAME).class
187$(APP4_JAR) : $(SAMPLE_CLASS_OUT)/$(APP4_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP4_NAME).class
188$(APP5_JAR) : $(SAMPLE_CLASS_OUT)/$(APP5_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP5_NAME).class
189
190$(SAMPLE_NAME) : $(COMP_REGISTERFLAG) $(APP1_JAR)  $(APP2_JAR)  $(APP3_JAR)  $(APP4_JAR)  $(APP5_JAR)
191	@echo --------------------------------------------------------------------------------
192	@echo When you run the "$(QM)$(APP5_NAME)$(QM)" example please select the
193	@echo legend or the title to add a $(APP5_NAME). The example terminates
194	@echo when the document is closed.
195	@echo -
196	@echo Please use the following commands to execute the examples!
197	@echo -
198	@echo $(MAKE) $(APP1_NAME).run
199	@echo $(MAKE) $(APP2_NAME).run
200	@echo $(MAKE) $(APP3_NAME).run
201	@echo $(MAKE) $(APP4_NAME).run
202	@echo $(MAKE) $(APP5_NAME).run
203	@echo --------
204	@echo The Chart add-in component was installed if SDK_AUTO_DEPLOYMENT = YES.
205	@echo Load the "$(QM)AddInChart.ods$(QM)" document in your office to see the new chart type,
206	@echo and see the example description.
207	@echo -
208	@echo $(MAKE) AddInChart.ods.load
209	@echo --------------------------------------------------------------------------------
210
211%.run: $(SAMPLE_CLASS_OUT)/%.jar
212	$(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
213
214AddInChart.ods.load : $(REGISTERFLAG)
215	"$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@)
216
217.PHONY: clean
218clean :
219	-$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT))
220	-$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
221	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
222