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