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 Charts examples of the Developers Guide.
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
32SAMPLE_NAME=DevGuideChartExample
33SAMPLE_CLASS_OUT = $(OUT_CLASS)/$(SAMPLE_NAME)
34SAMPLE_GEN_OUT = $(OUT_MISC)/$(SAMPLE_NAME)
35
36APP1_NAME=ChartInCalc
37APP1_JAR=$(SAMPLE_CLASS_OUT)/$(APP1_NAME).jar
38APP2_NAME=ChartInDraw
39APP2_JAR=$(SAMPLE_CLASS_OUT)/$(APP2_NAME).jar
40APP3_NAME=ChartInWriter
41APP3_JAR=$(SAMPLE_CLASS_OUT)/$(APP3_NAME).jar
42APP4_NAME=ListenAtCalcRangeInDraw
43APP4_JAR=$(SAMPLE_CLASS_OUT)/$(APP4_NAME).jar
44APP5_NAME=SelectionChangeListener
45APP5_JAR=$(SAMPLE_CLASS_OUT)/$(APP5_NAME).jar
46
47COMP_NAME=JavaSampleChartAddIn
48COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
49COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
50COMP_JAR_NAME = $(COMP_NAME).uno.jar
51COMP_JAR = $(SAMPLE_CLASS_OUT)/$(COMP_JAR_NAME)
52COMP_MANIFESTFILE = $(SAMPLE_CLASS_OUT)/$(COMP_NAME).uno.Manifest
53COMP_UNOPKG_MANIFEST = $(SAMPLE_CLASS_OUT)/$(COMP_NAME)/META-INF/manifest.xml
54COMP_REGISTERFLAG = $(SAMPLE_GEN_OUT)/devguide_$(COMP_NAME)_register_component.flag
55COMP_COMPONENTS=$(COMP_NAME).components
56
57COMPJAVAFILES  = \
58	   JavaSampleChartAddIn.java
59
60APP_JAVAFILES  = \
61	   Helper.java \
62	   CalcHelper.java \
63	   ChartHelper.java
64
65COMPCLASSFILES= $(patsubst %.java,$(SAMPLE_CLASS_OUT)/%.class,$(COMPJAVAFILES))
66
67APP_CLASSFILES= $(patsubst %.java,$(SAMPLE_CLASS_OUT)/%.class,$(APP_JAVAFILES))
68APP_CLASSNAMES= $(patsubst %.java,%.class,$(APP_JAVAFILES))
69
70$(COMP_NAME)_CLASSFILES = $(COMP_NAME).class
71
72SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
73		$(PATH_SEPARATOR)$(SAMPLE_CLASS_OUT))
74
75
76# Targets
77.PHONY: ALL
78ALL : $(SAMPLE_NAME)
79
80include $(SETTINGS)/stdtarget.mk
81
82$(SAMPLE_CLASS_OUT)/%.Manifest :
83	-$(MKDIR) $(subst /,$(PS),$(@D))
84	@echo RegistrationClassName: $(basename $(basename $(@F)))> $@
85
86# rule for client/example application class files, explicit dependencies to common
87# java files which are used in all examples.
88$(SAMPLE_CLASS_OUT)/%.class : %.java $(APP_JAVAFILES)
89	-$(MKDIR) $(subst /,$(PS),$(@D))
90	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(SAMPLE_CLASS_OUT) $< $(APP_JAVAFILES)
91
92$(COMPCLASSFILES) : $(JAVAFILES)
93	-$(MKDIR) $(subst /,$(PS),$(@D))
94	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(SAMPLE_CLASS_OUT) $(COMPJAVAFILES)
95
96# rule for client/example application manifest file
97$(SAMPLE_CLASS_OUT)/%.mf :
98	-$(MKDIR) $(subst /,$(PS),$(@D))
99	@echo Main-Class: com.sun.star.lib.loader.Loader> $@
100	$(ECHOLINE)>> $@
101	@echo Name: com/sun/star/lib/loader/Loader.class>> $@
102	@echo Application-Class: $*>> $@
103
104# rule for client/example application jar file
105$(SAMPLE_CLASS_OUT)/%.jar : $(SAMPLE_CLASS_OUT)/%.mf $(SAMPLE_CLASS_OUT)/%.class
106	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
107	-$(MKDIR) $(subst /,$(PS),$(@D))
108	+cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) cvfm $(@F) $*.mf $**.class $(APP_CLASSNAMES)
109
110	+$(SDK_JAR) uvf $@ $(SDK_JAVA_UNO_BOOTSTRAP_FILES)
111
112# rule for component jar file
113$(COMP_JAR) : $(COMP_MANIFESTFILE) $(COMPCLASSFILES)
114	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
115	-$(MKDIR) $(subst /,$(PS),$(@D))
116	cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_JAR) cvfm $(@F) $(<F) $($(basename $(basename $(@F)))_CLASSFILES)
117
118# rule for component package manifest
119$(SAMPLE_CLASS_OUT)/%/manifest.xml :
120	-$(MKDIR) $(subst /,$(PS),$(@D))
121	@echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
122	@echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
123	@echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
124	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components$(QM)">> $@
125	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(COMP_COMPONENTS)$(QM)"/$(CSEP)>> $@
126	@echo $(OSEP)/manifest:manifest$(CSEP) >> $@
127
128# rule for component pacakge file
129$(COMP_PACKAGE) : $(COMP_JAR) $(COMP_UNOPKG_MANIFEST) $(COMP_COMPONENTS)
130	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
131	-$(MKDIR) $(subst /,$(PS),$(@D))
132	$(SDK_ZIP) $@ $(COMP_COMPONENTS)
133	cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) ../../bin/$(@F) -u $(<F)
134	cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) ../../../bin/$(@F) -u META-INF/manifest.xml
135
136$(COMP_REGISTERFLAG) : $(COMP_PACKAGE)
137ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
138	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
139	-$(MKDIR) $(subst /,$(PS),$(@D))
140	$(DEPLOYTOOL) $(COMP_PACKAGE_URL)
141	@echo flagged > $(subst /,$(PS),$@)
142else
143	@echo --------------------------------------------------------------------------------
144	@echo  If you want to install your component automatically, please set the environment
145	@echo  variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
146	@echo  possible if no office instance is running.
147	@echo --------------------------------------------------------------------------------
148endif
149
150$(APP1_JAR) : $(SAMPLE_CLASS_OUT)/$(APP1_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP1_NAME).class
151$(APP2_JAR) : $(SAMPLE_CLASS_OUT)/$(APP2_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP2_NAME).class
152$(APP3_JAR) : $(SAMPLE_CLASS_OUT)/$(APP3_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP3_NAME).class
153$(APP4_JAR) : $(SAMPLE_CLASS_OUT)/$(APP4_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP4_NAME).class
154$(APP5_JAR) : $(SAMPLE_CLASS_OUT)/$(APP5_NAME).mf $(SAMPLE_CLASS_OUT)/$(APP5_NAME).class
155
156$(SAMPLE_NAME) : $(COMP_REGISTERFLAG) $(APP1_JAR)  $(APP2_JAR)  $(APP3_JAR)  $(APP4_JAR)  $(APP5_JAR)
157	@echo --------------------------------------------------------------------------------
158	@echo When you run the "$(QM)$(APP5_NAME)$(QM)" example please select the
159	@echo legend or the title to add a $(APP5_NAME). The example terminates
160	@echo when the document is closed.
161	@echo -
162	@echo Please use the following commands to execute the examples!
163	@echo -
164	@echo $(MAKE) $(APP1_NAME).run
165	@echo $(MAKE) $(APP2_NAME).run
166	@echo $(MAKE) $(APP3_NAME).run
167	@echo $(MAKE) $(APP4_NAME).run
168	@echo $(MAKE) $(APP5_NAME).run
169	@echo --------
170	@echo The Chart add-in component was installed if SDK_AUTO_DEPLOYMENT = YES.
171	@echo Load the "$(QM)AddInChart.ods$(QM)" document in your office to see the new chart type,
172	@echo and see the example description.
173	@echo -
174	@echo $(MAKE) AddInChart.ods.load
175	@echo --------------------------------------------------------------------------------
176
177%.run: $(SAMPLE_CLASS_OUT)/%.jar
178	$(SDK_JAVA) -Dcom.sun.star.lib.loader.unopath="$(OFFICE_PROGRAM_PATH)" -jar $<
179
180AddInChart.ods.load : $(REGISTERFLAG)
181	"$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@)
182
183.PHONY: clean
184clean :
185	-$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT))
186	-$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
187	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
188