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