Bump corefx
[mono.git] / mcs / build / rules.make
1 # -*- makefile -*-
2 #
3 # This is the makefile fragment with default rules
4 # for building things in MCS
5 #
6 # To customize the build, you should edit config.make.
7 # If you need to edit this file, that's a bug; email
8 # peter@newton.cx about it.
9
10 empty :=
11 space := $(empty) $(empty)
12 _FILTER_OUT = $(foreach x,$(2),$(if $(findstring $(1),$(x)),,$(x)))
13
14 # given $(thisdir), we compute the path to the top directory
15 #
16 # split_path = $(filter-out .,$(subst /,$(space),$(1)))
17 # make_path = ./$(subst $(space),/,$(1))
18 # dotdottify = $(patsubst %,..,$(1))
19 # topdir = $(call make_path,$(call dotdottify,$(call split_path,$(thisdir))))
20 topdir := ./$(subst $(space),/,$(patsubst %,..,$(filter-out .,$(subst /,$(space),$(thisdir)))))
21
22 VERSION = 0.93
23
24 Q=$(if $(V),,@)
25 # echo -e "\\t" does not work on some systems, so use 5 spaces
26 Q_MCS=$(if $(V),,@echo "$(if $(MCS_MODE),MCS,CSC)     [$(intermediate)$(PROFILE_DIRECTORY)] $(notdir $(@))";)
27 Q_AOT=$(if $(V),,@echo "AOT     [$(intermediate)$(PROFILE_DIRECTORY)] $(notdir $(@))";)
28
29 ifndef BUILD_TOOLS_PROFILE
30 ifeq ($(PROFILE),basic)
31 BUILD_TOOLS_PROFILE = basic
32 else
33 BUILD_TOOLS_PROFILE = build
34 endif
35 endif
36
37 USE_MCS_FLAGS = /codepage:$(CODEPAGE) /nologo /noconfig /deterministic $(LOCAL_MCS_FLAGS) $(PLATFORM_MCS_FLAGS) $(PROFILE_MCS_FLAGS) $(MCS_FLAGS)
38 USE_MBAS_FLAGS = /codepage:$(CODEPAGE) $(LOCAL_MBAS_FLAGS) $(PLATFORM_MBAS_FLAGS) $(PROFILE_MBAS_FLAGS) $(MBAS_FLAGS)
39 USE_CFLAGS = $(LOCAL_CFLAGS) $(CFLAGS) $(CPPFLAGS)
40 CSCOMPILE = $(Q_MCS) $(MCS) $(USE_MCS_FLAGS)
41 CSC_RUNTIME_FLAGS = --aot-path=$(abspath $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)) --gc-params=nursery-size=64m
42 BASCOMPILE = $(MBAS) $(USE_MBAS_FLAGS)
43 CCOMPILE = $(CC) $(USE_CFLAGS)
44 BOOT_COMPILE = $(Q_MCS) $(BOOTSTRAP_MCS) $(USE_MCS_FLAGS)
45 INSTALL = $(SHELL) $(topdir)/../mono/install-sh
46 INSTALL_DATA = $(INSTALL) -c -m 644
47 INSTALL_BIN = $(INSTALL) -c -m 755
48 INSTALL_LIB = $(INSTALL_BIN)
49 MKINSTALLDIRS = $(SHELL) $(topdir)/mkinstalldirs
50 INTERNAL_MBAS = $(RUNTIME) $(RUNTIME_FLAGS) $(topdir)/mbas/mbas.exe
51 INTERNAL_CSC_LOCATION = $(CSC_LOCATION)
52
53 # Using CSC_SDK_PATH_DISABLED for sanity check that all references have path specified
54 INTERNAL_CSC = CSC_SDK_PATH_DISABLED= $(RUNTIME) $(RUNTIME_FLAGS) $(CSC_RUNTIME_FLAGS) $(INTERNAL_CSC_LOCATION)
55
56 RESGEN = MONO_PATH="$(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/resgen.exe
57 STRING_REPLACER = MONO_PATH="$(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/cil-stringreplacer.exe
58 ILASM = MONO_PATH="$(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/ilasm.exe
59
60
61 depsdir = $(topdir)/build/deps
62
63 # Make sure these propagate if set manually
64
65 export PROFILE
66 export MCS
67 export MCS_FLAGS
68 export CC
69 export CFLAGS
70 export INSTALL
71 export MKINSTALLDIRS
72 export BOOTSTRAP_MCS
73 export DESTDIR
74 export RESGEN
75
76 # Get this so the platform.make platform-check rule doesn't become the
77 # default target
78
79 .DEFAULT: all
80 default: all
81
82 # Get initial configuration. pre-config is so that the builder can
83 # override BUILD_PLATFORM or PROFILE
84
85 include $(topdir)/build/config-default.make
86 -include $(topdir)/build/pre-config.make
87 -include $(topdir)/build/config.make
88
89 # Platform config
90
91 include $(topdir)/build/platforms/$(BUILD_PLATFORM).make
92
93 PROFILE_PLATFORM = $(if $(PLATFORMS),$(if $(filter $(PLATFORMS),$(HOST_PLATFORM)),$(HOST_PLATFORM),$(error Unknown platform "$(HOST_PLATFORM)" for profile "$(PROFILE)")))
94 PROFILE_DIRECTORY = $(PROFILE)$(if $(PROFILE_PLATFORM),-$(PROFILE_PLATFORM))
95
96 ifdef PLATFORM_CORLIB
97 corlib = $(PLATFORM_CORLIB)
98 endif
99 # Useful
100
101 ifeq ($(PLATFORM_RUNTIME),$(RUNTIME))
102 PLATFORM_MONO_NATIVE = yes
103 endif
104
105 # Rest of the configuration
106
107 ifndef PROFILE
108 PROFILE = $(DEFAULT_PROFILE)
109 endif
110
111 include $(topdir)/build/profiles/$(PROFILE).make
112
113 ifdef BCL_OPTIMIZE
114 PROFILE_MCS_FLAGS += -optimize
115 endif
116
117 ifdef MCS_MODE
118 INTERNAL_CSC_LOCATION = $(topdir)/class/lib/$(BOOTSTRAP_PROFILE)/mcs.exe
119
120 ifdef PLATFORM_DEBUG_FLAGS
121 PLATFORM_DEBUG_FLAGS = /debug:full
122 endif
123
124 endif
125
126 # Design:
127 # Problem: We want to be able to build aot
128 # assemblies as part of the build system. 
129 #
130 # For this to be done safely, we really need two passes. This
131 # ensures that all of the .dlls are compiled before trying to
132 # aot them. Because we want this to be the
133 # default target for some profiles(testing_aot_full) we have a
134 # two-level build system. The do-all-aot target is what
135 # gets invoked at the top-level when someone tries to build with aot.
136 # It will invoke the do-all target, and will set TOP_LEVEL_DO for this
137 # recursive make call in order to prevent this recursive call from trying
138 # to build aot in each of the subdirs. After this is done, we will aot
139 # everything that our building produced by aoting everything in
140 # mcs/class/lib/$(PROFILE)/
141 ifndef TOP_LEVEL_DO
142
143 ifdef ALWAYS_AOT
144 TOP_LEVEL_DO = do-all-aot
145 else
146 TOP_LEVEL_DO = do-all
147 endif # ALWAYS_AOT
148
149 endif # !TOP_LEVEL_DO
150
151 ifdef OVERRIDE_TARGET_ALL
152 all: all.override
153 else
154 all: $(TOP_LEVEL_DO)
155 endif
156
157 ifdef NO_INSTALL
158 GACUTIL = :
159 else
160 gacutil = $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/gacutil.exe
161 GACUTIL = MONO_PATH="$(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(gacutil)
162 endif
163
164 STD_TARGETS = test run-test run-test-ondotnet clean install uninstall doc-update
165
166 $(STD_TARGETS): %: do-%
167
168 ifdef PLATFORM_AOT_SUFFIX
169
170 do-all-aot:
171         $(MAKE) do-all TOP_LEVEL_DO=do-all
172         $(MAKE) aot-all-profile
173
174 # When we recursively call $(MAKE) aot-all-profile
175 # we will have created this directory, and so will
176 # be able to evaluate the .dylibs to make
177 ifneq ("$(wildcard $(topdir)/class/lib/$(PROFILE))","")
178
179 AOT_PROFILE_ASSEMBLIES := $(sort $(patsubst .//%,%,$(filter-out %.dll.dll %.exe.dll %bare% %plaincore% %secxml% %Facades% %ilasm%,$(filter %.dll %.exe,$(wildcard $(topdir)/class/lib/$(PROFILE)/*)))))
180
181 # This can run in parallel
182 .PHONY: aot-all-profile
183 ifdef AOT_BUILD_FLAGS
184 aot-all-profile: $(patsubst %,%$(PLATFORM_AOT_SUFFIX),$(AOT_PROFILE_ASSEMBLIES))
185 else
186 aot-all-profile:
187         echo AOT_BUILD_FLAGS not set, skipping AOT.
188 endif
189
190 %.dll$(PLATFORM_AOT_SUFFIX): %.dll
191         @ mkdir -p $<_bitcode_tmp
192         $(Q_AOT) MONO_PATH="$(dir $<)" $(RUNTIME) $(RUNTIME_FLAGS) $(AOT_BUILD_FLAGS),temp-path=$<_bitcode_tmp --verbose $< > $@.aot-log
193         @ rm -rf $<_bitcode_tmp
194
195 %.exe$(PLATFORM_AOT_SUFFIX): %.exe
196         @ mkdir -p $<_bitcode_tmp
197         $(Q_AOT) MONO_PATH="$(dir $<)" $(RUNTIME) $(RUNTIME_FLAGS) $(AOT_BUILD_FLAGS),temp-path=$<_bitcode_tmp --verbose $< > $@.aot-log
198         @ rm -rf $<_bitcode_tmp
199
200 endif #ifneq ("$(wildcard $(topdir)/class/lib/$(PROFILE))","")
201
202 endif # PLATFORM_AOT_SUFFIX
203
204 do-run-test:
205         ok=:; $(MAKE) run-test-recursive || ok=false; $(MAKE) run-test-local || ok=false; $$ok
206
207 do-%: %-recursive
208         $(MAKE) $*-local
209
210 .PHONY: all-local $(STD_TARGETS:=-local)
211 all-local $(STD_TARGETS:=-local):
212
213 csproj: do-csproj
214
215 # The way this is set up, any profile-specific subdirs list should
216 # be listed _before_ including rules.make.  However, the default
217 # SUBDIRS list can come after, so don't use the eager := syntax when
218 # using the defaults.
219 PROFILE_SUBDIRS = $(or $($(PROFILE)_SUBDIRS),$(SUBDIRS))
220
221 # These subdirs can be built in parallel
222 PROFILE_PARALLEL_SUBDIRS = $(or $($(PROFILE)_PARALLEL_SUBDIRS),$(PARALLEL_SUBDIRS))
223
224 ifndef FRAMEWORK_VERSION_MAJOR
225 FRAMEWORK_VERSION_MAJOR = $(basename $(FRAMEWORK_VERSION))
226 endif
227
228 %-recursive:
229         @set . $$MAKEFLAGS; \
230         case $$2 in --unix) shift ;; esac; \
231         case $$2 in *=*) dk="exit 1" ;; *k*) dk=: ;; *) dk="exit 1" ;; esac; \
232         final_exit=:; \
233         $(foreach subdir,$(PROFILE_SUBDIRS),$(MAKE) -C $(subdir) $* || { final_exit="exit 1"; $$dk; };) \
234         $(if $(PROFILE_PARALLEL_SUBDIRS), \
235                 $(if $(filter $*,all), \
236                         $(MAKE) $(PROFILE_PARALLEL_SUBDIRS) ENABLE_PARALLEL_SUBDIR_BUILD=1 || { final_exit="exit 1"; $$dk; };, \
237                         $(foreach subdir,$(PROFILE_PARALLEL_SUBDIRS),$(MAKE) -C $(subdir) $* || { final_exit="exit 1"; $$dk; };))) \
238         $$final_exit
239
240 ifdef ENABLE_PARALLEL_SUBDIR_BUILD
241 .PHONY: $(PROFILE_PARALLEL_SUBDIRS)
242 $(PROFILE_PARALLEL_SUBDIRS):
243         @set . $$MAKEFLAGS; \
244         $(MAKE) -C $@ all
245 endif
246
247 #
248 # Parallel build support
249 #
250 # The variable $(PROFILE)_PARALLEL_SUBDIRS should be set to the list of directories
251 # which could be built in parallel. These directories are built after the directories in
252 # $(PROFILE)_SUBDIRS.
253 # Parallel building is currently only supported for the 'all' target.
254 #
255 # Each directory's Makefile may define DEP_LIBS and DEP_DIRS to specify the libraries and
256 # directories it depends on.
257 #
258 ifneq ($(PROFILE_PARALLEL_SUBDIRS),)
259 dep_dirs = .dep_dirs-$(PROFILE)
260 $(dep_dirs):
261         @echo "Creating $@..."
262         list='$(PROFILE_PARALLEL_SUBDIRS)'; \
263         echo > $@; \
264         for d in $$list; do \
265                 $(MAKE) -C $$d gen-deps DEPS_TARGET_DIR=$$d DEPS_FILE=$(abspath $@); \
266         done
267 -include $(dep_dirs)
268 endif
269
270 .PHONY: gen-deps
271 # The gen-deps target is in library.make/executable.make so it can pick up
272 # DEP_LIBS/DEP_DIRS
273
274 clean-dep-dir:
275         $(RM) $(dep_dirs)
276
277 clean-local: clean-dep-dir
278
279 ifndef DIST_SUBDIRS
280 DIST_SUBDIRS = $(SUBDIRS) $(DIST_ONLY_SUBDIRS)
281 endif
282 dist-recursive: dist-local
283         @case '$(distdir)' in [\\/$$]* | ?:[\\/]* ) reldir='$(distdir)' ;; *) reldir='../$(distdir)' ;; esac ; \
284         list='$(DIST_SUBDIRS)'; for d in $$list ; do \
285             (cd $$d && $(MAKE) distdir=$$reldir/$$d $@) || exit 1 ; \
286         done
287
288 # The following target can be used like
289 #
290 #   dist-local: dist-default
291 #       ... additional commands ...
292 #
293 # Notes:
294 #  1. we invert the test here to not end in an error if ChangeLog doesn't exist.
295 #  2. we error out if we try to dist a nonexistant file.
296 #  3. we pick up Makefile, makefile, or GNUmakefile.
297 dist-default:
298         -mkdir -p $(distdir)
299         test '!' -f ChangeLog || cp ChangeLog $(distdir)
300         if test -f Makefile; then m=M; fi; \
301         if test -f makefile; then m=m; fi; \
302         if test -f GNUmakefile; then m=GNUm; fi; \
303         for f in $${m}akefile $(DISTFILES) ; do \
304             dest=`dirname "$(distdir)/$$f"` ; \
305             $(MKINSTALLDIRS) $$dest && cp -p "$$f" $$dest || exit 1 ; \
306         done
307         if test -d Documentation ; then \
308                 find . -name '*.xml' > .files ; \
309                 tar cTf .files - | (cd $(distdir); tar xf -) ; \
310                 rm .files ; \
311         fi
312
313 %/.stamp:
314         $(MKINSTALLDIRS) $(@D)
315         touch $@
316
317 ## Documentation stuff
318
319 Q_MDOC =$(if $(V),,@echo "MDOC    [$(PROFILE_DIRECTORY)] $(notdir $(@))";)
320 MDOC   =$(Q_MDOC) MONO_PATH="$(topdir)/class/lib/$(DEFAULT_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(topdir)/class/lib/$(DEFAULT_PROFILE)/mdoc.exe
321
322 Q_MDOC_UP=$(if $(V),,@echo "MDOC-UP [$(PROFILE_DIRECTORY)] $(notdir $(@))";)
323 MDOC_UP  =$(Q_MDOC_UP) MONO_PATH="$(topdir)/class/lib/$(DEFAULT_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(topdir)/class/lib/$(DEFAULT_PROFILE)/mdoc.exe update --delete -o Documentation/en