1#**************************************************************
2#
3#  Licensed to the Apache Software Foundation (ASF) under one
4#  or more contributor license agreements.  See the NOTICE file
5#  distributed with this work for additional information
6#  regarding copyright ownership.  The ASF licenses this file
7#  to you under the Apache License, Version 2.0 (the
8#  "License"); you may not use this file except in compliance
9#  with the License.  You may obtain a copy of the License at
10#
11#    http://www.apache.org/licenses/LICENSE-2.0
12#
13#  Unless required by applicable law or agreed to in writing,
14#  software distributed under the License is distributed on an
15#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16#  KIND, either express or implied.  See the License for the
17#  specific language governing permissions and limitations
18#  under the License.
19#
20#**************************************************************
21
22# Builds the Java Spreadsheet examples of the SDK.
23
24PRJ=../../..
25SETTINGS=$(PRJ)/settings
26
27include $(SETTINGS)/settings.mk
28include $(SETTINGS)/std.mk
29include $(SETTINGS)/dk.mk
30
31# Define non-platform/compiler specific settings
32EXAMPLE_NAME=JavaSpreadsheetExamples
33OUT_COMP_CLASS = $(OUT_CLASS)/$(EXAMPLE_NAME)
34OUT_COMP_GEN = $(OUT_MISC)/$(EXAMPLE_NAME)
35
36APP1_NAME=EuroAdaption
37APP1_JAR=$(OUT_COMP_CLASS)/$(APP1_NAME).jar
38APP2_NAME=SCalc
39APP2_JAR=$(OUT_COMP_CLASS)/$(APP2_NAME).jar
40APP3_NAME=ChartTypeChange
41APP3_JAR=$(OUT_COMP_CLASS)/$(APP3_NAME).jar
42
43COMP_NAME=CalcAddins
44COMP_RDB_NAME=$(COMP_NAME).uno.rdb
45COMP_RDB=$(OUT_COMP_GEN)/$(COMP_RDB_NAME)
46COMP_PACKAGE=$(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
47COMP_PACKAGE_URL=$(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
48COMP_JAR_NAME=$(COMP_NAME).uno.jar
49COMP_JAR=$(OUT_COMP_CLASS)/$(COMP_JAR_NAME)
50COMP_MANIFESTFILE=$(OUT_COMP_CLASS)/$(COMP_NAME).uno.Manifest
51COMP_UNOPKG_MANIFEST = $(OUT_COMP_CLASS)/$(COMP_NAME)/META-INF/manifest.xml
52COMP_REGISTERFLAG=$(OUT_MISC)$(PS)java_$(COMP_NAME)_register_component.flag
53COMP_COMPONENTS=$(COMP_NAME).components
54
55IDLFILES = XCalcAddins.idl
56
57# normally the idl file should be stored in a directory tree fitting the module structure,
58# for the example we know the module structure
59PACKAGE = org/openoffice/sheet/addin
60
61COMPJAVAFILES  = CalcAddins.java
62
63#GENJAVAFILES = $(patsubst %.idl,$(OUT_COMP_GEN)/$(PACKAGE)/%.java,$(IDLFILES))
64GENCLASSFILES = $(patsubst %.idl,$(OUT_COMP_CLASS)/$(PACKAGE)/%.class,$(IDLFILES))
65GENTYPELIST = $(subst /,.,$(patsubst %.idl,-T$(PACKAGE)/% ,$(IDLFILES)))
66GENURDFILES = $(patsubst %.idl,$(OUT_COMP_GEN)/%.urd,$(IDLFILES))
67
68COMPCLASSFILES = $(patsubst %.java,$(OUT_COMP_CLASS)/%.class,$(COMPJAVAFILES))
69#COMPCLASSFILES += $(subst $(OUT_COMP_GEN),$(OUT_COMP_CLASS),$(GENJAVAFILES:.java=.class))
70
71$(COMP_NAME)_CLASSFILES = $(COMP_NAME).class \
72		$(COMP_NAME)$(QUOTE)$$_$(COMP_NAME).class
73
74#$(COMP_NAME)_CLASSFILES += $(subst $(OUT_COMP_GEN)/,,$(GENJAVAFILES:.java=.class))
75$(COMP_NAME)_CLASSFILES += $(subst $(OUT_COMP_CLASS)/,,$(GENCLASSFILES))
76
77SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
78		$(PATH_SEPARATOR)$(OUT_COMP_CLASS))
79
80# Targets
81.PHONY: ALL
82ALL : $(EXAMPLE_NAME)
83
84include $(SETTINGS)/stdtarget.mk
85
86# rule for a component manifest file
87$(OUT_COMP_CLASS)/%.Manifest :
88	-$(MKDIR) $(subst /,$(PS),$(@D))
89	@echo UNO-Type-Path: $(basename $*).uno.jar> $@
90	@echo RegistrationClassName: $(basename $*)>> $@
91
92$(OUT_COMP_GEN)/%.urd : %.idl
93	-$(MKDIR) $(subst /,$(PS),$(@D))
94	$(IDLC) -C -I. -I$(IDL_DIR) -O$(OUT_COMP_GEN) $<
95
96$(OUT_COMP_GEN)/%.rdb : $(GENURDFILES)
97	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
98	-$(MKDIR) $(subst /,$(PS),$(@D))
99	$(REGMERGE) $@ /UCR $(GENURDFILES)
100
101#$(OUT_COMP_GEN)/%.java : $(COMP_RDB)
102$(GENCLASSFILES) : $(COMP_RDB)
103	-$(MKDIR) $(subst /,$(PS),$(@D))
104	$(JAVAMAKER) -BUCR -nD $(GENTYPELIST) -O$(OUT_COMP_CLASS) $(COMP_RDB) -X$(URE_TYPES) -X$(OFFICE_TYPES)
105
106$(OUT_COMP_CLASS)/%.class : %.java
107	-$(MKDIR) $(subst /,$(PS),$(@D))
108	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $<
109
110# only the component depends on the generated types
111$(COMPCLASSFILES) : $(JAVAFILES) $(GENCLASSFILES)
112	-$(MKDIR) $(subst /,$(PS),$(@D))
113	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(OUT_COMP_CLASS) $(COMPJAVAFILES)
114
115# rule for client/example application manifest file
116$(OUT_COMP_CLASS)/%.mf :
117	-$(MKDIR) $(subst /,$(PS),$(@D))
118	@echo Main-Class: com.sun.star.lib.loader.Loader> $@
119	$(ECHOLINE)>> $@
120	@echo Name: com/sun/star/lib/loader/Loader.class>> $@
121	@echo Application-Class: $*>> $@
122
123# rule for client/example application jar file
124$(OUT_COMP_CLASS)/%.jar : $(OUT_COMP_CLASS)/%.mf $(OUT_COMP_CLASS)/%.class
125	-$(MKDIR) $(subst /,$(PS),$(@D))
126	+cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $*.mf $*.class
127	+$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
128
129# rule for component jar file
130$(COMP_JAR) : $(COMP_MANIFESTFILE) $(COMPCLASSFILES)
131	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
132	-$(MKDIR) $(subst /,$(PS),$(@D))
133	cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
134
135# rule for component package manifest
136$(OUT_COMP_CLASS)/%/manifest.xml :
137	-$(MKDIR) $(subst /,$(PS),$(@D))
138	@echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
139	@echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
140	@echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
141	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-typelibrary;type=RDB$(QM)" >> $@
142	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(OUT_COMP_CLASS)/,,$(@D))).uno.rdb$(QM)"/$(CSEP) >> $@
143	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components$(QM)">> $@
144	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@
145	@echo $(OSEP)/manifest:manifest$(CSEP) >> $@
146
147# rule for component package file
148$(COMP_PACKAGE) : $(COMP_RDB) $(COMP_JAR) $(COMP_UNOPKG_MANIFEST) $(COMP_NAME).components
149	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
150	-$(MKDIR) $(subst /,$(PS),$(@D))
151	$(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(OUT_COMP_CLASS))
152	$(SDK_ZIP) $@ -u $(COMP_NAME).components
153	cd $(subst /,$(PS),$(OUT_COMP_CLASS)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_RDB_NAME) $(COMP_JAR_NAME)
154	cd $(subst /,$(PS),$(OUT_COMP_CLASS)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
155	$(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_COMP_CLASS)/$(<F)))
156
157$(COMP_REGISTERFLAG) : $(COMP_PACKAGE)
158ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
159	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
160	-$(MKDIR) $(subst /,$(PS),$(@D))
161	$(DEPLOYTOOL) $(COMP_PACKAGE_URL)
162	@echo flagged > $(subst /,$(PS),$@)
163else
164	@echo --------------------------------------------------------------------------------
165	@echo  If you want to install your component automatically, please set the environment
166	@echo  variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
167	@echo  possible if no office instance is running.
168	@echo --------------------------------------------------------------------------------
169endif
170
171$(APP1_JAR) : $(OUT_COMP_CLASS)/$(APP1_NAME).mf $(OUT_COMP_CLASS)/$(APP1_NAME).class
172$(APP2_JAR) : $(OUT_COMP_CLASS)/$(APP2_NAME).mf $(OUT_COMP_CLASS)/$(APP2_NAME).class
173$(APP3_JAR) : $(OUT_COMP_CLASS)/$(APP3_NAME).mf $(OUT_COMP_CLASS)/$(APP3_NAME).class
174
175$(EXAMPLE_NAME) : $(COMP_REGISTERFLAG) $(APP1_JAR) $(APP2_JAR) $(APP3_JAR)
176	@echo --------------------------------------------------------------------------------
177	@echo Please use the following command to execute the examples!
178	@echo -
179	@echo $(MAKE) EuroAdaption.run
180	@echo $(MAKE) SCalc.run
181	@echo $(MAKE) ChartTypeChange.run
182	@echo --------------------------------------------------------------------------------
183	@echo The Calc add-in component was installed if SDK_AUTO_DEPLOYMENT = YES.
184	@echo You can use this component inside your office installation, see the example
185	@echo description. You can also load the "$(QM)CalcAddins.ods$(QM)" document to see
186	@echo how the add-in functions works.
187	@echo -
188	@echo $(MAKE) CalcAddins.ods.load
189	@echo --------------------------------------------------------------------------------
190
191%.run: $(OUT_COMP_CLASS)/%.jar
192	$(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
193
194CalcAddins.ods.load : $(COMP_REGISTERFLAG)
195	"$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@)
196
197.PHONY: clean
198clean :
199	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_CLASS))
200	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN))
201	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
202	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_REGISTERFLAG)))
203