[mobile_static] Skip aot-ing ilasm
[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
13 # given $(thisdir), we compute the path to the top directory
14 #
15 # split_path = $(filter-out .,$(subst /,$(space),$(1)))
16 # make_path = ./$(subst $(space),/,$(1))
17 # dotdottify = $(patsubst %,..,$(1))
18 # topdir = $(call make_path,$(call dotdottify,$(call split_path,$(thisdir))))
19 topdir := ./$(subst $(space),/,$(patsubst %,..,$(filter-out .,$(subst /,$(space),$(thisdir)))))
20
21 VERSION = 0.93
22
23 Q=$(if $(V),,@)
24 # echo -e "\\t" does not work on some systems, so use 5 spaces
25 Q_MCS=$(if $(V),,@echo "MCS     [$(intermediate)$(PROFILE)] $(notdir $(@))";)
26
27 ifndef BUILD_TOOLS_PROFILE
28 BUILD_TOOLS_PROFILE = build
29 endif
30
31 USE_MCS_FLAGS = /codepage:$(CODEPAGE) $(LOCAL_MCS_FLAGS) $(PLATFORM_MCS_FLAGS) $(PROFILE_MCS_FLAGS) $(MCS_FLAGS)
32 USE_MBAS_FLAGS = /codepage:$(CODEPAGE) $(LOCAL_MBAS_FLAGS) $(PLATFORM_MBAS_FLAGS) $(PROFILE_MBAS_FLAGS) $(MBAS_FLAGS)
33 USE_CFLAGS = $(LOCAL_CFLAGS) $(CFLAGS) $(CPPFLAGS)
34 CSCOMPILE = $(Q_MCS) $(MCS) $(USE_MCS_FLAGS)
35 BASCOMPILE = $(MBAS) $(USE_MBAS_FLAGS)
36 CCOMPILE = $(CC) $(USE_CFLAGS)
37 BOOT_COMPILE = $(Q_MCS) $(BOOTSTRAP_MCS) $(USE_MCS_FLAGS)
38 INSTALL = $(SHELL) $(topdir)/../mono/install-sh
39 INSTALL_DATA = $(INSTALL) -c -m 644
40 INSTALL_BIN = $(INSTALL) -c -m 755
41 INSTALL_LIB = $(INSTALL_BIN)
42 MKINSTALLDIRS = $(SHELL) $(topdir)/mkinstalldirs
43 INTERNAL_MBAS = $(RUNTIME) $(RUNTIME_FLAGS) $(topdir)/mbas/mbas.exe
44 INTERNAL_GMCS = $(RUNTIME) $(RUNTIME_FLAGS) $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/mcs.exe
45 INTERNAL_ILASM = $(RUNTIME) $(RUNTIME_FLAGS) $(topdir)/class/lib/$(PROFILE)/ilasm.exe
46 INTERNAL_CSC = $(RUNTIME) $(RUNTIME_FLAGS) $(CSC_LOCATION)
47
48 RESGEN_EXE = $(topdir)/class/lib/$(PROFILE)/resgen.exe
49 INTERNAL_RESGEN = $(RUNTIME) $(RUNTIME_FLAGS) $(RESGEN_EXE)
50 RESGEN = MONO_PATH="$(topdir)/class/lib/$(PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(INTERNAL_RESGEN)
51 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
52
53 depsdir = $(topdir)/build/deps
54
55 # Make sure these propagate if set manually
56
57 export PLATFORM
58 export PROFILE
59 export MCS
60 export MCS_FLAGS
61 export CC
62 export CFLAGS
63 export INSTALL
64 export MKINSTALLDIRS
65 export BOOTSTRAP_MCS
66 export DESTDIR
67 export RESGEN
68
69 # Get this so the platform.make platform-check rule doesn't become the
70 # default target
71
72 .DEFAULT: all
73 default: all
74
75 # Get initial configuration. pre-config is so that the builder can
76 # override PLATFORM or PROFILE
77
78 include $(topdir)/build/config-default.make
79 -include $(topdir)/build/pre-config.make
80 -include $(topdir)/build/config.make
81
82 # Default PLATFORM and PROFILE if they're not already defined.
83
84 ifndef PLATFORM
85 ifeq ($(OS),Windows_NT)
86 ifneq ($(V),)
87 $(info *** Assuming PLATFORM is 'win32'.)
88 endif
89 PLATFORM = win32
90 else
91 ifneq ($(V),)
92 $(info *** Assuming PLATFORM is 'linux'.)
93 endif
94 PLATFORM = linux
95 endif
96 endif
97
98 # Platform config
99
100 include $(topdir)/build/platforms/$(PLATFORM).make
101
102 ifdef PLATFORM_CORLIB
103 corlib = $(PLATFORM_CORLIB)
104 endif
105 # Useful
106
107 ifeq ($(PLATFORM_RUNTIME),$(RUNTIME))
108 PLATFORM_MONO_NATIVE = yes
109 endif
110
111 # Rest of the configuration
112
113 ifndef PROFILE
114 PROFILE = $(DEFAULT_PROFILE)
115 endif
116
117 include $(topdir)/build/profiles/$(PROFILE).make
118
119 # If the profile is using nunit-lite, use it
120 ifdef NUNIT_LITE
121 TEST_HARNESS=$(topdir)/class/lib/$(PROFILE)/nunit-lite-console.exe
122 endif
123
124 # Make sure propagates
125 export TEST_HARNESS
126
127 # If the profile is using nunit-lite, use it
128 ifdef NUNIT_LITE
129 TEST_HARNESS=$(topdir)/class/lib/$(PROFILE)/nunit-lite-console.exe
130 endif
131
132 # Make sure propagates
133 export TEST_HARNESS
134
135 # start aot config
136
137 # We set the prefix of the aot build flags
138 # in the profile. This determines the aot type,
139 # whether it be llvmonly or full. To this we append the
140 # options which do not change between them, the INVARIANT_AOT_OPTIONS
141 ifndef AOT_BUILD_FLAGS_PREFIX
142 AOT_BUILD_FLAGS_PREFIX = --aot=
143 endif
144
145 # Set the options for building and running AOT
146 # The trampoline numbers are provisional, they are what is required
147 # to run the mcs/class test suites. They should be considered a lower bound.
148 INVARIANT_AOT_OPTIONS=nimt-trampolines=900,ntrampolines=8000,nrgctx-fetch-trampolines=256
149
150 ifndef MONO_DISABLE_GSHAREDVT
151 INVARIANT_AOT_OPTIONS:=$(INVARIANT_AOT_OPTIONS),ngsharedvt-trampolines=2800
152 endif
153
154 AOT_BUILD_FLAGS = $(AOT_BUILD_FLAGS_PREFIX)$(INVARIANT_AOT_OPTIONS)
155
156 # end AOT config
157
158 ifdef BCL_OPTIMIZE
159 PROFILE_MCS_FLAGS += -optimize
160 endif
161
162 # Design:
163 # Problem: We want to be able to build aot
164 # assemblies as part of the build system. 
165 #
166 # For this to be done safely, we really need two passes. This
167 # ensures that all of the .dlls are compiled before trying to
168 # aot them. Because we want this to be the
169 # default target for some profiles(mobile_static) we have a
170 # two-level build system. The do-all-aot target is what
171 # gets invoked at the top-level when someone tries to build with aot.
172 # It will invoke the do-all target, and will set TOP_LEVEL_DO for this
173 # recursive make call in order to prevent this recursive call from trying
174 # to build aot in each of the subdirs. After this is done, we will aot
175 # everything that our building produced by aoting everything in
176 # mcs/class/lib/$(PROFILE)/
177 ifndef TOP_LEVEL_DO
178
179 ifdef ALWAYS_AOT
180 TOP_LEVEL_DO = do-all-aot
181 else
182 TOP_LEVEL_DO = do-all
183 endif # ALWAYS_AOT
184
185 endif # !TOP_LEVEL_DO
186
187 ifdef OVERRIDE_TARGET_ALL
188 all: all.override
189 else
190 all: $(TOP_LEVEL_DO)
191 endif
192
193 ifdef NO_INSTALL
194 GACUTIL = :
195 else
196 gacutil = $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/gacutil.exe
197 GACUTIL = MONO_PATH="$(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(gacutil)
198 endif
199
200 STD_TARGETS = test run-test run-test-ondotnet clean install uninstall doc-update
201
202 $(STD_TARGETS): %: do-%
203
204 ifdef PLATFORM_AOT_SUFFIX
205 AOT_PROFILE_ASSEMBLIES = $(shell cd $(topdir)/class/lib/$(PROFILE)/ && find . | grep -E '(dll|exe)$$' | grep -v -E 'bare|plaincore|secxml|Facades' | sed 's:\./::g' | tr '\n' ' ')
206
207 do-all-aot:
208         $(MAKE) do-all TOP_LEVEL_DO=do-all
209         $(MAKE) aot-all-profile
210
211 # When we recursively call $(MAKE) aot-all-profile
212 # we will have created this directory, and so will
213 # be able to evaluate the .dylibs to make
214 ifneq ("$(wildcard $(topdir)/class/lib/$(PROFILE))","")
215
216 AOT_PROFILE_ASSEMBLIES_CMD = cd $(topdir)/class/lib/$(PROFILE)/ && find . | grep -E '(dll|exe)$$' | grep -v -E 'bare|plaincore|secxml|Facades|ilasm' | sed 's:\./::g' | tr '\n' ' '
217 AOT_PROFILE_ASSEMBLIES_CMD_SAFE = $(AOT_PROFILE_ASSEMBLIES_CMD) || true
218 AOT_PROFILE_ASSEMBLIES = $(shell $(AOT_PROFILE_ASSEMBLIES_CMD_SAFE))
219
220 # This can run in parallel
221 .PHONY: aot-all-profile
222 aot-all-profile: $(patsubst %,$(topdir)/class/lib/$(PROFILE)/%$(PLATFORM_AOT_SUFFIX),$(AOT_PROFILE_ASSEMBLIES))
223
224 $(topdir)/class/lib/$(PROFILE)/%$(PLATFORM_AOT_SUFFIX): $(topdir)/class/lib/$(PROFILE)/%
225         @ mkdir -p $(topdir)/class/lib/$(PROFILE)/$*_bitcode_tmp
226         @echo "AOT     [$(PROFILE)] AOT $* " && cd $(topdir)/class/lib/$(PROFILE)/ && MONO_PATH="." $(RUNTIME) $(RUNTIME_FLAGS) $(AOT_BUILD_FLAGS),temp-path=$*_bitcode $* >> $(PROFILE)-aot.log
227         @ rm -rf $(topdir)/class/lib/$(PROFILE)/$*_bitcode_tmp
228
229 endif #ifneq ("$(wildcard $(topdir)/class/lib/$(PROFILE))","")
230
231 endif # PLATFORM_AOT_SUFFIX
232
233 do-run-test:
234         ok=:; $(MAKE) run-test-recursive || ok=false; $(MAKE) run-test-local || ok=false; $$ok
235
236 do-%: %-recursive
237         $(MAKE) $*-local
238
239 .PHONY: all-local $(STD_TARGETS:=-local)
240 all-local $(STD_TARGETS:=-local):
241
242 csproj: do-csproj
243
244 # The way this is set up, any profile-specific subdirs list should
245 # be listed _before_ including rules.make.  However, the default
246 # SUBDIRS list can come after, so don't use the eager := syntax when
247 # using the defaults.
248 PROFILE_SUBDIRS := $($(PROFILE)_SUBDIRS)
249 ifndef PROFILE_SUBDIRS
250 PROFILE_SUBDIRS = $(SUBDIRS)
251 endif
252
253 # These subdirs can be built in parallel
254 PROFILE_PARALLEL_SUBDIRS := $($(PROFILE)_PARALLEL_SUBDIRS)
255 ifndef PROFILE_PARALLEL_SUBDIRS
256 PROFILE_PARALLEL_SUBDIRS = $(PARALLEL_SUBDIRS)
257 endif
258
259 ifndef FRAMEWORK_VERSION_MAJOR
260 FRAMEWORK_VERSION_MAJOR = $(basename $(FRAMEWORK_VERSION))
261 endif
262
263 %-recursive:
264         @set . $$MAKEFLAGS; final_exit=:; \
265         case $$2 in --unix) shift ;; esac; \
266         case $$2 in *=*) dk="exit 1" ;; *k*) dk=: ;; *) dk="exit 1" ;; esac; \
267         list='$(PROFILE_SUBDIRS)'; for d in $$list ; do \
268             (cd $$d && $(MAKE) $*) || { final_exit="exit 1"; $$dk; } ; \
269         done; \
270         if [ $* = "all" -a -n "$(PROFILE_PARALLEL_SUBDIRS)" ]; then \
271                 $(MAKE) do-all-parallel ENABLE_PARALLEL_SUBDIR_BUILD=1 || { final_exit="exit 1"; $$dk; } ; \
272         else \
273                 list='$(PROFILE_PARALLEL_SUBDIRS)'; for d in $$list ; do \
274                     (cd $$d && $(MAKE) $*) || { final_exit="exit 1"; $$dk; } ; \
275                 done; \
276         fi; \
277         $$final_exit
278
279 #
280 # Parallel build support
281 #
282 # The variable $(PROFILE)_PARALLEL_SUBDIRS should be set to the list of directories
283 # which could be built in parallel. These directories are built after the directories in
284 # $(PROFILE)_SUBDIRS.
285 # Parallel building is currently only supported for the 'all' target.
286 #
287 # Each directory's Makefile may define DEP_LIBS and DEP_DIRS to specify the libraries and
288 # directories it depends on.
289 #
290 ifneq ($(PROFILE_PARALLEL_SUBDIRS),)
291 dep_dirs = .dep_dirs-$(PROFILE)
292 $(dep_dirs):
293         @echo "Creating $@..."
294         list='$(PROFILE_PARALLEL_SUBDIRS)'; \
295         echo > $@; \
296         for d in $$list; do \
297                 $(MAKE) -C $$d gen-deps DEPS_TARGET_DIR=$$d DEPS_FILE=$(abspath $@); \
298         done
299 -include $(dep_dirs)
300 endif
301
302 .PHONY: gen-deps
303 # The gen-deps target is in library.make/executable.make so it can pick up
304 # DEP_LIBS/DEP_DIRS
305
306 clean-dep-dir:
307         $(RM) $(dep_dirs)
308
309 clean-local: clean-dep-dir
310
311 ifdef ENABLE_PARALLEL_SUBDIR_BUILD
312 .PHONY: do-all-parallel $(PROFILE_PARALLEL_SUBDIRS)
313
314 do-all-parallel: $(PROFILE_PARALLEL_SUBDIRS)
315
316 $(PROFILE_PARALLEL_SUBDIRS):
317         @set . $$MAKEFLAGS; \
318         cd $@ && $(MAKE)
319 endif
320
321 ifndef DIST_SUBDIRS
322 DIST_SUBDIRS = $(SUBDIRS) $(DIST_ONLY_SUBDIRS)
323 endif
324 dist-recursive: dist-local
325         @case '$(distdir)' in [\\/$$]* | ?:[\\/]* ) reldir='$(distdir)' ;; *) reldir='../$(distdir)' ;; esac ; \
326         list='$(DIST_SUBDIRS)'; for d in $$list ; do \
327             (cd $$d && $(MAKE) distdir=$$reldir/$$d $@) || exit 1 ; \
328         done
329
330 # The following target can be used like
331 #
332 #   dist-local: dist-default
333 #       ... additional commands ...
334 #
335 # Notes:
336 #  1. we invert the test here to not end in an error if ChangeLog doesn't exist.
337 #  2. we error out if we try to dist a nonexistant file.
338 #  3. we pick up Makefile, makefile, or GNUmakefile.
339 dist-default:
340         -mkdir -p $(distdir)
341         test '!' -f ChangeLog || cp ChangeLog $(distdir)
342         if test -f Makefile; then m=M; fi; \
343         if test -f makefile; then m=m; fi; \
344         if test -f GNUmakefile; then m=GNUm; fi; \
345         for f in $${m}akefile $(DISTFILES) ; do \
346             dest=`dirname "$(distdir)/$$f"` ; \
347             $(MKINSTALLDIRS) $$dest && cp -p "$$f" $$dest || exit 1 ; \
348         done
349         if test -d Documentation ; then \
350                 find . -name '*.xml' > .files ; \
351                 tar cTf .files - | (cd $(distdir); tar xf -) ; \
352                 rm .files ; \
353         fi
354
355 %/.stamp:
356         $(MKINSTALLDIRS) $(@D)
357         touch $@
358
359 ## Documentation stuff
360
361 Q_MDOC =$(if $(V),,@echo "MDOC    [$(PROFILE)] $(notdir $(@))";fi)
362 MDOC   =$(Q_MDOC) MONO_PATH="$(topdir)/class/lib/$(DEFAULT_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(topdir)/class/lib/$(DEFAULT_PROFILE)/mdoc.exe
363