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