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