[aprofutil] Add -p and -f options (#16766)
[mono-project.git] / mcs / build / library.make
blobca9b19344a9c6f8260439be17dce71a6934ccc53
1 # -*- makefile -*-
3 # The rules for building our class libraries.
5 # The NO_TEST stuff is not too pleasant but whatcha
6 # gonna do.
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.
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.
17 LIB_REFS_FULL = $(call _FILTER_OUT,=, $(LIB_REFS)) $(DEFAULT_REFERENCES)
18 LIB_REFS_ALIAS = $(filter-out $(LIB_REFS_FULL),$(LIB_REFS))
20 # All dependent libs become dependent dirs for parallel builds
21 DEP_LIBS = $(filter-out %=, $(subst =,= ,$(LIB_REFS)))
23 ifdef TARGET_NET_REFERENCE
24 # System*, mscorlib references come from the TARGET_NET_REFERENCE dir, others from the profile dir
25 LIB_REFS_MONO_FULL = $(call _FILTER_OUT,System,$(call _FILTER_OUT,mscorlib,$(LIB_REFS_FULL)))
26 LIB_REFS_MONO_ALIAS = $(call _FILTER_OUT,System,$(LIB_REFS_ALIAS))
28 LIB_REFS_NET_FULL = $(filter-out $(LIB_REFS_MONO_FULL),$(LIB_REFS_FULL))
29 LIB_REFS_NET_ALIAS = $(filter-out $(LIB_REFS_MONO_ALIAS),$(LIB_REFS_ALIAS))
31 LIB_MCS_FLAGS += $(patsubst %,-r:$(topdir)/../external/binary-reference-assemblies/$(TARGET_NET_REFERENCE)/%.dll,$(LIB_REFS_NET_FULL))
32 LIB_MCS_FLAGS += $(patsubst %,-r:%.dll, $(subst =,=$(topdir)/../external/binary-reference-assemblies/$(TARGET_NET_REFERENCE)/,$(LIB_REFS_NET_ALIAS)))
34 LIB_MCS_FLAGS += $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE_DIRECTORY)/%.dll,$(LIB_REFS_MONO_FULL))
35 LIB_MCS_FLAGS += $(patsubst %,-r:%.dll, $(subst =,=$(topdir)/class/lib/$(PROFILE_DIRECTORY)/,$(LIB_REFS_MONO_ALIAS)))
36 else
38 ifdef API_BIN_REFS
39 LIB_MCS_FLAGS += $(patsubst %,-r:$(topdir)/../external/binary-reference-assemblies/$(API_BIN_PROFILE)/%.dll,$(API_BIN_REFS))
40 endif
42 LIB_MCS_FLAGS += $(patsubst %,-r:$(topdir)/class/lib/$(PROFILE_DIRECTORY)/%.dll,$(LIB_REFS_FULL))
43 LIB_MCS_FLAGS += $(patsubst %,-r:%.dll, $(subst =,=$(topdir)/class/lib/$(PROFILE_DIRECTORY)/,$(LIB_REFS_ALIAS)))
44 endif
46 ifdef KEYFILE
47 KEYFILE_MCS_FLAGS += /keyfile:$(KEYFILE)
48 endif
50 ifndef LIBRARY_NAME
51 LIBRARY_NAME = $(LIBRARY)
52 endif
54 ifdef LIBRARY_COMPAT
55 lib_dir = compat
56 else
57 lib_dir = lib
58 endif
60 the_libdir_base = $(topdir)/class/$(lib_dir)/$(PROFILE_DIRECTORY)/$(if $(LIBRARY_SUBDIR),$(LIBRARY_SUBDIR)/)
62 ifdef RESOURCE_STRINGS
63 RESOURCE_STRINGS_FILES += $(RESOURCE_STRINGS:%=--resourcestrings:%)
64 IL_REPLACE_FILES += $(IL_REPLACE:%=--ilreplace:%)
65 endif
67 ifdef ENFORCE_LIBRARY_WARN_AS_ERROR
68 ifeq ($(LIBRARY_WARN_AS_ERROR),yes)
69 ifndef MCS_MODE
70 LIB_MCS_FLAGS += -warnaserror
71 endif
72 endif
73 endif
75 # add sourcelink information if we're building a portable PDB
76 ifneq (, $(findstring debug:portable, $(PROFILE_MCS_FLAGS)))
77 LIB_MCS_FLAGS += -sourcelink:$(topdir)/build/common/sourcelink.json
78 endif
80 the_libdir = $(the_libdir_base)$(intermediate)
82 ifdef LIBRARY_USE_INTERMEDIATE_FILE
83 build_libdir = $(the_libdir)tmp/
84 else
85 build_libdir = $(the_libdir)
86 endif
88 the_lib = $(the_libdir)$(LIBRARY_NAME)
89 build_lib = $(build_libdir)$(LIBRARY_NAME)
90 library_CLEAN_FILES += $(the_lib) $(the_lib).so $(the_lib).mdb $(the_lib:.dll=.pdb)
91 library_CLEAN_FILES += $(build_lib) $(build_lib).so $(build_lib).mdb $(build_lib:.dll=.pdb)
93 ifdef NO_SIGN_ASSEMBLY
94 SN = :
95 else
96 ifeq ("$(SN)","")
97 sn = $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/sn.exe
98 SN = MONO_PATH="$(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(sn) -q
99 endif
100 endif
102 ifeq ($(BUILD_PLATFORM), win32)
103 GACDIR = `cygpath -w $(mono_libdir)`
104 GACROOT = `cygpath -w $(DESTDIR)$(mono_libdir)`
105 test_flags += -d:WINDOWS
106 else
107 GACDIR = $(mono_libdir)
108 GACROOT = $(DESTDIR)$(mono_libdir)
109 endif
111 ifndef NO_BUILD
112 all-local: $(the_lib) $(extra_targets)
113 endif
115 ifeq ($(LIBRARY_COMPILE),$(BOOT_COMPILE))
116 is_boot=true
117 else
118 is_boot=false
119 endif
121 csproj-local: csproj-library csproj-test
123 intermediate_clean=$(subst /,-,$(intermediate))
124 csproj-library:
125 config_file=`basename $(LIBRARY) .dll`-$(intermediate_clean)$(PROFILE).input; \
126 case "$(thisdir)" in *"Facades"*) config_file=Facades_$$config_file;; *"legacy"*) config_file=legacy_$$config_file;; esac; \
127 echo $(thisdir):$$config_file >> $(topdir)/../msvc/scripts/order; \
128 (echo $(is_boot); \
129 echo $(USE_MCS_FLAGS) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) $(KEYFILE_MCS_FLAGS); \
130 echo $(LIBRARY); \
131 echo $(LIBRARY_NAME); \
132 echo $(BUILT_SOURCES_cmdline); \
133 echo $(build_lib); \
134 echo $(FRAMEWORK_VERSION); \
135 echo $(PROFILE); \
136 echo $(RESOURCE_DEFS); \
137 echo $(response)) > $(topdir)/../msvc/scripts/inputs/$$config_file
139 csproj-test:
141 install-local: all-local
142 test-local: all-local
143 uninstall-local:
145 ifdef NO_INSTALL
146 install-local uninstall-local:
149 else
151 aot_lib = $(the_lib)$(PLATFORM_AOT_SUFFIX)
152 aot_libname = $(LIBRARY_NAME)$(PLATFORM_AOT_SUFFIX)
154 ifdef LIBRARY_INSTALL_DIR
155 install-local:
156 $(MKINSTALLDIRS) $(DESTDIR)$(LIBRARY_INSTALL_DIR)
157 $(INSTALL_LIB) $(the_lib) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME)
158 test ! -f $(the_lib).mdb || $(INSTALL_LIB) $(the_lib).mdb $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb
159 test ! -f $(the_lib:.dll=.pdb) || $(INSTALL_LIB) $(the_lib:.dll=.pdb) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME:.dll=.pdb)
161 ifdef PLATFORM_AOT_SUFFIX
162 test ! -f $(aot_lib) || $(INSTALL_LIB) $(aot_lib) $(DESTDIR)$(LIBRARY_INSTALL_DIR)
163 endif
165 uninstall-local:
166 -rm -f $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME) $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME).mdb $(DESTDIR)$(LIBRARY_INSTALL_DIR)/$(LIBRARY_NAME:.dll=.pdb)
168 else
170 # If RUNTIME_HAS_CONSISTENT_GACDIR is set, it implies that the internal GACDIR
171 # of the runtime is the same as the GACDIR we want. So, we don't need to pass it
172 # to gacutil. Note that the GACDIR we want may not be the same as the value of
173 # GACDIR set above, since the user could have overridden the value of $(prefix).
175 # This makes a difference only when we're building from the mono/ tree, since we
176 # have to ensure that the internal GACDIR of the in-tree runtime matches where we
177 # install the DLLs.
179 ifndef RUNTIME_HAS_CONSISTENT_GACDIR
180 gacdir_flag = /gacdir $(GACDIR)
181 endif
183 ifndef LIBRARY_PACKAGE
184 ifdef LIBRARY_COMPAT
185 LIBRARY_PACKAGE = compat-$(FRAMEWORK_VERSION)
186 else
187 LIBRARY_PACKAGE = $(FRAMEWORK_VERSION)
188 endif
189 endif
191 ifneq (none, $(LIBRARY_PACKAGE))
192 package_flag = /package $(LIBRARY_PACKAGE)
193 endif
195 install-local: $(gacutil)
196 $(GACUTIL) /i $(the_lib) /f $(gacdir_flag) /root $(GACROOT) $(package_flag)
198 uninstall-local: $(gacutil)
199 -$(GACUTIL) /u $(LIBRARY_NAME:.dll=) $(gacdir_flag) /root $(GACROOT) $(package_flag)
201 endif # LIBRARY_INSTALL_DIR
202 endif # NO_INSTALL
204 clean-local:
205 -rm -f $(tests_CLEAN_FILES) $(library_CLEAN_FILES) $(CLEAN_FILES)
207 test-local run-test-local run-test-ondotnet-local:
211 # RESOURCES_DEFS is a list of ID,FILE pairs separated by spaces
212 # for each of those, generate a rule that produces ID.resource from
213 # FILE using the resgen tool, adds the generated file to CLENA_FILES and
214 # passes the resource to the compiler
216 ccomma = ,
217 define RESOURCE_template
218 $(1).resources: $(2)
219 $$(RESGEN) "$$<" "$$@"
221 GEN_RESOURCE_DEPS += $(1).resources
222 GEN_RESOURCE_FLAGS += -resource:$(1).resources
223 CLEAN_FILES += $(1).resources
224 DIST_LISTED_RESOURCES += $(2)
225 endef
227 ifdef RESOURCE_DEFS
228 $(foreach pair,$(RESOURCE_DEFS), $(eval $(call RESOURCE_template,$(word 1, $(subst $(ccomma), ,$(pair))), $(word 2, $(subst $(ccomma), ,$(pair))))))
229 endif
231 DISTFILES = $(wildcard *.sources) $(EXTRA_DISTFILES) $(DIST_LISTED_RESOURCES)
233 ASSEMBLY = $(LIBRARY)
234 ASSEMBLY_EXT = .dll
235 the_assembly = $(the_lib)
237 include $(topdir)/build/tests.make
239 ifdef HAVE_CS_TESTS
240 DISTFILES += $(test_sourcefile)
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 $(LIBRARY); \
248 echo $(test_lib); \
249 echo $(BUILT_SOURCES_cmdline); \
250 echo $(test_lib); \
251 echo $(FRAMEWORK_VERSION); \
252 echo $(PROFILE); \
253 echo ""; \
254 echo $(test_response)) > $(topdir)/../msvc/scripts/inputs/$$config_file
256 endif
258 # make dist will collect files in .sources files from all profiles
259 dist-local: dist-default
260 subs=' ' ; \
261 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 \
262 case $$f in \
263 ../*) : ;; \
264 *.g.cs) : ;; \
265 *) dest=`dirname "$$f"` ; \
266 case $$subs in *" $$dest "*) : ;; *) subs=" $$dest$$subs" ; $(MKINSTALLDIRS) $(distdir)/$$dest ;; esac ; \
267 cp -p "$$f" $(distdir)/$$dest || exit 1 ;; \
268 esac ; done ; \
269 for d in . $$subs ; do \
270 case $$d in .) : ;; *) test ! -f $$d/ChangeLog || cp -p $$d/ChangeLog $(distdir)/$$d ;; esac ; done
272 ifndef LIBRARY_COMPILE
273 LIBRARY_COMPILE = $(CSCOMPILE)
274 endif
276 ifndef LIBRARY_SNK
277 LIBRARY_SNK = $(topdir)/class/mono.snk
278 endif
280 ifdef BUILT_SOURCES
281 library_CLEAN_FILES += $(BUILT_SOURCES)
282 ifeq (cat, $(PLATFORM_CHANGE_SEPARATOR_CMD))
283 BUILT_SOURCES_cmdline = $(BUILT_SOURCES)
284 else
285 BUILT_SOURCES_cmdline = `echo $(BUILT_SOURCES) | $(PLATFORM_CHANGE_SEPARATOR_CMD)`
286 endif
287 endif
289 # The library
291 # If the directory contains the per profile include file, generate list file.
292 # TODO: depend on all *.sources (except tests) for now and figure out how to list only needed files later
293 PROFILE_sources = $(filter-out %test.dll.exclude.sources %test.dll.sources, $(wildcard *.sources))
294 PROFILE_excludes = $(filter-out %test.dll.exclude.sources %test.dll.sources, $(wildcard *.exclude.sources))
296 sourcefile = $(depsdir)/$(PROFILE_PLATFORM)_$(PROFILE)_$(LIBRARY_SUBDIR)_$(LIBRARY).sources
297 $(sourcefile): $(PROFILE_sources) $(PROFILE_excludes) $(depsdir)/.stamp
298 $(GENSOURCES) --strict --platformsdir:$(topdir)/build "$@" "$(LIBRARY)" "$(PROFILE_PLATFORM)" "$(PROFILE)"
300 library_CLEAN_FILES += $(sourcefile)
302 response = $(depsdir)/$(PROFILE_PLATFORM)_$(PROFILE)_$(LIBRARY_SUBDIR)_$(LIBRARY).response
303 $(response): $(sourcefile) $(topdir)/build/library.make $(depsdir)/.stamp
304 $(PLATFORM_CHANGE_SEPARATOR_CMD) <$(sourcefile) >$@
306 library_CLEAN_FILES += $(response)
308 makefrag = $(depsdir)/$(PROFILE_PLATFORM)_$(PROFILE)_$(LIBRARY_SUBDIR)_$(LIBRARY).makefrag
309 $(makefrag): $(sourcefile) $(topdir)/build/library.make $(depsdir)/.stamp
310 # @echo Creating $@ ...
311 @sed 's,^,$(build_lib): ,' $< >$@
312 @if test ! -f $(sourcefile).makefrag; then :; else \
313 cat $(sourcefile).makefrag >> $@ ; \
314 echo '$@: $(sourcefile).makefrag' >> $@; \
315 echo '$(sourcefile).makefrag:' >> $@; fi
317 library_CLEAN_FILES += $(makefrag)
319 ifndef NO_BUILD
320 all-local: $(makefrag)
321 endif
323 -include $(makefrag)
325 $(the_lib): $(the_libdir)/.stamp $(if $(PROFILE_PLATFORM),$(if $(filter $(HOST_PLATFORM),$(BUILD_PLATFORM)),$(topdir)/class/$(lib_dir)/$(PROFILE)/.stamp))
327 ifdef PROFILE_PLATFORM
328 $(topdir)/class/$(lib_dir)/$(PROFILE)/.stamp: | $(topdir)/class/$(lib_dir)/$(PROFILE)-$(HOST_PLATFORM)/.stamp
329 $(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)))
330 endif
332 ifndef NO_BUILD
334 $(build_lib): $(response) $(sn) $(BUILT_SOURCES) $(build_libdir)/.stamp $(GEN_RESOURCE_DEPS) $(MODULE_DEPS)
335 $(LIBRARY_COMPILE) $(LIBRARY_FLAGS) $(LIB_MCS_FLAGS) $(KEYFILE_MCS_FLAGS) $(GEN_RESOURCE_FLAGS) -target:library -out:$@ $(BUILT_SOURCES_cmdline) @$(response)
336 ifdef RESOURCE_STRINGS_FILES
337 $(Q) $(STRING_REPLACER) $(RESOURCE_STRINGS_FILES) $(IL_REPLACE_FILES) $@
338 endif
339 $(Q) $(SN) -R $@ $(LIBRARY_SNK)
341 ifdef LIBRARY_USE_INTERMEDIATE_FILE
342 $(the_lib): $(build_lib)
343 $(Q) cp $(build_lib) $@
344 $(Q) $(SN) -v $@
345 $(Q) test ! -f $(build_lib).mdb || mv $(build_lib).mdb $@.mdb
346 $(Q) test ! -f $(build_lib:.dll=.pdb) || mv $(build_lib:.dll=.pdb) $(the_lib:.dll=.pdb)
347 endif
349 endif
351 library_CLEAN_FILES += $(PROFILE)_$(LIBRARY_NAME)_aot.log
353 ifdef PLATFORM_AOT_SUFFIX
354 $(the_lib)$(PLATFORM_AOT_SUFFIX): $(the_lib)
355 $(Q_AOT) MONO_PATH='$(the_libdir_base)' $(RUNTIME) $(AOT_BUILD_FLAGS) --debug $(the_lib)
357 all-local-aot: $(the_lib)$(PLATFORM_AOT_SUFFIX)
358 endif
360 # for now, don't give any /lib flags or set MONO_PATH, since we
361 # give a full path to the assembly.
363 ## Include corcompare stuff
364 include $(topdir)/build/corcompare.make
366 ifndef NO_BUILD
367 all-local: $(test_makefrag) $(btest_makefrag)
368 endif
370 $(test_response) $(test_makefrag) $(btest_response) $(btest_makefrag): $(topdir)/build/library.make $(depsdir)/.stamp
372 ## Documentation stuff
374 doc-update-local: $(the_libdir)/.doc-stamp
376 $(the_libdir)/.doc-stamp: $(the_lib)
377 $(MDOC_UP) $(the_lib)
378 @echo "doc-stamp" > $@
380 # Need to be here so it comes after the definition of DEP_DIRS/DEP_LIBS
381 gen-deps:
382 @echo "$(DEPS_TARGET_DIR): $(DEP_DIRS) $(DEP_LIBS)" >> $(DEPS_FILE)
384 update-corefx-sr-generic:
385 ifneq ($(RESX_STRINGS),)
386 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_EXTRA_ARGUMENTS) $(RESX_STRINGS) >$(SR_OUTPUT)
387 endif
389 update-corefx-sr: $(RESX_RESOURCE_STRING) $(XTEST_RESX_RESOURCE_STRING)
390 $(MAKE) SR_OUTPUT=corefx/SR.cs RESX_STRINGS="$(RESX_RESOURCE_STRING)" RESX_EXTRA_ARGUMENTS="$(RESX_EXTRA_ARGUMENTS)" update-corefx-sr-generic \
391 && $(MAKE) SR_OUTPUT=corefx/SR.tests.cs RESX_STRINGS=$(XTEST_RESX_RESOURCE_STRING) update-corefx-sr-generic