1 #!/bin/sh 2 # 3 # Copyright (C) 2013 The Android Open Source Project 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 # 17 # Build the host version of the yasm executable and place it 18 # at the right location 19 20 PROGDIR=$(dirname $0) 21 . $PROGDIR/prebuilt-common.sh 22 23 PROGRAM_PARAMETERS="<src-dir> <ndk-dir>" 24 PROGRAM_DESCRIPTION=\ 25 "Rebuild yasm tool used by the NDK." 26 27 register_try64_option 28 register_canadian_option 29 register_jobs_option 30 31 BUILD_OUT=/tmp/ndk-$USER/build/yasm 32 OPTION_BUILD_OUT= 33 register_var_option "--build-out=<path>" OPTION_BUILD_OUT "Set temporary build directory" 34 35 PACKAGE_DIR= 36 register_var_option "--package-dir=<path>" PACKAGE_DIR "Archive binaries into package directory" 37 38 extract_parameters "$@" 39 40 set_parameters () 41 { 42 SRC_DIR="$1" 43 NDK_DIR="$2" 44 45 # Check source directory 46 # 47 if [ -z "$SRC_DIR" ] ; then 48 echo "ERROR: Missing source directory parameter. See --help for details." 49 exit 1 50 fi 51 52 if [ ! -d "$SRC_DIR/yasm" ] ; then 53 echo "ERROR: Source directory does not contain llvm sources: $SRC_DIR/yasm" 54 exit 1 55 fi 56 57 SRC_DIR=`cd $SRC_DIR; pwd` 58 log "Using source directory: $SRC_DIR" 59 60 # Check NDK installation directory 61 # 62 if [ -z "$NDK_DIR" ] ; then 63 echo "ERROR: Missing NDK directory parameter. See --help for details." 64 exit 1 65 fi 66 67 if [ ! -d "$NDK_DIR" ] ; then 68 mkdir -p $NDK_DIR 69 if [ $? != 0 ] ; then 70 echo "ERROR: Could not create target NDK installation path: $NDK_DIR" 71 exit 1 72 fi 73 fi 74 NDK_DIR=`cd $NDK_DIR; pwd` 75 log "Using NDK directory: $NDK_DIR" 76 } 77 78 set_parameters $PARAMETERS 79 80 prepare_abi_configure_build 81 prepare_host_build 82 83 fix_option BUILD_OUT "$OPTION_BUILD_OUT" "build directory" 84 setup_default_log_file $BUILD_OUT/config.log 85 86 rm -rf $BUILD_OUT 87 mkdir -p $BUILD_OUT 88 89 log "Copying yasm sources to $BUILD_OUT/src" 90 mkdir -p "$BUILD_OUT/src" && copy_directory "$SRC_DIR/yasm" "$BUILD_OUT/src" 91 fail_panic "Could not copy yasm sources to: $BUILD_OUT/src" 92 93 CONFIGURE_FLAGS="--disable-nls --disable-rpath --prefix=$BUILD_OUT/prefix" 94 if [ "$MINGW" = "yes" ]; then 95 # Required for a proper mingw cross compile 96 CONFIGURE_FLAGS=$CONFIGURE_FLAGS" --host=i586-pc-mingw32" 97 fi 98 99 if [ "$DARWIN" = "yes" ]; then 100 # Required for a proper darwin cross compile 101 CONFIGURE_FLAGS=$CONFIGURE_FLAGS" --host=$ABI_CONFIGURE_HOST" 102 fi 103 104 prepare_canadian_toolchain $BUILD_OUT 105 106 CFLAGS=$HOST_CFLAGS" -O2 -s" 107 export CC CFLAGS 108 109 log "Configuring the build" 110 cd $BUILD_OUT/src && run ./autogen.sh $CONFIGURE_FLAGS --build=$ABI_CONFIGURE_BUILD 111 fail_panic "Couldn't run autogen.sh in $BUILD_OUT/yasm!" 112 113 log "Building yasm" 114 # build yasm in -j1 to avoid a race condition not well understood at this moment 115 # which causes failure with error message reads: 116 # perfect.c: Duplicates keys! 117 # make: *** [x86insn_nasm.c] Error 1 118 # make: *** Waiting for unfinished jobs.... 119 run make -j1 # -j$NUM_JOBS 120 fail_panic "Failed to build the $BUILD_OUT/yasm!" 121 122 log "Installing yasm" 123 run make install 124 fail_panic "Failed to install $BUILD_OUT/yasm!" 125 126 run rm -rf $BUILD_OUT/prefix/share 127 128 log "Stripping yasm" 129 test -z "$STRIP" && STRIP=strip 130 find $BUILD_OUT/prefix/bin -maxdepth 1 -type f -exec $STRIP {} \; 131 132 log "Copying yasm" 133 #run copy_directory "$BUILD_OUT/prefix" "$(get_prebuilt_install_prefix)" 134 SUBDIR=$(get_prebuilt_host_exec yasm) 135 OUT=$NDK_DIR/$SUBDIR 136 run mkdir -p $(dirname "$OUT") && cp $BUILD_OUT/prefix/bin/$(get_host_exec_name yasm) $OUT 137 fail_panic "Could not copy yasm" 138 139 if [ "$PACKAGE_DIR" ]; then 140 ARCHIVE=ndk-yasm-$HOST_TAG.tar.bz2 141 dump "Packaging: $ARCHIVE" 142 mkdir -p "$PACKAGE_DIR" && 143 pack_archive "$PACKAGE_DIR/$ARCHIVE" "$NDK_DIR" "$SUBDIR" 144 fail_panic "Could not package archive: $PACKAGE_DIR/$ARCHIVE" 145 fi 146 147 log "Cleaning up" 148 if [ -z "$OPTION_BUILD_OUT" ] ; then 149 rm -rf $BUILD_OUT 150 fi 151