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