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 SpreadSheet 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=DevGuideSpreadsheetExamples
46SAMPLE_CLASS_OUT=$(OUT_CLASS)/$(SAMPLE_NAME)
47SAMPLE_GEN_OUT=$(OUT_MISC)/$(SAMPLE_NAME)
48
49# Example add-in component
50COMP1_NAME=ExampleAddIn
51COMP1_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(COMP1_NAME)
52COMP1_GEN_OUT=$(SAMPLE_GEN_OUT)/$(COMP1_NAME)
53COMP1_RDB_NAME=$(COMP1_NAME).uno.rdb
54COMP1_RDB=$(COMP1_GEN_OUT)/$(COMP1_RDB_NAME)
55COMP1_PACKAGE=$(OUT_BIN)/$(COMP1_NAME).$(UNOOXT_EXT)
56COMP1_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP1_NAME).$(UNOOXT_EXT)")
57COMP1_JAR_NAME=$(COMP1_NAME).uno.jar
58COMP1_JAR=$(SAMPLE_CLASS_OUT)/$(COMP1_JAR_NAME)
59COMP1_MANIFESTFILE=$(COMP1_GEN_OUT)/$(COMP1_NAME).uno.Manifest
60COMP1_UNOPKG_MANIFEST=$(COMP1_GEN_OUT)/$(COMP1_NAME)/META-INF/manifest.xml
61COMP1_REGISTERFLAG=$(SAMPLE_GEN_OUT)/devguide_$(COMP1_NAME)_register_component.flag
62COMP1_COMPONENTS=$(COMP1_NAME).components
63
64# Example DataPilot component
65COMP2_NAME=ExampleDataPilotSource
66COMP2_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(COMP2_NAME)
67COMP2_GEN_OUT=$(SAMPLE_GEN_OUT)/$(COMP2_NAME)
68COMP2_PACKAGE=$(OUT_BIN)/$(COMP2_NAME).$(UNOOXT_EXT)
69COMP2_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP2_NAME).$(UNOOXT_EXT)")
70COMP2_JAR_NAME=$(COMP2_NAME).uno.jar
71COMP2_JAR=$(SAMPLE_CLASS_OUT)/$(COMP2_JAR_NAME)
72COMP2_MANIFESTFILE=$(COMP2_GEN_OUT)/$(COMP2_NAME).uno.Manifest
73COMP2_UNOPKG_MANIFEST=$(COMP2_GEN_OUT)/$(COMP2_NAME)/META-INF/manifest.xml
74COMP2_REGISTERFLAG=$(SAMPLE_GEN_OUT)/devguide_$(COMP2_NAME)_register_component.flag
75COMP2_COMPONENTS=$(COMP2_NAME).components
76
77#REGISTERFLAG = $(OUT_MISC)$(PS)devguide_$(SAMPLE_NAME)_register_component.flag
78
79APP1_NAME=GeneralTableSample
80APP1_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(APP1_NAME)
81APP1_GEN_OUT=$(SAMPLE_GEN_OUT)/$(APP1_NAME)
82APP1_JAR=$(SAMPLE_CLASS_OUT)/$(APP1_NAME).jar
83
84APP2_NAME=SpreadsheetSample
85APP2_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(APP2_NAME)
86APP2_GEN_OUT=$(SAMPLE_GEN_OUT)/$(APP2_NAME)
87APP2_JAR=$(SAMPLE_CLASS_OUT)/$(APP2_NAME).jar
88
89APP3_NAME=ViewSample
90APP3_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(APP3_NAME)
91APP3_GEN_OUT=$(SAMPLE_GEN_OUT)/$(APP3_NAME)
92APP3_JAR=$(SAMPLE_CLASS_OUT)/$(APP3_NAME).jar
93
94
95COMP1_IDLFILES = XExampleAddIn.idl
96
97# normally the idl file should be stored in a directory tree fitting the
98# module structure, for the example we know the module structure
99PACKAGE = org/openoffice/sheet/addin
100
101COMP1_JAVAFILES  = \
102	   ExampleAddIn.java
103
104COMP2_JAVAFILES  = \
105	   ExampleDataPilotSource.java
106
107APP_JAVAFILES  = \
108	   SpreadsheetDocHelper.java
109
110APP_CLASSFILES = $(patsubst %.java,$(SAMPLE_CLASS_OUT)/%.class,$(APP_JAVAFILES))
111APP_CLASSNAMES = $(patsubst %.java,%.class,$(APP_JAVAFILES))
112
113COMP1_GENCLASSFILES = $(patsubst %.idl,$(COMP1_CLASS_OUT)/$(PACKAGE)/%.class,$(COMP1_IDLFILES))
114COMP1_GENTYPELIST = $(subst /,.,$(patsubst %.idl,-T$(PACKAGE)/% ,$(COMP1_IDLFILES)))
115COMP1_GENURDFILES = $(patsubst %.idl,$(COMP1_GEN_OUT)/%.urd,$(COMP1_IDLFILES))
116
117COMP1_CLASSFILES = $(patsubst %.java,$(COMP1_CLASS_OUT)/%.class,$(COMP1_JAVAFILES))
118
119COMP2_CLASSFILES = $(patsubst %.java,$(COMP2_CLASS_OUT)/%.class,$(COMP2_JAVAFILES))
120
121
122SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
123		$(PATH_SEPARATOR)$(SAMPLE_CLASS_OUT)\
124		$(PATH_SEPARATOR)$(COMP1_CLASS_OUT)\
125		$(PATH_SEPARATOR)$(COMP2_CLASS_OUT)\
126		$(PATH_SEPARATOR)$(APP1_CLASS_OUT)\
127		$(PATH_SEPARATOR)$(APP2_CLASS_OUT)\
128		$(PATH_SEPARATOR)$(APP3_CLASS_OUT))
129
130
131# Targets
132.PHONY: ALL
133ALL : $(SAMPLE_NAME)
134
135include $(SETTINGS)/stdtarget.mk
136
137$(SAMPLE_GEN_OUT)/%.Manifest :
138	-$(MKDIR) $(subst /,$(PS),$(@D))
139	@echo UNO-Type-Path: $(basename $(notdir $*)).uno.jar> $@
140	@echo RegistrationClassName: $(basename $(basename $(@F)))>> $@
141
142# IDLs only for component 1 relevant
143$(COMP1_GEN_OUT)/%.urd : %.idl
144	-$(MKDIR) $(subst /,$(PS),$(@D))
145	$(IDLC) -I. -I$(IDL_DIR) -O$(COMP1_GEN_OUT) $^
146
147$(COMP1_RDB) : $(COMP1_GENURDFILES)
148	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
149	-$(MKDIR) $(subst /,$(PS),$(@D))
150	$(REGMERGE) $@ /UCR $<
151
152$(COMP1_CLASS_OUT)/$(PACKAGE)/%.class : $(COMP1_RDB)
153	-$(MKDIR) $(subst /,$(PS),$(@D))
154	$(JAVAMAKER) -BUCR -nD $(COMP1_GENTYPELIST) -O$(COMP1_CLASS_OUT) $(COMP1_RDB) -X$(URE_TYPES) -X$(OFFICE_TYPES)
155
156$(COMP1_CLASSFILES) : $(COMP1_JAVAFILES) $(COMP1_GENCLASSFILES)
157	-$(MKDIR) $(subst /,$(PS),$(@D))
158	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(COMP1_CLASS_OUT) $(COMP1_JAVAFILES)
159
160$(COMP2_CLASSFILES) : $(COMP2_JAVAFILES)
161	-$(MKDIR) $(subst /,$(PS),$(@D))
162	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(COMP2_CLASS_OUT) $^
163
164$(COMP1_JAR) : $(COMP1_MANIFESTFILE) $(COMP1_CLASSFILES)
165	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
166	-$(MKDIR) $(subst /,$(PS),$(@D))
167	$(SDK_JAR) cvfm $@ $< -C $(COMP1_CLASS_OUT) .
168
169$(COMP2_JAR) : $(COMP2_MANIFESTFILE) $(COMP2_CLASSFILES)
170	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
171	-$(MKDIR) $(subst /,$(PS),$(@D))
172	$(SDK_JAR) cvfm $@ $< -C $(COMP2_CLASS_OUT) .
173
174$(COMP1_UNOPKG_MANIFEST) :
175	-$(MKDIR) $(subst /,$(PS),$(@D))
176	@echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
177	@echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
178	@echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
179	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-typelibrary;type=RDB$(QM)" >> $@
180	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(COMP1_GEN_OUT)/,,$(@D))).uno.rdb$(QM)"/$(CSEP) >> $@
181	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components$(QM)">> $@
182	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(COMP1_COMPONENTS)$(QM)"/$(CSEP)>> $@
183	@echo $(OSEP)/manifest:manifest$(CSEP) >> $@
184
185$(COMP2_UNOPKG_MANIFEST) :
186	-$(MKDIR) $(subst /,$(PS),$(@D))
187	@echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
188	@echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
189	@echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
190	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components$(QM)">> $@
191	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(COMP2_COMPONENTS)$(QM)"/$(CSEP)>> $@
192	@echo $(OSEP)/manifest:manifest$(CSEP) >> $@
193
194$(COMP1_PACKAGE) : $(COMP1_RDB) $(COMP1_JAR) $(COMP1_UNOPKG_MANIFEST) $(COMP1_COMPONENTS)
195	echo "####" $(@)
196	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
197	-$(MKDIR) $(subst /,$(PS),$(@D))
198	$(SDK_ZIP) $@ $(COMP1_COMPONENTS)
199	cd $(subst /,$(PS),$(COMP1_GEN_OUT)) && $(SDK_ZIP) -u ../../../bin/$(@F) $(<F)
200	cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP1_JAR_NAME)
201	cd $(subst /,$(PS),$(COMP1_GEN_OUT)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../../bin/$(@F) META-INF/manifest.xml
202
203$(COMP2_PACKAGE) : $(COMP2_JAR) $(COMP2_UNOPKG_MANIFEST) $(COMP2_COMPONENTS)
204	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
205	-$(MKDIR) $(subst /,$(PS),$(@D))
206	$(SDK_ZIP) $@ $(COMP2_COMPONENTS)
207	cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) -u ../../bin/$(@F) $(<F)
208	cd $(subst /,$(PS),$(COMP2_GEN_OUT)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../../bin/$(@F) META-INF/manifest.xml
209
210$(SAMPLE_GEN_OUT)/devguide_$(COMP1_NAME)_register_component.flag : $(OUT_BIN)/$(COMP1_NAME).$(UNOOXT_EXT)
211ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
212	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
213	-$(MKDIR) $(subst /,$(PS),$(@D))
214	$(DEPLOYTOOL) $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP1_NAME).$(UNOOXT_EXT)")
215	@echo flagged > $(subst /,$(PS),$@)
216else
217	@echo --------------------------------------------------------------------------------
218	@echo  If you want to install your component automatically, please set the environment
219	@echo  variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
220	@echo  possible if no office instance is running.
221	@echo --------------------------------------------------------------------------------
222endif
223
224$(SAMPLE_GEN_OUT)/devguide_$(COMP2_NAME)_register_component.flag : $(OUT_BIN)/$(COMP2_NAME).$(UNOOXT_EXT)
225ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
226	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
227	-$(MKDIR) $(subst /,$(PS),$(@D))
228	$(DEPLOYTOOL) $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP2_NAME).$(UNOOXT_EXT)")
229	@echo flagged > $(subst /,$(PS),$@)
230else
231	@echo --------------------------------------------------------------------------------
232	@echo  If you want to install your component automatically, please set the environment
233	@echo  variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
234	@echo  possible if no office instance is running.
235	@echo --------------------------------------------------------------------------------
236endif
237
238$(APP_CLASSFILES) : $(APP_JAVAFILES)
239	-$(MKDIR) $(subst /,$(PS),$(@D))
240	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(SAMPLE_CLASS_OUT) $(APP_JAVAFILES)
241
242$(APP1_CLASS_OUT)/%.class : %.java $(APP_CLASSFILES)
243	-$(MKDIR) $(subst /,$(PS),$(@D))
244	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(APP1_CLASS_OUT) $<
245
246$(APP2_CLASS_OUT)/%.class : %.java $(APP_CLASSFILES)
247	-$(MKDIR) $(subst /,$(PS),$(@D))
248	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(APP2_CLASS_OUT) $<
249
250$(APP3_CLASS_OUT)/%.class : %.java $(APP_CLASSFILES)
251	-$(MKDIR) $(subst /,$(PS),$(@D))
252	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(APP3_CLASS_OUT) $<
253
254$(SAMPLE_GEN_OUT)/%.mf :
255	-$(MKDIR) $(subst /,$(PS),$(@D))
256	@echo Main-Class: com.sun.star.lib.loader.Loader> $@
257	$(ECHOLINE)>> $@
258	@echo Name: com/sun/star/lib/loader/Loader.class>> $@
259	@echo Application-Class: $(basename $(@F))>> $@
260
261$(APP1_JAR) : $(APP1_GEN_OUT)/$(APP1_NAME).mf $(APP1_CLASS_OUT)/$(APP1_NAME).class $(APP_CLASSFILES)
262	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
263	-$(MKDIR) $(subst /,$(PS),$(@D))
264	+$(SDK_JAR) cvfm $@ $< -C $(APP1_CLASS_OUT) .
265	+$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
266	+cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) uvf $(@F) $(APP_CLASSNAMES)
267
268$(APP2_JAR) : $(APP2_GEN_OUT)/$(APP2_NAME).mf $(APP2_CLASS_OUT)/$(APP2_NAME).class $(APP_CLASSFILES)
269	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
270	-$(MKDIR) $(subst /,$(PS),$(@D))
271	+$(SDK_JAR) cvfm $@ $< -C $(APP2_CLASS_OUT) .
272	+$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
273	+cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) uvf $(@F) $(APP_CLASSNAMES)
274
275$(APP3_JAR) : $(APP3_GEN_OUT)/$(APP3_NAME).mf $(APP3_CLASS_OUT)/$(APP3_NAME).class $(APP_CLASSFILES)
276	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
277	-$(MKDIR) $(subst /,$(PS),$(@D))
278	+$(SDK_JAR) cvfm $@ $< -C $(APP3_CLASS_OUT) .
279	+$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
280	+cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) uvf $(@F) $(APP_CLASSNAMES)
281
282$(SAMPLE_NAME) : $(COMP1_REGISTERFLAG) $(COMP2_REGISTERFLAG) $(APP1_JAR) $(APP2_JAR) $(APP3_JAR)
283	@echo --------------------------------------------------------------------------------
284	@echo Please use one of the following commands to execute the examples!
285	@echo -
286	@echo $(MAKE) $(APP1_NAME).run
287	@echo $(MAKE) $(APP2_NAME).run
288	@echo $(MAKE) $(APP3_NAME).run
289	@echo --------
290	@echo The "$(QM)$(COMP1_NAME)$(QM)" and "$(QM)$(COMP2_NAME)$(QM)"  component are installed if
291	@echo SDK_AUTO_DEPLOYMENT = YES. You can use this components inside your office
292	@echo installation, see the example descriptions. You can also load the "$(QM)ExampleAddIn.ods$(QM)"
293	@echo  document to see how the add-in functions can be used. For more details about the
294	@echo "$(QM)$(COMP2_NAME)$(QM)" component see the "$(QM)DataPilotReadme.txt"$(QM).
295	@echo -
296	@echo $(MAKE) ExampleAddIn.ods.load
297	@echo --------------------------------------------------------------------------------
298
299%.run: $(SAMPLE_CLASS_OUT)/%.jar
300	$(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
301
302ExampleAddIn.ods.load : $(COMP1_REGISTERFLAG)
303	"$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@)
304
305.PHONY: clean
306clean :
307	-$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT))
308	-$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
309	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP1_PACKAGE_URL)))
310	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP2_PACKAGE_URL)))
311