2004-11-26 Martin Baulig <martin@ximian.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 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:$$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:$$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 else
96 GACDIR = $(libdir)
97 GACROOT = $(DESTDIR)$(libdir)
98 endif
99
100 all-local install-local test-local: $(the_lib)
101
102 ifdef NO_INSTALL
103 install-local uninstall-local:
104         @:
105
106 else
107
108 ifdef LIBRARY_INSTALL_DIR
109 install-local:
110         $(MKINSTALLDIRS) $(DESTDIR)$(LIBRARY_INSTALL_DIR)
111         $(INSTALL_LIB) $(the_lib) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME)
112         test ! -f $(the_lib).mdb || $(INSTALL_LIB) $(the_lib).mdb $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
113
114 uninstall-local:
115         -rm -f $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
116
117 else
118
119 install-local: $(gacutil)
120         $(GACUTIL) /i $(the_lib) /f /gacdir $(GACDIR) /root $(GACROOT) /package $(FRAMEWORK_VERSION)
121
122 uninstall-local: $(gacutil)
123         $(GACUTIL) /u $(LIBRARY_NAME:.dll=)
124
125 endif
126 endif
127
128 clean-local:
129         -rm -f $(library_CLEAN_FILES) $(CLEAN_FILES)
130
131 test-local run-test-local run-test-ondotnet-local:
132         @:
133
134 ifndef NO_TEST
135 $(test_nunit_dep): $(topdir)/build/deps/nunit-$(PROFILE).stamp
136         @if test -f $@; then :; else rm -f $<; $(MAKE) $<; fi
137 $(topdir)/build/deps/nunit-$(PROFILE).stamp:
138         cd ${topdir}/nunit20 && $(MAKE)
139         echo "stamp" >$@
140 library_CLEAN_FILES += $(topdir)/build/deps/nunit-$(PROFILE).stamp
141 endif
142
143 test_assemblies :=
144
145 ifdef HAVE_CS_TESTS
146 test_assemblies += $(test_lib)
147 endif
148
149 ifdef HAVE_VB_TESTS
150 test_assemblies += $(btest_lib)
151 endif
152
153 ifdef test_assemblies
154 test-local: $(test_assemblies)
155 run-test-local: run-test-lib
156 run-test-ondotnet-local: run-test-ondotnet-lib
157
158 run-test-lib: test-local
159         $(TEST_RUNTIME) $(TEST_HARNESS) $(TEST_HARNESS_FLAGS) /output:TestResult-$(PROFILE).log /xml:TestResult-$(PROFILE).xml $(test_assemblies)
160
161 run-test-ondotnet-lib: test-local
162         $(TEST_HARNESS) $(TEST_HARNESS_FLAGS) /output:TestResult-$(PROFILE).log /xml:TestResult-ondotnet-$(PROFILE).xml $(test_assemblies)
163 endif
164
165 DISTFILES = $(sourcefile) $(test_sourcefile) $(EXTRA_DISTFILES)
166
167 TEST_FILES = 
168
169 ifdef HAVE_CS_TESTS
170 TEST_FILES += `sed 's,^,Test/,' $(test_sourcefile)`
171 endif
172 ifdef HAVE_VB_TESTS
173 TEST_FILES += `sed 's,^,Test/,' $(btest_sourcefile)`
174 endif
175
176 dist-local: dist-default
177         for f in `cat $(sourcefile)` $(TEST_FILES) ; do \
178           case $$f in \
179           ../*) : ;; \
180           *) dest=`dirname $(distdir)/$$f` ; $(MKINSTALLDIRS) $$dest && cp -p $$f $$dest || exit 1 ;; \
181           esac ; done
182
183 ifndef LIBRARY_COMPILE
184 LIBRARY_COMPILE = $(CSCOMPILE)
185 endif
186
187 ifndef TEST_COMPILE
188 TEST_COMPILE = $(CSCOMPILE)
189 endif
190
191 ifndef BTEST_COMPILE
192 BTEST_COMPILE = $(BASCOMPILE)
193 endif
194
195 ifndef LIBRARY_SNK
196 LIBRARY_SNK = $(topdir)/class/mono.snk
197 endif
198
199 $(gacutil):
200         cd $(topdir)/tools/gacutil && $(MAKE) PROFILE=default
201
202 ifdef sn
203 $(sn):
204         cd $(topdir) && $(MAKE) PROFILE=net_1_1_bootstrap
205 endif
206
207 # The library
208
209 $(the_lib): $(response) $(sn) $(BUILT_SOURCES)
210 ifdef LIBRARY_USE_INTERMEDIATE_FILE
211         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) /target:library /out:$(@F) $(BUILT_SOURCES) @$(response)
212         $(SN) $(SNFLAGS) $(@F) $(LIBRARY_SNK)
213         mv $(@F) $@
214         test ! -f $(@F).mdb || mv $(@F).mdb $@.mdb
215 else
216         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) /target:library /out:$@ $(BUILT_SOURCES) @$(response)
217         $(SN) $(SNFLAGS) $@ $(LIBRARY_SNK)
218 endif
219
220 $(makefrag): $(sourcefile)
221         @echo Creating $@ ...
222         @sed 's,^,$(the_lib): ,' $< >$@
223
224 ifneq ($(response),$(sourcefile))
225 $(response): $(sourcefile) $(PLATFORM_excludes)
226         @echo Creating $@ ...
227         @sort $(sourcefile) $(PLATFORM_excludes) | uniq -u | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
228 endif
229
230 -include $(makefrag)
231
232 # for now, don't give any /lib flags or set MONO_PATH, since we
233 # give a full path to the assembly.
234
235 ifdef HAVE_CS_TESTS
236
237 $(test_lib): $(test_dep) $(test_response) $(test_nunit_dep)
238         $(TEST_COMPILE) /target:library /out:$@ $(test_flags) @$(test_response)
239
240 $(test_response): $(test_sourcefile)
241         @echo Creating $@ ...
242         @sed 's,^,Test/,' $(test_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
243
244 $(test_makefrag): $(test_response)
245         @echo Creating $@ ...
246         @sed 's,^,$(test_lib): ,' $< >$@
247
248 -include $(test_makefrag)
249
250 endif
251
252 ifdef HAVE_VB_TESTS
253
254 $(btest_lib): $(test_dep) $(btest_response) $(test_nunit_dep)
255         $(BTEST_COMPILE) /target:library /out:$@ $(btest_flags) @$(btest_response)
256
257 $(btest_response): $(btest_sourcefile)
258         @echo Creating $@ ...
259         @sed 's,^,Test/,' $(btest_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
260
261 $(btest_makefrag): $(btest_response)
262         @echo Creating $@ ...
263         @sed 's,^,$(btest_lib): ,' $< >$@
264
265 -include $(btest_makefrag)
266
267 endif
268
269 all-local: $(makefrag) $(test_makefrag) $(btest_makefrag)
270 $(makefrag) $(test_makefrag) $(btest_makefrag): $(topdir)/build/library.make