2009-01-07 Geoff Norton <gnorton@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 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_libdir = $(topdir)/class/$(lib_dir)/$(PROFILE)/
49 the_lib = $(the_libdir)$(LIBRARY_NAME)
50 the_pdb = $(the_lib:.dll=.pdb)
51 the_mdb = $(the_lib).mdb
52 library_CLEAN_FILES += $(makefrag) $(the_lib) $(the_lib).so $(the_pdb) $(the_mdb)
53
54 ifdef LIBRARY_NEEDS_POSTPROCESSING
55 build_libdir = fixup/$(PROFILE)/
56 build_lib = $(build_libdir)$(LIBRARY_NAME)
57 library_CLEAN_FILES += $(build_lib) $(build_lib:.dll=.pdb)
58 else
59 build_lib = $(the_lib)
60 endif
61
62 ifndef NO_TEST
63 test_nunit_lib = nunit.framework.dll nunit.core.dll nunit.util.dll
64 test_nunit_dep = $(test_nunit_lib:%=$(topdir)/class/lib/$(PROFILE)/%)
65 test_nunit_ref = $(test_nunit_dep:%=-r:%)
66 library_CLEAN_FILES += TestResult*.xml
67
68 test_lib = $(LIBRARY:.dll=_test_$(PROFILE).dll)
69 test_sourcefile = $(LIBRARY:.dll=_test.dll.sources)
70 test_pdb = $(test_lib:.dll=.pdb)
71 test_response = $(depsdir)/$(test_lib).response
72 test_makefrag = $(depsdir)/$(test_lib).makefrag
73 test_flags = -r:$(the_lib) $(test_nunit_ref) $(TEST_MCS_FLAGS)
74 library_CLEAN_FILES += $(LIBRARY:.dll=_test*.dll) $(LIBRARY:.dll=_test*.pdb) $(test_response) $(test_makefrag)
75
76 btest_lib = $(LIBRARY:.dll=_btest_$(PROFILE).dll)
77 btest_sourcefile = $(LIBRARY:.dll=_btest.dll.sources)
78 btest_pdb = $(btest_lib:.dll=.pdb)
79 btest_response = $(depsdir)/$(btest_lib).response
80 btest_makefrag = $(depsdir)/$(btest_lib).makefrag
81 btest_flags = -r:$(the_lib) $(test_nunit_ref) $(TEST_MBAS_FLAGS)
82 library_CLEAN_FILES += $(LIBRARY:.dll=_btest*.dll) $(LIBRARY:.dll=_btest*.pdb) $(btest_response) $(btest_makefrag)
83
84 ifndef HAVE_CS_TESTS
85 HAVE_CS_TESTS := $(wildcard $(test_sourcefile))
86 endif
87 ifndef HAVE_VB_TESTS
88 HAVE_VB_TESTS := $(wildcard $(btest_sourcefile))
89 endif
90
91 endif
92
93 ifdef NO_SIGN_ASSEMBLY
94 SN = :
95 else
96 sn = $(topdir)/class/lib/net_1_1_bootstrap/sn.exe
97 SN = $(Q) MONO_PATH="$(topdir)/class/lib/net_1_1_bootstrap$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(sn)
98 SNFLAGS = -q -R
99 endif
100
101 ifeq ($(PLATFORM), win32)
102 GACDIR = `cygpath -w $(mono_libdir)`
103 GACROOT = `cygpath -w $(DESTDIR)$(mono_libdir)`
104 test_flags += -d:WINDOWS
105 else
106 GACDIR = $(mono_libdir)
107 GACROOT = $(DESTDIR)$(mono_libdir)
108 endif
109
110 all-local: $(the_lib)
111
112 install-local: all-local
113 test-local: all-local
114 uninstall-local:
115
116 ifdef NO_INSTALL
117 install-local uninstall-local:
118         @:
119
120 else
121
122 ifdef LIBRARY_INSTALL_DIR
123 install-local:
124         $(MKINSTALLDIRS) $(DESTDIR)$(LIBRARY_INSTALL_DIR)
125         $(INSTALL_LIB) $(the_lib) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME)
126         test ! -f $(the_lib).mdb || $(INSTALL_LIB) $(the_lib).mdb $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
127
128 uninstall-local:
129         -rm -f $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
130
131 else
132
133 # If RUNTIME_HAS_CONSISTENT_GACDIR is set, it implies that the internal GACDIR
134 # of the runtime is the same as the GACDIR we want.  So, we don't need to pass it
135 # to gacutil.  Note that the GACDIR we want may not be the same as the value of
136 # GACDIR set above, since the user could have overridden the value of $(prefix).
137 #
138 # This makes a difference only when we're building from the mono/ tree, since we
139 # have to ensure that the internal GACDIR of the in-tree runtime matches where we
140 # install the DLLs.
141
142 ifndef RUNTIME_HAS_CONSISTENT_GACDIR
143 gacdir_flag = /gacdir $(GACDIR)
144 endif
145
146 ifndef LIBRARY_PACKAGE
147 ifdef LIBRARY_COMPAT
148 LIBRARY_PACKAGE = compat-$(FRAMEWORK_VERSION)
149 else
150 LIBRARY_PACKAGE = $(FRAMEWORK_VERSION)
151 endif
152 endif
153
154 ifneq (none, $(LIBRARY_PACKAGE))
155 package_flag = /package $(LIBRARY_PACKAGE)
156 endif
157
158 install-local: $(gacutil)
159         $(GACUTIL) /i $(the_lib) /f $(gacdir_flag) /root $(GACROOT) $(package_flag)
160
161 uninstall-local: $(gacutil)
162         -$(GACUTIL) /u $(LIBRARY_NAME:.dll=) $(gacdir_flag) /root $(GACROOT) $(package_flag)
163
164 endif
165 endif
166
167 clean-local:
168         -rm -f $(library_CLEAN_FILES) $(CLEAN_FILES)
169
170 test-local run-test-local run-test-ondotnet-local:
171         @:
172
173 ifndef NO_TEST
174 $(test_nunit_dep): $(topdir)/build/deps/nunit-$(PROFILE).stamp
175         @if test -f $@; then :; else rm -f $<; $(MAKE) $<; fi
176 $(topdir)/build/deps/nunit-$(PROFILE).stamp:
177         cd ${topdir}/nunit24 && $(MAKE)
178         echo "stamp" >$@
179 library_CLEAN_FILES += $(topdir)/build/deps/nunit-$(PROFILE).stamp
180 endif
181
182 test_assemblies :=
183
184 ifdef HAVE_CS_TESTS
185 test_assemblies += $(test_lib)
186 endif
187
188 ifdef HAVE_VB_TESTS
189 test_assemblies += $(btest_lib)
190 endif
191
192 ifdef test_assemblies
193 check: run-test
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=$(PLATFORM_TEST_HARNESS_EXCLUDES)NotWorking,ValueAdd,CAS,InetAccess
199 TEST_HARNESS_EXCLUDES_ONDOTNET = /exclude:$(PLATFORM_TEST_HARNESS_EXCLUDES)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'; xsltproc $(topdir)/build/nunit-summary.xsl TestResult-$(PROFILE).xml >> TestResult-$(PROFILE).log
210 TEST_HARNESS_POSTPROC_ONDOTNET = (echo ''; cat TestResult-ondotnet-$(PROFILE).log) | sed '1,/^Tests run: /d'; xsltproc $(topdir)/build/nunit-summary.xsl TestResult-ondotnet-$(PROFILE).xml >> TestResult-ondotnet-$(PROFILE).log
211 endif
212
213 ifdef FIXTURE
214 FIXTURE_ARG = -fixture=MonoTests.$(FIXTURE)
215 endif
216
217 ifdef TESTNAME
218 TESTNAME_ARG = -run=MonoTests.$(TESTNAME)
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_assemblies) -noshadow $(TEST_HARNESS_FLAGS) $(LOCAL_TEST_HARNESS_FLAGS) $(TEST_HARNESS_EXCLUDES) $(TEST_HARNESS_OUTPUT) -xml=TestResult-$(PROFILE).xml $(FIXTURE_ARG) $(TESTNAME_ARG)|| ok=false; \
225         $(TEST_HARNESS_POSTPROC) ; $$ok
226
227 run-test-ondotnet-lib: test-local
228         ok=:; \
229         $(TEST_HARNESS) $(test_assemblies) -noshadow $(TEST_HARNESS_FLAGS) $(LOCAL_TEST_HARNESS_ONDOTNET_FLAGS) $(TEST_HARNESS_EXCLUDES_ONDOTNET) $(TEST_HARNESS_OUTPUT_ONDOTNET) -xml=TestResult-ondotnet-$(PROFILE).xml $(FIXTURE_ARG) $(TESTNAME_ARG) || ok=false; \
230         $(TEST_HARNESS_POSTPROC_ONDOTNET) ; $$ok
231 endif
232
233 DISTFILES = $(wildcard *$(LIBRARY)*.sources) $(EXTRA_DISTFILES)
234
235 TEST_FILES =
236
237 ifdef HAVE_CS_TESTS
238 TEST_FILES += `sed -e '/^$$/d' -e 's,^../,,' -et -e 's,^,Test/,' $(test_sourcefile)`
239 DISTFILES += $(test_sourcefile)
240 endif
241 ifdef HAVE_VB_TESTS
242 TEST_FILES += `sed -e '/^$$/d' -e 's,^../,,' -et -e 's,^,Test/,' $(btest_sourcefile)`
243 DISTFILES += $(btest_sourcefile)
244 endif
245
246 # make dist will collect files in .sources files from all profiles
247 dist-local: dist-default
248         subs=' ' ; \
249         for f in `$(topdir)/tools/removecomments.sh $(wildcard *$(LIBRARY).sources)` $(TEST_FILES) ; do \
250           case $$f in \
251           ../*) : ;; \
252           *) dest=`dirname $$f` ; \
253              case $$subs in *" $$dest "*) : ;; *) subs=" $$dest$$subs" ; $(MKINSTALLDIRS) $(distdir)/$$dest ;; esac ; \
254              cp -p $$f $(distdir)/$$dest || exit 1 ;; \
255           esac ; done ; \
256         for d in . $$subs ; do \
257           case $$d in .) : ;; *) test ! -f $$d/ChangeLog || cp -p $$d/ChangeLog $(distdir)/$$d ;; esac ; done
258
259 ifdef LIBRARY_NEEDS_POSTPROCESSING
260 dist-local: dist-fixup
261 FIXUP_PROFILES = default net_2_0
262 dist-fixup:
263         $(MKINSTALLDIRS) $(distdir)/fixup $(FIXUP_PROFILES:%=$(distdir)/fixup/%)
264 endif
265
266 ifndef LIBRARY_COMPILE
267 LIBRARY_COMPILE = $(CSCOMPILE)
268 endif
269
270 ifndef TEST_COMPILE
271 TEST_COMPILE = $(CSCOMPILE)
272 endif
273
274 ifndef BTEST_COMPILE
275 BTEST_COMPILE = $(BASCOMPILE)
276 endif
277
278 ifndef LIBRARY_SNK
279 LIBRARY_SNK = $(topdir)/class/mono.snk
280 endif
281
282 ifdef gacutil
283 $(gacutil):
284         cd $(topdir) && $(MAKE) PROFILE=net_1_1_bootstrap
285 endif
286
287 ifdef sn
288 $(sn):
289         cd $(topdir) && $(MAKE) PROFILE=net_1_1_bootstrap
290 endif
291
292 ifdef BUILT_SOURCES
293 ifeq (cat, $(PLATFORM_CHANGE_SEPARATOR_CMD))
294 BUILT_SOURCES_cmdline = $(BUILT_SOURCES)
295 else
296 BUILT_SOURCES_cmdline = `echo $(BUILT_SOURCES) | $(PLATFORM_CHANGE_SEPARATOR_CMD)`
297 endif
298 endif
299
300 Q_AOT=$(if $(V),,@echo "AOT [$(PROFILE)] $(notdir $(@))";)
301
302 # The library
303
304 $(the_lib): $(the_libdir)/.stamp
305
306 $(build_lib): $(response) $(sn) $(BUILT_SOURCES) $(build_libdir:=/.stamp)
307 ifdef LIBRARY_USE_INTERMEDIATE_FILE
308         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) -target:library -out:$(LIBRARY_NAME) $(BUILT_SOURCES_cmdline) @$(response)
309         $(SN) $(SNFLAGS) $(LIBRARY_NAME) $(LIBRARY_SNK)
310         $(Q) mv $(LIBRARY_NAME) $@
311         $(Q) test ! -f $(LIBRARY_NAME).mdb || mv $(LIBRARY_NAME).mdb $@.mdb
312         $(Q) test ! -f $(LIBRARY_NAME:.dll=.pdb) || mv $(LIBRARY_NAME:.dll=.pdb) $(dir $@)$(LIBRARY_NAME:.dll=.pdb)
313 else
314         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) -target:library -out:$@ $(BUILT_SOURCES_cmdline) @$(response)
315         $(SN) $(SNFLAGS) $@ $(LIBRARY_SNK)
316 endif
317 ifdef ENABLE_AOT
318 ifneq (,$(filter $(AOT_IN_PROFILES), $(PROFILE)))
319         $(Q_AOT) MONO_PATH=$(the_libdir) $(RUNTIME) --aot=bind-to-runtime-version $@ > $(PROFILE)_aot.log 2>&1
320 endif
321 endif
322
323 $(makefrag): $(sourcefile)
324         @echo Creating $@ ...
325         @sed 's,^,$(build_lib): ,' $< >$@
326
327 ifneq ($(response),$(sourcefile))
328 $(response): $(sourcefile) $(PLATFORM_excludes)
329         @echo Creating $@ ...
330         @sort $(sourcefile) $(PLATFORM_excludes) | uniq -u | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
331 endif
332
333 -include $(makefrag)
334
335 # for now, don't give any /lib flags or set MONO_PATH, since we
336 # give a full path to the assembly.
337
338 ifdef HAVE_CS_TESTS
339
340 $(test_lib): $(the_lib) $(test_response) $(test_nunit_dep)
341         $(TEST_COMPILE) -target:library -out:$@ $(test_flags) @$(test_response)
342
343 $(test_response): $(test_sourcefile)
344         @echo Creating $@ ...
345         @sed -e '/^$$/d' -e 's,^,Test/,' $(test_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
346
347 $(test_makefrag): $(test_response)
348         @echo Creating $@ ...
349         @sed 's,^,$(test_lib): ,' $< >$@
350
351 -include $(test_makefrag)
352
353 endif
354
355 ifdef HAVE_VB_TESTS
356
357 $(btest_lib): $(the_lib) $(btest_response) $(test_nunit_dep)
358         $(BTEST_COMPILE) -target:library -out:$@ $(btest_flags) @$(btest_response)
359
360 $(btest_response): $(btest_sourcefile)
361         @echo Creating $@ ...
362         @sed -e '/^$$/d' -e 's,^,Test/,' $(btest_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
363
364 $(btest_makefrag): $(btest_response)
365         @echo Creating $@ ...
366         @sed 's,^,$(btest_lib): ,' $< >$@
367
368 -include $(btest_makefrag)
369
370 endif
371
372 ## Include corcompare stuff
373 include $(topdir)/build/corcompare.make
374
375 all-local: $(makefrag) $(test_makefrag) $(btest_makefrag)
376 ifneq ($(response),$(sourcefile))
377 $(response): $(topdir)/build/library.make $(depsdir)/.stamp
378 endif
379 $(makefrag) $(test_response) $(test_makefrag) $(btest_response) $(btest_makefrag): $(topdir)/build/library.make $(depsdir)/.stamp
380
381 ## Documentation stuff
382
383 Q_MDOC_UP=$(if $(V),,@echo "MDOC-UP [$(PROFILE)] $(notdir $(@))";)
384 MDOC_UP  =$(Q_MDOC_UP) \
385         if `echo $(PROFILE) | grep ^net_1_ > /dev/null 2>/dev/null` ; then    \
386                 $(RUNTIME) $(topdir)/tools/mdoc/monodocer1.exe                      \
387                         -path:Documentation/en -assembly:$(the_lib) ;                     \
388         else                                                                  \
389                 $(RUNTIME) $(topdir)/tools/mdoc/mdoc.exe update --delete            \
390                         -o Documentation/en $(the_lib) ;                                  \
391         fi
392
393 doc-update-local: $(the_libdir)/.doc-stamp
394
395 $(the_libdir)/.doc-stamp: $(the_lib)
396         $(MDOC_UP)
397         @echo "doc-stamp" > $@
398