482d318b1f435bae3ba70b3716c76669f4fcd0dd
[android/toolchain/build.git] / Makefile.in
1 # -------------------------------
2 # Standard Autoconf-set variables
3 # -------------------------------
4 VPATH=@srcdir@
5
6 build_alias=@build_alias@
7 build_vendor=@build_vendor@
8 build_os=@build_os@
9 build=@build@
10 host_alias=@host_alias@
11 host_vendor=@host_vendor@
12 host_os=@host_os@
13 host=@host@
14 target_alias=@target_alias@
15 target_vendor=@target_vendor@
16 target_os=@target_os@
17 target_cpu=@target_cpu@
18 target=@target@
19
20 program_transform_name = @program_transform_name@
21
22 prefix = @prefix@
23 exec_prefix = @exec_prefix@
24
25 srcdir = @srcdir@
26 abs_srcdir = @abs_srcdir@
27
28 bindir = @bindir@
29 sbindir = @sbindir@
30 libexecdir = @libexecdir@
31 datadir = @datadir@
32 sysconfdir = @sysconfdir@
33 sharedstatedir = @sharedstatedir@
34 localstatedir = @localstatedir@
35 libdir = @libdir@
36 includedir = @includedir@
37 oldincludedir = @oldincludedir@
38 infodir = @infodir@
39 datarootdir = @datarootdir@
40 docdir = @docdir@
41 pdfdir = @pdfdir@
42 htmldir = @htmldir@
43 mandir = @mandir@
44
45 builddir = @builddir@
46 abs_builddir = @abs_builddir@
47
48 INSTALL=@INSTALL@
49
50 #
51 # miscellaneous variables
52 #
53 INSTALL:=@INSTALL@
54 INSTALL_DATA:=@INSTALL_DATA@
55 TOPLEVEL_CONFIGURE_ARGUMENTS:=@TOPLEVEL_CONFIGURE_ARGUMENTS@
56 baseargs = @baseargs@
57 GCC_MIN_VERSION_4_3_0:=@GCC_MIN_VERSION_4_3_0@
58 GCC_MIN_VERSION_4_5_0:=@GCC_MIN_VERSION_4_5_0@
59 GDB_MIN_VERSION_7_2:=@GDB_MIN_VERSION_7_2@
60 BINUTILS_MIN_VERSION_2_21:=@BINUTILS_MIN_VERSION_2_21@
61 GOLD_MIN_VERSION_2_21:=@GOLD_MIN_VERSION_2_21@
62 ENABLE_GRAPHITE:=@ENABLE_GRAPHITE@
63 PACKAGE_TO_SRCDIR:=@package_to_srcdir@
64 BUILD_ANDROID_GCC:=@BUILD_ANDROID_GCC@
65 GDB_TARGET:=@GDB_TARGET@
66
67 # We need to figure out how to get to top level source directory from
68 # a package build directory. 
69 # For host modules, accept cache file option, or specification as blank.
70
71
72 BINUTILS_VERSION=binutils-@BINUTILS_VERSION@
73 GOLD_VERSION=binutils-@GOLD_VERSION@
74 GCC_VERSION=gcc-@GCC_VERSION@
75 NEWLIB_VERSION=newlib-@NEWLIB_VERSION@
76 GMP_VERSION=gmp-@GMP_VERSION@
77 MPFR_VERSION=mpfr-@MPFR_VERSION@
78 MPC_VERSION=mpc-@MPC_VERSION@
79 PPL_VERSION=ppl-@PPL_VERSION@
80 CLOOG_VERSION=cloog-@CLOOG_VERSION@
81 GDB_VERSION=gdb-@GDB_VERSION@
82 EXPAT_VERSION=expat-@EXPAT_VERSION@
83 HAVE_MPC=@have_mpc@
84 HAVE_MPFR=@have_mpfr@
85 HAVE_GMP=@have_gmp@
86 HAVE_PPL=@have_ppl@
87 HAVE_CLOOG=@have_cloog@
88 HAVE_EXPAT=@have_expat@
89 ENABLE_GOLD=@enable_gold@
90 ENABLE_LD_DEFAULT=@enable_ld_default@
91 STAMP=touch
92
93 TARGET_BINUTILS_BUILDDIR=$(abs_builddir)/$(BINUTILS_VERSION)
94 TARGET_GCC_BUILDDIR=$(abs_builddir)/$(GCC_VERSION)
95 TEMP_INSTALLDIR=$(abs_builddir)/temp-install
96
97 ifeq ($(HAVE_MPC),no)
98   MPC_DIR=$(TEMP_INSTALLDIR)
99 endif
100
101 ifeq ($(HAVE_MPFR),no)
102   MPFR_DIR=$(TEMP_INSTALLDIR)
103 endif
104
105 ifeq ($(HAVE_GMP),no)
106   GMP_DIR=$(TEMP_INSTALLDIR)
107 endif
108
109 ifeq ($(HAVE_PPL), no)
110   PPL_DIR=$(TEMP_INSTALLDIR)
111 endif
112
113 ifeq ($(HAVE_CLOOG), no)
114   CLOOG_DIR=$(TEMP_INSTALLDIR)
115 endif
116
117 ifeq ($(HAVE_EXPAT),no)
118   EXPAT_DIR=$(TEMP_INSTALLDIR)
119 endif
120
121 # Figure out where to find the ld binary.
122 FIND_TARGET_LD=\
123         `[ -d $(TARGET_BINUTILS_BUILDDIR)/gold ] && echo "gold" || echo "ld"`
124
125 # We export these insteading when configuring target gcc and newlib
126 TARGET_BINUTILS_EXPORTS= \
127 export  AS_FOR_TARGET=$(TARGET_BINUTILS_BUILDDIR)/gas/as-new \
128         LD_FOR_TARGET=$(TARGET_BINUTILS_BUILDDIR)/$(FIND_TARGET_LD)/ld-new \
129         AR_FOR_TARGET=$(TARGET_BINUTILS_BUILDDIR)/binutils/ar \
130         NM_FOR_TARGET=$(TARGET_BINUTILS_BUILDDIR)/binutils/nm-new \
131         STRIP_FOR_TARGET=$(TARGET_BINUTILS_BUILDDIR)/binutils/strip-new \
132         RANLIB_FOR_TARGET=$(TARGET_BINUTILS_BUILDDIR)/binutils/ranlib \
133         OBJDUMP_FOR_TARGET=$(TARGET_BINUTILS_BUILDDIR)/binutils/objdump
134
135 TARGET_MINIMAL_GCC_EXPORTS= \
136 export  CC_FOR_TARGET="$(TARGET_GCC_BUILDDIR)/gcc/xgcc \
137                       -B $(TARGET_GCC_BUILDDIR)/gcc \
138                       -isystem $(TARGET_GCC_BUILDDIR)/gcc/include-fixed \
139                       -isystem $(TARGET_GCC_BUILDDIR)/gcc/include"
140 #
141 # We need -Os as the overrides below interfere with --enable-target-optspace.
142 # We also need -mandroid for for target libraries to pass linking test
143 # in configuration.
144
145 # To build libstdc++ with RTTI and exceptions do:
146 #
147 #export CFLAGS_FOR_TARGET=-fexceptions
148 #export CXXFLAGS_FOR_TARGET=-frtti
149 #
150 CFLAGS_FOR_TARGET+= -O2 -Os -g
151 CXXFLAGS_FOR_TARGET+=$(CFLAGS_FOR_TARGET)
152 LDFLAGS_FOR_TARGET=
153
154 # Helper
155 prefix-list = $(foreach e, $(2), $(join $1, $e))
156
157 # find source directory for package. This can either be <srcdir>/<package>
158 # or <objdir>/temp-src/<package>
159
160 find-package-srcdir = $(shell \
161   if [ -f $(srcdir)/../$(firstword $(subst -, ,$1))/$(strip $1)/configure ]; then \
162      echo $(PACKAGE_TO_SRCDIR)/../$(firstword $(subst -, ,$1))/$(strip $1); \
163   elif [ -f $(abs_builddir)/temp-src/$(strip $1)/configure ]; then \
164     echo $(abs_builddir)/temp-src/$(strip $1) ; \
165   else \
166     echo 'error cannot find $(strip $1)' ; \
167   fi)
168
169 # Set effective <build>, <host> and <target>.
170
171 ifneq ($(build_alias),)
172 cur_build := $(build_alias)
173 else
174 cur_build := $(build)
175 endif
176
177 ifneq ($(host_alias),)
178 cur_host := $(host_alias)
179 else
180 cur_host := $(host)
181 endif
182
183 ifneq ($(target_alias),)
184 cur_target := $(target_alias)
185 else
186 cur_target := $(target)
187 endif
188
189 # Define environment variables for canadian cross build.
190 ifneq ($(cur_host),$(cur_build))
191 canadian_build_env := \
192         export CC_FOR_BUILD=$(cur_build)-gcc ; \
193         export CC=$(cur_build)-gcc ; \
194         export CXX=$(cur_build)-g++ ;
195
196 CANADIAN_ROOT := $(PWD)/host-${cur_build}
197 canadian_env := \
198         export CC_FOR_BUILD=$(cur_build)-gcc ; \
199         export CC=$(cur_host)-gcc ; \
200         export CXX=$(cur_host)-g++ ; \
201         export AR=$(cur_host)-ar ; \
202         export RANLIB=$(cur_host)-ranlib ; \
203         export PATH="$(CANADIAN_ROOT)/install/bin:${PATH}" ;
204 endif
205
206 #
207 # Make rules
208 #
209
210 .PHONY: all clean
211
212 all: build
213
214 # top level
215 ifeq ($(ENABLE_GRAPHITE),yes)
216 build: install-host-cloog
217 endif
218 build: build-target-binutils build-host-libbfd build-target-gcc \
219         build-target-gdb
220
221 install: install-target-binutils install-host-libbfd install-target-gcc \
222         install-target-gdb
223
224 # To support canadian cross build we need to build build->target toolchain
225 # as well as final host->target toolchain.
226 ifneq ($(cur_host),$(cur_build))
227 .PHONY: config-canadian-tools build-canadian-tools install-canadian-tools
228
229 config-canadian-tools: stmp-config-canadian-tools
230 stmp-config-canadian-tools:
231         ([ -d $(CANADIAN_ROOT) ] || \
232           mkdir $(CANADIAN_ROOT)) && \
233         ($(canadian_build_env) \
234          cd $(CANADIAN_ROOT) && \
235          $(abs_srcdir)/configure $(baseargs) --build=$(cur_build) \
236                 --host=$(cur_build) --target=$(cur_target)) && \
237         $(STAMP) $@
238
239 build-canadian-tools: stmp-build-canadian-tools
240 stmp-build-canadian-tools: stmp-config-canadian-tools
241         ($(canadian_build_env) \
242          cd $(CANADIAN_ROOT) && \
243          $(MAKE)) && \
244         $(STAMP) $@
245
246 install-canadian-tools: stmp-install-canadian-tools
247 stmp-install-canadian-tools: stmp-build-canadian-tools
248         ($(canadian_build_env) \
249          cd $(CANADIAN_ROOT) && \
250          $(MAKE) install prefix=$(CANADIAN_ROOT)/install) && \
251         $(STAMP) $@
252
253 # When building canadian cross toolchain we cannot build GCC target libraries.
254 # So we build the compilers only and copy the target libaries from
255 # $(CANADIAN_ROOT)/install/ installation.
256 gcc_build_target := all-gcc
257 gcc_install_target := install-gcc
258 install-target-gcc-multilibs: stmp-install-canadian-tools
259         mkdir -p $(prefix)/lib/gcc/
260         rsync -a $(CANADIAN_ROOT)/install/lib/gcc/ $(prefix)/lib/gcc/
261 install-target-gcc-multilibs := install-target-gcc-multilibs
262
263 # We add canadian_stmp dependency to rules that have no dependencies
264 # on other modules.  This is to ensure that simple cross toolchain is built
265 # before canadian cross toolchain.
266 canadian_stmp := stmp-install-canadian-tools
267 else
268 gcc_build_target :=
269 gcc_install_target := install
270 install-target-gcc-multilibs :=
271 canadian_stmp :=
272 endif
273
274 ifneq ($(BINUTILS_VERSION), $(GOLD_VERSION))
275 build: build-target-gold
276 install: install-target-gold
277 endif
278
279 # target binutils rules
280 .PHONY: config-target-binutils build-target-binutils install-target-binutils
281 config-target-binutils: stmp-config-target-binutils
282 # We do not want to enable shared libraries in binutils
283 BINUTILS_CONFIG_ARGS=--prefix=$(prefix) \
284         --target=${cur_target} --host=${cur_host} --build=${cur_build} \
285         $(baseargs) --disable-shared
286 ifeq ($(ENABLE_GRAPHITE),yes)
287 BINUTILS_CONFIG_ARGS+= --with-cloog=${CLOOG_DIR} --with-gmp=${GMP_DIR} \
288         --disable-ppl-version-check --disable-cloog-version-check
289 # links to the static C++ runtime to avoid depending on the host version
290 BINUTILS_CONFIG_ARGS+= \
291         '--with-host-libstdcxx=-static-libgcc \
292          -Wl,-Bstatic,-lstdc++,-Bdynamic -lm'
293 endif
294 # Enable dual linker support and make gold as default linker when gold is
295 # enabled. Notice that our binutils take different --enable-gold=xxx options.
296 ifneq ($(ENABLE_GOLD),)
297 ifeq ($(BINUTILS_MIN_VERSION_2_21),yes)
298 ifeq ($(ENABLE_LD_DEFAULT),)
299 BINUTILS_CONFIG_ARGS += --enable-gold=default
300 endif
301 else
302 ifeq ($(ENABLE_LD_DEFAULT),)
303 BINUTILS_CONFIG_ARGS += --enable-gold=both/gold
304 else
305 BINUTILS_CONFIG_ARGS += --enable-gold=both/ld
306 endif
307 endif
308 endif
309 stmp-config-target-binutils: config.status $(canadian_stmp)
310         ([ -d ${BINUTILS_VERSION} ] || \
311           mkdir ${BINUTILS_VERSION}) && \
312         ($(canadian_env) \
313          cd ${BINUTILS_VERSION} ; \
314          $(call find-package-srcdir, ${BINUTILS_VERSION})/configure \
315           $(BINUTILS_CONFIG_ARGS)) && \
316         $(STAMP) $@
317 build-target-binutils: stmp-build-target-binutils
318 stmp-build-target-binutils: stmp-config-target-binutils
319         ($(canadian_env) \
320          $(MAKE) -C ${BINUTILS_VERSION}) && $(STAMP) $@
321 install-target-binutils: stmp-build-target-binutils
322         ($(canadian_env) \
323          $(MAKE) -C ${BINUTILS_VERSION} install)
324
325 # target gold rules.  We need these only if BINUTILS_VERSION != GOLD_VERSION
326 ifneq ($(BINUTILS_VERSION), $(GOLD_VERSION))
327 .PHONY: config-target-gold build-target-gold install-target-gold
328 config-target-gold: stmp-config-target-gold
329 # We do not want to enable shared libraries in gold
330 GOLD_CONFIG_ARGS=--prefix=$(prefix) \
331         --target=${target_alias} --host=${host} --build=${build} \
332         $(baseargs) --disable-shared
333 ifeq ($(GOLD_MIN_VERSION_2_21),yes)
334         GOLD_CONFIG_ARGS += --enable-gold=default
335 else
336         GOLD_CONFIG_ARGS += --enable-gold=both/gold
337 endif
338 stmp-config-target-gold: config.status
339         ([ -d ${GOLD_VERSION} ] || \
340           mkdir ${GOLD_VERSION}) && \
341         (cd ${GOLD_VERSION} ; \
342          $(call find-package-srcdir, ${GOLD_VERSION})/configure \
343           $(GOLD_CONFIG_ARGS)) && \
344         $(STAMP) $@
345 build-target-gold: stmp-build-target-gold
346 stmp-build-target-gold: stmp-config-target-gold
347         ($(canadian_env) \
348      $(MAKE) -C ${GOLD_VERSION} && $(STAMP) $@)
349
350 # If we use a different binutils version of gold, we build gold twice.  We
351 # first build everything, including gold with the main binutils version and
352 # then install it.  Then we build the gold-only binutils version and install
353 # just gold.  We don't bother to skip building the first gold to simplify
354 # handling of all combinations of --enable-gold[=*]
355
356 install-target-gold: stmp-build-target-gold install-target-binutils
357         ($(canadian_env) \
358      make -C $(GOLD_VERSION)/gold install)
359
360 endif
361
362 # build libbfd for host.  We configure with all targets, so this is built
363 # separately from the same source.
364 # Required by Android build, we always build 32bit host libraries, and
365 # put the 32bit host libraries into /lib32.
366 .PHONY: config-host-libbfd build-host-libbfd install-host-libbfd
367 config-host-libbfd: stmp-config-host-libbfd
368 LIBBFD_CONFIG_ARGS=--prefix=$(prefix) \
369         --target=${target_alias} --host=${host} --build=${build} \
370         $(baseargs) --disable-shared \
371         --enable-install-libbfd --with-included-gettext \
372         CFLAGS="$(CFLAGS) -m32"
373 stmp-config-host-libbfd: config.status
374         ([ -d libbfd-${BINUTILS_VERSION} ] || \
375           mkdir libbfd-${BINUTILS_VERSION}) && \
376         (cd libbfd-${BINUTILS_VERSION} ; \
377          $(call find-package-srcdir, ${BINUTILS_VERSION})/configure \
378           $(LIBBFD_CONFIG_ARGS)) && \
379         $(STAMP) $@
380 build-host-libbfd: stmp-build-host-libbfd
381 stmp-build-host-libbfd: stmp-config-host-libbfd
382         $(MAKE) -C libbfd-${BINUTILS_VERSION} all-bfd all-libiberty && \
383         $(MAKE) -C libbfd-${BINUTILS_VERSION}/intl libintl.a && \
384         $(STAMP) $@
385 # Also include libintl.a.  We have to do this manully since the
386 # source of libintl in binutils is modified to not install the library.
387 # We build with -m32 always, and install host libs into /lib32.
388 LIB32DIR=$(libdir)32
389 install-host-libbfd: stmp-build-host-libbfd install-target-binutils
390         $(MAKE) -C libbfd-${BINUTILS_VERSION}/bfd install \
391                 bfdlibdir=$(LIB32DIR) bfdincludedir=$(includedir) && \
392         $(INSTALL_DATA) libbfd-${BINUTILS_VERSION}/intl/libintl.a \
393                 $(LIB32DIR) && \
394         $(INSTALL_DATA) libbfd-${BINUTILS_VERSION}/libiberty/libiberty.a \
395                 $(LIB32DIR)
396
397 # target gcc rules
398 .PHONY: config-target-gcc build-target-gcc install-target-gcc
399 .PHONY: install-target-gcc-gcc $(install-target-gcc-multilibs)
400 config-target-gcc: stmp-config-target-gcc
401
402 GCC_CONFIG_ARGS=--prefix=$(prefix) \
403           --target=${cur_target} --host=${cur_host} --build=${cur_build} \
404           --with-gnu-as --with-gnu-ld --enable-languages=c,c++
405
406 # For gcc versions 4.3.0 and later, gmp and mpfr are required.
407 # Also build libgcc is a seperate sub-target in 4.3.0+.
408 ifeq ($(GCC_MIN_VERSION_4_3_0),yes)
409 stmp-config-target-gcc: stmp-install-host-gmp stmp-install-host-mpfr
410 GCC_CONFIG_ARGS += --with-gmp=$(GMP_DIR) --with-mpfr=$(MPFR_DIR)
411 endif
412
413 # For gcc versions 4.5.0 and higher, mpc is required.
414 ifeq ($(GCC_MIN_VERSION_4_5_0),yes)
415 stmp-config-target-gcc: stmp-install-host-mpc
416 GCC_CONFIG_ARGS += --with-mpc=$(MPC_DIR)
417 endif
418
419 # For gcc 4.5+ with graphite optimization, cloog and ppl are required.
420 ifeq ($(ENABLE_GRAPHITE),yes)
421 GCC_CONFIG_ARGS += --with-cloog=${CLOOG_DIR} --with-ppl=${PPL_DIR} \
422         --disable-ppl-version-check --disable-cloog-version-check
423 # links to the static C++ runtime to avoid depending on the host version
424 GCC_CONFIG_ARGS += \
425         '--with-host-libstdcxx=-static-libgcc \
426          -Wl,-Bstatic,-lstdc++,-Bdynamic -lm'
427 else
428 # Disable ppl and cloog just in case the host have them install.
429 GCC_CONFIG_ARGS += --without-ppl --without-cloog
430 endif
431
432 # Add Android specific gcc options.
433 # FIXME: These should be overridable by configure options.
434
435
436 # Target indenpendent Android gcc options.
437 ifeq ($(BUILD_ANDROID_GCC),yes)
438 GCC_CONFIG_ARGS += $(GCC_CONFIG_LIBSTDCXX_V3) --disable-libssp \
439         --enable-threads --disable-nls --disable-libmudflap --disable-libgomp \
440         --disable-libstdc__-v3 --disable-sjlj-exceptions --disable-shared \
441         --disable-tls --disable-libitm
442
443 CFLAGS_FOR_TARGET += -DTARGET_POSIX_IO -fno-short-enums
444
445 ifeq ($(target_cpu),x86)
446 # Options brought in from core/combo/* for IA
447 CFLAGS_FOR_TARGET += \
448         -DANDROID -D__ANDROID__ -Ulinux \
449         -fPIC -Wa,--noexecstack -m32 -fstack-protector \
450         -W -Wall -Werror=address -Werror=format-security -Werror=non-virtual-dtor -Werror=return-type \
451         -Werror=sequence-point -Winit-self -Wno-multichar -Wno-unused -Wpointer-arith -Wstrict-aliasing=2 \
452         -fexceptions -ffunction-sections -finline-functions \
453         -finline-limit=300 -fmessage-length=0 -fno-inline-functions-called-once \
454         -fno-strict-aliasing -frtti \
455         -fstrict-aliasing -funswitch-loops -funwind-tables \
456         -march=i686 -mtune=atom -mbionic -mfpmath=sse -mstackrealign -DUSE_SSE2
457
458 LDFLAGS_FOR_TARGET += \
459         -m32 -O2 -g -fPIC \
460         -nostartfiles \
461         -Wl,-z,noexecstack -Wl,--gc-sections -nostdlib \
462         -fexceptions -frtti -fstrict-aliasing -ffunction-sections -finline-functions  \
463         -finline-limit=300 -fno-inline-functions-called-once \
464         -funswitch-loops -funwind-tables -mstackrealign \
465         -ffunction-sections -funwind-tables -fmessage-length=0 \
466         -march=atom -mstackrealign -mfpmath=sse -mbionic \
467         -Wno-multichar -Wl,-z,noexecstack -Werror=format-security -Wstrict-aliasing=2 \
468         -W -Wall -Wno-unused -Winit-self -Wpointer-arith -Werror=return-type -Werror=non-virtual-dtor \
469         -Werror=address -Werror=sequence-point \
470         -Werror=format-security -Wl,--no-undefined
471 endif
472
473 # ARM specific options.
474 ifeq ($(target_cpu),arm)
475 GCC_CONFIG_ARGS += --with-float=soft --with-fpu=vfp --with-arch=armv5te \
476         --enable-target-optspace
477
478 ifneq ($(target_os),linux-androideabi)
479 GCC_CONFIG_ARGS += --with-abi=aapcs
480 endif
481 endif
482
483 endif
484
485 # We add the baseargs and the end so that they override any default args
486 GCC_CONFIG_ARGS += $(baseargs)
487
488 # Add user specified --enable-gold=xxx option to gcc
489 ifneq ($(ENABLE_GOLD),)
490 GCC_CONFIG_ARGS += $(ENABLE_GOLD)
491 endif
492
493 # We have to add -mandroid in target CFLAGS and CXXFLAGS
494 stmp-config-target-gcc: config.status stmp-build-target-binutils
495         ([ -d ${GCC_VERSION} ] || \
496           mkdir ${GCC_VERSION}) && \
497         ($(canadian_env) \
498          cd ${GCC_VERSION} ; \
499          $(TARGET_BINUTILS_EXPORTS) ; \
500          export CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" ; \
501          export CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" ; \
502          export LDFLAGS_FOR_TARGET="$(LDFLAGS_FOR_TARGET)" ; \
503          $(call find-package-srcdir, ${GCC_VERSION})/configure \
504            $(GCC_CONFIG_ARGS)) && \
505         $(STAMP) $@
506 build-target-gcc: stmp-build-target-gcc
507 stmp-build-target-gcc: stmp-config-target-gcc
508         ($(canadian_env) \
509          $(MAKE) -C ${GCC_VERSION} \
510                 CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \
511                 CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \
512                 LDFLAGS_FOR_TARGET="$(LDFLAGS_FOR_TARGET)" \
513                 $(gcc_build_target)) \
514         && $(STAMP) $@
515 install-target-gcc-gcc: stmp-build-target-gcc
516         ($(canadian_env) \
517          $(MAKE) -C ${GCC_VERSION} $(gcc_install_target))
518 install-target-gcc: install-target-gcc-gcc $(install-target-gcc-multilibs)
519
520 # minimal gcc rules
521 # minimal gcc only builds the C and C++ compilers and libgcc
522 # We use the full gcc configure rules.
523 .PHONY: build-target-minimal-gcc install-target-minimal-gcc
524 ifeq ("$(GCC_MIN_VERSION_4_3_0)","yes")
525 MINIMAL_GCC_BUILD_TARGETS:= gcc target-libgcc 
526 else
527 MINIMAL_GCC_BUILD_TARGETS:= gcc
528 endif
529
530 build-target-minimal-gcc: stmp-build-target-minimal-gcc
531 stmp-build-target-minimal-gcc: stmp-config-target-gcc
532         ($(canadian_env) \
533          $(MAKE) -C ${GCC_VERSION} \
534                 $(call prefix-list, all-, $(MINIMAL_GCC_BUILD_TARGETS))) && \
535         $(STAMP) $@
536 install-target-minimal-gcc: stmp-build-target-minimal-gcc
537         ($(canadian_env) \
538          $(MAKE) -C ${GCC_VERSION} \
539                 $(call prefix-list, install-, $(MINIMAL_GCC_BUILD_TARGETS)))
540
541 # target newlib rules
542 .PHONY: config-target-newlib build-target-newlib install-target-newlib
543 config-target-newlib: stmp-config-target-newlib
544 NEWLIB_CONFIG_ARGS=$(baseargs) --prefix=$(prefix) \
545           --target=${cur_target} --host=${cur_host} --build=${cur_build}
546
547 stmp-config-target-newlib: stmp-build-target-binutils \
548                            stmp-build-target-minimal-gcc
549         ([ -d ${NEWLIB_VERSION} ] || \
550           mkdir ${NEWLIB_VERSION}) && \
551         ($(canadian_env) \
552          cd ${NEWLIB_VERSION} ; \
553          $(TARGET_BINUTILS_EXPORTS) ; \
554          $(TARGET_MINIMAL_GCC_EXPORTS) ; \
555          $(call find-package-srcdir, ${NEWLIB_VERSION})/configure \
556           $(NEWLIB_CONFIG_ARGS)) && \
557         $(STAMP) $@
558 stmp-build-target-newlib: stmp-config-target-newlib
559         ($(canadian_env) \
560          $(MAKE) -C ${NEWLIB_VERSION}) && $(STAMP) $@
561 install-target-newlib: stmp-build-target-newlib
562         ($(canadian_env) \
563          $(MAKE) -C ${NEWLIB_VERSION} install)
564
565 # host gmp rules
566 .PHONY: config-host-gmp build-host-gmp install-host-gmp
567 config-host-gmp: stmp-config-host-gmp
568 GMP_CONFIG_ARGS=$(baseargs) --prefix=$(TEMP_INSTALLDIR) --disable-shared \
569           --host=${cur_host} --build=${cur_build}
570
571 ifeq ($(ENABLE_GRAPHITE),yes)
572 GMP_CONFIG_ARGS+= --enable-cxx
573 endif
574
575 stmp-config-host-gmp: config.status $(canadian_stmp)
576         ([ -d ${GMP_VERSION} ] || \
577           mkdir ${GMP_VERSION}) && \
578         ($(canadian_env) \
579          cd ${GMP_VERSION} ; \
580          $(call find-package-srcdir, ${GMP_VERSION})/configure \
581           $(GMP_CONFIG_ARGS)) && \
582         $(STAMP) $@
583 stmp-build-host-gmp: stmp-config-host-gmp
584         ($(canadian_env) \
585          $(MAKE) -C ${GMP_VERSION}) && $(STAMP) $@
586 build-host-gmp: stmp-build-host-gmp
587 # Need -j1 to avoid a race condition in building on OS X.
588 ifeq ($(HAVE_GMP),no)
589 stmp-install-host-gmp: stmp-build-host-gmp
590         $(MAKE) -C ${GMP_VERSION} install -j1 && $(STAMP) $@
591 else
592 stmp-install-host-gmp:
593 endif
594 install-host-gmp: stmp-install-host-gmp
595
596 # host mpfr rules
597 .PHONY: config-host-mpfr build-host-mpfr install-host-mpfr
598 config-host-mpfr: stmp-config-host-mpfr
599 MPFR_CONFIG_ARGS=$(baseargs) --prefix=$(TEMP_INSTALLDIR) --disable-shared \
600           --host=${cur_host} --build=${cur_build} \
601           --with-gmp=$(GMP_DIR)
602 stmp-config-host-mpfr: config.status stmp-install-host-gmp
603         ([ -d ${MPFR_VERSION} ] || \
604           mkdir ${MPFR_VERSION}) && \
605         ($(canadian_env) \
606          cd ${MPFR_VERSION} ; \
607          $(call find-package-srcdir, ${MPFR_VERSION})/configure \
608           $(MPFR_CONFIG_ARGS)) && \
609         $(STAMP) $@
610 stmp-build-host-mpfr: stmp-config-host-mpfr
611         ($(canadian_env) \
612          $(MAKE) -C ${MPFR_VERSION}) && $(STAMP) $@
613 build-host-mpfr: stmp-build-host-mpfr
614 ifeq ($(HAVE_MPFR),no)
615 stmp-install-host-mpfr: stmp-build-host-mpfr
616         $(MAKE) -C ${MPFR_VERSION} install && $(STAMP) $@
617 else
618 stmp-install-host-mpfr:
619 endif
620 install-host-mpfr: stmp-install-host-mpfr
621
622 # host mpc rules
623 .PHONY: config-host-mpc build-host-mpc install-host-mpc
624 config-host-mpc: stmp-config-host-mpc
625 MPC_CONFIG_ARGS=$(baseargs) --prefix=$(TEMP_INSTALLDIR) --disable-shared \
626          --host=${cur_host} --build=${cur_build} \
627          --with-gmp=$(GMP_DIR) --with-mpfr=$(MPFR_DIR)
628 stmp-config-host-mpc: config.status stmp-install-host-gmp stmp-install-host-mpfr
629         ([ -d ${MPC_VERSION} ] || \
630           mkdir ${MPC_VERSION}) && \
631         ($(canadian_env) \
632          cd ${MPC_VERSION} ; \
633          $(call find-package-srcdir, ${MPC_VERSION})/configure \
634           $(MPC_CONFIG_ARGS)) && \
635         $(STAMP) $@
636 stmp-build-host-mpc: stmp-config-host-mpc
637         ($(canadian_env) \
638          $(MAKE) -C ${MPC_VERSION}) && $(STAMP) $@
639 build-host-mpc: stmp-build-host-mpc
640 ifeq ($(HAVE_MPC),no)
641 stmp-install-host-mpc: stmp-build-host-mpc
642         $(MAKE) -C ${MPC_VERSION} install && $(STAMP) $@
643 else
644 stmp-install-host-mpc:
645 endif
646 install-host-mpc: stmp-install-host-mpc
647
648 # host ppl rules
649 .PHONY: config-host-ppl build-host-ppl install-host-ppl
650 config-host-ppl: stmp-config-host-ppl
651 PPL_CONFIG_ARGS=$(baseargs) --prefix=$(TEMP_INSTALLDIR) --disable-shared \
652           --target=${target_alias} \
653           --host=${host} --build=${build} \
654           --disable-nls --with-gmp-prefix=$(GMP_DIR) \
655           --disable-watchdog \
656           --disable-ppl_lcdd --disable-ppl_lpsol --disable-ppl_pips
657 stmp-config-host-ppl: config.status stmp-install-host-gmp
658         ([ -d ${PPL_VERSION} ] || \
659          mkdir ${PPL_VERSION}) && \
660         ($(canadian_env) \
661          cd ${PPL_VERSION} ; \
662         $(call find-package-srcdir, ${PPL_VERSION})/configure \
663          $(PPL_CONFIG_ARGS)) && \
664         $(STAMP) $@
665 stmp-build-host-ppl: stmp-config-host-ppl
666         $(MAKE) -C ${PPL_VERSION} && $(STAMP) $@
667 build-host-ppl: stmp-build-host-ppl
668 stmp-install-host-ppl: stmp-build-host-ppl
669         $(MAKE) -C ${PPL_VERSION} install && \
670         $(STAMP) $@
671 install-host-ppl: stmp-install-host-ppl
672
673 # host cloog rules
674 .PHONY: config-host-cloog build-host-cloog install-host-cloog
675 config-host-cloog: stmp-config-host-cloog
676 CLOOG_CONFIG_ARGS=$(baseargs) --prefix=$(TEMP_INSTALLDIR) --disable-shared \
677           --target=${target_alias} \
678           --host=${host} --build=${build} \
679           --disable-nls \
680           --with-gmp=$(GMP_DIR)
681 # for cloog-ppl version 0.15.x, ppl is required.
682 ifneq ($(findstring ppl-,$(CLOOG_VERSION)),)
683 stmp-config-host-cloog: config.status stmp-install-host-ppl \
684           stmp-install-host-ppl-workaround
685 stmp-install-host-ppl-workaround:
686         # cloog 0.15.9 is unable to detect newer versions of ppl.
687         # Thus we modify the version definition in header file to satisfy.
688         sed -i -e 's/PPL_VERSION_MINOR 11/PPL_VERSION_MINOR 10/' \
689           $(PPL_DIR)/include/ppl_c.h
690         $(STAMP) $@
691 CLOOG_CONFIG_ARGS+= --with-ppl=$(PPL_DIR)
692 endif
693 stmp-config-host-cloog: config.status stmp-install-host-gmp
694         ([ -d ${CLOOG_VERSION} ] || \
695          mkdir ${CLOOG_VERSION}) && \
696         ($(canadian_env) \
697          cd ${CLOOG_VERSION} ; \
698         $(call find-package-srcdir, ${CLOOG_VERSION})/configure \
699          $(CLOOG_CONFIG_ARGS)) && \
700         $(STAMP) $@
701 stmp-build-host-cloog: stmp-config-host-cloog
702         # Ignore the generation of cloog utilities
703         $(MAKE) -C ${CLOOG_VERSION} libcloog.la && \
704         $(STAMP) $@
705 build-host-cloog: stmp-build-host-cloog
706 stmp-install-host-cloog: stmp-build-host-cloog
707         $(MAKE) -C ${CLOOG_VERSION} install-libLTLIBRARIES \
708                 install-pkgincludeHEADERS && \
709         $(STAMP) $@
710 install-host-cloog: stmp-install-host-cloog
711
712 # host expat rules
713 .PHONY: config-host-expat build-host-expat install-host-expat
714 config-host-expat: stmp-config-host-expat
715 EXPAT_CONFIG_ARGS=$(baseargs) --prefix=$(TEMP_INSTALLDIR) --disable-shared \
716         --host=${cur_host} --build=${cur_build}
717 stmp-config-host-expat: config.status  $(canadian_stmp)
718         ([ -d ${EXPAT_VERSION} ] || \
719           mkdir ${EXPAT_VERSION}) && \
720         ($(canadian_env) \
721          cd ${EXPAT_VERSION} ; \
722          $(call find-package-srcdir, ${EXPAT_VERSION})/configure \
723           $(EXPAT_CONFIG_ARGS)) && \
724         $(STAMP) $@
725 stmp-build-host-expat: stmp-config-host-expat
726         ($(canadian_env) \
727          $(MAKE) -C ${EXPAT_VERSION}) && $(STAMP) $@
728 build-host-expat: stmp_build-host-expat
729 ifeq ($(HAVE_EXPAT),no)
730 stmp-install-host-expat: stmp-build-host-expat
731         $(MAKE) -C ${EXPAT_VERSION} install -j1 && $(STAMP) $@
732 else
733 stmp-install-host-expat:
734 endif
735 install-host-expat: stmp-install-host-expat
736
737 # target gdb rules
738 .PHONY: config-target-gdb build-target-gdb install-target-gdb
739 ifeq ($(GDB_VERSION),gdb-none)
740 config-target-gdb:
741 build-target-gdb:
742 install-target-gdb:
743 else
744 config-target-gdb: stmp-config-target-gdb
745
746 GDB_CONFIG_ARGS=$(baseargs) --prefix=$(prefix) \
747         --target=$(GDB_TARGET) --host=${cur_host} --build=${cur_build} \
748         --disable-nls
749
750 # For gdb versions 7.2 and higher, expat is required.
751 ifeq ($(GDB_MIN_VERSION_7_2),yes)
752 stmp-config-target-gdb: stmp-install-host-expat
753 GDB_CONFIG_ARGS += --with-expat --with-libexpat-prefix=$(EXPAT_DIR)
754 endif
755
756 # For gdb 7.x, disable python support for now
757 ifeq ($(filter gdb-6.%,$(GDB_VERSION)),)
758 GDB_CONFIG_ARGS += --with-python=no
759 endif
760
761 stmp-config-target-gdb: config.status $(canadian_stmp)
762         ([ -d ${GDB_VERSION} ] || \
763           mkdir ${GDB_VERSION}) && \
764         ($(canadian_env) \
765          cd ${GDB_VERSION} ; \
766          $(call find-package-srcdir, ${GDB_VERSION})/configure \
767           $(GDB_CONFIG_ARGS)) && \
768         $(STAMP) $@
769 build-target-gdb: stmp-build-target-gdb
770 stmp-build-target-gdb: stmp-config-target-gdb
771         ($(canadian_env) \
772          $(MAKE) -C ${GDB_VERSION}) && $(STAMP) $@
773 install-target-gdb: stmp-build-target-gdb
774         ($(canadian_env) \
775          $(MAKE) -C ${GDB_VERSION} install)
776 endif
777
778 # clean rules
779 .PHONY: clean
780 clean:
781         $(RM) -r $(TEMP_INSTALLDIR) stmp-build-* stmp-install-* && \
782         for sub in [ * ]; do \
783           if [ -f $$sub/Makefile ]; then \
784             $(MAKE) -C $$sub clean ; \
785           fi; \
786         done
787
788 .PHONY: distclean
789 distclean:
790         @$(RM) -r config.log config.status \
791                   $(TEMP_INSTALLDIR) temp-src \
792                   stmp-config-* stmp-build-* stmp-install-* && \
793         for sub in [ * ]; do \
794           if [ -f $$sub/config.status ]; then \
795             echo "Deleting " $$sub "..." && $(RM) -r $$sub ; \
796           fi; \
797         done
798         @$(RM) Makefile