d5bf65c3e23ff96372a954109cf36542ffc02b00
[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 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 # If RUNTIME_HAS_CONSISTENT_GACDIR is set, it implies that the internal GACDIR
120 # of the runtime is the same as the GACDIR we want.  So, we don't need to pass it
121 # to gacutil.  Note that the GACDIR we want may not be the same as the value of 
122 # GACDIR set above, since the user could have overridden the value of $(prefix).
123 #
124 # This makes a difference only when we're building from the mono/ tree, since we
125 # have to ensure that the internal GACDIR of the in-tree runtime matches where we 
126 # install the DLLs.
127
128 ifndef RUNTIME_HAS_CONSISTENT_GACDIR
129 gacdir_flag = /gacdir $(GACDIR)
130 endif
131
132 install-local: $(gacutil)
133         $(GACUTIL) /i $(the_lib) /f $(gacdir_flag) /root $(GACROOT) /package $(FRAMEWORK_VERSION)
134
135 uninstall-local: $(gacutil)
136         -$(GACUTIL) /u $(LIBRARY_NAME:.dll=) $(gacdir_flag) /root $(GACROOT) /package $(FRAMEWORK_VERSION)
137
138 endif
139 endif
140
141 clean-local:
142         -rm -f $(library_CLEAN_FILES) $(CLEAN_FILES)
143
144 test-local run-test-local run-test-ondotnet-local:
145         @:
146
147 ifndef NO_TEST
148 $(test_nunit_dep): $(topdir)/build/deps/nunit-$(PROFILE).stamp
149         @if test -f $@; then :; else rm -f $<; $(MAKE) $<; fi
150 $(topdir)/build/deps/nunit-$(PROFILE).stamp:
151         cd ${topdir}/nunit20 && $(MAKE)
152         echo "stamp" >$@
153 library_CLEAN_FILES += $(topdir)/build/deps/nunit-$(PROFILE).stamp
154 endif
155
156 test_assemblies :=
157
158 ifdef HAVE_CS_TESTS
159 test_assemblies += $(test_lib)
160 endif
161
162 ifdef HAVE_VB_TESTS
163 test_assemblies += $(btest_lib)
164 endif
165
166 ifdef test_assemblies
167 test-local: $(test_assemblies)
168 run-test-local: run-test-lib
169 run-test-ondotnet-local: run-test-ondotnet-lib
170
171 run-test-lib: test-local
172         $(TEST_RUNTIME) $(TEST_HARNESS) $(TEST_HARNESS_FLAGS) /output:TestResult-$(PROFILE).log /xml:TestResult-$(PROFILE).xml $(test_assemblies)
173
174 run-test-ondotnet-lib: test-local
175         $(TEST_HARNESS) $(TEST_HARNESS_FLAGS) /output:TestResult-$(PROFILE).log /xml:TestResult-ondotnet-$(PROFILE).xml $(test_assemblies)
176 endif
177
178 DISTFILES = $(sourcefile) $(test_sourcefile) $(EXTRA_DISTFILES)
179
180 TEST_FILES = 
181
182 ifdef HAVE_CS_TESTS
183 TEST_FILES += `sed 's,^,Test/,' $(test_sourcefile)`
184 endif
185 ifdef HAVE_VB_TESTS
186 TEST_FILES += `sed 's,^,Test/,' $(btest_sourcefile)`
187 endif
188
189 dist-local: dist-default
190         for f in `cat $(sourcefile)` $(TEST_FILES) ; do \
191           case $$f in \
192           ../*) : ;; \
193           *) dest=`dirname $(distdir)/$$f` ; $(MKINSTALLDIRS) $$dest && cp -p $$f $$dest || exit 1 ;; \
194           esac ; done
195
196 ifndef LIBRARY_COMPILE
197 LIBRARY_COMPILE = $(CSCOMPILE)
198 endif
199
200 ifndef TEST_COMPILE
201 TEST_COMPILE = $(CSCOMPILE)
202 endif
203
204 ifndef BTEST_COMPILE
205 BTEST_COMPILE = $(BASCOMPILE)
206 endif
207
208 ifndef LIBRARY_SNK
209 LIBRARY_SNK = $(topdir)/class/mono.snk
210 endif
211
212 $(gacutil):
213         cd $(topdir)/tools/gacutil && $(MAKE) PROFILE=default
214
215 ifdef sn
216 $(sn):
217         cd $(topdir) && $(MAKE) PROFILE=net_1_1_bootstrap
218 endif
219
220 ifeq (cat, $(PLATFORM_CHANGE_SEPARATOR_CMD))
221 BUILT_SOURCES_cmdline = $(BUILT_SOURCES)
222 else
223 BUILT_SOURCES_cmdline = `echo $(BUILT_SOURCES) | $(PLATFORM_CHANGE_SEPARATOR_CMD)`
224 endif
225
226 # The library
227
228 $(the_lib): $(response) $(sn) $(BUILT_SOURCES)
229 ifdef LIBRARY_USE_INTERMEDIATE_FILE
230         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) /target:library /out:$(@F) $(BUILT_SOURCES_cmdline) @$(response)
231         $(SN) $(SNFLAGS) $(@F) $(LIBRARY_SNK)
232         mv $(@F) $@
233         test ! -f $(@F).mdb || mv $(@F).mdb $@.mdb
234 else
235         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) /target:library /out:$@ $(BUILT_SOURCES_cmdline) @$(response)
236         $(SN) $(SNFLAGS) $@ $(LIBRARY_SNK)
237 endif
238
239 $(makefrag): $(sourcefile)
240         @echo Creating $@ ...
241         @sed 's,^,$(the_lib): ,' $< >$@
242
243 ifneq ($(response),$(sourcefile))
244 $(response): $(sourcefile) $(PLATFORM_excludes)
245         @echo Creating $@ ...
246         @sort $(sourcefile) $(PLATFORM_excludes) | uniq -u | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
247 endif
248
249 -include $(makefrag)
250
251 # for now, don't give any /lib flags or set MONO_PATH, since we
252 # give a full path to the assembly.
253
254 ifdef HAVE_CS_TESTS
255
256 $(test_lib): $(test_dep) $(test_response) $(test_nunit_dep)
257         $(TEST_COMPILE) /target:library /out:$@ $(test_flags) @$(test_response)
258
259 $(test_response): $(test_sourcefile)
260         @echo Creating $@ ...
261         @sed 's,^,Test/,' $(test_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
262
263 $(test_makefrag): $(test_response)
264         @echo Creating $@ ...
265         @sed 's,^,$(test_lib): ,' $< >$@
266
267 -include $(test_makefrag)
268
269 endif
270
271 ifdef HAVE_VB_TESTS
272
273 $(btest_lib): $(test_dep) $(btest_response) $(test_nunit_dep)
274         $(BTEST_COMPILE) /target:library /out:$@ $(btest_flags) @$(btest_response)
275
276 $(btest_response): $(btest_sourcefile)
277         @echo Creating $@ ...
278         @sed 's,^,Test/,' $(btest_sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
279
280 $(btest_makefrag): $(btest_response)
281         @echo Creating $@ ...
282         @sed 's,^,$(btest_lib): ,' $< >$@
283
284 -include $(btest_makefrag)
285
286 endif
287
288 all-local: $(makefrag) $(test_makefrag) $(btest_makefrag)
289 $(makefrag) $(test_makefrag) $(btest_makefrag): $(topdir)/build/library.make