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