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