diff --git a/buildenv.sh b/buildenv.sh index 8cd732e..e189a23 100644 --- a/buildenv.sh +++ b/buildenv.sh @@ -1,9 +1,18 @@ -# The compiler that will be used to build packages for the target system. -# Change this to cross-compile, etc. -CC=gcc -CXX=g++ -export CC CXX +# Value passed to ./configure for the --host argument. If empty, then +# --host will not be passed. Set this if you want to cross-compile. +BUILD_HOST= + +# An example of how to cross-compile to mingw32 for Windows builds: +#BUILD_HOST=i586-mingw32msvc + +# If we're cross-compiling to a different platform, this should be set +# to true. We initialize this based on whether BUILD_HOST has been set. +if [ "$BUILD_HOST" != "" ]; then + IS_CROSS_COMPILE=true +else + IS_CROSS_COMPILE=false +fi # On OS X, we must set additional options: build 32-bit binaries, and the # target API version. @@ -12,8 +21,13 @@ if [ $(uname) = "Darwin" ]; then CXX="g++ -m32" LDFLAGS="-lobjc ${LDFLAGS:-}" MACOSX_DEPLOYMENT_TARGET=10.7 - export MACOSX_DEPLOYMENT_TARGET + export CC CXX LDFLAGS MACOSX_DEPLOYMENT_TARGET + + # Treat this like a cross-compile, since we're building 32-bit: + IS_CROSS_COMPILE=true else + # TODO: explain what this does LDFLAGS="-Wl,-rpath -Wl,$INSTALL_DIR/lib ${LDFLAGS:-}" + export LDFLAGS fi diff --git a/chocpkg/chocpkg b/chocpkg/chocpkg index 581deec..34780c1 100755 --- a/chocpkg/chocpkg +++ b/chocpkg/chocpkg @@ -127,6 +127,14 @@ fetch_package() { setup_build_environment() { if [ "$PACKAGE_TYPE" = "target" ]; then . "$CHOCPKG_ROOT/buildenv.sh" + + # When cross-compiling, reconfigure pkg-config to not look for .pc + # files in the standard system directories; only in our own build + # directory. It may be that a library is installed on the system + # but that is useless if it is for the wrong architecture. + if $IS_CROSS_COMPILE; then + export PKG_CONFIG_LIBDIR= + fi fi CPPFLAGS="-I$PACKAGE_INSTALL_DIR/include" @@ -158,7 +166,13 @@ build_package() { error_exit "Failed pre-build setup step for $PACKAGE_NAME." fi - ./configure --prefix="$PACKAGE_INSTALL_DIR" $PACKAGE_CONFIGURE_OPTS || ( + local host_opt="" + if [ "$PACKAGE_TYPE" = "target" ] && [ "$BUILD_HOST" != "" ]; then + host_opt="--host=$BUILD_HOST" + fi + + ./configure --prefix="$PACKAGE_INSTALL_DIR" $host_opt \ + $PACKAGE_CONFIGURE_OPTS || ( error_exit "Failed to configure package $PACKAGE_NAME for build." )