2007-01-17 Adar Wesley <adarw@mainsoft.com>
[mono.git] / mcs / build / library.make
1 # -*- makefile -*-
2 #
3 # The rules for building our class libraries.
4 #
5 # The NO_TEST stuff is not too pleasant but whatcha
6 # gonna do.
7
8 # All the dep files now land in the same directory so we
9 # munge in the library name to keep the files from clashing.
10
11 sourcefile = $(LIBRARY).sources
12
13 # If the directory contains the per profile include file, generate list file.
14 PROFILE_sources = $(PROFILE)_$(LIBRARY).sources
15 ifeq ($(wildcard $(PROFILE_sources)), $(PROFILE_sources))
16 PROFILE_excludes = $(wildcard $(PROFILE)_$(LIBRARY).exclude.sources)
17 COMMON_sourcefile := $(sourcefile)
18 sourcefile = $(depsdir)/$(PROFILE)_$(LIBRARY).sources
19 $(sourcefile): $(PROFILE_sources) $(PROFILE_excludes) $(COMMON_sourcefile)
20         @echo Creating the per profile list $@ ...
21         $(topdir)/tools/gensources.sh $(PROFILE_sources) $(PROFILE_excludes) > $@
22 endif
23
24 PLATFORM_excludes := $(wildcard $(LIBRARY).$(PLATFORM)-excludes)
25
26 ifndef PLATFORM_excludes
27 ifeq (cat,$(PLATFORM_CHANGE_SEPARATOR_CMD))
28 response = $(sourcefile)
29 endif
30 endif
31
32 ifndef response
33 response = $(depsdir)/$(PROFILE)_$(LIBRARY).response
34 library_CLEAN_FILES += $(response) $(LIBRARY).mdb $(BUILT_SOURCES)
35 endif
36
37 ifndef LIBRARY_NAME
38 LIBRARY_NAME = $(LIBRARY)
39 endif
40
41 ifdef LIBRARY_COMPAT
42 lib_dir = compat
43 else
44 lib_dir = lib
45 endif
46
47 makefrag = $(depsdir)/$(PROFILE)_$(LIBRARY).makefrag
48 the_lib = $(topdir)/class/$(lib_dir)/$(PROFILE)/$(LIBRARY_NAME)
49 the_pdb = $(the_lib:.dll=.pdb)
50 the_mdb = $(the_lib).mdb
51 library_CLEAN_FILES += $(makefrag) $(the_lib) $(the_pdb) $(the_mdb)
52
53 ifdef LIBRARY_NEEDS_POSTPROCESSING
54 build_lib = fixup/$(PROFILE)/$(LIBRARY_NAME)
55 library_CLEAN_FILES += $(build_lib) $(build_lib:.dll=.pdb)
56 else
57 build_lib = $(the_lib)
58 endif
59
60 ifndef NO_TEST
61 test_nunit_lib = nunit.framework.dll nunit.core.dll nunit.util.dll
62 test_nunit_dep = $(test_nunit_lib:%=$(topdir)/class/lib/$(PROFILE)/%)
63 test_nunit_ref = $(test_nunit_dep:%=-r:%)
64 library_CLEAN_FILES += TestResult*.xml
65
66 test_lib = $(LIBRARY:.dll=_test_$(PROFILE).dll)
67 test_sourcefile = $(LIBRARY:.dll=_test.dll.sources)
68 test_pdb = $(test_lib:.dll=.pdb)
69 test_response = $(depsdir)/$(test_lib).response
70 test_makefrag = $(depsdir)/$(test_lib).makefrag
71 test_flags = -r:$(the_lib) $(test_nunit_ref) $(TEST_MCS_FLAGS)
72 library_CLEAN_FILES += $(LIBRARY:.dll=_test*.dll) $(LIBRARY:.dll=_test*.pdb) $(test_response) $(test_makefrag)
73
74 btest_lib = $(LIBRARY:.dll=_btest_$(PROFILE).dll)
75 btest_sourcefile = $(LIBRARY:.dll=_btest.dll.sources)
76 btest_pdb = $(btest_lib:.dll=.pdb)
77 btest_response = $(depsdir)/$(btest_lib).response
78 btest_makefrag = $(depsdir)/$(btest_lib).makefrag
79 btest_flags = -r:$(the_lib) $(test_nunit_ref) $(TEST_MBAS_FLAGS)
80 library_CLEAN_FILES += $(LIBRARY:.dll=_btest*.dll) $(LIBRARY:.dll=_btest*.pdb) $(btest_response) $(btest_makefrag)
81
82 ifndef HAVE_CS_TESTS
83 HAVE_CS_TESTS := $(wildcard $(test_sourcefile))
84 endif
85 ifndef HAVE_VB_TESTS
86 HAVE_VB_TESTS := $(wildcard $(btest_sourcefile))
87 endif
88
89 endif
90
91 ifdef NO_INSTALL
92 GACUTIL = :
93 else
94 gacutil = $(topdir)/class/lib/net_1_1_bootstrap/gacutil.exe
95 GACUTIL = MONO_PATH="$(topdir)/class/lib/net_1_1_bootstrap$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(gacutil)
96 endif
97
98 ifdef NO_SIGN_ASSEMBLY
99 SN = :
100 else
101 sn = $(topdir)/class/lib/net_1_1_bootstrap/sn.exe
102 SN = MONO_PATH="$(topdir)/class/lib/net_1_1_bootstrap$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(sn)
103 SNFLAGS = -q -R
104 endif
105
106 ifeq ($(PLATFORM), win32)
107 GACDIR = `cygpath -w $(mono_libdir)`
108 GACROOT = `cygpath -w $(DESTDIR)$(mono_libdir)`
109 test_flags += -d:WINDOWS
110 else
111 GACDIR = $(mono_libdir)
112 GACROOT = $(DESTDIR)$(mono_libdir)
113 endif
114
115 all-local: $(the_lib)
116
117 install-local: all-local
118 test-local: all-local
119 uninstall-local:
120
121 ifdef NO_INSTALL
122 install-local uninstall-local:
123         @:
124
125 else
126
127 ifdef LIBRARY_INSTALL_DIR
128 install-local:
129         $(MKINSTALLDIRS) $(DESTDIR)$(LIBRARY_INSTALL_DIR)
130         $(INSTALL_LIB) $(the_lib) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME)
131         test ! -f $(the_lib).mdb || $(INSTALL_LIB) $(the_lib).mdb $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
132
133 uninstall-local:
134         -rm -f $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
135
136 else
137
138 # If RUNTIME_HAS_CONSISTENT_GACDIR is set, it implies that the internal GACDIR
139 # of the runtime is the same as the GACDIR we want.  So, we don't need to pass it
140 # to gacutil.  Note that the GACDIR we want may not be the same as the value of
141 # GACDIR set above, since the user could have overridden the value of $(prefix).
142 #
143 # This makes a difference only when we're building from the mono/ tree, since we
144 # have to ensure that the internal GACDIR of the in-tree runtime matches where we
145 # install the DLLs.
146
147 ifndef RUNTIME_HAS_CONSISTENT_GACDIR
148 gacdir_flag = /gacdir $(GACDIR)
149 endif
150
151 ifndef LIBRARY_PACKAGE
152 ifdef LIBRARY_COMPAT
153 LIBRARY_PACKAGE = compat-$(FRAMEWORK_VERSION)
154 else
155 LIBRARY_PACKAGE = $(FRAMEWORK_VERSION)
156 endif
157 endif
158
159 install-local: $(gacutil)
160         $(GACUTIL) /i $(the_lib) /f $(gacdir_flag) /root $(GACROOT) /package $(LIBRARY_PACKAGE)
161
162 uninstall-local: $(gacutil)
163         -$(GACUTIL) /u $(LIBRARY_NAME:.dll=) $(gacdir_flag) /root $(GACROOT) /package $(LIBRARY_PACKAGE)
164
165 endif
166 endif
167
168 clean-local:
169         -rm -f $(library_CLEAN_FILES) $(CLEAN_FILES)
170
171 test-local run-test-local run-test-ondotnet-local:
172         @:
173
174 ifndef NO_TEST
175 $(test_nunit_dep): $(topdir)/build/deps/nunit-$(PROFILE).stamp
176         @if test -f $@; then :; else rm -f $<; $(MAKE) $<; fi
177 $(topdir)/build/deps/nunit-$(PROFILE).stamp:
178         cd ${topdir}/nunit20 && $(MAKE)
179         echo "stamp" >$@
180 library_CLEAN_FILES += $(topdir)/build/deps/nunit-$(PROFILE).stamp
181 endif
182
183 test_assemblies :=
184
185 ifdef HAVE_CS_TESTS
186 test_assemblies += $(test_lib)
187 endif
188
189 ifdef HAVE_VB_TESTS
190 test_assemblies += $(btest_lib)
191 endif
192
193 ifdef test_assemblies
194 test-local: $(test_assemblies)
195 run-test-local: run-test-lib
196 run-test-ondotnet-local: run-test-ondotnet-lib
197
198 TEST_HARNESS_EXCLUDES = /exclude:NotWorking,ValueAdd,CAS,InetAccess
199 TEST_HARNESS_EXCLUDES_ONDOTNET = /exclude:NotDotNet,CAS
200
201 ifdef TEST_HARNESS_VERBOSE
202 TEST_HARNESS_OUTPUT = /labels
203 TEST_HARNESS_OUTPUT_ONDOTNET = /labels
204 TEST_HARNESS_POSTPROC = :
205 TEST_HARNESS_POSTPROC_ONDOTNET = :
206 else
207 TEST_HARNESS_OUTPUT = /output:TestResult-$(PROFILE).log
208 TEST_HARNESS_OUTPUT_ONDOTNET = /output:TestResult-ondotnet-$(PROFILE).log
209 TEST_HARNESS_POSTPROC = (echo ''; cat TestResult-$(PROFILE).log) | sed '1,/^Tests run: /d'
210 TEST_HARNESS_POSTPROC_ONDOTNET = (echo ''; cat TestResult-$(PROFILE).log) | sed '1,/^Tests run: /d'
211 endif
212
213 ## FIXME: i18n problem in the 'sed' command below
214 run-test-lib: test-local
215         ok=:; \
216         MONO_REGISTRY_PATH="$(HOME)/.mono/registry" $(TEST_RUNTIME) $(RUNTIME_FLAGS) $(TEST_HARNESS) $(TEST_HARNESS_FLAGS) $(LOCAL_TEST_HARNESS_FLAGS) $(TEST_HARNESS_EXCLUDES) $(TEST_HARNESS_OUTPUT) /xml:TestResult-$(PROFILE).xml $(test_assemblies) || ok=false; \
217         $(TEST_HARNESS_POSTPROC) ; $$ok
218
219 run-test-ondotnet-lib: test-local
220         ok=:; \
221         $(TEST_HARNESS) $(TEST_HARNESS_FLAGS) $(LOCAL_TEST_HARNESS_ONDOTNET_FLAGS) $(TEST_HARNESS_EXCLUDES_ONDOTNET) $(TEST_HARNESS_OUTPUT_ONDOTNET) /xml:TestResult-ondotnet-$(PROFILE).xml $(test_assemblies) || ok=false; \
222         $(TEST_HARNESS_POSTPROC_ONDOTNET) ; $$ok
223 endif
224
225 DISTFILES = $(sourcefile) $(EXTRA_DISTFILES)
226
227 TEST_FILES =
228
229 ifdef HAVE_CS_TESTS
230 TEST_FILES += `sed -e '/^$$/d' -e 's,^,Test/,' $(test_sourcefile)`
231 DISTFILES += $(test_sourcefile)
232 endif
233 ifdef HAVE_VB_TESTS
234 TEST_FILES += `sed -e '/^$$/d' -e 's,^,Test/,' $(btest_sourcefile)`
235 DISTFILES += $(btest_sourcefile)
236 endif
237
238 dist-local: dist-default
239         subs=' ' ; \
240         for f in `cat $(sourcefile)` $(TEST_FILES) ; do \
241           case $$f in \
242           ../*) : ;; \
243           *) dest=`dirname $$f` ; \
244              case $$subs in *" $$dest "*) : ;; *) subs=" $$dest$$subs" ; $(MKINSTALLDIRS) $(distdir)/$$dest ;; esac ; \
245              cp -p $$f $(distdir)/$$dest || exit 1 ;; \
246           esac ; done ; \
247         for d in . $$subs ; do \
248           case $$d in .) : ;; *) test ! -f $$d/ChangeLog || cp -p $$d/ChangeLog $(distdir)/$$d ;; esac ; done
249
250 ifdef LIBRARY_NEEDS_POSTPROCESSING
251 dist-local: dist-fixup
252 FIXUP_PROFILES = default net_2_0
253 dist-fixup:
254         $(MKINSTALLDIRS) $(distdir)/fixup $(FIXUP_PROFILES:%=$(distdir)/fixup/%)
255 endif
256
257 ifndef LIBRARY_COMPILE
258 LIBRARY_COMPILE = $(CSCOMPILE)
259 endif
260
261 ifndef TEST_COMPILE
262 TEST_COMPILE = $(CSCOMPILE)
263 endif
264
265 ifndef BTEST_COMPILE
266 BTEST_COMPILE = $(BASCOMPILE)
267 endif
268
269 ifndef LIBRARY_SNK
270 LIBRARY_SNK = $(topdir)/class/mono.snk
271 endif
272
273 ifdef gacutil
274 $(gacutil):
275         cd $(topdir) && $(MAKE) PROFILE=net_1_1_bootstrap
276 endif
277
278 ifdef sn
279 $(sn):
280         cd $(topdir) && $(MAKE) PROFILE=net_1_1_bootstrap
281 endif
282
283 ifdef BUILT_SOURCES
284 ifeq (cat, $(PLATFORM_CHANGE_SEPARATOR_CMD))
285 BUILT_SOURCES_cmdline = $(BUILT_SOURCES)
286 else
287 BUILT_SOURCES_cmdline = `echo $(BUILT_SOURCES) | $(PLATFORM_CHANGE_SEPARATOR_CMD)`
288 endif
289 endif
290
291 # The library
292
293 $(build_lib): $(response) $(sn) $(BUILT_SOURCES)
294 ifdef LIBRARY_USE_INTERMEDIATE_FILE
295         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) -target:library -out:$(LIBRARY_NAME) $(BUILT_SOURCES_cmdline) @$(response)
296         $(SN) $(SNFLAGS) $(LIBRARY_NAME) $(LIBRARY_SNK)
297         mv $(LIBRARY_NAME) $@
298         test ! -f $(LIBRARY_NAME).mdb || mv $(LIBRARY_NAME).mdb $@.mdb
299         test ! -f $(LIBRARY_NAME:.dll=.pdb) || mv $(LIBRARY_NAME:.dll=.pdb) $(dir $@)$(LIBRARY_NAME:.dll=.pdb)
300 else
301         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) -target:library -out:$@ $(BUILT_SOURCES_cmdline) @$(response)
302         $(SN) $(SNFLAGS) $@ $(LIBRARY_SNK)
303 endif
304
305 $(makefrag): $(sourcefile)
306         @echo Creating $@ ...
307         @sed 's,^,$(build_lib): ,' $< >$@
308
309 ifneq ($(response),$(sourcefile))
310 $(response): $(sourcefile) $(PLATFORM_excludes)
311         @echo Creating $@ ...
312         @sort $(sourcefile) $(PLATFORM_excludes) | uniq -u | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
313 endif
314
315 -include $(makefrag)
316
317 # for now, don't give any /lib flags or set MONO_PATH, since we
318 # give a full path to the assembly.
319
320 ifdef HAVE_CS_TESTS
321
322 $(test_lib): $(the_lib) $(test_response) $(test_nunit_dep)
323         $(TEST_COMPILE) -target:library -out:$@ $(test_flags) @$(test_response)
324
325 $(test_response): $(test_sourcefile)
326         @echo Creating $@ ...
327         @sed -e '/^$$/d' -e 's,^,Test/,' $(test_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
328
329 $(test_makefrag): $(test_response)
330         @echo Creating $@ ...
331         @sed 's,^,$(test_lib): ,' $< >$@
332
333 -include $(test_makefrag)
334
335 endif
336
337 ifdef HAVE_VB_TESTS
338
339 $(btest_lib): $(the_lib) $(btest_response) $(test_nunit_dep)
340         $(BTEST_COMPILE) -target:library -out:$@ $(btest_flags) @$(btest_response)
341
342 $(btest_response): $(btest_sourcefile)
343         @echo Creating $@ ...
344         @sed -e '/^$$/d' -e 's,^,Test/,' $(btest_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
345
346 $(btest_makefrag): $(btest_response)
347         @echo Creating $@ ...
348         @sed 's,^,$(btest_lib): ,' $< >$@
349
350 -include $(btest_makefrag)
351
352 endif
353
354 all-local: $(makefrag) $(test_makefrag) $(btest_makefrag)
355 $(makefrag) $(test_makefrag) $(btest_makefrag): $(topdir)/build/library.make