**** Merged from MCS ****
[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
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_lib_signature_stamp = $(makefrag:.makefrag=.was_signed)
32 the_pdb = $(the_lib:.dll=.pdb)
33 the_mdb = $(the_lib:.dll=.mdb)
34 library_CLEAN_FILES += $(makefrag) $(the_lib) $(the_pdb) \
35                         $(the_mdb) $(the_lib_signature_stamp)
36
37 ifndef NO_TEST
38 test_nunit_lib = nunit.framework.dll nunit.core.dll nunit.util.dll
39 test_nunit_dep = $(test_nunit_lib:%=$(topdir)/class/lib/$(PROFILE)/%)
40 test_nunit_ref = $(test_nunit_dep:%=-r:%)
41 library_CLEAN_FILES += TestResult.xml
42
43 ifndef test_against
44 test_against = $(the_lib)
45 test_dep = $(the_lib)
46 endif
47
48 ifndef test_lib
49 test_lib = $(LIBRARY:.dll=_test.dll)
50 endif
51 test_pdb = $(test_lib:.dll=.pdb)
52 test_sourcefile = $(test_lib).sources
53 test_response = $(depsdir)/$(PROFILE)_$(test_lib).response
54 test_makefrag = $(depsdir)/$(PROFILE)_$(test_lib).makefrag
55 test_flags = /r:$(test_against) $(test_nunit_ref) $(TEST_MCS_FLAGS)
56 library_CLEAN_FILES += $(test_lib) $(test_pdb) $(test_response) $(test_makefrag)
57
58 ifndef btest_lib
59 btest_lib = $(LIBRARY:.dll=_btest.dll)
60 endif
61 btest_pdb = $(btest_lib:.dll=.pdb)
62 btest_sourcefile = $(btest_lib).sources
63 btest_response = $(depsdir)/$(btest_lib).response
64 btest_makefrag = $(depsdir)/$(btest_lib).makefrag
65 btest_flags = /r:$(test_against) $(test_nunit_ref) $(TEST_MBAS_FLAGS)
66 library_CLEAN_FILES += $(btest_lib) $(btest_pdb) $(btest_response) $(btest_makefrag)
67
68 ifndef HAVE_CS_TESTS
69 HAVE_CS_TESTS := $(wildcard $(test_sourcefile))
70 endif
71 ifndef HAVE_VB_TESTS
72 HAVE_VB_TESTS := $(wildcard $(btest_sourcefile))
73 endif
74
75 endif
76
77 gacutil = $(topdir)/tools/gacutil/gacutil.exe
78 sn = $(topdir)/tools/security/sn.exe
79
80 PACKAGE = 1.0
81
82 ifeq ($(PROFILE), net_2_0)
83 PACKAGE = 2.0
84 endif
85
86 ifeq ($(PLATFORM), win32)
87 GACDIR = `cygpath -w $(DESTDIR)$(prefix)/lib`
88 else
89 GACDIR = $(DESTDIR)$(prefix)/lib
90 endif
91
92 all-local install-local test-local: $(the_lib)
93
94 ifdef LIBRARY_INSTALL_DIR
95 install-local:
96         $(MKINSTALLDIRS) $(DESTDIR)$(LIBRARY_INSTALL_DIR)
97         $(INSTALL_LIB) $(the_lib) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME)
98         -$(INSTALL_LIB) $(the_lib).mdb $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
99
100 uninstall-local:
101         -rm -f $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
102
103 else
104
105 install-local: $(gacutil)
106         MONO_PATH="$(topdir)/class/lib/$(PROFILE):$$MONO_PATH" $(RUNTIME) $(gacutil) /i $(the_lib) /f /root $(GACDIR) /package $(PACKAGE)
107
108 uninstall-local: $(gacutil)
109         MONO_PATH="$(topdir)/class/lib/$(PROFILE):$$MONO_PATH" $(RUNTIME) $(gacutil) /u $(LIBRARY_NAME:.dll=)
110
111 endif
112
113 ifndef NO_SIGN_ASSEMBLY
114 all-local install-local: $(the_lib_signature_stamp)
115
116 ifndef LIBRARY_SNK
117 LIBRARY_SNK = $(topdir)/class/mono.snk
118 endif
119
120 $(the_lib_signature_stamp): $(the_lib) $(sn)
121         MONO_PATH="$(topdir)/class/lib/$(PROFILE):$$MONO_PATH" $(RUNTIME) $(sn) -q -R $(the_lib) $(LIBRARY_SNK)
122         echo stamp > $@
123 endif
124
125 clean-local:
126         -rm -f $(library_CLEAN_FILES) $(CLEAN_FILES)
127
128 test-local run-test-local run-test-ondotnet-local:
129         @:
130
131 ifndef NO_TEST
132 $(test_nunit_dep): $(topdir)/build/deps/nunit.stamp
133         @if test -f $@; then :; else rm -f $<; $(MAKE) $<; fi
134 $(topdir)/build/deps/nunit.stamp:
135         cd ${topdir}/nunit20 && $(MAKE)
136         echo "stamp" >$@
137 endif
138
139 ifdef HAVE_CS_TESTS
140
141 test-local: $(test_lib)
142
143 run-test-local: run-test-lib
144
145 run-test-lib: test-local
146         $(TEST_RUNTIME) $(TEST_HARNESS) $(test_lib)
147
148 run-test-ondotnet-local: run-test-ondotnet-lib
149
150 run-test-ondotnet-lib: test-local
151         $(TEST_HARNESS) $(test_lib)
152 endif
153
154 ifdef HAVE_VB_TESTS
155
156 test-local: $(btest_lib)
157
158 run-test-local: run-btest-lib
159
160 run-btest-lib: test-local
161         $(TEST_RUNTIME) $(TEST_HARNESS) $(btest_lib)
162
163 run-test-ondotnet-local: run-btest-ondotnet-lib
164
165 run-btest-ondotnet-lib: test-local
166         $(TEST_HARNESS) $(btest_lib)
167
168 endif
169
170 DISTFILES = $(sourcefile) $(test_sourcefile) $(EXTRA_DISTFILES)
171
172 TEST_FILES = 
173
174 ifdef HAVE_CS_TESTS
175 TEST_FILES += `sed 's,^,Test/,' $(test_sourcefile)`
176 endif
177 ifdef HAVE_VB_TESTS
178 TEST_FILES += `sed 's,^,Test/,' $(btest_sourcefile)`
179 endif
180
181 dist-local: dist-default
182         for f in `cat $(sourcefile)` $(TEST_FILES) ; do \
183             dest=`dirname $(distdir)/$$f` ; \
184             $(MKINSTALLDIRS) $$dest && cp $$f $$dest || exit 1 ; \
185         done
186
187 ifndef LIBRARY_COMPILE
188 LIBRARY_COMPILE = $(CSCOMPILE)
189 endif
190
191 ifndef TEST_COMPILE
192 TEST_COMPILE = $(CSCOMPILE)
193 endif
194
195 ifndef BTEST_COMPILE
196 BTEST_COMPILE = $(BASCOMPILE)
197 endif
198
199 $(gacutil) $(sn):
200         cd $(@D) && $(MAKE) $(@F)
201
202 # The library
203
204 $(the_lib): $(response)
205 ifdef LIBRARY_USE_INTERMEDIATE_FILE
206         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) /target:library /out:$(@F) @$(response)
207         mv $(@F) $@
208         -mv $(@F).mdb $@.mdb
209 else
210         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) /target:library /out:$@ @$(response)
211 endif
212
213 $(makefrag): $(sourcefile)
214         @echo Creating $@ ...
215         @sed 's,^,$(the_lib): ,' $< >$@
216
217 ifneq ($(response),$(sourcefile))
218 $(response): $(sourcefile) $(PLATFORM_excludes)
219         @echo Creating $@ ...
220         @sort $(sourcefile) $(PLATFORM_excludes) | uniq -u | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
221 endif
222
223 -include $(makefrag)
224
225 # for now, don't give any /lib flags or set MONO_PATH, since we
226 # give a full path to the assembly.
227
228 ifdef HAVE_CS_TESTS
229
230 $(test_lib): $(test_dep) $(test_response) $(test_nunit_dep)
231         $(TEST_COMPILE) /target:library /out:$@ $(test_flags) @$(test_response)
232
233 $(test_response): $(test_sourcefile)
234         @echo Creating $@ ...
235         @sed 's,^,Test/,' $(test_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
236
237 $(test_makefrag): $(test_response)
238         @echo Creating $@ ...
239         @sed 's,^,$(test_lib): ,' $< >$@
240
241 -include $(test_makefrag)
242
243 endif
244
245 ifdef HAVE_VB_TESTS
246
247 $(btest_lib): $(test_dep) $(btest_response) $(test_nunit_dep)
248         $(BTEST_COMPILE) /target:library /out:$@ $(btest_flags) @$(btest_response)
249
250 $(btest_response): $(btest_sourcefile)
251         @echo Creating $@ ...
252         @sed 's,^,Test/,' $(btest_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
253
254 $(btest_makefrag): $(btest_response)
255         @echo Creating $@ ...
256         @sed 's,^,$(btest_lib): ,' $< >$@
257
258 -include $(btest_makefrag)
259
260 endif
261
262 all-local: $(makefrag) $(test_makefrag) $(btest_makefrag)
263 $(makefrag) $(test_makefrag) $(btest_makefrag): $(topdir)/build/library.make