| #!/bin/sh |
| # |
| # Copyright (C) 2013 The Android Open Source Project |
| # |
| # Licensed under the Apache License, Version 2.0 (the "License"); |
| # you may not use this file except in compliance with the License. |
| # You may obtain a copy of the License at |
| # |
| # http://www.apache.org/licenses/LICENSE-2.0 |
| # |
| # Unless required by applicable law or agreed to in writing, software |
| # distributed under the License is distributed on an "AS IS" BASIS, |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| # See the License for the specific language governing permissions and |
| # limitations under the License. |
| # |
| # Build the host version of the yasm executable and place it |
| # at the right location |
| |
| PROGDIR=$(dirname $0) |
| . $NDK_BUILDTOOLS_PATH/prebuilt-common.sh |
| |
| PROGRAM_PARAMETERS="<src-dir> <ndk-dir>" |
| PROGRAM_DESCRIPTION=\ |
| "Rebuild yasm tool used by the NDK." |
| |
| register_try64_option |
| register_canadian_option |
| register_jobs_option |
| |
| BUILD_DIR= |
| register_var_option "--build-dir=<path>" BUILD_DIR "Set temporary build directory" |
| |
| PACKAGE_DIR= |
| register_var_option "--package-dir=<path>" PACKAGE_DIR "Archive binaries into package directory" |
| |
| extract_parameters "$@" |
| |
| set_parameters () |
| { |
| SRC_DIR="$1" |
| NDK_DIR="$2" |
| |
| # Check source directory |
| # |
| if [ -z "$SRC_DIR" ] ; then |
| echo "ERROR: Missing source directory parameter. See --help for details." |
| exit 1 |
| fi |
| |
| if [ ! -d "$SRC_DIR/yasm" ] ; then |
| echo "ERROR: Source directory does not contain llvm sources: $SRC_DIR/yasm" |
| exit 1 |
| fi |
| |
| SRC_DIR=`cd $SRC_DIR; pwd` |
| log "Using source directory: $SRC_DIR" |
| |
| # Check NDK installation directory |
| # |
| if [ -z "$NDK_DIR" ] ; then |
| echo "ERROR: Missing NDK directory parameter. See --help for details." |
| exit 1 |
| fi |
| |
| if [ ! -d "$NDK_DIR" ] ; then |
| mkdir -p $NDK_DIR |
| if [ $? != 0 ] ; then |
| echo "ERROR: Could not create target NDK installation path: $NDK_DIR" |
| exit 1 |
| fi |
| fi |
| NDK_DIR=`cd $NDK_DIR; pwd` |
| log "Using NDK directory: $NDK_DIR" |
| } |
| |
| set_parameters $PARAMETERS |
| |
| prepare_abi_configure_build |
| prepare_host_build |
| |
| if [ -z "$BUILD_DIR" ]; then |
| panic "--build-dir is required" |
| fi |
| |
| INSTALL_DIR=$BUILD_DIR/install |
| BUILD_DIR=$BUILD_DIR/build |
| |
| rm -rf $BUILD_DIR |
| mkdir -p $BUILD_DIR |
| |
| log "Copying yasm sources to $BUILD_DIR/src" |
| mkdir -p "$BUILD_DIR/src" && copy_directory "$SRC_DIR/yasm" "$BUILD_DIR/src" |
| fail_panic "Could not copy yasm sources to: $BUILD_DIR/src" |
| |
| CONFIGURE_FLAGS="--disable-nls --disable-rpath --prefix=$BUILD_DIR/prefix" |
| if [ "$MINGW" = "yes" -o "$DARWIN" = "yes" ]; then |
| # Required for a proper mingw or darwin cross compile |
| CONFIGURE_FLAGS=$CONFIGURE_FLAGS" --host=$ABI_CONFIGURE_HOST" |
| fi |
| |
| prepare_canadian_toolchain $BUILD_DIR |
| |
| CFLAGS=$HOST_CFLAGS" -O2 -s" |
| CFLAGS_FOR_BUILD=$CFLAGS |
| export CC CFLAGS CFLAGS_FOR_BUILD |
| |
| log "Configuring the build" |
| cd $BUILD_DIR/src && run ./configure $CONFIGURE_FLAGS --build=$ABI_CONFIGURE_BUILD |
| fail_panic "configure failed in $BUILD_DIR/yasm!" |
| |
| log "Building yasm" |
| # build yasm in -j1 to avoid a race condition not well understood at this moment |
| # which causes failure with error message reads: |
| # perfect.c: Duplicates keys! |
| # make: *** [x86insn_nasm.c] Error 1 |
| # make: *** Waiting for unfinished jobs.... |
| run make -j1 # -j$NUM_JOBS |
| fail_panic "Failed to build the $BUILD_DIR/yasm!" |
| |
| log "Installing yasm" |
| run make install |
| fail_panic "Failed to install $BUILD_DIR/yasm!" |
| |
| run rm -rf $BUILD_DIR/prefix/share |
| |
| log "Stripping yasm" |
| test -z "$STRIP" && STRIP=strip |
| find $BUILD_DIR/prefix/bin -maxdepth 1 -type f -exec $STRIP {} \; |
| |
| log "Copying yasm" |
| #run copy_directory "$BUILD_DIR/prefix" "$(get_prebuilt_install_prefix)" |
| SUBDIR=$(get_prebuilt_host_exec yasm) |
| OUT=$INSTALL_DIR/$SUBDIR |
| run mkdir -p $(dirname "$OUT") && cp $BUILD_DIR/prefix/bin/$(get_host_exec_name yasm) $OUT |
| fail_panic "Could not copy yasm" |
| |
| if [ "$PACKAGE_DIR" ]; then |
| ARCHIVE=ndk-yasm-$HOST_TAG.tar.bz2 |
| dump "Packaging: $ARCHIVE" |
| mkdir -p "$PACKAGE_DIR" && |
| pack_archive "$PACKAGE_DIR/$ARCHIVE" "$INSTALL_DIR" "$SUBDIR" |
| fail_panic "Could not package archive: $PACKAGE_DIR/$ARCHIVE" |
| fi |