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