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