• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
20PROGDIR=$(dirname $0)
21. $PROGDIR/prebuilt-common.sh
22
23PROGRAM_PARAMETERS="<src-dir> <ndk-dir>"
24PROGRAM_DESCRIPTION=\
25"Rebuild yasm tool used by the NDK."
26
27register_try64_option
28register_canadian_option
29register_jobs_option
30
31BUILD_OUT=/tmp/ndk-$USER/build/yasm
32OPTION_BUILD_OUT=
33register_var_option "--build-out=<path>" OPTION_BUILD_OUT "Set temporary build directory"
34
35PACKAGE_DIR=
36register_var_option "--package-dir=<path>" PACKAGE_DIR "Archive binaries into package directory"
37
38extract_parameters "$@"
39
40set_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
78set_parameters $PARAMETERS
79
80prepare_abi_configure_build
81prepare_host_build
82
83fix_option BUILD_OUT "$OPTION_BUILD_OUT" "build directory"
84setup_default_log_file $BUILD_OUT/config.log
85
86rm -rf $BUILD_OUT
87mkdir -p $BUILD_OUT
88
89log "Copying yasm sources to $BUILD_OUT/src"
90mkdir -p "$BUILD_OUT/src" && copy_directory "$SRC_DIR/yasm" "$BUILD_OUT/src"
91fail_panic "Could not copy yasm sources to: $BUILD_OUT/src"
92
93CONFIGURE_FLAGS="--disable-nls --disable-rpath --prefix=$BUILD_OUT/prefix"
94if [ "$MINGW" = "yes" ]; then
95    # Required for a proper mingw cross compile
96    CONFIGURE_FLAGS=$CONFIGURE_FLAGS" --host=i586-pc-mingw32"
97fi
98
99if [ "$DARWIN" = "yes" ]; then
100    # Required for a proper darwin cross compile
101    CONFIGURE_FLAGS=$CONFIGURE_FLAGS" --host=$ABI_CONFIGURE_HOST"
102fi
103
104prepare_canadian_toolchain $BUILD_OUT
105
106CFLAGS=$HOST_CFLAGS" -O2 -s"
107export CC CFLAGS
108
109log "Configuring the build"
110cd $BUILD_OUT/src && run ./autogen.sh $CONFIGURE_FLAGS --build=$ABI_CONFIGURE_BUILD
111fail_panic "Couldn't run autogen.sh in $BUILD_OUT/yasm!"
112
113log "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....
119run make -j1 # -j$NUM_JOBS
120fail_panic "Failed to build the $BUILD_OUT/yasm!"
121
122log "Installing yasm"
123run make install
124fail_panic "Failed to install $BUILD_OUT/yasm!"
125
126run rm -rf $BUILD_OUT/prefix/share
127
128log "Stripping yasm"
129test -z "$STRIP" && STRIP=strip
130find $BUILD_OUT/prefix/bin -maxdepth 1 -type f -exec $STRIP {} \;
131
132log "Copying yasm"
133#run copy_directory "$BUILD_OUT/prefix" "$(get_prebuilt_install_prefix)"
134SUBDIR=$(get_prebuilt_host_exec yasm)
135OUT=$NDK_DIR/$SUBDIR
136run mkdir -p $(dirname "$OUT") && cp $BUILD_OUT/prefix/bin/$(get_host_exec_name yasm) $OUT
137fail_panic "Could not copy yasm"
138
139if [ "$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"
145fi
146
147log "Cleaning up"
148if [ -z "$OPTION_BUILD_OUT" ] ; then
149    rm -rf $BUILD_OUT
150fi
151