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