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