[build] Roslyn switch
[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 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 BASCOMPILE = $(MBAS) $(USE_MBAS_FLAGS)
37 CCOMPILE = $(CC) $(USE_CFLAGS)
38 BOOT_COMPILE = $(Q_MCS) $(BOOTSTRAP_MCS) $(USE_MCS_FLAGS)
39 INSTALL = $(SHELL) $(topdir)/../mono/install-sh
40 INSTALL_DATA = $(INSTALL) -c -m 644
41 INSTALL_BIN = $(INSTALL) -c -m 755
42 INSTALL_LIB = $(INSTALL_BIN)
43 MKINSTALLDIRS = $(SHELL) $(topdir)/mkinstalldirs
44 INTERNAL_MBAS = $(RUNTIME) $(RUNTIME_FLAGS) $(topdir)/mbas/mbas.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)/$(PARENT_PROFILE)resgen.exe
49 INTERNAL_RESGEN = $(RUNTIME) $(RUNTIME_FLAGS) $(RESGEN_EXE)
50 RESGEN = MONO_PATH="$(topdir)/class/lib/$(PROFILE)/$(PARENT_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 ifdef BCL_OPTIMIZE
120 PROFILE_MCS_FLAGS += -optimize
121 endif
122
123 # Design:
124 # Problem: We want to be able to build aot
125 # assemblies as part of the build system. 
126 #
127 # For this to be done safely, we really need two passes. This
128 # ensures that all of the .dlls are compiled before trying to
129 # aot them. Because we want this to be the
130 # default target for some profiles(aot_only) we have a
131 # two-level build system. The do-all-aot target is what
132 # gets invoked at the top-level when someone tries to build with aot.
133 # It will invoke the do-all target, and will set TOP_LEVEL_DO for this
134 # recursive make call in order to prevent this recursive call from trying
135 # to build aot in each of the subdirs. After this is done, we will aot
136 # everything that our building produced by aoting everything in
137 # mcs/class/lib/$(PROFILE)/
138 ifndef TOP_LEVEL_DO
139
140 ifdef ALWAYS_AOT
141 TOP_LEVEL_DO = do-all-aot
142 else
143 TOP_LEVEL_DO = do-all
144 endif # ALWAYS_AOT
145
146 endif # !TOP_LEVEL_DO
147
148 ifdef OVERRIDE_TARGET_ALL
149 all: all.override
150 else
151 all: $(TOP_LEVEL_DO)
152 endif
153
154 ifdef NO_INSTALL
155 GACUTIL = :
156 else
157 gacutil = $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/gacutil.exe
158 GACUTIL = MONO_PATH="$(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(gacutil)
159 endif
160
161 STD_TARGETS = test run-test run-test-ondotnet clean install uninstall doc-update
162
163 $(STD_TARGETS): %: do-%
164
165 ifdef PLATFORM_AOT_SUFFIX
166
167 do-all-aot:
168         $(MAKE) do-all TOP_LEVEL_DO=do-all
169         $(MAKE) aot-all-profile
170
171 # When we recursively call $(MAKE) aot-all-profile
172 # we will have created this directory, and so will
173 # be able to evaluate the .dylibs to make
174 ifneq ("$(wildcard $(topdir)/class/lib/$(PROFILE))","")
175
176 AOT_PROFILE_ASSEMBLIES := $(sort $(patsubst .//%,%,$(filter-out %bare% %plaincore% %secxml% %Facades% %ilasm%,$(filter %.dll %.exe,$(wildcard $(topdir)/class/lib/$(PROFILE)/*)))))
177
178 # This can run in parallel
179 .PHONY: aot-all-profile
180 aot-all-profile: $(patsubst %,%$(PLATFORM_AOT_SUFFIX),$(AOT_PROFILE_ASSEMBLIES))
181
182 %$(PLATFORM_AOT_SUFFIX): %
183         @ mkdir -p $*_bitcode_tmp
184         $(Q_AOT) MONO_PATH="$(dir $*)" $(RUNTIME) $(RUNTIME_FLAGS) $(AOT_BUILD_FLAGS),temp-path=$*_bitcode_tmp --verbose $* > $@.aot-log
185         @ rm -rf $*_bitcode_tmp
186
187 endif #ifneq ("$(wildcard $(topdir)/class/lib/$(PROFILE))","")
188
189 endif # PLATFORM_AOT_SUFFIX
190
191 do-run-test:
192         ok=:; $(MAKE) run-test-recursive || ok=false; $(MAKE) run-test-local || ok=false; $$ok
193
194 do-%: %-recursive
195         $(MAKE) $*-local
196
197 .PHONY: all-local $(STD_TARGETS:=-local)
198 all-local $(STD_TARGETS:=-local):
199
200 csproj: do-csproj
201
202 # The way this is set up, any profile-specific subdirs list should
203 # be listed _before_ including rules.make.  However, the default
204 # SUBDIRS list can come after, so don't use the eager := syntax when
205 # using the defaults.
206 PROFILE_SUBDIRS := $($(PROFILE)_SUBDIRS)
207 ifndef PROFILE_SUBDIRS
208 PROFILE_SUBDIRS = $(SUBDIRS)
209 endif
210
211 # These subdirs can be built in parallel
212 PROFILE_PARALLEL_SUBDIRS := $($(PROFILE)_PARALLEL_SUBDIRS)
213 ifndef PROFILE_PARALLEL_SUBDIRS
214 PROFILE_PARALLEL_SUBDIRS = $(PARALLEL_SUBDIRS)
215 endif
216
217 ifndef FRAMEWORK_VERSION_MAJOR
218 FRAMEWORK_VERSION_MAJOR = $(basename $(FRAMEWORK_VERSION))
219 endif
220
221 %-recursive:
222         @set . $$MAKEFLAGS; final_exit=:; \
223         case $$2 in --unix) shift ;; esac; \
224         case $$2 in *=*) dk="exit 1" ;; *k*) dk=: ;; *) dk="exit 1" ;; esac; \
225         list='$(PROFILE_SUBDIRS)'; for d in $$list ; do \
226             (cd $$d && $(MAKE) $*) || { final_exit="exit 1"; $$dk; } ; \
227         done; \
228         if [ $* = "all" -a -n "$(PROFILE_PARALLEL_SUBDIRS)" ]; then \
229                 $(MAKE) do-all-parallel ENABLE_PARALLEL_SUBDIR_BUILD=1 || { final_exit="exit 1"; $$dk; } ; \
230         else \
231                 list='$(PROFILE_PARALLEL_SUBDIRS)'; for d in $$list ; do \
232                     (cd $$d && $(MAKE) $*) || { final_exit="exit 1"; $$dk; } ; \
233                 done; \
234         fi; \
235         $$final_exit
236
237 #
238 # Parallel build support
239 #
240 # The variable $(PROFILE)_PARALLEL_SUBDIRS should be set to the list of directories
241 # which could be built in parallel. These directories are built after the directories in
242 # $(PROFILE)_SUBDIRS.
243 # Parallel building is currently only supported for the 'all' target.
244 #
245 # Each directory's Makefile may define DEP_LIBS and DEP_DIRS to specify the libraries and
246 # directories it depends on.
247 #
248 ifneq ($(PROFILE_PARALLEL_SUBDIRS),)
249 dep_dirs = .dep_dirs-$(PROFILE)
250 $(dep_dirs):
251         @echo "Creating $@..."
252         list='$(PROFILE_PARALLEL_SUBDIRS)'; \
253         echo > $@; \
254         for d in $$list; do \
255                 $(MAKE) -C $$d gen-deps DEPS_TARGET_DIR=$$d DEPS_FILE=$(abspath $@); \
256         done
257 -include $(dep_dirs)
258 endif
259
260 .PHONY: gen-deps
261 # The gen-deps target is in library.make/executable.make so it can pick up
262 # DEP_LIBS/DEP_DIRS
263
264 clean-dep-dir:
265         $(RM) $(dep_dirs)
266
267 clean-local: clean-dep-dir
268
269 ifdef ENABLE_PARALLEL_SUBDIR_BUILD
270 .PHONY: do-all-parallel $(PROFILE_PARALLEL_SUBDIRS)
271
272 do-all-parallel: $(PROFILE_PARALLEL_SUBDIRS)
273
274 $(PROFILE_PARALLEL_SUBDIRS):
275         @set . $$MAKEFLAGS; \
276         cd $@ && $(MAKE)
277 endif
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)] $(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