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