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 C++ component example of the Developers Guide.
36
37PRJ=../../../..
38SETTINGS=$(PRJ)/settings
39
40include $(SETTINGS)/settings.mk
41include $(SETTINGS)/std.mk
42include $(SETTINGS)/dk.mk
43
44# Define non-platform/compiler specific settings
45SAMPLE_NAME=CppComponentSample
46SAMPLE_INC_OUT=$(OUT_INC)/$(SAMPLE_NAME)
47SAMPLE_GEN_OUT=$(OUT_MISC)/$(SAMPLE_NAME)
48SAMPLE_SLO_OUT=$(OUT_SLO)/$(SAMPLE_NAME)
49SAMPLE_OBJ_OUT=$(OUT_OBJ)/$(SAMPLE_NAME)
50
51COMP_NAME=CppComponent
52COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT)
53
54APP1_NAME= TestCppComponent
55APP1_BINARY= $(OUT_BIN)/$(APP1_NAME)$(EXE_EXT)
56
57COMP_RDB_NAME = $(COMP_NAME).uno.rdb
58COMP_RDB = $(SAMPLE_GEN_OUT)/$(COMP_RDB_NAME)
59COMP_PACKAGE = $(OUT_BIN)/$(COMP_NAME).$(UNOOXT_EXT)
60COMP_PACKAGE_URL = $(subst \\,\,"$(COMP_PACKAGE_DIR)$(PS)$(COMP_NAME).$(UNOOXT_EXT)")
61COMP_UNOPKG_MANIFEST = $(SAMPLE_GEN_OUT)/$(COMP_NAME)/META-INF/manifest.xml
62#COMP_MAPFILE = $(SAMPLE_GEN_OUT)/$(COMP_NAME).uno.map
63COMP_COMPONENTS = $(SAMPLE_GEN_OUT)/$(COMP_NAME).components
64
65COMP_REGISTERFLAG = $(SAMPLE_GEN_OUT)/devguide_$(COMP_NAME)_register_component.flag
66COMP_TYPEFLAG = $(SAMPLE_GEN_OUT)/devguide_$(COMP_NAME)_types.flag
67
68IDLFILES = some.idl
69
70CXXFILES = service1_impl.cxx \
71	service2_impl.cxx
72
73SLOFILES = $(patsubst %.cxx,$(SAMPLE_SLO_OUT)/%.$(OBJ_EXT),$(CXXFILES))
74
75GENURDFILES = $(patsubst %.idl,$(SAMPLE_GEN_OUT)/%.urd,$(IDLFILES))
76
77TYPELIST=-Tmy_module.XSomething  \
78	-Tmy_modules.MyService1 \
79	-Tmy_module.MyService2
80
81# Targets
82.PHONY: ALL
83ALL : \
84	$(SAMPLE_NAME)
85
86include $(SETTINGS)/stdtarget.mk
87
88$(SAMPLE_GEN_OUT)/%.urd : %.idl
89	-$(MKDIR) $(subst /,$(PS),$(@D))
90	$(IDLC) -I. -I$(IDL_DIR) -O$(SAMPLE_GEN_OUT) $<
91
92$(SAMPLE_GEN_OUT)/%.rdb : $(GENURDFILES)
93	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
94	-$(MKDIR) $(subst /,$(PS),$(@D))
95	$(REGMERGE) $@ /UCR $(GENURDFILES)
96
97$(COMP_TYPEFLAG) : $(COMP_RDB) $(SDKTYPEFLAG)
98	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
99	-$(MKDIR) $(subst /,$(PS),$(@D))
100	$(CPPUMAKER) -Gc -BUCR -O$(SAMPLE_INC_OUT) $(TYPESLIST) $(COMP_RDB) -X$(URE_TYPES) -X$(OFFICE_TYPES)
101	echo flagged > $@
102
103$(SAMPLE_SLO_OUT)/%.$(OBJ_EXT) : %.cxx $(COMP_TYPEFLAG)
104	-$(MKDIR) $(subst /,$(PS),$(@D))
105	$(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(SAMPLE_INC_OUT) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $<
106
107#$(COMP_MAPFILE) : $(SLOFILES)
108#	-$(MKDIR) $(subst /,$(PS),$(@D))
109#	cat $(PRJ)/settings/component.uno.map > $(COMP_MAPFILE)
110#ifeq "$(OS)" "MACOSX"
111#	nm -gx $(SLOFILES) | $(ADDSYMBOLS) >> $(COMP_MAPFILE)
112#endif
113
114ifeq "$(OS)" "WIN"
115$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES)
116	-$(MKDIR) $(subst /,$(PS),$(@D))
117	-$(MKDIR) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
118	$(LINK) $(COMP_LINK_FLAGS) /OUT:$@ \
119	/MAP:$(SAMPLE_GEN_OUT)/$(subst $(SHAREDLIB_EXT),map,$(@F)) $(SLOFILES) \
120	$(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) msvcrt.lib kernel32.lib
121	$(LINK_MANIFEST)
122else
123#$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) $(COMP_MAPFILE)
124$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES)
125	-$(MKDIR) $(subst /,$(PS),$(@D)) && $(DEL) $(subst \\,\,$(subst /,$(PS),$@))
126	$(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \
127	$(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) $(STC++LIB) $(CPPUHELPERDYLIB) $(CPPUDYLIB) $(SALDYLIB)
128ifeq "$(OS)" "MACOSX"
129	$(INSTALL_NAME_URELIBS)  $@
130endif
131endif
132
133# rule for component package manifest
134$(SAMPLE_GEN_OUT)/%/manifest.xml :
135	-$(MKDIR) $(subst /,$(PS),$(@D))
136	@echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
137	@echo $(OSEP)!DOCTYPE manifest:manifest PUBLIC "$(QM)-//OpenOffice.org//DTD Manifest 1.0//EN$(QM)" "$(QM)Manifest.dtd$(QM)"$(CSEP) >> $@
138	@echo $(OSEP)manifest:manifest xmlns:manifest="$(QM)http://openoffice.org/2001/manifest$(QM)"$(CSEP) >> $@
139	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-typelibrary;type=RDB$(QM)" >> $@
140	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(subst /META-INF,,$(subst $(SAMPLE_GEN_OUT)/,,$(@D))).uno.rdb$(QM)"/$(CSEP) >> $@
141	@echo $(SQM)  $(SQM)$(OSEP)manifest:file-entry manifest:media-type="$(QM)application/vnd.sun.star.uno-components;platform=$(UNOPKG_PLATFORM)$(QM)">> $@
142	@echo $(SQM)                       $(SQM)manifest:full-path="$(QM)$(COMP_NAME).components$(QM)"/$(CSEP)>> $@
143	@echo $(OSEP)/manifest:manifest$(CSEP) >> $@
144
145$(COMP_COMPONENTS) :
146	-$(MKDIR) $(subst /,$(PS),$(@D))
147	@echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@
148	@echo $(OSEP)components xmlns="$(QM)http://openoffice.org/2010/uno-components$(QM)"$(CSEP) >> $@
149	@echo $(SQM)  $(SQM)$(OSEP)component loader="$(QM)com.sun.star.loader.SharedLibrary$(QM)" uri="$(QM)$(UNOPKG_PLATFORM)/$(COMP_IMPL_NAME)$(QM)"$(CSEP) >> $@
150	@echo $(SQM)    $(SQM)$(OSEP)implementation name="$(QM)my_module.my_sc_implementation.MyService1$(QM)"$(CSEP) >> $@
151	@echo $(SQM)      $(SQM)$(OSEP)service name="$(QM)my_module.MyService1$(QM)"/$(CSEP) >> $@
152	@echo $(SQM)    $(SQM)$(OSEP)/implementation$(CSEP) >> $@
153	@echo $(SQM)    $(SQM)$(OSEP)implementation name="$(QM)my_module.my_sc_implementation.MyService2$(QM)"$(CSEP) >> $@
154	@echo $(SQM)      $(SQM)$(OSEP)service name="$(QM)my_module.MyService2$(QM)"/$(CSEP) >> $@
155	@echo $(SQM)    $(SQM)$(OSEP)/implementation$(CSEP) >> $@
156	@echo $(SQM)  $(SQM)$(OSEP)/component$(CSEP) >> $@
157	@echo $(OSEP)/components$(CSEP) >> $@
158
159$(COMP_PACKAGE) : $(SHAREDLIB_OUT)/$(COMP_IMPL_NAME) $(COMP_RDB) $(COMP_UNOPKG_MANIFEST) $(COMP_COMPONENTS)
160	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
161	-$(MKDIR) $(subst /,$(PS),$(@D))
162	-$(MKDIR) $(subst /,$(PS),$(SAMPLE_GEN_OUT)/$(UNOPKG_PLATFORM))
163	$(COPY) $(subst /,$(PS),$<) $(subst /,$(PS),$(SAMPLE_GEN_OUT)/$(UNOPKG_PLATFORM))
164	cd $(subst /,$(PS),$(SAMPLE_GEN_OUT)) && $(SDK_ZIP) ../../bin/$(@F) $(COMP_NAME).components
165	cd $(subst /,$(PS),$(SAMPLE_GEN_OUT)) && $(SDK_ZIP) -u ../../bin/$(@F) $(COMP_RDB_NAME) $(UNOPKG_PLATFORM)/$(<F)
166	cd $(subst /,$(PS),$(SAMPLE_GEN_OUT)/$(subst .$(UNOOXT_EXT),,$(@F))) && $(SDK_ZIP) -u ../../../bin/$(@F) META-INF/manifest.xml
167
168
169$(COMP_REGISTERFLAG) : $(COMP_PACKAGE)
170ifeq "$(SDK_AUTO_DEPLOYMENT)" "YES"
171	-$(DEL) $(subst \\,\,$(subst /,$(PS),$@))
172	-$(MKDIR) $(subst /,$(PS),$(@D))
173	$(DEPLOYTOOL) $(COMP_PACKAGE_URL)
174	@echo flagged > $(subst /,$(PS),$@)
175else
176	@echo --------------------------------------------------------------------------------
177	@echo  If you want to install your component automatically, please set the environment
178	@echo  variable SDK_AUTO_DEPLOYMENT = YES. But note that auto deployment is only
179	@echo  possible if no office instance is running.
180	@echo --------------------------------------------------------------------------------
181endif
182
183$(SAMPLE_OBJ_OUT)/$(APP1_NAME).$(OBJ_EXT) : $(APP1_NAME).cxx $(COMP_TYPEFLAG)
184	-$(MKDIR) $(subst /,$(PS),$(@D))
185	$(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(SAMPLE_INC_OUT) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $<
186
187$(OUT_BIN)/_$(APP1_NAME)$(EXE_EXT) : $(SAMPLE_OBJ_OUT)/$(APP1_NAME).$(OBJ_EXT)
188	-$(MKDIR) $(subst /,$(PS),$(@D))
189	-$(MKDIR) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
190ifeq "$(OS)" "WIN"
191	$(LINK) $(EXE_LINK_FLAGS) /OUT:$@ /MAP:$(SAMPLE_GEN_OUT)/$(basename $(@F)).map \
192	  $< $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) $(STLPORTLIB)
193else
194	$(LINK) $(EXE_LINK_FLAGS) $(LINK_LIBS) -o $@ $< \
195	  $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) $(STLPORTLIB) $(STDC++LIB) $(CPPUHELPERDYLIB) $(CPPUDYLIB) $(SALHELPERDYLIB) $(SALDYLIB)
196ifeq "$(OS)" "MACOSX"
197	$(INSTALL_NAME_URELIBS_BIN)  $@
198endif
199endif
200
201$(OUT_BIN)/$(APP1_NAME)$(EXE_EXT) : $(OUT_BIN)/_$(APP1_NAME)$(EXE_EXT)
202	$(COPY) $(subst /,$(PS),$(BIN_DIR)/unoapploader$(EXE_EXT)) $(subst /,$(PS),$@)
203# touch the target to renew the date for correct dependencies.
204# Note: no touch under windows! The unoapploader.exe is copied always.
205ifneq "$(OS)" "WIN"
206	touch $@
207endif
208
209$(SAMPLE_NAME) : $(COMP_REGISTERFLAG) $(APP1_BINARY)
210	@echo --------------------------------------------------------------------------------
211	@echo Please use the following command to execute the example!
212	@echo -
213	@echo $(MAKE) $(APP1_NAME).run
214	@echo --------
215	@echo The simple C++ component was installed if SDK_AUTO_DEPLOYMENT = YES.
216	@echo You can use this component inside your office installation, see the example
217	@echo description. You can also load the "$(QM)SimpleComponent.odt$(QM)" document containing
218	@echo a StarBasic macro which uses this component.
219	@echo -
220	@echo $(MAKE) SimpleComponent.odt.load
221	@echo --------------------------------------------------------------------------------
222
223%.run: $(OUT_BIN)/%$(EXE_EXT)
224	$(subst /,$(PS),$(OUT_BIN))$(PS)$(basename $@)
225#	cd $(subst /,$(PS),$(OUT_BIN)) && $(basename $@)
226
227SimpleComponent.odt.load : $(COMP_REGISTERFLAG)
228	"$(OFFICE_PROGRAM_PATH)$(PS)soffice" $(basename $@)
229
230.PHONY: clean
231clean :
232	-$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_INC_OUT))
233	-$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_GEN_OUT))
234	-$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_SLO_OUT))
235	-$(DELRECURSIVE) $(subst /,$(PS),$(SAMPLE_OBJ_OUT))
236	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_COMPONENTS)))
237	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_BIN)/$(COMP_NAME)*))
238	-$(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_BIN)/*$(APP1_NAME)*))
239