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