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 #*************************************************************************
23 #
24 #  The Contents of this file are made available subject to the terms of
25 #  the BSD license.
26 #
27 #  Copyright 2000, 2010 Oracle and/or its affiliates.
28 #  All rights reserved.
29 #
30 #  Redistribution and use in source and binary forms, with or without
31 #  modification, are permitted provided that the following conditions
32 #  are met:
33 #  1. Redistributions of source code must retain the above copyright
34 #     notice, this list of conditions and the following disclaimer.
35 #  2. Redistributions in binary form must reproduce the above copyright
36 #     notice, this list of conditions and the following disclaimer in the
37 #     documentation and/or other materials provided with the distribution.
38 #  3. Neither the name of Sun Microsystems, Inc. nor the names of its
39 #     contributors may be used to endorse or promote products derived
40 #     from this software without specific prior written permission.
41 #
42 #  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
43 #  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
44 #  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
45 #  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
46 #  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
47 #  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
48 #  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
49 #  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
50 #  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
51 #  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
52 #  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
53 #
54 #**************************************************************************
55 
56 # Builds the ProtocolHandlerAddon C++ component example of the SDK.
57 
58 PRJ=../../../../..
59 SETTINGS=$(PRJ)/settings
60 
61 include $(SETTINGS)/settings.mk
62 include $(SETTINGS)/std.mk
63 include $(SETTINGS)/dk.mk
64 
65 # Define non-platform/compiler specific settings
66 COMP_NAME=ProtocolHandlerAddon_cpp
67 COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT)
68 OUT_COMP_INC=$(OUT_INC)/$(COMP_NAME)
69 OUT_COMP_GEN=$(OUT_MISC)/$(COMP_NAME)
70 OUT_COMP_SLO=$(OUT_SLO)/$(COMP_NAME)
71 COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
72 COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
73 COMP_UNOPKG_MANIFEST = $(OUT_COMP_GEN)/$(COMP_NAME)/META-INF/manifest.xml
74 #COMP_MAPFILE = $(OUT_COMP_GEN)/$(COMP_NAME).uno.map
75 COMP_COMPONENTS = $(OUT_COMP_GEN)/$(COMP_NAME).components
76 
77 REGISTERFLAG = $(OUT_MISC)/cpp_$(COMP_NAME)_register_component.flag
78 
79 CXXFILES = component.cxx \
80 	   addon.cxx
81 
82 SLOFILES = $(patsubst %.cxx,$(OUT_COMP_SLO)/%.$(OBJ_EXT),$(CXXFILES))
83 
84 # Targets
85 .PHONY: ALL
86 ALL : \
87 	Example
88 
89 include $(SETTINGS)/stdtarget.mk
90 
91 $(OUT_COMP_SLO)/%.$(OBJ_EXT) : %.cxx $(SDKTYPEFLAG)
92 	-$(MKDIR) $(subst /,$(PS),$(@D))
93 	$(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $<
94 
95 #$(COMP_MAPFILE) : $(SLOFILES)
96 #	-$(MKDIR) $(subst /,$(PS),$(@D))
97 #	cat $(PRJ)/settings/component.uno.map > $(COMP_MAPFILE)
98 #ifeq "$(OS)" "MACOSX"
99 #	nm -gx $(SLOFILES) | $(ADDSYMBOLS) >> $(COMP_MAPFILE)
100 #endif
101 
102 ifeq "$(OS)" "WIN"
103 $(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES)
104 	-$(MKDIR) $(subst /,$(PS),$(@D))
105 	-$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN))
106 	$(LINK) $(COMP_LINK_FLAGS) /OUT:$@ \
107 	/MAP:$(OUT_COMP_GEN)/$(subst $(SHAREDLIB_EXT),map,$(@F)) $(SLOFILES) \
108 	$(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) msvcrt.lib kernel32.lib
109 	$(LINK_MANIFEST)
110 else
111 #$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) $(COMP_MAPFILE)
112 $(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES)
113 	-$(MKDIR) $(subst /,$(PS),$(@D))
114 	$(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \
115 	$(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) $(STC++LIB) $(CPPUHELPERDYLIB) $(CPPUDYLIB) $(SALDYLIB)
116 ifeq "$(OS)" "MACOSX"
117 	$(INSTALL_NAME_URELIBS)  $@
118 endif
119 endif
120 
121 # rule for component package manifest
122 $(OUT_COMP_GEN)/%/manifest.xml :
123 	-$(MKDIR) $(subst /,$(PS),$(@D))
124 	@echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
125 	@echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
126 	@echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
127 	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@
128 	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)Addons.xcu$(QM)"/$(CSEP) >> $@
129 	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.configuration-data$(QM)" >> $@
130 	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)ProtocolHandler.xcu$(QM)"/$(CSEP) >> $@
131 	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components;platform=$(UNOPKG_PLATFORM)$(QM)">> $@
132 	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@
133 	@echo $(OSEP)/manifest:manifest$(CSEP) >> $@
134 
135 $(COMP_COMPONENTS) :
136 	-$(MKDIR) $(subst /,$(PS),$(@D))
137 	@echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
138 	@echo $(OSEP)components xmlns="$(QM)http://openoffice.org/2010/uno-components$(QM)"$(CSEP) >> $@
139 	@echo $(SQM)  $(SQM)$(OSEP)component loader="$(QM)com.sun.star.loader.SharedLibrary$(QM)" uri="$(QM)$(UNOPKG_PLATFORM)/$(COMP_IMPL_NAME)$(QM)"$(CSEP) >> $@
140 	@echo $(SQM)    $(SQM)$(OSEP)implementation name="$(QM)org.openoffice.Office.addon.example$(QM)"$(CSEP) >> $@
141 	@echo $(SQM)      $(SQM)$(OSEP)service name="$(QM)com.sun.star.frame.ProtocolHandler$(QM)"/$(CSEP) >> $@
142 	@echo $(SQM)    $(SQM)$(OSEP)/implementation$(CSEP) >> $@
143 	@echo $(SQM)  $(SQM)$(OSEP)/component$(CSEP) >> $@
144 	@echo $(OSEP)/components$(CSEP) >> $@
145 
146 # rule for component package file
147 $(COMP_PACKAGE) : $(SHAREDLIB_OUT)/$(COMP_IMPL_NAME) Addons.xcu ProtocolHandler.xcu $(COMP_UNOPKG_MANIFEST) $(COMP_COMPONENTS)
148 	-$(MKDIR) $(subst /,$(PS),$(@D)) && $(DEL) $(subst \\,\,$(subst /,$(PS),$@))
149 	-$(MKDIR) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM))
150 	$(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(OUT_COMP_GEN)/$(UNOPKG_PLATFORM))
151 	cd $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) ../../bin/$(@F) $(COMP_NAME).components
152 	cd $(subst /,$(PS),$(OUT_COMP_GEN)) && $(SDK_ZIP) -u ../../bin/$(@F) $(UNOPKG_PLATFORM)/$(<F)
153 	$(SDK_ZIP) -u $@ Addons.xcu ProtocolHandler.xcu
154 	cd $(subst /,$(PS),$(OUT_COMP_GEN)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
155 
156 $(REGISTERFLAG) : $(COMP_PACKAGE)
157 ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
158 	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
159 	$(DEPLOYTOOL) $(COMP_PACKAGE_URL)
160 	@echo flagged > $(subst /,$(PS),$@)
161 else
162 	@echo --------------------------------------------------------------------------------
163 	@echo  If you want to install your component automatically, please set the environment
164 	@echo  variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
165 	@echo  possible if no office instance is running.
166 	@echo --------------------------------------------------------------------------------
167 endif
168 
169 Example : $(REGISTERFLAG)
170 	@echo --------------------------------------------------------------------------------
171 	@echo The "$(QM)ProtocolHandler$(QM)" addon component was installed if SDK_AUTO_DEPLOYMENT = YES.
172 	@echo You can use this component inside your office installation, see the example
173 	@echo description.
174 	@echo --------------------------------------------------------------------------------
175 
176 .PHONY: clean
177 clean :
178 	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_INC))
179 	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_GEN))
180 	-$(DELRECURSIVE) $(subst /,$(PS),$(OUT_COMP_SLO))
181 	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_PACKAGE_URL)))
182 	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_COMPONENTS)))
183 	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(REGISTERFLAG)))
184 	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(SHAREDLIB_OUT)/$(COMP_NAME).*))
185