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 OfficeDevLinguistic 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
45EXAMPLE_NAME=OfficeDevLinguisticExample
46OUT_COMP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
47
48COMP1_NAME=SampleHyphenator
49COMP1_PACKAGE = $(OUT_BIN)/$(COMP1_NAME).$(UNOOXT_EXT)
50COMP1_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP1_NAME).$(UNOOXT_EXT)")
51COMP1_JAR_NAME = $(COMP1_NAME).uno.jar
52COMP1_JAR = $(OUT_COMP_CLASS)/$(COMP1_JAR_NAME)
53COMP1_MANIFESTFILE = $(OUT_COMP_CLASS)/$(COMP1_NAME).uno.Manifest
54COMP1_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMP1_NAME)/META-INF/manifest.xml
55COMP1_COMPONENTS=$(COMP1_NAME).components
56
57COMP2_NAME=SampleSpellChecker
58COMP2_PACKAGE = $(OUT_BIN)/$(COMP2_NAME).$(UNOOXT_EXT)
59COMP2_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP2_NAME).$(UNOOXT_EXT)")
60COMP2_JAR_NAME = $(COMP2_NAME).uno.jar
61COMP2_JAR = $(OUT_COMP_CLASS)/$(COMP2_JAR_NAME)
62COMP2_MANIFESTFILE = $(OUT_COMP_CLASS)/$(COMP2_NAME).uno.Manifest
63COMP2_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMP2_NAME)/META-INF/manifest.xml
64COMP2_COMPONENTS=$(COMP2_NAME).components
65
66COMP3_NAME=SampleThesaurus
67COMP3_PACKAGE = $(OUT_BIN)/$(COMP3_NAME).$(UNOOXT_EXT)
68COMP3_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP3_NAME).$(UNOOXT_EXT)")
69COMP3_JAR_NAME = $(COMP3_NAME).uno.jar
70COMP3_JAR = $(OUT_COMP_CLASS)/$(COMP3_JAR_NAME)
71COMP3_MANIFESTFILE = $(OUT_COMP_CLASS)/$(COMP3_NAME).uno.Manifest
72COMP3_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMP3_NAME)/META-INF/manifest.xml
73COMP3_COMPONENTS=$(COMP2_NAME).components
74
75APP1_NAME=LinguisticExamples
76APP1_JAR=$(OUT_COMP_CLASS)/$(APP1_NAME).jar
77
78REGISTERFLAG = $(OUT_MISC)/devguide_officedevlinguistic_register_component.flag
79
80JAVAFILES  = \
81	OneInstanceFactory.java \
82	PropChgHelper.java \
83	PropChgHelper_Hyph.java \
84	PropChgHelper_Spell.java \
85	XHyphenatedWord_impl.java \
86	XMeaning_impl.java \
87	XPossibleHyphens_impl.java \
88	XSpellAlternatives_impl.java \
89	SampleHyphenator.java \
90	SampleSpellChecker.java \
91	SampleThesaurus.java
92
93CLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(JAVAFILES))
94
95$(COMP1_NAME)_CLASSFILES = XHyphenatedWord_impl.class \
96	XPossibleHyphens_impl.class \
97	PropChgHelper.class \
98	PropChgHelper_Hyph.class \
99	OneInstanceFactory.class \
100	$(COMP1_NAME).class
101
102$(COMP2_NAME)_CLASSFILES = XSpellAlternatives_impl.class \
103	PropChgHelper_Spell.class \
104	PropChgHelper.class \
105	OneInstanceFactory.class \
106	$(COMP2_NAME).class
107
108$(COMP3_NAME)_CLASSFILES = XMeaning_impl.class \
109	OneInstanceFactory.class \
110	$(COMP3_NAME).class
111
112SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
113		$(PATH_SEPARATOR)$(OUT_COMP_CLASS))
114
115.PHONY: ALL
116ALL : $(EXAMPLE_NAME)
117
118include $(SETTINGS)/stdtarget.mk
119
120$(OUT_COMP_CLASS)/%.Manifest :
121	-$(MKDIR) $(subst /,$(PS),$(@D))
122	@echo RegistrationClassName: $(basename $(basename $(@F)))> $@
123
124$(CLASSFILES) : $(JAVAFILES)
125	-$(MKDIR) $(subst /,$(PS),$(@D))
126	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $(JAVAFILES)
127
128# NOTE: because of gnu make problems with full qualified paths, the pattern
129# rules for the component jars and the packages doesn't work proper and we
130# defined explicit rules
131
132# rule for component package manifest
133$(OUT_COMP_CLASS)/%/manifest.xml :
134	-$(MKDIR) $(subst /,$(PS),$(@D))
135	@echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
136	@echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
137	@echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
138	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components$(QM)" >> $@
139	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_CLASS)/,,$(@D))).components$(QM)"/$(CSEP) >> $@
140	@echo $(OSEP)/manifest:manifest$(CSEP) >> $@
141
142$(COMP1_JAR) : $(COMP1_MANIFESTFILE) $(CLASSFILES)
143	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
144	-$(MKDIR) $(subst /,$(PS),$(@D))
145	cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
146
147$(COMP1_PACKAGE) : $(COMP1_JAR) $(COMP1_UNOPKG_MANIFEST) $(COMP1_COMPONENTS)
148	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
149	-$(MKDIR) $(subst /,$(PS),$(@D))
150	$(SDK_ZIP) $@ $(COMP1_COMPONENTS)
151	cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) -u ../../bin/$(@F) $(<F)
152	cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
153
154$(COMP2_JAR) : $(COMP2_MANIFESTFILE) $(CLASSFILES)
155	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
156	-$(MKDIR) $(subst /,$(PS),$(@D))
157	cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
158
159$(COMP2_PACKAGE) : $(COMP2_JAR) $(COMP2_UNOPKG_MANIFEST) $(COMP2_COMPONENTS)
160	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
161	-$(MKDIR) $(subst /,$(PS),$(@D))
162	$(SDK_ZIP) $@ $(COMP2_COMPONENTS)
163	cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) -u ../../bin/$(@F) $(<F)
164	cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
165
166$(COMP3_JAR) : $(COMP3_MANIFESTFILE) $(CLASSFILES)
167	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
168	-$(MKDIR) $(subst /,$(PS),$(@D))
169	cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
170
171$(COMP3_PACKAGE) : $(COMP3_JAR) $(COMP3_UNOPKG_MANIFEST) $(COMP3_COMPONENTS)
172	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
173	-$(MKDIR) $(subst /,$(PS),$(@D))
174	$(SDK_ZIP) $@ $(COMP3_COMPONENTS)
175	cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) -u ../../bin/$(@F) $(<F)
176	cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
177
178$(REGISTERFLAG) : $(COMP1_PACKAGE) $(COMP2_PACKAGE) $(COMP3_PACKAGE)
179ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
180	-$(MKDIR) $(subst /,$(PS),$(@D))
181	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
182	$(DEPLOYTOOL) $(COMP1_PACKAGE_URL)
183	$(DEPLOYTOOL) $(COMP2_PACKAGE_URL)
184	$(DEPLOYTOOL) $(COMP3_PACKAGE_URL)
185	@echo flagged > $(subst /,$(PS),$@)
186else
187	@echo --------------------------------------------------------------------------------
188	@echo  If you want to install your component automatically, please set the environment
189	@echo  variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
190	@echo  possible if no office instance is running.
191	@echo --------------------------------------------------------------------------------
192endif
193
194$(OUT_COMP_CLASS)/%.class : %.java
195	-$(MKDIR) $(subst /,$(PS),$(@D))
196	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $<
197
198$(OUT_COMP_CLASS)/%.mf :
199	-$(MKDIR) $(subst /,$(PS),$(@D))
200	@echo Main-Class: com.sun.star.lib.loader.Loader> $@
201	$(ECHOLINE)>> $@
202	@echo Name: com/sun/star/lib/loader/Loader.class>> $@
203	@echo Application-Class: $*>> $@
204
205$(APP1_JAR) : $(OUT_COMP_CLASS)/$(APP1_NAME).mf $(OUT_COMP_CLASS)/$(APP1_NAME).class
206	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
207	-$(MKDIR) $(subst /,$(PS),$(@D))
208	+cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(basename $(@F)).mf $(basename $(@F)).class $(basename $(@F))$(QUOTE)$$Client.class
209	+$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
210
211
212$(EXAMPLE_NAME) : $(REGISTERFLAG) $(APP1_JAR)
213	@echo --------------------------------------------------------------------------------
214	@echo Please use the following command to execute the example!
215	@echo -
216	@echo $(MAKE) $(APP1_NAME).run
217	@echo --------
218	@echo Before you can run the examples the components "$(QM)$(COMP1_NAME)$(QM)",
219	@echo "$(QM)$(COMP2_NAME)$(QM)" and "$(QM)$(COMP3_NAME)$(QM)" must be deployed.
220	@echo The components will be automatically deployed if SDK_AUTO_DEPLOYMENT = YES.
221	@echo --------------------------------------------------------------------------------
222
223%.run: $(OUT_COMP_CLASS)/%.jar
224	$(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
225
226.PHONY: clean
227clean :
228	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_CLASS))
229	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP1_PACKAGE_URL)))
230	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP2_PACKAGE_URL)))
231	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP3_PACKAGE_URL)))
232	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(REGISTERFLAG)))
233