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 Java Spreadsheet examples of the SDK.
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
45EXAMPLE_NAME=JavaSpreadsheetExamples
46OUT_COMP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
47OUT_COMP_GEN = $(OUT_MISC)/$(EXAMPLE_NAME)
48
49APP1_NAME=EuroAdaption
50APP1_JAR=$(OUT_COMP_CLASS)/$(APP1_NAME).jar
51APP2_NAME=SCalc
52APP2_JAR=$(OUT_COMP_CLASS)/$(APP2_NAME).jar
53APP3_NAME=ChartTypeChange
54APP3_JAR=$(OUT_COMP_CLASS)/$(APP3_NAME).jar
55
56COMP_NAME=CalcAddins
57COMP_RDB_NAME=$(COMP_NAME).uno.rdb
58COMP_RDB=$(OUT_COMP_GEN)/$(COMP_RDB_NAME)
59COMP_PACKAGE=$(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
60COMP_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
61COMP_JAR_NAME=$(COMP_NAME).uno.jar
62COMP_JAR=$(OUT_COMP_CLASS)/$(COMP_JAR_NAME)
63COMP_MANIFESTFILE=$(OUT_COMP_CLASS)/$(COMP_NAME).uno.Manifest
64COMP_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMP_NAME)/META-INF/manifest.xml
65COMP_REGISTERFLAG=$(OUT_MISC)$(PS)java_$(COMP_NAME)_register_component.flag
66COMP_COMPONENTS=$(COMP_NAME).components
67
68IDLFILES = XCalcAddins.idl
69
70# normally the idl file should be stored in a directory tree fitting the module structure,
71# for the example we know the module structure
72PACKAGE = org/openoffice/sheet/addin
73
74COMPJAVAFILES  = CalcAddins.java
75
76#GENJAVAFILES = $(patsubst %.idl,$(OUT_COMP_GEN)/$(PACKAGE)/%.java,$(IDLFILES))
77GENCLASSFILES = $(patsubst %.idl,$(OUT_COMP_CLASS)/$(PACKAGE)/%.class,$(IDLFILES))
78GENTYPELIST = $(subst /,.,$(patsubst %.idl,-T$(PACKAGE)/% ,$(IDLFILES)))
79GENURDFILES = $(patsubst %.idl,$(OUT_COMP_GEN)/%.urd,$(IDLFILES))
80
81COMPCLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(COMPJAVAFILES))
82#COMPCLASSFILES += $(subst $(OUT_COMP_GEN),$(OUT_COMP_CLASS),$(GENJAVAFILES:.java=.class))
83
84$(COMP_NAME)_CLASSFILES = $(COMP_NAME).class \
85		$(COMP_NAME)$(QUOTE)$$_$(COMP_NAME).class
86
87#$(COMP_NAME)_CLASSFILES += $(subst $(OUT_COMP_GEN)/,,$(GENJAVAFILES:.java=.class))
88$(COMP_NAME)_CLASSFILES += $(subst $(OUT_COMP_CLASS)/,,$(GENCLASSFILES))
89
90SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
91		$(PATH_SEPARATOR)$(OUT_COMP_CLASS))
92
93# Targets
94.PHONY: ALL
95ALL : $(EXAMPLE_NAME)
96
97include $(SETTINGS)/stdtarget.mk
98
99# rule for a component manifest file
100$(OUT_COMP_CLASS)/%.Manifest :
101	-$(MKDIR) $(subst /,$(PS),$(@D))
102	@echo UNO-Type-Path: $(basename $*).uno.jar> $@
103	@echo RegistrationClassName: $(basename $*)>> $@
104
105$(OUT_COMP_GEN)/%.urd : %.idl
106	-$(MKDIR) $(subst /,$(PS),$(@D))
107	$(IDLC) -C -I. -I$(IDL_DIR) -O$(OUT_COMP_GEN) $<
108
109$(OUT_COMP_GEN)/%.rdb : $(GENURDFILES)
110	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
111	-$(MKDIR) $(subst /,$(PS),$(@D))
112	$(REGMERGE) $@ /UCR $(GENURDFILES)
113
114#$(OUT_COMP_GEN)/%.java : $(COMP_RDB)
115$(GENCLASSFILES) : $(COMP_RDB)
116	-$(MKDIR) $(subst /,$(PS),$(@D))
117	$(JAVAMAKER) -BUCR -nD $(GENTYPELIST) -O$(OUT_COMP_CLASS) $(COMP_RDB) -X$(URE_TYPES) -X$(OFFICE_TYPES)
118
119$(OUT_COMP_CLASS)/%.class : %.java
120	-$(MKDIR) $(subst /,$(PS),$(@D))
121	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $<
122
123# only the component depends on the generated types
124$(COMPCLASSFILES) : $(JAVAFILES) $(GENCLASSFILES)
125	-$(MKDIR) $(subst /,$(PS),$(@D))
126	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $(COMPJAVAFILES)
127
128# rule for client/example application manifest file
129$(OUT_COMP_CLASS)/%.mf :
130	-$(MKDIR) $(subst /,$(PS),$(@D))
131	@echo Main-Class: com.sun.star.lib.loader.Loader> $@
132	$(ECHOLINE)>> $@
133	@echo Name: com/sun/star/lib/loader/Loader.class>> $@
134	@echo Application-Class: $*>> $@
135
136# rule for client/example application jar file
137$(OUT_COMP_CLASS)/%.jar : $(OUT_COMP_CLASS)/%.mf $(OUT_COMP_CLASS)/%.class
138	-$(MKDIR) $(subst /,$(PS),$(@D))
139	+cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class
140	+$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
141
142# rule for component jar file
143$(COMP_JAR) : $(COMP_MANIFESTFILE) $(COMPCLASSFILES)
144	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
145	-$(MKDIR) $(subst /,$(PS),$(@D))
146	cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
147
148# rule for component package manifest
149$(OUT_COMP_CLASS)/%/manifest.xml :
150	-$(MKDIR) $(subst /,$(PS),$(@D))
151	@echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
152	@echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
153	@echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
154	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-typelibrary;type=RDB$(QM)" >> $@
155	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_CLASS)/,,$(@D))).uno.rdb$(QM)"/$(CSEP) >> $@
156	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components$(QM)">> $@
157	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@
158	@echo $(OSEP)/manifest:manifest$(CSEP) >> $@
159
160# rule for component package file
161$(COMP_PACKAGE) : $(COMP_RDB) $(COMP_JAR) $(COMP_UNOPKG_MANIFEST) $(COMP_NAME).components
162	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
163	-$(MKDIR) $(subst /,$(PS),$(@D))
164	$(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(OUT_COMP_CLASS))
165	$(SDK_ZIP) $@ -u $(COMP_NAME).components
166	cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_RDB_NAME) $(COMP_JAR_NAME)
167	cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
168	$(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_COMP_CLASS)/$(<F)))
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) : $(OUT_COMP_CLASS)/$(APP1_NAME).mf $(OUT_COMP_CLASS)/$(APP1_NAME).class
185$(APP2_JAR) : $(OUT_COMP_CLASS)/$(APP2_NAME).mf $(OUT_COMP_CLASS)/$(APP2_NAME).class
186$(APP3_JAR) : $(OUT_COMP_CLASS)/$(APP3_NAME).mf $(OUT_COMP_CLASS)/$(APP3_NAME).class
187
188$(EXAMPLE_NAME) : $(COMP_REGISTERFLAG) $(APP1_JAR) $(APP2_JAR) $(APP3_JAR)
189	@echo --------------------------------------------------------------------------------
190	@echo Please use the following command to execute the examples!
191	@echo -
192	@echo $(MAKE) EuroAdaption.run
193	@echo $(MAKE) SCalc.run
194	@echo $(MAKE) ChartTypeChange.run
195	@echo --------------------------------------------------------------------------------
196	@echo The Calc add-in component was installed if SDK_AUTO_DEPLOYMENT = YES.
197	@echo You can use this component inside your office installation, see the example
198	@echo description. You can also load the "$(QM)CalcAddins.ods$(QM)" document to see
199	@echo how the add-in functions works.
200	@echo -
201	@echo $(MAKE) CalcAddins.ods.load
202	@echo --------------------------------------------------------------------------------
203
204%.run: $(OUT_COMP_CLASS)/%.jar
205	$(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
206
207CalcAddins.ods.load : $(COMP_REGISTERFLAG)
208	"$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@)
209
210.PHONY: clean
211clean :
212	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_CLASS))
213	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN))
214	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
215	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_REGISTERFLAG)))
216