5ed34b8ff1ac9b583c3ef3b3d1c526eaa1f7079e
[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     [$(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 $(info *** Assuming PLATFORM is 'win32'.)
85 PLATFORM = win32
86 else
87 $(info *** Assuming PLATFORM is 'linux'.)
88 PLATFORM = linux
89 endif
90 endif
91
92 # Platform config
93
94 include $(topdir)/build/platforms/$(PLATFORM).make
95
96 ifdef PLATFORM_CORLIB
97 corlib = $(PLATFORM_CORLIB)
98 endif
99 # Useful
100
101 ifeq ($(PLATFORM_RUNTIME),$(RUNTIME))
102 PLATFORM_MONO_NATIVE = yes
103 endif
104
105 # Rest of the configuration
106
107 ifndef PROFILE
108 PROFILE = $(DEFAULT_PROFILE)
109 endif
110
111 include $(topdir)/build/profiles/$(PROFILE).make
112 -include $(topdir)/build/config.make
113
114 ifdef BCL_OPTIMIZE
115 PROFILE_MCS_FLAGS += -optimize
116 endif
117
118 ifdef OVERRIDE_TARGET_ALL
119 all: all.override
120 else
121 all: do-all
122 endif
123
124 ifdef NO_INSTALL
125 GACUTIL = :
126 else
127 gacutil = $(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)/gacutil.exe
128 GACUTIL = MONO_PATH="$(topdir)/class/lib/$(BUILD_TOOLS_PROFILE)$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(RUNTIME_FLAGS) $(gacutil)
129 endif
130
131 STD_TARGETS = test run-test run-test-ondotnet clean install uninstall doc-update
132
133 $(STD_TARGETS): %: do-%
134
135 do-run-test:
136         ok=:; $(MAKE) run-test-recursive || ok=false; $(MAKE) run-test-local || ok=false; $$ok
137
138 do-%: %-recursive
139         $(MAKE) $*-local
140
141 .PHONY: all-local $(STD_TARGETS:=-local)
142 all-local $(STD_TARGETS:=-local):
143
144 csproj: do-csproj
145
146 # The way this is set up, any profile-specific subdirs list should
147 # be listed _before_ including rules.make.  However, the default
148 # SUBDIRS list can come after, so don't use the eager := syntax when
149 # using the defaults.
150 PROFILE_SUBDIRS := $($(PROFILE)_SUBDIRS)
151 ifndef PROFILE_SUBDIRS
152 PROFILE_SUBDIRS = $(SUBDIRS)
153 endif
154
155 ifndef FRAMEWORK_VERSION_MAJOR
156 FRAMEWORK_VERSION_MAJOR = $(basename $(FRAMEWORK_VERSION))
157 endif
158
159 %-recursive:
160         @set . $$MAKEFLAGS; final_exit=:; \
161         case $$2 in --unix) shift ;; esac; \
162         case $$2 in *=*) dk="exit 1" ;; *k*) dk=: ;; *) dk="exit 1" ;; esac; \
163         list='$(PROFILE_SUBDIRS)'; for d in $$list ; do \
164             (cd $$d && $(MAKE) $*) || { final_exit="exit 1"; $$dk; } ; \
165         done; \
166         $$final_exit
167
168 ifndef DIST_SUBDIRS
169 DIST_SUBDIRS = $(SUBDIRS) $(DIST_ONLY_SUBDIRS)
170 endif
171 dist-recursive: dist-local
172         @case '$(distdir)' in [\\/$$]* | ?:[\\/]* ) reldir='$(distdir)' ;; *) reldir='../$(distdir)' ;; esac ; \
173         list='$(DIST_SUBDIRS)'; for d in $$list ; do \
174             (cd $$d && $(MAKE) distdir=$$reldir/$$d $@) || exit 1 ; \
175         done
176
177 # The following target can be used like
178 #
179 #   dist-local: dist-default
180 #       ... additional commands ...
181 #
182 # Notes:
183 #  1. we invert the test here to not end in an error if ChangeLog doesn't exist.
184 #  2. we error out if we try to dist a nonexistant file.
185 #  3. we pick up Makefile, makefile, or GNUmakefile.
186 dist-default:
187         -mkdir -p $(distdir)
188         test '!' -f ChangeLog || cp ChangeLog $(distdir)
189         if test -f Makefile; then m=M; fi; \
190         if test -f makefile; then m=m; fi; \
191         if test -f GNUmakefile; then m=GNUm; fi; \
192         for f in $${m}akefile $(DISTFILES) ; do \
193             dest=`dirname "$(distdir)/$$f"` ; \
194             $(MKINSTALLDIRS) $$dest && cp -p "$$f" $$dest || exit 1 ; \
195         done
196         if test -d Documentation ; then \
197                 find . -name '*.xml' > .files ; \
198                 tar cTf .files - | (cd $(distdir); tar xf -) ; \
199                 rm .files ; \
200         fi
201
202 %/.stamp:
203         $(MKINSTALLDIRS) $(@D)
204         touch $@
205
206 ## Documentation stuff
207
208 Q_MDOC =$(if $(V),,@echo "MDOC    [$(PROFILE)] $(notdir $(@))";)
209 # net_2_0 is needed because monodoc is only compiled in that profile
210 MDOC   =$(Q_MDOC) MONO_PATH="$(topdir)/class/lib/$(DEFAULT_PROFILE)$(PLATFORM_PATH_SEPARATOR)$(topdir)/class/lib/net_2_0$(PLATFORM_PATH_SEPARATOR)$$MONO_PATH" $(RUNTIME) $(topdir)/class/lib/$(DEFAULT_PROFILE)/mdoc.exe
211