Merge pull request #1609 from iainx/build-cov-for-osx
[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 corlib = mscorlib.dll
47
48 INTERNAL_RESGEN = $(RUNTIME) $(RUNTIME_FLAGS) $(topdir)/class/lib/$(PROFILE)/resgen.exe
49 RESGEN = MONO_PATH="$(topdir)/class/lib/$(PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(INTERNAL_RESGEN)
50
51 depsdir = $(topdir)/build/deps
52
53 # Make sure these propagate if set manually
54
55 export PLATFORM
56 export PROFILE
57 export MCS
58 export MCS_FLAGS
59 export CC
60 export CFLAGS
61 export INSTALL
62 export MKINSTALLDIRS
63 export TEST_HARNESS
64 export BOOTSTRAP_MCS
65 export DESTDIR
66 export RESGEN
67
68 # Get this so the platform.make platform-check rule doesn't become the
69 # default target
70
71 .DEFAULT: all
72 default: all
73
74 # Get initial configuration. pre-config is so that the builder can
75 # override PLATFORM or PROFILE
76
77 include $(topdir)/build/config-default.make
78 -include $(topdir)/build/pre-config.make
79
80 # Default PLATFORM and PROFILE if they're not already defined.
81
82 ifndef PLATFORM
83 ifeq ($(OS),Windows_NT)
84 ifneq ($(V),)
85 $(info *** Assuming PLATFORM is 'win32'.)
86 endif
87 PLATFORM = win32
88 else
89 ifneq ($(V),)
90 $(info *** Assuming PLATFORM is 'linux'.)
91 endif
92 PLATFORM = linux
93 endif
94 endif
95
96 # Platform config
97
98 include $(topdir)/build/platforms/$(PLATFORM).make
99
100 ifdef PLATFORM_CORLIB
101 corlib = $(PLATFORM_CORLIB)
102 endif
103 # Useful
104
105 ifeq ($(PLATFORM_RUNTIME),$(RUNTIME))
106 PLATFORM_MONO_NATIVE = yes
107 endif
108
109 # Rest of the configuration
110
111 ifndef PROFILE
112 PROFILE = $(DEFAULT_PROFILE)
113 endif
114
115 include $(topdir)/build/profiles/$(PROFILE).make
116 -include $(topdir)/build/config.make
117
118 ifdef BCL_OPTIMIZE
119 PROFILE_MCS_FLAGS += -optimize
120 endif
121
122 ifdef OVERRIDE_TARGET_ALL
123 all: all.override
124 else
125 all: do-all
126 endif
127
128 ifdef NO_INSTALL
129 GACUTIL = :
130 else
131 gacutil = $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/gacutil.exe
132 GACUTIL = MONO_PATH="$(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(gacutil)
133 endif
134
135 STD_TARGETS = test run-test run-test-ondotnet clean install uninstall doc-update
136
137 $(STD_TARGETS): %: do-%
138
139 do-run-test:
140         ok=:; $(MAKE) run-test-recursive || ok=false; $(MAKE) run-test-local || ok=false; $$ok
141
142 do-%: %-recursive
143         $(MAKE) $*-local
144
145 .PHONY: all-local $(STD_TARGETS:=-local)
146 all-local $(STD_TARGETS:=-local):
147
148 csproj: do-csproj
149
150 # The way this is set up, any profile-specific subdirs list should
151 # be listed _before_ including rules.make.  However, the default
152 # SUBDIRS list can come after, so don't use the eager := syntax when
153 # using the defaults.
154 PROFILE_SUBDIRS := $($(PROFILE)_SUBDIRS)
155 ifndef PROFILE_SUBDIRS
156 PROFILE_SUBDIRS = $(SUBDIRS)
157 endif
158
159 # These subdirs can be built in parallel
160 PROFILE_PARALLEL_SUBDIRS := $($(PROFILE)_PARALLEL_SUBDIRS)
161 ifndef PROFILE_PARALLEL_SUBDIRS
162 PROFILE_PARALLEL_SUBDIRS = $(PARALLEL_SUBDIRS)
163 endif
164
165 ifndef FRAMEWORK_VERSION_MAJOR
166 FRAMEWORK_VERSION_MAJOR = $(basename $(FRAMEWORK_VERSION))
167 endif
168
169 %-recursive:
170         @set . $$MAKEFLAGS; final_exit=:; \
171         case $$2 in --unix) shift ;; esac; \
172         case $$2 in *=*) dk="exit 1" ;; *k*) dk=: ;; *) dk="exit 1" ;; esac; \
173         list='$(PROFILE_SUBDIRS)'; for d in $$list ; do \
174             (cd $$d && $(MAKE) $*) || { final_exit="exit 1"; $$dk; } ; \
175         done; \
176         if [ $* = "all" -a -n "$(PROFILE_PARALLEL_SUBDIRS)" ]; then \
177                 $(MAKE) do-all-parallel ENABLE_PARALLEL_SUBDIR_BUILD=1 || { final_exit="exit 1"; $$dk; } ; \
178         else \
179                 list='$(PROFILE_PARALLEL_SUBDIRS)'; for d in $$list ; do \
180                     (cd $$d && $(MAKE) $*) || { final_exit="exit 1"; $$dk; } ; \
181                 done; \
182         fi; \
183         $$final_exit
184
185 #
186 # Parallel build support
187 #
188 # The variable $(PROFILE)_PARALLEL_SUBDIRS should be set to the list of directories
189 # which could be built in parallel. These directories are built after the directories in
190 # $(PROFILE)_SUBDIRS.
191 # Parallel building is currently only supported for the 'all' target.
192 #
193 # Each directory's Makefile may define DEP_LIBS and DEP_DIRS to specify the libraries and
194 # directories it depends on.
195 #
196 # It would be nice to reduce the duplication between DEP_LIBS and LIB_MCS_FLAGS, but
197 # there are too many special cases
198 # (System.Windows.Forms/Managed.Windows.Forms,System.Xml/System.XML) etc.
199 ifneq ($(PROFILE_PARALLEL_SUBDIRS),)
200 dep_dirs = .dep_dirs-$(PROFILE)
201 $(dep_dirs):
202         @echo "Creating $@..."
203         list='$(PROFILE_PARALLEL_SUBDIRS)'; \
204         echo > $@; \
205         for d in $$list; do \
206                 $(MAKE) -C $$d gen-deps DEPS_TARGET_DIR=$$d DEPS_FILE=$(abspath $@); \
207         done
208 -include $(dep_dirs)
209 endif
210
211 .PHONY: gen-deps
212 # The gen-deps target is in library.make/executable.make so it can pick up
213 # DEP_LIBS/DEP_DIRS
214
215 clean-dep-dir:
216         $(RM) $(dep_dirs)
217
218 clean-local: clean-dep-dir
219
220 ifdef ENABLE_PARALLEL_SUBDIR_BUILD
221 .PHONY: do-all-parallel $(PROFILE_PARALLEL_SUBDIRS)
222
223 do-all-parallel: $(PROFILE_PARALLEL_SUBDIRS)
224
225 $(PROFILE_PARALLEL_SUBDIRS):
226         @set . $$MAKEFLAGS; \
227         cd $@ && $(MAKE)
228 endif
229
230 ifndef DIST_SUBDIRS
231 DIST_SUBDIRS = $(SUBDIRS) $(DIST_ONLY_SUBDIRS)
232 endif
233 dist-recursive: dist-local
234         @case '$(distdir)' in [\\/$$]* | ?:[\\/]* ) reldir='$(distdir)' ;; *) reldir='../$(distdir)' ;; esac ; \
235         list='$(DIST_SUBDIRS)'; for d in $$list ; do \
236             (cd $$d && $(MAKE) distdir=$$reldir/$$d $@) || exit 1 ; \
237         done
238
239 # The following target can be used like
240 #
241 #   dist-local: dist-default
242 #       ... additional commands ...
243 #
244 # Notes:
245 #  1. we invert the test here to not end in an error if ChangeLog doesn't exist.
246 #  2. we error out if we try to dist a nonexistant file.
247 #  3. we pick up Makefile, makefile, or GNUmakefile.
248 dist-default:
249         -mkdir -p $(distdir)
250         test '!' -f ChangeLog || cp ChangeLog $(distdir)
251         if test -f Makefile; then m=M; fi; \
252         if test -f makefile; then m=m; fi; \
253         if test -f GNUmakefile; then m=GNUm; fi; \
254         for f in $${m}akefile $(DISTFILES) ; do \
255             dest=`dirname "$(distdir)/$$f"` ; \
256             $(MKINSTALLDIRS) $$dest && cp -p "$$f" $$dest || exit 1 ; \
257         done
258         if test -d Documentation ; then \
259                 find . -name '*.xml' > .files ; \
260                 tar cTf .files - | (cd $(distdir); tar xf -) ; \
261                 rm .files ; \
262         fi
263
264 %/.stamp:
265         $(MKINSTALLDIRS) $(@D)
266         touch $@
267
268 ## Documentation stuff
269
270 Q_MDOC =$(if $(V),,@echo "MDOC    [$(PROFILE)] $(notdir $(@))";)
271 MDOC   =$(Q_MDOC) MONO_PATH="$(topdir)/class/lib/$(DEFAULT_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(topdir)/class/lib/$(DEFAULT_PROFILE)/mdoc.exe
272