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