1 From 5dbbf4cf3abac1b8bba459ddae7c572636a82915 Mon Sep 17 00:00:00 2001 2 From: David 'Digit' Turner <digit (a] android.com> 3 Date: Tue, 5 Oct 2010 22:06:25 +0200 4 Subject: [PATCH] Add canadian-cross build support. 5 6 Change-Id: Ie21aaa2be8f27b37d5821b1f6eab1e08e679720d 7 --- 8 Makefile.in | 191 ++++++++++++++++++++++++++++++++++++++++++++++------------ 9 configure | 48 ++++++++++---- 10 configure.ac | 31 +++++++--- 11 3 files changed, 209 insertions(+), 61 deletions(-) 12 13 diff --git a/Makefile.in b/Makefile.in 14 index 2c905de..c8b704c 100644 15 --- a/Makefile.in 16 +++ b/Makefile.in 17 @@ -23,6 +23,7 @@ prefix = @prefix@ 18 exec_prefix = @exec_prefix@ 19 20 srcdir = @srcdir@ 21 +abs_srcdir = @abs_srcdir@ 22 23 bindir = @bindir@ 24 sbindir = @sbindir@ 25 @@ -120,6 +121,43 @@ find-package-srcdir = $(shell \ 26 echo 'error cannot find $(strip $1)' ; \ 27 fi) 28 29 +# Set effective <build>, <host> and <target>. 30 + 31 +ifneq ($(build_alias),) 32 +cur_build := $(build_alias) 33 +else 34 +cur_build := $(build) 35 +endif 36 + 37 +ifneq ($(host_alias),) 38 +cur_host := $(host_alias) 39 +else 40 +cur_host := $(host) 41 +endif 42 + 43 +ifneq ($(target_alias),) 44 +cur_target := $(target_alias) 45 +else 46 +cur_target := $(target) 47 +endif 48 + 49 +# Define environment variables for canadian cross build. 50 +ifneq ($(cur_host),$(cur_build)) 51 +canadian_build_env := \ 52 + export CC_FOR_BUILD=$(cur_build)-gcc ; \ 53 + export CC=$(cur_build)-gcc ; \ 54 + export CXX=$(cur_build)-g++ ; 55 + 56 +CANADIAN_ROOT := $(PWD)/host-${cur_build} 57 +canadian_env := \ 58 + export CC_FOR_BUILD=$(cur_build)-gcc ; \ 59 + export CC=$(cur_host)-gcc ; \ 60 + export CXX=$(cur_host)-g++ ; \ 61 + export AR=$(cur_host)-ar ; \ 62 + export RANLIB=$(cur_host)-ranlib ; \ 63 + export PATH="$(CANADIAN_ROOT)/install/bin:${PATH}" ; 64 +endif 65 + 66 # 67 # Make rules 68 # 69 @@ -133,33 +171,87 @@ build: build-target-binutils build-target-gcc build-target-gdb 70 71 install: install-target-binutils install-target-gcc install-target-gdb 72 73 +# To support canadian cross build we need to build build->target toolchain 74 +# as well as final host->target toolchain. 75 +ifneq ($(cur_host),$(cur_build)) 76 +.PHONY: config-canadian-tools build-canadian-tools install-canadian-tools 77 + 78 +config-canadian-tools: stmp-config-canadian-tools 79 +stmp-config-canadian-tools: 80 + ([ -d $(CANADIAN_ROOT) ] || \ 81 + mkdir $(CANADIAN_ROOT)) && \ 82 + ($(canadian_build_env) \ 83 + cd $(CANADIAN_ROOT) && \ 84 + $(abs_srcdir)/configure $(baseargs) --build=$(cur_build) \ 85 + --host=$(cur_build) --target=$(cur_target)) && \ 86 + $(STAMP) $@ 87 + 88 +build-canadian-tools: stmp-build-canadian-tools 89 +stmp-build-canadian-tools: stmp-config-canadian-tools 90 + ($(canadian_build_env) \ 91 + cd $(CANADIAN_ROOT) && \ 92 + $(MAKE)) && \ 93 + $(STAMP) $@ 94 + 95 +install-canadian-tools: stmp-install-canadian-tools 96 +stmp-install-canadian-tools: stmp-build-canadian-tools 97 + ($(canadian_build_env) \ 98 + cd $(CANADIAN_ROOT) && \ 99 + $(MAKE) install prefix=$(CANADIAN_ROOT)/install) && \ 100 + $(STAMP) $@ 101 + 102 +# When building canadian cross toolchain we cannot build GCC target libraries. 103 +# So we build the compilers only and copy the target libaries from 104 +# $(CANADIAN_ROOT)/install/ installation. 105 +gcc_build_target := all-gcc 106 +gcc_install_target := install-gcc 107 +install-target-gcc-multilibs: stmp-install-canadian-tools 108 + mkdir -p $(prefix)/lib/gcc/ 109 + rsync -a $(CANADIAN_ROOT)/install/lib/gcc/ $(prefix)/lib/gcc/ 110 +install-target-gcc-multilibs := install-target-gcc-multilibs 111 + 112 +# We add canadian_stmp dependency to rules that have no dependencies 113 +# on other modules. This is to ensure that simple cross toolchain is built 114 +# before canadian cross toolchain. 115 +canadian_stmp := stmp-install-canadian-tools 116 +else 117 +gcc_build_target := 118 +gcc_install_target := install 119 +install-target-gcc-multilibs := 120 +canadian_stmp := 121 +endif 122 + 123 # target binutils rules 124 .PHONY: config-target-binutils build-target-binutils install-target-binutils 125 config-target-binutils: stmp-config-target-binutils 126 # We do not want to enable shared libraries in binutils 127 BINUTILS_CONFIG_ARGS=--prefix=$(prefix) \ 128 - --target=${target_alias} --host=${host} --build=${build} \ 129 + --target=${cur_target} --host=${cur_host} --build=${cur_build} \ 130 $(baseargs) --disable-shared 131 -stmp-config-target-binutils: config.status 132 +stmp-config-target-binutils: config.status $(canadian_stmp) 133 ([ -d ${BINUTILS_VERSION} ] || \ 134 mkdir ${BINUTILS_VERSION}) && \ 135 - (cd ${BINUTILS_VERSION} ; \ 136 + ($(canadian_env) \ 137 + cd ${BINUTILS_VERSION} ; \ 138 $(call find-package-srcdir, ${BINUTILS_VERSION})/configure \ 139 $(BINUTILS_CONFIG_ARGS)) && \ 140 $(STAMP) $@ 141 build-target-binutils: stmp-build-target-binutils 142 stmp-build-target-binutils: stmp-config-target-binutils 143 - $(MAKE) -C ${BINUTILS_VERSION} && $(STAMP) $@ 144 + ($(canadian_env) \ 145 + $(MAKE) -C ${BINUTILS_VERSION}) && $(STAMP) $@ 146 install-target-binutils: stmp-build-target-binutils 147 - $(MAKE) -C ${BINUTILS_VERSION} install 148 + ($(canadian_env) \ 149 + $(MAKE) -C ${BINUTILS_VERSION} install) 150 151 # target gcc rules 152 .PHONY: config-target-gcc build-target-gcc install-target-gcc 153 +.PHONY: install-target-gcc-gcc $(install-target-gcc-multilibs) 154 config-target-gcc: stmp-config-target-gcc 155 156 GCC_CONFIG_ARGS=--prefix=$(prefix) \ 157 - --target=${target_alias} --host=${host} --build=${build} \ 158 - --enable-languages=c,c++ 159 + --target=${cur_target} --host=${cur_host} --build=${cur_build} \ 160 + --with-gnu-as --with-gnu-ld --enable-languages=c,c++ 161 162 # For gcc versions 4.3.0 and later, gmp and mpfr are required. 163 # Also build libgcc is a seperate sub-target in 4.3.0+. 164 @@ -203,7 +295,8 @@ GCC_CONFIG_ARGS += $(baseargs) 165 stmp-config-target-gcc: config.status stmp-build-target-binutils 166 ([ -d ${GCC_VERSION} ] || \ 167 mkdir ${GCC_VERSION}) && \ 168 - (cd ${GCC_VERSION} ; \ 169 + ($(canadian_env) \ 170 + cd ${GCC_VERSION} ; \ 171 $(TARGET_BINUTILS_EXPORTS) ; \ 172 export CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" ; \ 173 export CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" ; \ 174 @@ -213,13 +306,17 @@ stmp-config-target-gcc: config.status stmp-build-target-binutils 175 $(STAMP) $@ 176 build-target-gcc: stmp-build-target-gcc 177 stmp-build-target-gcc: stmp-config-target-gcc 178 - $(MAKE) -C ${GCC_VERSION} \ 179 + ($(canadian_env) \ 180 + $(MAKE) -C ${GCC_VERSION} \ 181 CFLAGS_FOR_TARGET="$(CFLAGS_FOR_TARGET)" \ 182 CXXFLAGS_FOR_TARGET="$(CXXFLAGS_FOR_TARGET)" \ 183 LDFLAGS_FOR_TARGET="$(LDFLAGS_FOR_TARGET)" \ 184 + $(gcc_build_target)) \ 185 && $(STAMP) $@ 186 -install-target-gcc: stmp-build-target-gcc 187 - $(MAKE) -C ${GCC_VERSION} install 188 +install-target-gcc-gcc: stmp-build-target-gcc 189 + ($(canadian_env) \ 190 + $(MAKE) -C ${GCC_VERSION} $(gcc_install_target)) 191 +install-target-gcc: install-target-gcc-gcc $(install-target-gcc-multilibs) 192 193 # minimal gcc rules 194 # minimal gcc only builds the C and C++ compilers and libgcc 195 @@ -233,52 +330,60 @@ endif 196 197 build-target-minimal-gcc: stmp-build-target-minimal-gcc 198 stmp-build-target-minimal-gcc: stmp-config-target-gcc 199 - $(MAKE) -C ${GCC_VERSION} \ 200 - $(call prefix-list, all-, $(MINIMAL_GCC_BUILD_TARGETS)) && \ 201 + ($(canadian_env) \ 202 + $(MAKE) -C ${GCC_VERSION} \ 203 + $(call prefix-list, all-, $(MINIMAL_GCC_BUILD_TARGETS))) && \ 204 $(STAMP) $@ 205 install-target-minimal-gcc: stmp-build-target-minimal-gcc 206 - $(MAKE) -C ${GCC_VERSION} \ 207 - $(call prefix-list, install-, $(MINIMAL_GCC_BUILD_TARGETS)) 208 + ($(canadian_env) \ 209 + $(MAKE) -C ${GCC_VERSION} \ 210 + $(call prefix-list, install-, $(MINIMAL_GCC_BUILD_TARGETS))) 211 212 # target newlib rules 213 .PHONY: config-target-newlib build-target-newlib install-target-newlib 214 config-target-newlib: stmp-config-target-newlib 215 NEWLIB_CONFIG_ARGS=$(baseargs) --prefix=$(prefix) \ 216 - --target=${target_alias} --host=${host} --build=${build} 217 + --target=${cur_target} --host=${cur_host} --build=${cur_build} 218 219 stmp-config-target-newlib: stmp-build-target-binutils \ 220 stmp-build-target-minimal-gcc 221 ([ -d ${NEWLIB_VERSION} ] || \ 222 mkdir ${NEWLIB_VERSION}) && \ 223 - (cd ${NEWLIB_VERSION} ; \ 224 + ($(canadian_env) \ 225 + cd ${NEWLIB_VERSION} ; \ 226 $(TARGET_BINUTILS_EXPORTS) ; \ 227 $(TARGET_MINIMAL_GCC_EXPORTS) ; \ 228 $(call find-package-srcdir, ${NEWLIB_VERSION})/configure \ 229 $(NEWLIB_CONFIG_ARGS)) && \ 230 $(STAMP) $@ 231 stmp-build-target-newlib: stmp-config-target-newlib 232 - $(MAKE) -C ${NEWLIB_VERSION} && $(STAMP) $@ 233 + ($(canadian_env) \ 234 + $(MAKE) -C ${NEWLIB_VERSION}) && $(STAMP) $@ 235 install-target-newlib: stmp-build-target-newlib 236 - $(MAKE) -C ${NEWLIB_VERSION} install 237 + ($(canadian_env) \ 238 + $(MAKE) -C ${NEWLIB_VERSION} install) 239 240 # host gmp rules 241 .PHONY: config-host-gmp build-host-gmp install-host-gmp 242 config-host-gmp: stmp-config-host-gmp 243 GMP_CONFIG_ARGS=$(baseargs) --prefix=$(TEMP_INSTALLDIR) --disable-shared \ 244 - --host=${host} --build=${build} 245 -stmp-config-host-gmp: config.status 246 + --host=${cur_host} --build=${cur_build} 247 +stmp-config-host-gmp: config.status $(canadian_stmp) 248 ([ -d ${GMP_VERSION} ] || \ 249 mkdir ${GMP_VERSION}) && \ 250 - (cd ${GMP_VERSION} ; \ 251 + ($(canadian_env) \ 252 + cd ${GMP_VERSION} ; \ 253 $(call find-package-srcdir, ${GMP_VERSION})/configure \ 254 $(GMP_CONFIG_ARGS)) && \ 255 $(STAMP) $@ 256 stmp-build-host-gmp: stmp-config-host-gmp 257 - $(MAKE) -C ${GMP_VERSION} && $(STAMP) $@ 258 + ($(canadian_env) \ 259 + $(MAKE) -C ${GMP_VERSION}) && $(STAMP) $@ 260 build-host-gmp: stmp-build-host-gmp 261 # Need -j1 to avoid a race condition in building on OS X. 262 stmp-install-host-gmp: stmp-build-host-gmp 263 - $(MAKE) -C ${GMP_VERSION} install -j1 && \ 264 + ($(canadian_env) \ 265 + $(MAKE) -C ${GMP_VERSION} install -j1) && \ 266 $(STAMP) $@ 267 install-host-gmp: stmp-install-host-gmp 268 269 @@ -286,19 +391,23 @@ install-host-gmp: stmp-install-host-gmp 270 .PHONY: config-host-mpfr build-host-mpfr install-host-mpfr 271 config-host-mpfr: stmp-config-host-mpfr 272 MPFR_CONFIG_ARGS=$(baseargs) --prefix=$(TEMP_INSTALLDIR) --disable-shared \ 273 - --host=${host} --build=${build} --with-gmp=$(TEMP_INSTALLDIR) 274 + --host=${cur_host} --build=${cur_build} \ 275 + --with-gmp=$(TEMP_INSTALLDIR) 276 stmp-config-host-mpfr: config.status stmp-install-host-gmp 277 ([ -d ${MPFR_VERSION} ] || \ 278 mkdir ${MPFR_VERSION}) && \ 279 - (cd ${MPFR_VERSION} ; \ 280 + ($(canadian_env) \ 281 + cd ${MPFR_VERSION} ; \ 282 $(call find-package-srcdir, ${MPFR_VERSION})/configure \ 283 $(MPFR_CONFIG_ARGS)) && \ 284 $(STAMP) $@ 285 stmp-build-host-mpfr: stmp-config-host-mpfr 286 - $(MAKE) -C ${MPFR_VERSION} && $(STAMP) $@ 287 + ($(canadian_env) \ 288 + $(MAKE) -C ${MPFR_VERSION}) && $(STAMP) $@ 289 build-host-mpfr: stmp-build-host-mpfr 290 stmp-install-host-mpfr: stmp-build-host-mpfr 291 - $(MAKE) -C ${MPFR_VERSION} install && \ 292 + ($(canadian_env) \ 293 + $(MAKE) -C ${MPFR_VERSION} install) && \ 294 $(STAMP) $@ 295 install-host-mpfr: stmp-install-host-mpfr 296 297 @@ -306,20 +415,23 @@ install-host-mpfr: stmp-install-host-mpfr 298 .PHONY: config-host-mpc build-host-mpc install-host-mpc 299 config-host-mpc: stmp-config-host-mpc 300 MPC_CONFIG_ARGS=$(baseargs) --prefix=$(TEMP_INSTALLDIR) --disable-shared \ 301 - --host=${host} --build=${build} --with-gmp=$(TEMP_INSTALLDIR) \ 302 - --with-mpfr=$(TEMP_INSTALLDIR) 303 + --host=${cur_host} --build=${cur_build} \ 304 + --with-gmp=$(TEMP_INSTALLDIR) --with-mpfr=$(TEMP_INSTALLDIR) 305 stmp-config-host-mpc: config.status stmp-install-host-gmp stmp-install-host-mpfr 306 ([ -d ${MPC_VERSION} ] || \ 307 mkdir ${MPC_VERSION}) && \ 308 - (cd ${MPC_VERSION} ; \ 309 + ($(canadian_env) \ 310 + cd ${MPC_VERSION} ; \ 311 $(call find-package-srcdir, ${MPC_VERSION})/configure \ 312 $(MPC_CONFIG_ARGS)) && \ 313 $(STAMP) $@ 314 stmp-build-host-mpc: stmp-config-host-mpc 315 - $(MAKE) -C ${MPC_VERSION} && $(STAMP) $@ 316 + ($(canadian_env) \ 317 + $(MAKE) -C ${MPC_VERSION}) && $(STAMP) $@ 318 build-host-mpc: stmp-build-host-mpc 319 stmp-install-host-mpc: stmp-build-host-mpc 320 - $(MAKE) -C ${MPC_VERSION} install && \ 321 + ($(canadian_env) \ 322 + $(MAKE) -C ${MPC_VERSION} install) && \ 323 $(STAMP) $@ 324 install-host-mpc: stmp-install-host-mpc 325 326 @@ -328,21 +440,24 @@ install-host-mpc: stmp-install-host-mpc 327 config-target-gdb: stmp-config-target-gdb 328 329 GDB_CONFIG_ARGS=$(baseargs) --prefix=$(prefix) \ 330 - --target=$(GDB_TARGET) --host=${host} --build=${build} \ 331 + --target=$(GDB_TARGET) --host=${cur_host} --build=${cur_build} \ 332 --disable-nls 333 334 -stmp-config-target-gdb: config.status 335 +stmp-config-target-gdb: config.status $(canadian_stmp) 336 ([ -d ${GDB_VERSION} ] || \ 337 mkdir ${GDB_VERSION}) && \ 338 - (cd ${GDB_VERSION} ; \ 339 + ($(canadian_env) \ 340 + cd ${GDB_VERSION} ; \ 341 $(call find-package-srcdir, ${GDB_VERSION})/configure \ 342 $(GDB_CONFIG_ARGS)) && \ 343 $(STAMP) $@ 344 build-target-gdb: stmp-build-target-gdb 345 stmp-build-target-gdb: stmp-config-target-gdb 346 - $(MAKE) -C ${GDB_VERSION} && $(STAMP) $@ 347 + ($(canadian_env) \ 348 + $(MAKE) -C ${GDB_VERSION}) && $(STAMP) $@ 349 install-target-gdb: stmp-build-target-gdb 350 - $(MAKE) -C ${GDB_VERSION} install 351 + ($(canadian_env) \ 352 + $(MAKE) -C ${GDB_VERSION} install) 353 354 # clean rules 355 .PHONY: clean 356 diff --git a/configure b/configure 357 index 96a2d52..37db9be 100755 358 --- a/configure 359 +++ b/configure 360 @@ -639,6 +639,7 @@ GMP_VERSION 361 MPFR_VERSION 362 MPC_VERSION 363 GDB_VERSION 364 +sysroot 365 LIBOBJS 366 LTLIBOBJS' 367 ac_subst_files='' 368 @@ -1239,6 +1240,8 @@ Optional Packages: 369 use mpc-VERSION (default is 0.8.1) 370 --with-gdb-version=VERSION 371 use gdb-VERSION (default is 6.6) 372 + --with-sysroot=DIR 373 + use target sysroot in DIR 374 375 _ACEOF 376 ac_status=$? 377 @@ -1997,19 +2000,6 @@ fi 378 379 380 381 -# 382 -# Check for Canadian cross, which is not supported. 383 -# 384 -{ echo "$as_me:$LINENO: checking for Canadian cross" >&5 385 -echo $ECHO_N "checking for Canadian cross... $ECHO_C" >&6; } 386 -if test $build != $host ; then 387 - { { echo "$as_me:$LINENO: error: Canadian cross build not supported." >&5 388 -echo "$as_me: error: Canadian cross build not supported." >&2;} 389 - { (exit 1); exit 1; }; } 390 -fi 391 -{ echo "$as_me:$LINENO: result: no" >&5 392 -echo "${ECHO_T}no" >&6; } 393 - 394 # package to source path 395 case $srcdir in 396 /* | A-Za-z:*) package_to_srcdir=$srcdir ;; 397 @@ -2353,6 +2343,35 @@ echo "$as_me: error: 'package gdb-${GDB_VERSION} does not exist.'" >&2;} 398 fi 399 fi 400 401 +# Sysroot location 402 + 403 +# Check whether --with-sysroot was given. 404 +if test "${with_sysroot+set}" = set; then 405 + withval=$with_sysroot; if test x"$withval" != x ; then 406 + if test $build != $host ; then 407 + case "$withval" in 408 + "$prefix"|"${prefix%/}/"*) 409 + ;; 410 + *) 411 + { { echo "$as_me:$LINENO: error: 'Target sysroot must be a subdirectory of <prefix> for canadian cross build $prefix ; $withval'" >&5 412 +echo "$as_me: error: 'Target sysroot must be a subdirectory of <prefix> for canadian cross build $prefix ; $withval'" >&2;} 413 + { (exit 1); exit 1; }; } 414 + ;; 415 + esac 416 + fi 417 + 418 + sysroot="$withval" 419 + fi 420 +else 421 + if test $build != $host ; then 422 + { { echo "$as_me:$LINENO: error: 'Target sysroot is not set for canadian cross build'" >&5 423 +echo "$as_me: error: 'Target sysroot is not set for canadian cross build'" >&2;} 424 + { (exit 1); exit 1; }; } 425 + fi 426 +fi 427 + 428 + 429 + 430 cat >confcache <<\_ACEOF 431 # This file is a shell script that caches the results of configure 432 # tests run on this system so they can be shared between configure 433 @@ -3044,11 +3063,12 @@ GMP_VERSION!$GMP_VERSION$ac_delim 434 MPFR_VERSION!$MPFR_VERSION$ac_delim 435 MPC_VERSION!$MPC_VERSION$ac_delim 436 GDB_VERSION!$GDB_VERSION$ac_delim 437 +sysroot!$sysroot$ac_delim 438 LIBOBJS!$LIBOBJS$ac_delim 439 LTLIBOBJS!$LTLIBOBJS$ac_delim 440 _ACEOF 441 442 - if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 65; then 443 + if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 66; then 444 break 445 elif $ac_last_try; then 446 { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5 447 diff --git a/configure.ac b/configure.ac 448 index 973b8f4..4180f29 100644 449 --- a/configure.ac 450 +++ b/configure.ac 451 @@ -171,15 +171,6 @@ fi 452 453 AC_SUBST(baseargs) 454 455 -# 456 -# Check for Canadian cross, which is not supported. 457 -# 458 -AC_MSG_CHECKING([for Canadian cross]) 459 -if test $build != $host ; then 460 - AC_MSG_ERROR(Canadian cross build not supported.) 461 -fi 462 -AC_MSG_RESULT(no) 463 - 464 # package to source path 465 case $srcdir in 466 /* | [A-Za-z]:*) package_to_srcdir=$srcdir ;; 467 @@ -349,4 +340,26 @@ AC_MSG_RESULT($GDB_VERSION) 468 AC_SUBST(GDB_VERSION) 469 ANDROID_CHECK_PACKAGE(gdb-${GDB_VERSION}) 470 471 +# Sysroot location 472 +AC_ARG_WITH([sysroot], 473 + [ --with-sysroot=DIR 474 + use target sysroot in DIR], 475 + [if test x"$withval" != x ; then 476 + if test $build != $host ; then 477 + case "$withval" in 478 + "$prefix"|"${prefix%/}/"*) 479 + ;; 480 + *) 481 + AC_MSG_ERROR('Target sysroot must be a subdirectory of <prefix> for canadian cross build $prefix ; $withval') 482 + ;; 483 + esac 484 + fi 485 + 486 + sysroot="$withval" 487 + fi], 488 +[if test $build != $host ; then 489 + AC_MSG_ERROR('Target sysroot is not set for canadian cross build') 490 + fi]) 491 +AC_SUBST(sysroot) 492 + 493 AC_OUTPUT 494 -- 495 1.7.1 496 497