2004-11-09 Atsushi Enomoto <atsushi@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
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).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_$(PROFILE).dll)
50 test_sourcefile = $(LIBRARY:.dll=_test.dll.sources)
51 else
52 test_sourcefile = $(test_lib).sources
53 endif
54 test_pdb = $(test_lib:.dll=.pdb)
55 test_response = $(depsdir)/$(test_lib).response
56 test_makefrag = $(depsdir)/$(test_lib).makefrag
57 test_flags = /r:$(test_against) $(test_nunit_ref) $(TEST_MCS_FLAGS)
58 library_CLEAN_FILES += $(LIBRARY:.dll=_test*.dll) $(LIBRARY:.dll=_test*.pdb) $(test_response) $(test_makefrag)
59
60 ifndef btest_lib
61 btest_lib = $(LIBRARY:.dll=_btest_$(PROFILE).dll)
62 btest_sourcefile = $(LIBRARY:.dll=_btest.dll.sources)
63 else
64 btest_sourcefile = $(btest_lib).sources
65 endif
66 btest_pdb = $(btest_lib:.dll=.pdb)
67 btest_response = $(depsdir)/$(btest_lib).response
68 btest_makefrag = $(depsdir)/$(btest_lib).makefrag
69 btest_flags = /r:$(test_against) $(test_nunit_ref) $(TEST_MBAS_FLAGS)
70 library_CLEAN_FILES += $(LIBRARY:.dll=_btest*.dll) $(LIBRARY:.dll=_btest*.pdb) $(btest_response) $(btest_makefrag)
71
72 ifndef HAVE_CS_TESTS
73 HAVE_CS_TESTS := $(wildcard $(test_sourcefile))
74 endif
75 ifndef HAVE_VB_TESTS
76 HAVE_VB_TESTS := $(wildcard $(btest_sourcefile))
77 endif
78
79 endif
80
81 gacutil = $(topdir)/tools/gacutil/gacutil.exe
82 sn = $(topdir)/tools/security/sn.exe
83
84 PACKAGE = 1.0
85
86 ifeq ($(PROFILE), net_2_0)
87 PACKAGE = 2.0
88 endif
89
90 ifeq ($(PLATFORM), win32)
91 GACDIR = `cygpath -w $(DESTDIR)$(prefix)/lib`
92 else
93 GACDIR = $(DESTDIR)$(prefix)/lib
94 endif
95
96 all-local install-local test-local: $(the_lib)
97
98 ifdef LIBRARY_INSTALL_DIR
99 install-local:
100         $(MKINSTALLDIRS) $(DESTDIR)$(LIBRARY_INSTALL_DIR)
101         $(INSTALL_LIB) $(the_lib) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME)
102         -$(INSTALL_LIB) $(the_lib).mdb $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
103
104 uninstall-local:
105         -rm -f $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
106
107 else
108
109 install-local: $(gacutil)
110         MONO_PATH="$(topdir)/class/lib/$(PROFILE):$$MONO_PATH" $(RUNTIME) $(gacutil) /i $(the_lib) /f /root $(GACDIR) /package $(PACKAGE)
111
112 uninstall-local: $(gacutil)
113         MONO_PATH="$(topdir)/class/lib/$(PROFILE):$$MONO_PATH" $(RUNTIME) $(gacutil) /u $(LIBRARY_NAME:.dll=)
114
115 endif
116
117 ifndef NO_SIGN_ASSEMBLY
118 all-local install-local: $(the_lib_signature_stamp)
119
120 ifndef LIBRARY_SNK
121 LIBRARY_SNK = $(topdir)/class/mono.snk
122 endif
123
124 $(the_lib_signature_stamp): $(the_lib) $(sn)
125         MONO_PATH="$(topdir)/class/lib/$(PROFILE):$$MONO_PATH" $(RUNTIME) $(sn) -q -R $(the_lib) $(LIBRARY_SNK)
126         echo stamp > $@
127 endif
128
129 clean-local:
130         -rm -f $(library_CLEAN_FILES) $(CLEAN_FILES)
131
132 test-local run-test-local run-test-ondotnet-local:
133         @:
134
135 ifndef NO_TEST
136 $(test_nunit_dep): $(topdir)/build/deps/nunit-$(PROFILE).stamp
137         @if test -f $@; then :; else rm -f $<; $(MAKE) $<; fi
138 $(topdir)/build/deps/nunit-$(PROFILE).stamp:
139         cd ${topdir}/nunit20 && $(MAKE)
140         echo "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) /xml:TestResult-$(PROFILE).xml $(test_assemblies)
160
161 run-test-ondotnet-lib: test-local
162         $(TEST_HARNESS) /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 $$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 $(gacutil) $(sn):
196         cd $(@D) && $(MAKE) $(@F)
197
198 # The library
199
200 $(the_lib): $(response)
201 ifdef LIBRARY_USE_INTERMEDIATE_FILE
202         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) /target:library /out:$(@F) @$(response)
203         mv $(@F) $@
204         -mv $(@F).mdb $@.mdb
205 else
206         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) /target:library /out:$@ @$(response)
207 endif
208
209 $(makefrag): $(sourcefile)
210         @echo Creating $@ ...
211         @sed 's,^,$(the_lib): ,' $< >$@
212
213 ifneq ($(response),$(sourcefile))
214 $(response): $(sourcefile) $(PLATFORM_excludes)
215         @echo Creating $@ ...
216         @sort $(sourcefile) $(PLATFORM_excludes) | uniq -u | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
217 endif
218
219 -include $(makefrag)
220
221 # for now, don't give any /lib flags or set MONO_PATH, since we
222 # give a full path to the assembly.
223
224 ifdef HAVE_CS_TESTS
225
226 $(test_lib): $(test_dep) $(test_response) $(test_nunit_dep)
227         $(TEST_COMPILE) /target:library /out:$@ $(test_flags) @$(test_response)
228
229 $(test_response): $(test_sourcefile)
230         @echo Creating $@ ...
231         @sed 's,^,Test/,' $(test_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
232
233 $(test_makefrag): $(test_response)
234         @echo Creating $@ ...
235         @sed 's,^,$(test_lib): ,' $< >$@
236
237 -include $(test_makefrag)
238
239 endif
240
241 ifdef HAVE_VB_TESTS
242
243 $(btest_lib): $(test_dep) $(btest_response) $(test_nunit_dep)
244         $(BTEST_COMPILE) /target:library /out:$@ $(btest_flags) @$(btest_response)
245
246 $(btest_response): $(btest_sourcefile)
247         @echo Creating $@ ...
248         @sed 's,^,Test/,' $(btest_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
249
250 $(btest_makefrag): $(btest_response)
251         @echo Creating $@ ...
252         @sed 's,^,$(btest_lib): ,' $< >$@
253
254 -include $(btest_makefrag)
255
256 endif
257
258 all-local: $(makefrag) $(test_makefrag) $(btest_makefrag)
259 $(makefrag) $(test_makefrag) $(btest_makefrag): $(topdir)/build/library.make