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