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
45
46COMP_NAME=JavaComponent
47OUT_COMP_CLASS = $(OUT_CLASS)/$(COMP_NAME)
48OUT_COMP_GEN = $(OUT_MISC)/$(COMP_NAME)
49COMP_RDB_NAME = $(COMP_NAME).uno.rdb
50COMP_RDB = $(OUT_COMP_GEN)/$(COMP_RDB_NAME)
51COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
52COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
53COMP_JAR_NAME = $(COMP_NAME).uno.jar
54COMP_JAR = $(OUT_COMP_CLASS)/$(COMP_JAR_NAME)
55COMP_MANIFESTFILE = $(OUT_COMP_CLASS)/$(COMP_NAME).uno.Manifest
56COMP_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMP_NAME)/META-INF/manifest.xml
57COMP_COMPONENTS=$(COMP_NAME).components
58
59APP1_NAME=TestJavaComponent
60APP1_JAR=$(OUT_COMP_CLASS)/$(APP1_NAME).jar
61
62REGISTERFLAG = $(OUT_MISC)$(PS)devguide_$(COMP_NAME)_register_component.flag
63
64IDLFILES = XSomethingA.idl \
65	XSomethingB.idl \
66	SomethingA.idl \
67	SomethingB.idl
68
69# normally the idl file should be stored in a directory tree fitting the module
70# structure, for the example we know the module structure
71PACKAGE = com/sun/star/test
72
73COMPJAVAFILES  = \
74	   TestComponentA.java \
75	   TestComponentB.java  \
76	   TestServiceProvider.java
77
78GENCLASSFILES = $(patsubst %.idl,$(OUT_COMP_CLASS)/$(PACKAGE)/%.class,$(IDLFILES))
79GENCLASSNAMES = $(patsubst %.idl,$(PACKAGE)/%.class,$(IDLFILES))
80GENTYPELIST = $(subst /,.,$(patsubst %.idl,-T$(PACKAGE)/% ,$(IDLFILES)))
81GENURDFILES = $(patsubst %.idl,$(OUT_COMP_GEN)/%.urd,$(IDLFILES))
82
83COMPCLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(COMPJAVAFILES))
84
85$(COMP_NAME)_CLASSFILES = $(patsubst %.java,%.class,$(COMPJAVAFILES))
86
87$(COMP_NAME)_CLASSFILES += $(subst $(OUT_COMP_CLASS)/,,$(GENCLASSFILES))
88
89SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
90		$(PATH_SEPARATOR)$(OUT_COMP_CLASS))
91
92
93# Targets
94.PHONY: ALL
95ALL : \
96	JavaComponentExample
97
98include $(SETTINGS)/stdtarget.mk
99
100$(OUT_COMP_CLASS)/%.Manifest :
101	-$(MKDIR) $(subst /,$(PS),$(@D))
102	@echo UNO-Type-Path: $(basename $(notdir $*)).uno.jar> $@
103	@echo RegistrationClassName: TestServiceProvider>> $@
104
105$(OUT_COMP_GEN)/%.urd : %.idl
106	-$(MKDIR) $(subst /,$(PS),$(@D))
107	$(IDLC) -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_CLASS)/$(PACKAGE)/%.class : $(COMP_RDB)
115	-$(MKDIR) $(subst /,$(PS),$(@D))
116	$(JAVAMAKER) -BUCR -nD $(GENTYPELIST) -O$(OUT_COMP_CLASS) $(COMP_RDB) -X$(URE_TYPES) -X$(OFFICE_TYPES)
117
118$(OUT_COMP_CLASS)/%.class : %.java $(GENCLASSFILES)
119	-$(MKDIR) $(subst /,$(PS),$(@D))
120	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $<
121
122$(COMPCLASSFILES) : $(COMPJAVAFILES) $(GENCLASSFILES)
123	-$(MKDIR) $(subst /,$(PS),$(@D))
124	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $(COMPJAVAFILES)
125
126# rule for client/example application manifest file
127$(OUT_COMP_CLASS)/%.mf :
128	-$(MKDIR) $(subst /,$(PS),$(@D))
129	@echo Main-Class: com.sun.star.lib.loader.Loader> $@
130	$(ECHOLINE)>> $@
131	@echo Name: com/sun/star/lib/loader/Loader.class>> $@
132	@echo Application-Class: $*>> $@
133
134# rule for client/example application jar file
135# Note that the example needs the component files as well for local usage
136$(APP1_JAR) : $(OUT_COMP_CLASS)/$(APP1_NAME).mf $(OUT_COMP_CLASS)/$(APP1_NAME).class $(COMPCLASSFILES) $(GENCLASSFILES)
137	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
138	-$(MKDIR) $(subst /,$(PS),$(@D))
139	+cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(basename $(@F)).mf $(basename $(@F)).class $($(COMP_NAME)_CLASSFILES)
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_COMPONENTS)$(QM)"/$(CSEP)>> $@
158	@echo $(OSEP)/manifest:manifest$(CSEP) >> $@
159
160# rule for component pacakge file
161$(COMP_PACKAGE) : $(COMP_RDB) $(COMP_JAR) $(COMP_UNOPKG_MANIFEST) $(COMP_COMPONENTS)
162	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
163	-$(MKDIR) $(subst /,$(PS),$(@D))
164	$(COPY) $(subst /,$(PS),$(COMP_RDB)) $(subst /,$(PS),$(OUT_COMP_CLASS))
165	$(SDK_ZIP) $@ $(COMP_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)/$(COMP_RDB_NAME)))
169
170$(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
184JavaComponentExample : $(REGISTERFLAG) $(APP1_JAR)
185	@echo --------------------------------------------------------------------------------
186	@echo Please use one of the following commands to execute the examples!
187	@echo -
188	@echo $(MAKE) $(APP1_NAME).run
189	@echo $(MAKE) $(APP1_NAME).local
190	@echo --------
191	@echo The Java components were installed if SDK_AUTO_DEPLOYMENT = YES.
192	@echo You can use this component inside your office installation, see the
193	@echo example description.
194	@echo --------------------------------------------------------------------------------
195
196%.run: $(OUT_COMP_CLASS)/%.jar
197	$(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
198
199%.local: $(OUT_COMP_CLASS)/%.jar
200	$(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $< local
201
202.PHONY: clean
203clean :
204	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_CLASS))
205	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN))
206	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
207	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(REGISTERFLAG)))
208