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 Minimal component example of the SDK.
36 
37 PRJ=../../..
38 SETTINGS=$(PRJ)/settings
39 
40 include $(SETTINGS)/settings.mk
41 include $(SETTINGS)/std.mk
42 include $(SETTINGS)/dk.mk
43 
44 # Define non-platform/compiler specific settings
45 
46 # we use the sample directory name dor separating this example
47 # from others in the output directory
48 SAMPLE_NAME=MinimalComponent
49 SAMPLE_CLASS_OUT=$(OUT_CLASS)/$(SAMPLE_NAME)
50 SAMPLE_GEN_OUT=$(OUT_MISC)/$(SAMPLE_NAME)
51 
52 COMP_NAME=MinimalComponent
53 COMP_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(COMP_NAME)
54 COMP_GEN_OUT=$(SAMPLE_GEN_OUT)/$(COMP_NAME)
55 COMP_RDB_NAME=$(COMP_NAME).uno.rdb
56 COMP_RDB=$(COMP_GEN_OUT)/$(COMP_RDB_NAME)
57 COMP_PACKAGE=$(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
58 COMP_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
59 COMP_JAR_NAME=$(COMP_NAME).uno.jar
60 COMP_JAR=$(SAMPLE_CLASS_OUT)/$(COMP_JAR_NAME)
61 COMP_JAR_MANIFEST=$(COMP_GEN_OUT)/$(COMP_NAME).uno.Manifest
62 COMP_UNOPKG_MANIFEST = $(COMP_GEN_OUT)/META-INF/manifest.xml
63 COMP_REGISTERFLAG=$(COMP_GEN_OUT)$(PS)java_$(COMP_NAME)_register_component.flag
64 COMP_COMPONENTS=$(COMP_NAME).components
65 
66 APP1_NAME=TestMinimalComponent
67 APP1_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(APP1_NAME)
68 APP1_GEN_OUT=$(SAMPLE_GEN_OUT)/$(APP1_NAME)
69 APP1_JAR=$(SAMPLE_CLASS_OUT)/$(APP1_NAME).jar
70 APP1_JAR_MANIFEST=$(APP1_GEN_OUT)/$(APP1_NAME).mf
71 
72 IDLFILES = MinimalComponent.idl
73 
74 # normally the idl file should be stored in a directory tree fitting the module structure,
75 # for the example we know the module structure
76 PACKAGE = org/openoffice
77 
78 COMP_JAVAFILES  = MinimalComponent.java
79 COMP_CLASSFILES = $(patsubst %.java,$(COMP_CLASS_OUT)/%.class,$(COMP_JAVAFILES))
80 
81 GEN_CLASSFILES = $(patsubst %.idl,$(SAMPLE_CLASS_OUT)/$(PACKAGE)/%.class,$(IDLFILES))
82 GEN_TYPELIST = $(subst /,.,$(patsubst %.idl,-T$(PACKAGE)/% ,$(IDLFILES)))
83 GEN_URDFILES = $(patsubst %.idl,$(SAMPLE_GEN_OUT)/%.urd,$(IDLFILES))
84 
85 # the generated types are necessary for the component and the application jar
86 GEN_CLASSFILENAMES = $(subst $(SAMPLE_CLASS_OUT)/,,$(GEN_CLASSFILES))
87 
88 SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
89 		$(PATH_SEPARATOR)$(SAMPLE_CLASS_OUT)\
90 		$(PATH_SEPARATOR)$(COMP_CLASS_OUT)\
91 		$(PATH_SEPARATOR)$(APP1_CLASS_OUT))
92 
93 
94 # Targets
95 .PHONY: ALL
96 ALL : JavaMinimalComponentExample
97 
98 include $(SETTINGS)/stdtarget.mk
99 
100 $(COMP_GEN_OUT)/%.Manifest :
101 	-$(MKDIR) $(subst /,$(PS),$(@D))
102 	@echo UNO-Type-Path: $(basename $*).uno.jar> $@
103 	@echo RegistrationClassName: $(basename $*)>> $@
104 
105 $(SAMPLE_GEN_OUT)/%.urd : %.idl
106 	-$(MKDIR) $(subst /,$(PS),$(@D))
107 	$(IDLC) -C -I. -I$(IDL_DIR) -O$(SAMPLE_GEN_OUT) $<
108 
109 $(COMP_GEN_OUT)/%.rdb : $(GEN_URDFILES)
110 	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
111 	-$(MKDIR) $(subst /,$(PS),$(@D))
112 	$(REGMERGE) $@ /UCR $(GEN_URDFILES)
113 
114 $(GEN_CLASSFILES) : $(COMP_RDB)
115 	-$(MKDIR) $(subst /,$(PS),$(@D))
116 	$(JAVAMAKER) -BUCR -nD $(GEN_TYPELIST) -O$(SAMPLE_CLASS_OUT) $(COMP_RDB) -X$(URE_TYPES) -X$(OFFICE_TYPES)
117 
118 # component as well as application are dependent from the generated types
119 # rule for component class files
120 $(COMP_CLASS_OUT)/%.class : %.java $(GEN_CLASSFILES)
121 	-$(MKDIR) $(subst /,$(PS),$(@D))
122 	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(COMP_CLASS_OUT) $<
123 
124 # rule for example application class files
125 $(APP1_CLASS_OUT)/%.class : %.java $(GEN_CLASSFILES)
126 	-$(MKDIR) $(subst /,$(PS),$(@D))
127 	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(APP1_CLASS_OUT) $<
128 
129 # rule for client/example application manifest file
130 $(APP1_GEN_OUT)/%.mf :
131 	-$(MKDIR) $(subst /,$(PS),$(@D))
132 	@echo Main-Class: com.sun.star.lib.loader.Loader> $@
133 	$(ECHOLINE)>> $@
134 	@echo Name: com/sun/star/lib/loader/Loader.class>> $@
135 	@echo Application-Class: $*>> $@
136 
137 # rule for client/example application jar file
138 $(APP1_JAR) : $(APP1_JAR_MANIFEST) $(APP1_CLASS_OUT)/$(APP1_NAME).class $(GEN_CLASSFILES)
139 	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
140 	-$(MKDIR) $(subst /,$(PS),$(@D))
141 	$(SDK_JAR) cvfm $@  $< -C $(APP1_CLASS_OUT) .
142 	+cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) uvf $(@F) $(GEN_CLASSFILENAMES)
143 	+$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
144 
145 # rule for component jar file
146 $(COMP_JAR) : $(COMP_JAR_MANIFEST) $(COMP_CLASSFILES)
147 	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
148 	-$(MKDIR) $(subst /,$(PS),$(@D))
149 	$(SDK_JAR) cvfm $@  $< -C $(COMP_CLASS_OUT) .
150 	+cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) uvf $(@F) $(GEN_CLASSFILENAMES)
151 
152 # rule for component package manifest
153 $(COMP_GEN_OUT)/%/manifest.xml :
154 	-$(MKDIR) $(subst /,$(PS),$(@D))
155 	@echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
156 	@echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP)>> $@
157 	@echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP)>> $@
158 	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-typelibrary;type=RDB$(QM)">> $@
159 	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(SAMPLE_GEN_OUT)/,,$(@D))).uno.rdb$(QM)"/$(CSEP)>> $@
160 	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components$(QM)">> $@
161 	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@
162 	@echo $(OSEP)/manifest:manifest$(CSEP) >> $@
163 
164 # rule for component package file
165 $(COMP_PACKAGE) : $(COMP_RDB) $(COMP_JAR) $(COMP_UNOPKG_MANIFEST) $(COMP_NAME).components
166 	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
167 	-$(MKDIR) $(subst /,$(PS),$(@D))
168 	$(SDK_ZIP) $@ $(COMP_NAME).components
169 	cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) -u ../../../bin/$(@F) $(COMP_RDB_NAME)
170 	cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_JAR_NAME)
171 	cd $(subst /,$(PS),$(COMP_GEN_OUT)) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
172 
173 $(COMP_REGISTERFLAG) : $(COMP_PACKAGE)
174 ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
175 	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
176 	-$(MKDIR) $(subst /,$(PS),$(@D))
177 	$(DEPLOYTOOL) $(COMP_PACKAGE_URL)
178 	@echo flagged > $(subst /,$(PS),$@)
179 else
180 	@echo --------------------------------------------------------------------------------
181 	@echo  If you want to install your component automatically, please set the environment
182 	@echo  variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
183 	@echo  possible if no office instance is running.
184 	@echo --------------------------------------------------------------------------------
185 endif
186 
187 JavaMinimalComponentExample : $(COMP_REGISTERFLAG) $(APP1_JAR)
188 	@echo --------------------------------------------------------------------------------
189 	@echo Please use the following command to execute the example!
190 	@echo -
191 	@echo $(MAKE) $(APP1_NAME).run
192 	@echo ------
193 	@echo The $(COMP_NAME) component was installed if SDK_AUTO_DEPLOYMENT = YES.
194 	@echo You can use this component inside your office installation, see the example
195 	@echo description.
196 	@echo --------------------------------------------------------------------------------
197 
198 %.run: $(SAMPLE_CLASS_OUT)/%.jar
199 	$(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
200 
201 .PHONY: clean
202 clean :
203 	-$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT))
204 	-$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
205 	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
206