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