Merge pull request #819 from brendanzagaeski/patch-1
[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
13 # If the directory contains the per profile include file, generate list file.
14 PROFILE_sources := $(wildcard $(PROFILE)_$(LIBRARY).sources)
15 ifdef PROFILE_sources
16 PROFILE_excludes = $(wildcard $(PROFILE)_$(LIBRARY).exclude.sources)
17 sourcefile = $(depsdir)/$(PROFILE)_$(LIBRARY).sources
18 library_CLEAN_FILES += $(sourcefile)
19
20 ifdef EXTENSION_MODULE
21 EXTENSION_include = $(wildcard $(topdir)/../../mono-extensions/mcs/$(thisdir)/$(PROFILE)_$(LIBRARY).sources)
22 else
23 EXTENSION_include = $(wildcard $(PROFILE)_opt_$(LIBRARY).sources)
24 endif
25
26
27 ifdef EXTENSION_MODULE
28 EXTENSION_exclude = $(wildcard $(topdir)/../../mono-extensions/mcs/$(thisdir)/$(PROFILE)_$(LIBRARY).exclude.sources)
29 else
30 EXTENSION_exclude = $(wildcard $(PROFILE)_opt_$(LIBRARY).exclude.sources)
31 endif
32
33 # Note, gensources.sh can create a $(sourcefile).makefrag if it sees any '#include's
34 # We don't include it in the dependencies since it isn't always created
35 $(sourcefile): $(PROFILE_sources) $(PROFILE_excludes) $(topdir)/build/gensources.sh $(EXTENSION_include)
36         @echo Creating the per profile list $@ ...
37         $(SHELL) $(topdir)/build/gensources.sh $@ '$(PROFILE_sources)' '$(PROFILE_excludes)' '$(EXTENSION_include)' '$(EXTENSION_exclude)'
38 endif
39
40 PLATFORM_excludes := $(wildcard $(LIBRARY).$(PLATFORM)-excludes)
41
42 ifndef PLATFORM_excludes
43 ifeq (cat,$(PLATFORM_CHANGE_SEPARATOR_CMD))
44 response = $(sourcefile)
45 endif
46 endif
47
48 ifndef response
49 response = $(depsdir)/$(PROFILE)_$(LIBRARY).response
50 library_CLEAN_FILES += $(response)
51 endif
52
53 ifndef LIBRARY_NAME
54 LIBRARY_NAME = $(LIBRARY)
55 endif
56
57 ifdef LIBRARY_COMPAT
58 lib_dir = compat
59 else
60 lib_dir = lib
61 endif
62
63 ifdef LIBRARY_SUBDIR
64 the_libdir = $(topdir)/class/$(lib_dir)/$(PROFILE)/$(LIBRARY_SUBDIR)/
65 else
66 the_libdir = $(topdir)/class/$(lib_dir)/$(PROFILE)/
67 endif
68 ifdef LIBRARY_NEEDS_POSTPROCESSING
69 build_libdir = fixup/$(PROFILE)/
70 else
71 ifdef LIBRARY_USE_INTERMEDIATE_FILE
72 build_libdir = $(the_libdir)tmp/
73 else
74 build_libdir = $(the_libdir)
75 endif
76 endif
77
78 the_lib   = $(the_libdir)$(LIBRARY_NAME)
79 build_lib = $(build_libdir)$(LIBRARY_NAME)
80 library_CLEAN_FILES += $(the_lib)   $(the_lib).so   $(the_lib).mdb   $(the_lib:.dll=.pdb)
81 library_CLEAN_FILES += $(build_lib) $(build_lib).so $(build_lib).mdb $(build_lib:.dll=.pdb)
82
83 ifdef NO_SIGN_ASSEMBLY
84 SN = :
85 else
86 ifeq ("$(SN)","")
87 sn = $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/sn.exe
88 SN = MONO_PATH="$(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(sn) -q
89 endif
90 endif
91
92 ifeq ($(PLATFORM), win32)
93 GACDIR = `cygpath -w $(mono_libdir)`
94 GACROOT = `cygpath -w $(DESTDIR)$(mono_libdir)`
95 test_flags += -d:WINDOWS
96 else
97 GACDIR = $(mono_libdir)
98 GACROOT = $(DESTDIR)$(mono_libdir)
99 endif
100
101 ifndef NO_BUILD
102 all-local: $(the_lib) $(extra_targets)
103 endif
104
105 ifeq ($(LIBRARY_COMPILE),$(BOOT_COMPILE))
106 is_boot=true
107 else
108 is_boot=false
109 endif
110
111 csproj-local: csproj-library csproj-test
112
113 # to overcome the issues with circular dependencies, we'll create csprojs with a counter increment. 
114 # This is more amenable for use in VS solutions to reference projects rather than transient dll files in the build process.
115 csproj-library:
116         config_file=`basename $(LIBRARY) .dll`-$(PROFILE).input; \
117         for counter in 1 2 3 4 5 ; do if test -f $(topdir)/../msvc/scripts/inputs/$$config_file ; then config_file=`basename $(LIBRARY) .dll`-$(PROFILE)-$$counter.input; fi ; done ;\
118         echo $(thisdir):$$config_file >> $(topdir)/../msvc/scripts/order; \
119         (echo $(is_boot); \
120         echo $(USE_MCS_FLAGS) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS); \
121         echo $(LIBRARY_NAME); \
122         echo $(BUILT_SOURCES_cmdline); \
123         echo $(build_lib); \
124         echo $(FRAMEWORK_VERSION); \
125         echo $(PROFILE); \
126         echo $(response)) > $(topdir)/../msvc/scripts/inputs/$$config_file
127
128 csproj-test:
129
130 install-local: all-local
131 test-local: all-local
132 uninstall-local:
133
134 ifdef NO_INSTALL
135 install-local uninstall-local:
136         @:
137
138 else
139
140 aot_lib = $(the_lib)$(PLATFORM_AOT_SUFFIX)
141 aot_libname = $(LIBRARY_NAME)$(PLATFORM_AOT_SUFFIX)
142
143 ifdef LIBRARY_INSTALL_DIR
144 install-local:
145         $(MKINSTALLDIRS) $(DESTDIR)$(LIBRARY_INSTALL_DIR)
146         $(INSTALL_LIB) $(the_lib) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME)
147         test ! -f $(the_lib).mdb || $(INSTALL_LIB) $(the_lib).mdb $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
148 ifdef PLATFORM_AOT_SUFFIX
149         test ! -f $(aot_lib) || $(INSTALL_LIB) $(aot_lib) $(DESTDIR)$(LIBRARY_INSTALL_DIR)
150 endif
151
152 uninstall-local:
153         -rm -f $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
154
155 else
156
157 # If RUNTIME_HAS_CONSISTENT_GACDIR is set, it implies that the internal GACDIR
158 # of the runtime is the same as the GACDIR we want.  So, we don't need to pass it
159 # to gacutil.  Note that the GACDIR we want may not be the same as the value of
160 # GACDIR set above, since the user could have overridden the value of $(prefix).
161 #
162 # This makes a difference only when we're building from the mono/ tree, since we
163 # have to ensure that the internal GACDIR of the in-tree runtime matches where we
164 # install the DLLs.
165
166 ifndef RUNTIME_HAS_CONSISTENT_GACDIR
167 gacdir_flag = /gacdir $(GACDIR)
168 endif
169
170 ifndef LIBRARY_PACKAGE
171 ifdef LIBRARY_COMPAT
172 LIBRARY_PACKAGE = compat-$(FRAMEWORK_VERSION)
173 else
174 LIBRARY_PACKAGE = $(FRAMEWORK_VERSION)
175 endif
176 endif
177
178 ifneq (none, $(LIBRARY_PACKAGE))
179 package_flag = /package $(LIBRARY_PACKAGE)
180 endif
181
182 install-local: $(gacutil)
183         $(GACUTIL) /i $(the_lib) /f $(gacdir_flag) /root $(GACROOT) $(package_flag)
184
185 uninstall-local: $(gacutil)
186         -$(GACUTIL) /u $(LIBRARY_NAME:.dll=) $(gacdir_flag) /root $(GACROOT) $(package_flag)
187
188 endif # LIBRARY_INSTALL_DIR
189 endif # NO_INSTALL
190
191 clean-local:
192         -rm -f $(tests_CLEAN_FILES) $(library_CLEAN_FILES) $(CLEAN_FILES)
193
194 test-local run-test-local run-test-ondotnet-local:
195         @:
196
197 DISTFILES = $(wildcard *$(LIBRARY)*.sources) $(EXTRA_DISTFILES)
198
199 ASSEMBLY      = $(LIBRARY)
200 ASSEMBLY_EXT  = .dll
201 the_assembly  = $(the_lib)
202 include $(topdir)/build/tests.make
203
204 ifdef HAVE_CS_TESTS
205 DISTFILES += $(test_sourcefile)
206
207 csproj-test:
208         config_file=`basename $(LIBRARY) .dll`-tests-$(PROFILE).input; \
209         echo $(thisdir):$$config_file >> $(topdir)/../msvc/scripts/order; \
210         (echo false; \
211         echo $(USE_MCS_FLAGS) -r:$(the_assembly) $(TEST_MCS_FLAGS); \
212         echo $(test_lib); \
213         echo $(BUILT_SOURCES_cmdline); \
214         echo $(test_lib); \
215         echo $(FRAMEWORK_VERSION); \
216         echo $(PROFILE); \
217         echo $(test_response)) > $(topdir)/../msvc/scripts/inputs/$$config_file
218
219 endif
220
221 # make dist will collect files in .sources files from all profiles
222 dist-local: dist-default
223         subs=' ' ; \
224         for f in `$(topdir)/tools/removecomments.sh $(wildcard *$(LIBRARY).sources)` $(TEST_FILES) ; do \
225           case $$f in \
226           ../*) : ;; \
227           *) dest=`dirname "$$f"` ; \
228              case $$subs in *" $$dest "*) : ;; *) subs=" $$dest$$subs" ; $(MKINSTALLDIRS) $(distdir)/$$dest ;; esac ; \
229              cp -p "$$f" $(distdir)/$$dest || exit 1 ;; \
230           esac ; done ; \
231         for d in . $$subs ; do \
232           case $$d in .) : ;; *) test ! -f $$d/ChangeLog || cp -p $$d/ChangeLog $(distdir)/$$d ;; esac ; done
233
234 ifdef LIBRARY_NEEDS_POSTPROCESSING
235 dist-local: dist-fixup
236 FIXUP_PROFILES = default net_2_0
237 dist-fixup:
238         $(MKINSTALLDIRS) $(distdir)/fixup $(FIXUP_PROFILES:%=$(distdir)/fixup/%)
239 endif
240
241 ifndef LIBRARY_COMPILE
242 LIBRARY_COMPILE = $(CSCOMPILE)
243 endif
244
245 ifndef LIBRARY_SNK
246 LIBRARY_SNK = $(topdir)/class/mono.snk
247 endif
248
249 ifdef BUILT_SOURCES
250 library_CLEAN_FILES += $(BUILT_SOURCES)
251 ifeq (cat, $(PLATFORM_CHANGE_SEPARATOR_CMD))
252 BUILT_SOURCES_cmdline = $(BUILT_SOURCES)
253 else
254 BUILT_SOURCES_cmdline = `echo $(BUILT_SOURCES) | $(PLATFORM_CHANGE_SEPARATOR_CMD)`
255 endif
256 endif
257
258 # The library
259
260 $(the_lib): $(the_libdir)/.stamp
261
262 $(build_lib): $(response) $(sn) $(BUILT_SOURCES) $(build_libdir:=/.stamp)
263         $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) -target:library -out:$@ $(BUILT_SOURCES_cmdline) @$(response)
264         $(Q) $(SN) -R $@ $(LIBRARY_SNK)
265
266 ifdef LIBRARY_USE_INTERMEDIATE_FILE
267 $(the_lib): $(build_lib)
268         $(Q) cp $(build_lib) $@
269         $(Q) $(SN) -v $@
270         $(Q) test ! -f $(build_lib).mdb || mv $(build_lib).mdb $@.mdb
271         $(Q) test ! -f $(build_lib:.dll=.pdb) || mv $(build_lib:.dll=.pdb) $(the_lib:.dll=.pdb)
272 endif
273
274 library_CLEAN_FILES += $(PROFILE)_aot.log
275
276 ifdef PLATFORM_AOT_SUFFIX
277 Q_AOT=$(if $(V),,@echo "AOT     [$(PROFILE)] $(notdir $(@))";)
278 $(the_lib)$(PLATFORM_AOT_SUFFIX): $(the_lib)
279         $(Q_AOT) MONO_PATH='$(the_libdir)' > $(PROFILE)_aot.log 2>&1 $(RUNTIME) --aot=bind-to-runtime-version --debug $(the_lib)
280 endif
281
282 ifdef ENABLE_AOT
283 ifneq (,$(filter $(AOT_IN_PROFILES), $(PROFILE)))
284
285 all-local: $(the_lib)$(PLATFORM_AOT_SUFFIX)
286
287 endif
288 endif
289
290 makefrag = $(depsdir)/$(PROFILE)_$(LIBRARY).makefrag
291 library_CLEAN_FILES += $(makefrag)
292 $(makefrag): $(sourcefile)
293 #       @echo Creating $@ ...
294         @sed 's,^,$(build_lib): ,' $< >$@
295         @if test ! -f $(sourcefile).makefrag; then :; else \
296            cat $(sourcefile).makefrag >> $@ ; \
297            echo '$@: $(sourcefile).makefrag' >> $@; \
298            echo '$(sourcefile).makefrag:' >> $@; fi
299
300 ifneq ($(response),$(sourcefile))
301
302 ifdef PLATFORM_excludes
303 $(response): $(sourcefile) $(PLATFORM_excludes)
304         @echo Filtering $(sourcefile) to $@ ...
305         @sort $(sourcefile) $(PLATFORM_excludes) | uniq -u | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
306 else
307 $(response): $(sourcefile)
308         @echo Converting $(sourcefile) to $@ ...
309         @cat $(sourcefile) | $(PLATFORM_CHANGE_SEPARATOR_CMD) >$@
310 endif
311
312 endif
313
314 -include $(makefrag)
315
316 # for now, don't give any /lib flags or set MONO_PATH, since we
317 # give a full path to the assembly.
318
319 ## Include corcompare stuff
320 include $(topdir)/build/corcompare.make
321
322 all-local: $(makefrag) $(test_makefrag) $(btest_makefrag)
323 ifneq ($(response),$(sourcefile))
324 $(response): $(topdir)/build/library.make $(depsdir)/.stamp
325 endif
326 $(makefrag) $(test_response) $(test_makefrag) $(btest_response) $(btest_makefrag): $(topdir)/build/library.make $(depsdir)/.stamp
327
328 ## Documentation stuff
329
330 Q_MDOC_UP=$(if $(V),,@echo "MDOC-UP [$(PROFILE)] $(notdir $(@))";)
331 # net_2_0 is needed because monodoc is only compiled in that profile
332 MDOC_UP  =$(Q_MDOC_UP) \
333                 MONO_PATH="$(topdir)/class/lib/$(DEFAULT_PROFILE)$(PLATFORM_PATH_SEPARATOR)$(topdir)/class/lib/net_2_0$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(topdir)/class/lib/$(DEFAULT_PROFILE)/mdoc.exe \
334                 update --delete -o Documentation/en $(the_lib)
335
336 doc-update-local: $(the_libdir)/.doc-stamp
337
338 $(the_libdir)/.doc-stamp: $(the_lib)
339         $(MDOC_UP)
340         @echo "doc-stamp" > $@
341