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 OfficeDevFilter example 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=OfficeDevAsciiFilterExample
33SAMPLE_CLASS_OUT = $(OUT_CLASS)/$(SAMPLE_NAME)
34SAMPLE_GEN_OUT = $(OUT_MISC)/$(SAMPLE_NAME)
35
36COMP_NAME=SampleFilter
37COMP_CLASS_OUT=$(SAMPLE_CLASS_OUT)/$(COMP_NAME)
38COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
39COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
40COMP_JAR_NAME = $(COMP_NAME).uno.jar
41COMP_JAR = $(SAMPLE_CLASS_OUT)/$(COMP_JAR_NAME)
42COMP_MANIFESTFILE = $(SAMPLE_GEN_OUT)/$(COMP_NAME).uno.Manifest
43COMP_UNOPKG_MANIFEST = $(SAMPLE_GEN_OUT)/$(COMP_NAME)/META-INF/manifest.xml
44COMP_REGISTERFLAG = $(SAMPLE_GEN_OUT)/devguide_$(COMP_NAME)_component.flag
45COMP_COMPONENTS=$(COMP_NAME).components
46
47# often the java files are structured in a hierarchy similar to the package,
48# for the example we know the package
49PACKAGE = OfficeDev/samples/Filter
50
51COMP_JAVAFILES  = \
52		   FilterOptions.java \
53		   AsciiReplaceFilter.java
54
55COMP_CLASSFILES = $(patsubst %.java,$(COMP_CLASS_OUT)/$(PACKAGE)/%.class,$(COMP_JAVAFILES))
56
57SDK_CLASSPATH = $(subst $(EMPTYSTRING) $(PATH_SEPARATOR),$(PATH_SEPARATOR),$(CLASSPATH)\
58		$(PATH_SEPARATOR)$(COMP_CLASS_OUT))
59
60
61# Targets
62.PHONY: ALL
63ALL : $(SAMPLE_NAME)
64
65include $(SETTINGS)/stdtarget.mk
66
67$(SAMPLE_GEN_OUT)/%.Manifest :
68	-$(MKDIR) $(subst /,$(PS),$(@D))
69	@echo RegistrationClassName: $(subst /,.,$(PACKAGE)).AsciiReplaceFilter> $@
70
71$(COMP_CLASSFILES) : $(COMP_JAVAFILES)
72	-$(MKDIR) $(subst /,$(PS),$(@D))
73	$(SDK_JAVAC) $(JAVAC_FLAGS) -classpath "$(SDK_CLASSPATH)" -d $(COMP_CLASS_OUT) $(COMP_JAVAFILES)
74
75# rule for component jar file
76$(COMP_JAR) : $(COMP_MANIFESTFILE) $(COMP_CLASSFILES)
77	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
78	-$(MKDIR) $(subst /,$(PS),$(@D))
79	$(SDK_JAR) cvfm $@ $< -C $(COMP_CLASS_OUT) .
80
81# rule for component package manifest
82$(SAMPLE_GEN_OUT)/%/manifest.xml :
83	-$(MKDIR) $(subst /,$(PS),$(@D))
84	@echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
85	@echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
86	@echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
87	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@
88	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)TypeDetection.xcu$(QM)"/$(CSEP) >> $@
89	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components$(QM)">> $@
90	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(COMP_COMPONENTS)$(QM)"/$(CSEP)>> $@
91	@echo $(OSEP)/manifest:manifest$(CSEP) >> $@
92
93# rule for component package file
94$(COMP_PACKAGE) : $(COMP_JAR) TypeDetection.xcu $(COMP_UNOPKG_MANIFEST) $(COMP_COMPONENTS)
95	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
96	-$(MKDIR) $(subst /,$(PS),$(@D))
97	$(SDK_ZIP) $@ TypeDetection.xcu
98	$(SDK_ZIP) -u $@ $(COMP_COMPONENTS)
99	cd $(subst /,$(PS),$(SAMPLE_CLASS_OUT)) && $(SDK_ZIP) -u ../../bin/$(@F) $(<F)
100	cd $(subst /,$(PS),$(SAMPLE_GEN_OUT)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
101
102$(COMP_REGISTERFLAG) : $(COMP_PACKAGE)
103ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
104	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
105	-$(MKDIR) $(subst /,$(PS),$(@D))
106	$(DEPLOYTOOL) $(COMP_PACKAGE_URL)
107	@echo flagged > $(subst /,$(PS),$@)
108else
109	@echo --------------------------------------------------------------------------------
110	@echo  If you want to install your component automatically, please set the environment
111	@echo  variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
112	@echo  possible if no office instance is running.
113	@echo --------------------------------------------------------------------------------
114endif
115
116$(SAMPLE_NAME) : $(COMP_REGISTERFLAG)
117	@echo --------------------------------------------------------------------------------
118	@echo The "$(QM)$(COMP_NAME)$(QM)" Java component was installed if SDK_AUTO_DEPLOYMENT = YES.
119	@echo You can use the "$(QM)ASCII Replace$(QM)" filter in your office installation, see the
120	@echo example description.
121	@echo --------------------------------------------------------------------------------
122
123.PHONY: clean
124clean :
125	-$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_CLASS_OUT))
126	-$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
127	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
128