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