2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[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 PLATFORM_excludes := $(wildcard $(LIBRARY).$(PLATFORM)-excludes)
13
14 ifndef PLATFORM_excludes
15 ifeq (cat,$(PLATFORM_CHANGE_SEPARATOR_CMD))
16 response = $(sourcefile)
17 endif
18 endif
19
20 ifndef response
21 response = $(depsdir)/$(PROFILE)_$(LIBRARY).response
22 library_CLEAN_FILES += $(response) $(LIBRARY).mdb $(BUILT_SOURCES)
23 endif
24
25 ifndef LIBRARY_NAME
26 LIBRARY_NAME = $(LIBRARY)
27 endif
28
29 makefrag = $(depsdir)/$(PROFILE)_$(LIBRARY).makefrag
30 the_lib = $(topdir)/class/lib/$(PROFILE)/$(LIBRARY_NAME)
31 the_pdb = $(the_lib:.dll=.pdb)
32 the_mdb = $(the_lib).mdb
33 library_CLEAN_FILES += $(makefrag) $(the_lib) $(the_pdb) $(the_mdb)
34
35 ifndef NO_TEST
36 test_nunit_lib = nunit.framework.dll nunit.core.dll nunit.util.dll
37 test_nunit_dep = $(test_nunit_lib:%=$(topdir)/class/lib/$(PROFILE)/%)
38 test_nunit_ref = $(test_nunit_dep:%=-r:%)
39 library_CLEAN_FILES += TestResult*.xml
40
41 ifndef test_against
42 test_against = $(the_lib)
43 test_dep = $(the_lib)
44 endif
45
46 ifndef test_lib
47 test_lib = $(LIBRARY:.dll=_test_$(PROFILE).dll)
48 test_sourcefile = $(LIBRARY:.dll=_test.dll.sources)
49 else
50 test_sourcefile = $(test_lib).sources
51 endif
52 test_pdb = $(test_lib:.dll=.pdb)
53 test_response = $(depsdir)/$(test_lib).response
54 test_makefrag = $(depsdir)/$(test_lib).makefrag
55 test_flags = /r:$(test_against) $(test_nunit_ref) $(TEST_MCS_FLAGS)
56 library_CLEAN_FILES += $(LIBRARY:.dll=_test*.dll) $(LIBRARY:.dll=_test*.pdb) $(test_response) $(test_makefrag)
57
58 ifndef btest_lib
59 btest_lib = $(LIBRARY:.dll=_btest_$(PROFILE).dll)
60 btest_sourcefile = $(LIBRARY:.dll=_btest.dll.sources)
61 else
62 btest_sourcefile = $(btest_lib).sources
63 endif
64 btest_pdb = $(btest_lib:.dll=.pdb)
65 btest_response = $(depsdir)/$(btest_lib).response
66 btest_makefrag = $(depsdir)/$(btest_lib).makefrag
67 btest_flags = /r:$(test_against) $(test_nunit_ref) $(TEST_MBAS_FLAGS)
68 library_CLEAN_FILES += $(LIBRARY:.dll=_btest*.dll) $(LIBRARY:.dll=_btest*.pdb) $(btest_response) $(btest_makefrag)
69
70 ifndef HAVE_CS_TESTS
71 HAVE_CS_TESTS := $(wildcard $(test_sourcefile))
72 endif
73 ifndef HAVE_VB_TESTS
74 HAVE_VB_TESTS := $(wildcard $(btest_sourcefile))
75 endif
76
77 endif
78
79 gacutil = $(topdir)/tools/gacutil/gacutil.exe
80 GACUTIL = MONO_PATH="$(topdir)/class/lib/default$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(gacutil)
81
82 ifdef NO_SIGN_ASSEMBLY
83 SN = :
84 else
85 sn = $(topdir)/class/lib/net_1_1_bootstrap/sn.exe
86 SN = MONO_PATH="$(topdir)/class/lib/net_1_1_bootstrap/$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(sn)
87 SNFLAGS = -q -R
88 endif
89
90 libdir = $(prefix)/lib
91
92 ifeq ($(PLATFORM), win32)
93 GACDIR = `cygpath -w $(libdir)`
94 GACROOT = `cygpath -w $(DESTDIR)$(libdir)`
95 test_flags += -d:WINDOWS
96 else
97 GACDIR = $(libdir)
98 GACROOT = $(DESTDIR)$(libdir)
99 endif
100
101 all-local install-local test-local: $(the_lib)
102
103 ifdef NO_INSTALL
104 install-local uninstall-local:
105         @:
106
107 else
108
109 ifdef LIBRARY_INSTALL_DIR
110 install-local:
111         $(MKINSTALLDIRS) $(DESTDIR)$(LIBRARY_INSTALL_DIR)
112         $(INSTALL_LIB) $(the_lib) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME)
113         test ! -f $(the_lib).mdb || $(INSTALL_LIB) $(the_lib).mdb $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
114
115 uninstall-local:
116         -rm -f $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
117
118 else
119
120 # If RUNTIME_HAS_CONSISTENT_GACDIR is set, it implies that the internal GACDIR
121 # of the runtime is the same as the GACDIR we want.  So, we don't need to pass it
122 # to gacutil.  Note that the GACDIR we want may not be the same as the value of 
123 # GACDIR set above, since the user could have overridden the value of $(prefix).
124 #
125 # This makes a difference only when we're building from the mono/ tree, since we
126 # have to ensure that the internal GACDIR of the in-tree runtime matches where we 
127 # install the DLLs.
128
129 ifndef RUNTIME_HAS_CONSISTENT_GACDIR
130 gacdir_flag = /gacdir $(GACDIR)
131 endif
132
133 install-local: $(gacutil)
134         $(GACUTIL) /i $(the_lib) /f $(gacdir_flag) /root $(GACROOT) /package $(FRAMEWORK_VERSION)
135
136 uninstall-local: $(gacutil)
137         -$(GACUTIL) /u $(LIBRARY_NAME:.dll=) $(gacdir_flag) /root $(GACROOT) /package $(FRAMEWORK_VERSION)
138
139 endif
140 endif
141
142 clean-local:
143         -rm -f $(library_CLEAN_FILES) $(CLEAN_FILES)
144
145 test-local run-test-local run-test-ondotnet-local:
146         @:
147
148 ifndef NO_TEST
149 $(test_nunit_dep): $(topdir)/build/deps/nunit-$(PROFILE).stamp
150         @if test -f $@; then :; else rm -f $<; $(MAKE) $<; fi
151 $(topdir)/build/deps/nunit-$(PROFILE).stamp:
152         cd ${topdir}/nunit20 && $(MAKE)
153         echo "stamp" >$@
154 library_CLEAN_FILES += $(topdir)/build/deps/nunit-$(PROFILE).stamp
155 endif
156
157 test_assemblies :=
158
159 ifdef HAVE_CS_TESTS
160 test_assemblies += $(test_lib)
161 endif
162
163 ifdef HAVE_VB_TESTS
164 test_assemblies += $(btest_lib)
165 endif
166
167 ifdef test_assemblies
168 test-local: $(test_assemblies)
169 run-test-local: run-test-lib
170 run-test-ondotnet-local: run-test-ondotnet-lib
171
172 ## FIXME: i18n problem in the 'sed' command below
173 run-test-lib: test-local
174         ok=:; \
175         $(TEST_RUNTIME) $(TEST_HARNESS) $(TEST_HARNESS_FLAGS) /output:TestResult-$(PROFILE).log /exclude:NotWorking,ValueAdd,CAS /xml:TestResult-$(PROFILE).xml $(test_assemblies) || ok=false; \
176         sed '1,/^Tests run: /d' TestResult-$(PROFILE).log; \
177         $$ok
178
179 run-test-ondotnet-lib: test-local
180         ok=:; \
181         $(TEST_HARNESS) $(TEST_HARNESS_FLAGS) /exclude=NotDotNet /output:TestResult-ondotnet-$(PROFILE).log /xml:TestResult-ondotnet-$(PROFILE).xml $(test_assemblies) || ok=false; \
182         sed '1,/^Tests run: /d' TestResult-ondotnet-$(PROFILE).log; \
183         $$ok
184 endif
185
186 DISTFILES = $(sourcefile) $(test_sourcefile) $(EXTRA_DISTFILES)
187
188 TEST_FILES = 
189
190 ifdef HAVE_CS_TESTS
191 TEST_FILES += `sed 's,^,Test/,' $(test_sourcefile)`
192 endif
193 ifdef HAVE_VB_TESTS
194 TEST_FILES += `sed 's,^,Test/,' $(btest_sourcefile)`
195 endif
196
197 dist-local: dist-default
198         for f in `cat $(sourcefile)` $(TEST_FILES) ; do \
199           case $$f in \
200           ../*) : ;; \
201           *) dest=`dirname $(distdir)/$$f` ; $(MKINSTALLDIRS) $$dest && cp -p $$f $$dest || exit 1 ;; \
202           esac ; done
203
204 ifndef LIBRARY_COMPILE
205 LIBRARY_COMPILE = $(CSCOMPILE)
206 endif
207
208 ifndef TEST_COMPILE
209 TEST_COMPILE = $(CSCOMPILE)
210 endif
211
212 ifndef BTEST_COMPILE
213 BTEST_COMPILE = $(BASCOMPILE)
214 endif
215
216 ifndef LIBRARY_SNK
217 LIBRARY_SNK = $(topdir)/class/mono.snk
218 endif
219
220 $(gacutil):
221         cd $(topdir)/tools/gacutil && $(MAKE) PROFILE=default
222
223 ifdef sn
224 $(sn):
225         cd $(topdir) && $(MAKE) PROFILE=net_1_1_bootstrap
226 endif
227
228 ifeq (cat, $(PLATFORM_CHANGE_SEPARATOR_CMD))
229 BUILT_SOURCES_cmdline = $(BUILT_SOURCES)
230 else
231 BUILT_SOURCES_cmdline = `echo $(BUILT_SOURCES) | $(PLATFORM_CHANGE_SEPARATOR_CMD)`
232 endif
233
234 # The library
235
236 $(the_lib): $(response) $(sn) $(BUILT_SOURCES)
237 ifdef LIBRARY_USE_INTERMEDIATE_FILE
238         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) /target:library /out:$(@F) $(BUILT_SOURCES_cmdline) @$(response)
239         $(SN) $(SNFLAGS) $(@F) $(LIBRARY_SNK)
240         mv $(@F) $@
241         test ! -f $(@F).mdb || mv $(@F).mdb $@.mdb
242 else
243         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) /target:library /out:$@ $(BUILT_SOURCES_cmdline) @$(response)
244         $(SN) $(SNFLAGS) $@ $(LIBRARY_SNK)
245 endif
246
247 $(makefrag): $(sourcefile)
248         @echo Creating $@ ...
249         @sed 's,^,$(the_lib): ,' $< >$@
250
251 ifneq ($(response),$(sourcefile))
252 $(response): $(sourcefile) $(PLATFORM_excludes)
253         @echo Creating $@ ...
254         @sort $(sourcefile) $(PLATFORM_excludes) | uniq -u | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
255 endif
256
257 -include $(makefrag)
258
259 # for now, don't give any /lib flags or set MONO_PATH, since we
260 # give a full path to the assembly.
261
262 ifdef HAVE_CS_TESTS
263
264 $(test_lib): $(test_dep) $(test_response) $(test_nunit_dep)
265         $(TEST_COMPILE) /target:library /out:$@ $(test_flags) @$(test_response)
266
267 $(test_response): $(test_sourcefile)
268         @echo Creating $@ ...
269         @sed 's,^,Test/,' $(test_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
270
271 $(test_makefrag): $(test_response)
272         @echo Creating $@ ...
273         @sed 's,^,$(test_lib): ,' $< >$@
274
275 -include $(test_makefrag)
276
277 endif
278
279 ifdef HAVE_VB_TESTS
280
281 $(btest_lib): $(test_dep) $(btest_response) $(test_nunit_dep)
282         $(BTEST_COMPILE) /target:library /out:$@ $(btest_flags) @$(btest_response)
283
284 $(btest_response): $(btest_sourcefile)
285         @echo Creating $@ ...
286         @sed 's,^,Test/,' $(btest_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
287
288 $(btest_makefrag): $(btest_response)
289         @echo Creating $@ ...
290         @sed 's,^,$(btest_lib): ,' $< >$@
291
292 -include $(btest_makefrag)
293
294 endif
295
296 all-local: $(makefrag) $(test_makefrag) $(btest_makefrag)
297 $(makefrag) $(test_makefrag) $(btest_makefrag): $(topdir)/build/library.make