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