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