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