1#
2# Copyright (C) 2011 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#      http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16#  This file contains various shell function definitions that can be
17#  used to either build a static and shared libraries from sources, or
18#  generate a Makefile to do it in parallel.
19#
20
21_BUILD_TAB=$(echo " " | tr ' ' '\t')
22
23builder_command ()
24{
25    if [ -z "$_BUILD_MK" ]; then
26        if [ "$VERBOSE2" = "yes" ]; then
27            echo "$@"
28        fi
29        "$@"
30    else
31        echo "${_BUILD_TAB}${_BUILD_HIDE}$@" >> $_BUILD_MK
32    fi
33}
34
35
36builder_log ()
37{
38    if [ "$_BUILD_MK" ]; then
39        echo "${_BUILD_TAB}${_BUILD_HIDE}echo $@" >> $_BUILD_MK
40    else
41        log "$@"
42    fi
43}
44
45# $1: Build directory
46# $2: Optional Makefile name
47builder_begin ()
48{
49    _BUILD_DIR_NEW=
50    _BUILD_DIR=$1
51    if [ ! -d "$_BUILD_DIR" ]; then
52        mkdir -p "$_BUILD_DIR"
53        fail_panic "Can't create build directory: $_BUILD_DIR"
54        _BUILD_DIR_NEW=true
55    else
56        rm -rf "$_BUILD_DIR/*"
57        fail_panic "Can't cleanup build directory: $_BUILD_DIR"
58    fi
59    _BUILD_TARGETS=
60    _BUILD_PREFIX=
61    _BUILD_MK=$2
62    if [ -n "$_BUILD_MK" ]; then
63        log "Creating temporary build Makefile: $_BUILD_MK"
64        rm -f $_BUILD_MK &&
65        echo "# Auto-generated by $0 - do not edit!" > $_BUILD_MK
66        echo ".PHONY: all" >> $_BUILD_MK
67        echo "all:" >> $_BUILD_MK
68    fi
69    # HIDE is used to hide the Makefile output, unless --verbose --verbose
70    # is used.
71    if [ "$VERBOSE2" = "yes" ]; then
72        _BUILD_HIDE=""
73    else
74        _BUILD_HIDE=@
75    fi
76
77    builder_begin_module
78}
79
80# $1: Variable name
81# out: Variable value
82_builder_varval ()
83{
84    eval echo "\$$1"
85}
86
87_builder_varadd ()
88{
89    local _varname="$1"
90    local _varval="$(_builder_varval $_varname)"
91    shift
92    if [ -z "$_varval" ]; then
93        eval $_varname=\"$@\"
94    else
95        eval $_varname=\$$_varname\" $@\"
96    fi
97}
98
99
100builder_set_prefix ()
101{
102    _BUILD_PREFIX="$@"
103}
104
105builder_begin_module ()
106{
107    _BUILD_CC=
108    _BUILD_CXX=
109    _BUILD_AR=
110    _BUILD_C_INCLUDES=
111    _BUILD_CFLAGS=
112    _BUILD_CXXFLAGS=
113    _BUILD_LDFLAGS_BEGIN_SO=
114    _BUILD_LDFLAGS_END_SO=
115    _BUILD_LDFLAGS_BEGIN_EXE=
116    _BUILD_LDFLAGS_END_EXE=
117    _BUILD_LDFLAGS=
118    _BUILD_BINPREFIX=
119    _BUILD_DSTDIR=
120    _BUILD_SRCDIR=.
121    _BUILD_OBJECTS=
122    _BUILD_STATIC_LIBRARIES=
123    _BUILD_SHARED_LIBRARIES=
124    _BUILD_COMPILER_RUNTIME_LDFLAGS=-lgcc
125}
126
127builder_set_binprefix ()
128{
129    _BUILD_BINPREFIX=$1
130    _BUILD_CC=${1}gcc
131    _BUILD_CXX=${1}g++
132    _BUILD_AR=${1}ar
133}
134
135builder_set_binprefix_llvm ()
136{
137    _BUILD_BINPREFIX=$1
138    _BUILD_CC=${1}clang
139    _BUILD_CXX=${1}clang++
140    _BUILD_AR=${2}ar
141}
142
143builder_set_builddir ()
144{
145    _BUILD_DIR=$1
146}
147
148builder_set_srcdir ()
149{
150    _BUILD_SRCDIR=$1
151}
152
153builder_set_dstdir ()
154{
155    _BUILD_DSTDIR=$1
156}
157
158builder_ldflags ()
159{
160    _builder_varadd _BUILD_LDFLAGS "$@"
161}
162
163builder_ldflags_exe ()
164{
165    _builder_varadd _BUILD_LDFLAGS_EXE "$@"
166}
167
168builder_cflags ()
169{
170    _builder_varadd _BUILD_CFLAGS "$@"
171}
172
173builder_cxxflags ()
174{
175    _builder_varadd _BUILD_CXXFLAGS "$@"
176}
177
178builder_c_includes ()
179{
180    _builder_varadd _BUILD_C_INCLUDES "$@"
181}
182
183# $1: optional var to hold the original cflags before reset
184builder_reset_cflags ()
185{
186    local _varname="$1"
187    if [ -n "$_varname" ] ; then
188        eval $_varname=\"$_BUILD_CFLAGS\"
189    fi
190    _BUILD_CFLAGS=
191}
192
193# $1: optional var to hold the original cxxflags before reset
194builder_reset_cxxflags ()
195{
196    local _varname="$1"
197    if [ -n "$_varname" ] ; then
198        eval $_varname=\"$_BUILD_CXXFLAGS\"
199    fi
200    _BUILD_CXXFLAGS=
201}
202
203# $1: optional var to hold the original c_includes before reset
204builder_reset_c_includes ()
205{
206    local _varname="$1"
207    if [ -n "$_varname" ] ; then
208        eval $_varname=\"$_BUILD_C_INCLUDES\"
209    fi
210    _BUILD_C_INCLUDES=
211}
212
213builder_compiler_runtime_ldflags ()
214{
215    _BUILD_COMPILER_RUNTIME_LDFLAGS=$1
216}
217
218builder_link_with ()
219{
220    local LIB
221    for LIB; do
222        case $LIB in
223            *.a)
224                _builder_varadd _BUILD_STATIC_LIBRARIES $LIB
225                ;;
226            *.so)
227                _builder_varadd _BUILD_SHARED_LIBRARIES $LIB
228                ;;
229            *)
230                echo "ERROR: Unknown link library extension: $LIB"
231                exit 1
232        esac
233    done
234}
235
236builder_sources ()
237{
238    local src srcfull obj cc cflags text
239    if [ -z "$_BUILD_DIR" ]; then
240        panic "Build directory not set!"
241    fi
242    if [ -z "$_BUILD_CC" ]; then
243        _BUILD_CC=${CC:-gcc}
244    fi
245    if [ -z "$_BUILD_CXX" ]; then
246        _BUILD_CXX=${CXX:-g++}
247    fi
248    for src in "$@"; do
249        srcfull=$_BUILD_SRCDIR/$src
250        if [ ! -f "$srcfull" ]; then
251            echo "ERROR: Missing source file: $srcfull"
252            exit 1
253        fi
254        obj=$src
255        cflags=""
256        for inc in $_BUILD_C_INCLUDES; do
257            cflags=$cflags" -I$inc"
258        done
259        cflags=$cflags" -I$_BUILD_SRCDIR"
260        case $obj in
261            *.c)
262                obj=${obj%%.c}
263                text="C"
264                cc=$_BUILD_CC
265                cflags="$cflags $_BUILD_CFLAGS"
266                ;;
267            *.cpp)
268                obj=${obj%%.cpp}
269                text="C++"
270                cc=$_BUILD_CXX
271                cflags="$cflags $_BUILD_CXXFLAGS"
272                ;;
273            *.cc)
274                obj=${obj%%.cc}
275                text="C++"
276                cc=$_BUILD_CXX
277                cflags="$cflags $_BUILD_CXXFLAGS"
278                ;;
279            *.S|*.s)
280                obj=${obj%%.$obj}
281                text="ASM"
282                cc=$_BUILD_CC
283                cflags="$cflags $_BUILD_CFLAGS"
284                ;;
285            *)
286                echo "Unknown source file extension: $obj"
287                exit 1
288                ;;
289        esac
290
291        # Source file path can include ../ path items, ensure
292        # that the generated object do not back up the output
293        # directory by translating them to __/
294        obj=$(echo "$obj" | tr '../' '__/')
295
296        # Ensure we have unwind tables in the generated machine code
297        # This is useful to get good stack traces
298        cflags=$cflags" -funwind-tables"
299
300        obj=$_BUILD_DIR/$obj.o
301        if [ "$_BUILD_MK" ]; then
302            echo "$obj: $srcfull" >> $_BUILD_MK
303        fi
304        builder_log "${_BUILD_PREFIX}$text: $src"
305        builder_command mkdir -p $(dirname "$obj")
306        builder_command $NDK_CCACHE $cc -c -o "$obj" "$srcfull" $cflags
307        fail_panic "Could not compile ${_BUILD_PREFIX}$src"
308        _BUILD_OBJECTS=$_BUILD_OBJECTS" $obj"
309    done
310}
311
312builder_static_library ()
313{
314    local lib libname arflags
315    libname=$1
316    if [ -z "$_BUILD_DSTDIR" ]; then
317        panic "Destination directory not set"
318    fi
319    lib=$_BUILD_DSTDIR/$libname
320    lib=${lib%%.a}.a
321    if [ "$_BUILD_MK" ]; then
322        _BUILD_TARGETS=$_BUILD_TARGETS" $lib"
323        echo "$lib: $_BUILD_OBJECTS" >> $_BUILD_MK
324    fi
325    if [ -z "${_BUILD_AR}" ]; then
326        _BUILD_AR=${AR:-ar}
327    fi
328    builder_log "${_BUILD_PREFIX}Archive: $libname"
329    rm -f "$lib"
330    arflags="crs"
331    case $HOST_TAG in
332        darwin*)
333            # XCode 'ar' doesn't support D flag
334            ;;
335        *)
336            arflags="${arflags}D"
337            ;;
338    esac
339    builder_command ${_BUILD_AR} $arflags "$lib" "$_BUILD_OBJECTS"
340    fail_panic "Could not archive ${_BUILD_PREFIX}$libname objects!"
341}
342
343builder_host_static_library ()
344{
345    local lib libname
346    libname=$1
347    if [ -z "$_BUILD_DSTDIR" ]; then
348        panic "Destination directory not set"
349    fi
350    lib=$_BUILD_DSTDIR/$libname
351    lib=${lib%%.a}.a
352    if [ "$_BUILD_MK" ]; then
353        _BUILD_TARGETS=$_BUILD_TARGETS" $lib"
354        echo "$lib: $_BUILD_OBJECTS" >> $_BUILD_MK
355    fi
356    if [ -z "$BUILD_AR" ]; then
357        _BUILD_AR=${AR:-ar}
358    fi
359    builder_log "${_BUILD_PREFIX}Archive: $libname"
360    rm -f "$lib"
361    builder_command ${_BUILD_AR} crsD "$lib" "$_BUILD_OBJECTS"
362    fail_panic "Could not archive ${_BUILD_PREFIX}$libname objects!"
363}
364
365builder_shared_library ()
366{
367    local lib libname suffix libm
368    libname=$1
369    suffix=$2
370    armeabi_v7a_float_abi=$3
371
372    if [ -z "$suffix" ]; then
373        suffix=".so"
374    fi
375    libm="-lm"
376    if [ "$armeabi_v7a_float_abi" = "hard" ]; then
377        libm="-lm_hard"
378    fi
379    lib=$_BUILD_DSTDIR/$libname
380    lib=${lib%%${suffix}}${suffix}
381    if [ "$_BUILD_MK" ]; then
382        _BUILD_TARGETS=$_BUILD_TARGETS" $lib"
383        echo "$lib: $_BUILD_OBJECTS" >> $_BUILD_MK
384    fi
385    builder_log "${_BUILD_PREFIX}SharedLibrary: $libname"
386
387    # Important: -lgcc must appear after objects and static libraries,
388    #            but before shared libraries for Android. It doesn't hurt
389    #            for other platforms.
390    #            Also $libm must come before -lc because bionic libc
391    #            accidentally exports a soft-float version of ldexp.
392    builder_command ${_BUILD_CXX} \
393        -Wl,-soname,$(basename $lib) \
394        -Wl,-shared \
395        $_BUILD_LDFLAGS_BEGIN_SO \
396        $_BUILD_OBJECTS \
397        $_BUILD_STATIC_LIBRARIES \
398        $_BUILD_COMPILER_RUNTIME_LDFLAGS \
399        $_BUILD_SHARED_LIBRARIES \
400        $libm -lc \
401        $_BUILD_LDFLAGS \
402        $_BUILD_LDFLAGS_END_SO \
403        -o $lib
404    fail_panic "Could not create ${_BUILD_PREFIX}shared library $libname"
405}
406
407# Same as builder_shared_library, but do not link the default libs
408builder_nostdlib_shared_library ()
409{
410    local lib libname suffix
411    libname=$1
412    suffix=$2
413    if [ -z "$suffix" ]; then
414        suffix=".so"
415    fi
416    lib=$_BUILD_DSTDIR/$libname
417    lib=${lib%%${suffix}}${suffix}
418    if [ "$_BUILD_MK" ]; then
419        _BUILD_TARGETS=$_BUILD_TARGETS" $lib"
420        echo "$lib: $_BUILD_OBJECTS" >> $_BUILD_MK
421    fi
422    builder_log "${_BUILD_PREFIX}SharedLibrary: $libname"
423
424    builder_command ${_BUILD_CXX} \
425        -Wl,-soname,$(basename $lib) \
426        -Wl,-shared \
427        $_BUILD_LDFLAGS_BEGIN_SO \
428        $_BUILD_OBJECTS \
429        $_BUILD_STATIC_LIBRARIES \
430        $_BUILD_SHARED_LIBRARIES \
431        $_BUILD_LDFLAGS \
432        $_BUILD_LDFLAGS_END_SO \
433        -o $lib
434    fail_panic "Could not create ${_BUILD_PREFIX}shared library $libname"
435}
436
437builder_host_shared_library ()
438{
439    local lib libname
440    libname=$1
441    lib=$_BUILD_DSTDIR/$libname
442    lib=${lib%%.so}.so
443    if [ "$_BUILD_MK" ]; then
444        _BUILD_TARGETS=$_BUILD_TARGETS" $lib"
445        echo "$lib: $_BUILD_OBJECTS" >> $_BUILD_MK
446    fi
447    builder_log "${_BUILD_PREFIX}SharedLibrary: $libname"
448
449    if [ -z "$_BUILD_CXX" ]; then
450        _BUILD_CXX=${CXX:-g++}
451    fi
452
453    # Important: -lgcc must appear after objects and static libraries,
454    #            but before shared libraries for Android. It doesn't hurt
455    #            for other platforms.
456    builder_command ${_BUILD_CXX} \
457        -shared -s \
458        $_BUILD_OBJECTS \
459        $_BUILD_STATIC_LIBRARIES \
460        $_BUILD_SHARED_LIBRARIES \
461        $_BUILD_LDFLAGS \
462        -o $lib
463    fail_panic "Could not create ${_BUILD_PREFIX}shared library $libname"
464}
465
466builder_host_executable ()
467{
468    local exe exename
469    exename=$1
470    exe=$_BUILD_DSTDIR/$exename$HOST_EXE
471    if [ "$_BUILD_MK" ]; then
472        _BUILD_TARGETS=$_BUILD_TARGETS" $exe"
473        echo "$exe: $_BUILD_OBJECTS" >> $_BUILD_MK
474    fi
475    builder_log "${_BUILD_PREFIX}Executable: $exename$HOST_EXE"
476
477    if [ -z "$_BUILD_CXX" ]; then
478        _BUILD_CXX=${CXX:-g++}
479    fi
480
481    # Important: -lgcc must appear after objects and static libraries,
482    #            but before shared libraries for Android. It doesn't hurt
483    #            for other platforms.
484    builder_command ${_BUILD_CXX} \
485        -s \
486        $_BUILD_OBJECTS \
487        $_BUILD_STATIC_LIBRARIES \
488        $_BUILD_SHARED_LIBRARIES \
489        $_BUILD_LDFLAGS \
490        -o $exe
491    fail_panic "Could not create ${_BUILD_PREFIX}executable $libname"
492}
493
494
495builder_end ()
496{
497    if [ "$_BUILD_MK" ]; then
498        echo "all: $_BUILD_TARGETS" >> $_BUILD_MK
499        run make -j$NUM_JOBS -f $_BUILD_MK
500        fail_panic "Could not build project!"
501    fi
502
503    if [ "$_BUILD_DIR_NEW" ]; then
504        log2 "Cleaning up build directory: $_BUILD_DIR"
505        rm -rf "$_BUILD_DIR"
506        _BUILD_DIR_NEW=
507    fi
508}
509
510# Same as builder_begin, but to target Android with a specific ABI
511# $1: ABI name (e.g. armeabi)
512# $2: Build directory
513# $3: Gcc version
514# $4: Optional llvm version
515# $5: Optional Makefile name
516# $6: Platform (android-X)
517builder_begin_android ()
518{
519    local ABI BUILDDIR LLVM_VERSION MAKEFILE
520    local ARCH SYSROOT LDIR FLAGS
521    local CRTBEGIN_SO_O CRTEND_SO_O CRTBEGIN_EXE_SO CRTEND_SO_O
522    local BINPREFIX GCC_TOOLCHAIN LLVM_TRIPLE GCC_VERSION
523    local SCRATCH_FLAGS PLATFORM
524    if [ -z "$NDK_DIR" ]; then
525        panic "NDK_DIR is not defined!"
526    elif [ ! -d "$NDK_DIR/platforms" ]; then
527        panic "Missing directory: $NDK_DIR/platforms"
528    fi
529    ABI=$1
530    BUILDDIR=$2
531    GCC_VERSION=$3
532    LLVM_VERSION=$4
533    MAKEFILE=$5
534    ARCH=$(convert_abi_to_arch $ABI)
535    PLATFORM=$6
536
537    if [ "$(arch_in_unknown_archs $ARCH)" = "yes" ]; then
538        LLVM_VERSION=$DEFAULT_LLVM_VERSION
539    fi
540    if [ -n "$LLVM_VERSION" ]; then
541        # override GCC_VERSION to pick $DEFAULT_LLVM_GCC??_VERSION instead
542        if [ "$ABI" != "${ABI%%64*}" ]; then
543            GCC_VERSION=$DEFAULT_LLVM_GCC64_VERSION
544        else
545            GCC_VERSION=$DEFAULT_LLVM_GCC32_VERSION
546        fi
547    fi
548    for TAG in $HOST_TAG $HOST_TAG32; do
549        BINPREFIX=$NDK_DIR/$(get_toolchain_binprefix_for_arch $ARCH $GCC_VERSION $TAG)
550        if [ -f ${BINPREFIX}gcc ]; then
551            break;
552        fi
553    done
554    if [ -n "$LLVM_VERSION" ]; then
555        GCC_TOOLCHAIN=`dirname $BINPREFIX`
556        GCC_TOOLCHAIN=`dirname $GCC_TOOLCHAIN`
557        BINPREFIX=$NDK_DIR/$(get_llvm_toolchain_binprefix $LLVM_VERSION $TAG)
558    fi
559
560    if [ -z "$PLATFORM" ]; then
561      SYSROOT=$NDK_DIR/$(get_default_platform_sysroot_for_arch $ARCH)
562    else
563      SYSROOT=$NDK_DIR/platforms/$PLATFORM/arch-$ARCH
564    fi
565    LDIR=$SYSROOT"/usr/"$(get_default_libdir_for_abi $ABI)
566
567    CRTBEGIN_EXE_O=$LDIR/crtbegin_dynamic.o
568    CRTEND_EXE_O=$LDIR/crtend_android.o
569
570    CRTBEGIN_SO_O=$LDIR/crtbegin_so.o
571    CRTEND_SO_O=$LDIR/crtend_so.o
572    if [ ! -f "$CRTBEGIN_SO_O" ]; then
573        CRTBEGIN_SO_O=$CRTBEGIN_EXE_O
574    fi
575    if [ ! -f "$CRTEND_SO_O" ]; then
576        CRTEND_SO_O=$CRTEND_EXE_O
577    fi
578
579    builder_begin "$BUILDDIR" "$MAKEFILE"
580    builder_set_prefix "$ABI "
581    if [ -z "$LLVM_VERSION" ]; then
582        builder_set_binprefix "$BINPREFIX"
583    else
584        builder_set_binprefix_llvm "$BINPREFIX"
585        case $ABI in
586            armeabi)
587                LLVM_TRIPLE=armv5te-none-linux-androideabi
588                ;;
589            armeabi-v7a|armeabi-v7a-hard)
590                LLVM_TRIPLE=armv7-none-linux-androideabi
591                ;;
592            arm64-v8a)
593                LLVM_TRIPLE=aarch64-none-linux-android
594                ;;
595            x86)
596                LLVM_TRIPLE=i686-none-linux-android
597                ;;
598            x86_64)
599                LLVM_TRIPLE=x86_64-none-linux-android
600                ;;
601            mips|mips32r6)
602                LLVM_TRIPLE=mipsel-none-linux-android
603                ;;
604            mips64)
605                LLVM_TRIPLE=mips64el-none-linux-android
606                ;;
607            *)
608                LLVM_TRIPLE=le32-none-ndk
609                GCC_TOOLCHAIN=
610                CRTBEGIN_SO_O=
611                CRTEND_SO_O=
612                CRTBEGIN_EXE_O=
613                CRTEND_EXE_O=
614                FLAGS=-emit-llvm
615                ;;
616        esac
617        SCRATCH_FLAGS="-target $LLVM_TRIPLE $FLAGS"
618        builder_ldflags "$SCRATCH_FLAGS"
619        if [ "$LLVM_VERSION" \> "3.4" ]; then
620            # Turn off integrated-as for clang >= 3.5 due to ill-formed object it produces
621            # involving inline-assembly .pushsection/.popsection which crashes ld.gold
622            # BUG=18589643
623            SCRATCH_FLAGS="$SCRATCH_FLAGS -fno-integrated-as"
624        fi
625        builder_cflags  "$SCRATCH_FLAGS"
626        builder_cxxflags "$SCRATCH_FLAGS"
627        if [ ! -z $GCC_TOOLCHAIN ]; then
628            SCRATCH_FLAGS="-gcc-toolchain $GCC_TOOLCHAIN"
629            builder_cflags "$SCRATCH_FLAGS"
630            builder_cxxflags "$SCRATCH_FLAGS"
631            builder_ldflags "$SCRATCH_FLAGS"
632        fi
633    fi
634
635    SCRATCH_FLAGS="--sysroot=$SYSROOT"
636    builder_cflags "$SCRATCH_FLAGS"
637    builder_cxxflags "$SCRATCH_FLAGS"
638
639    SCRATCH_FLAGS="--sysroot=$SYSROOT -nostdlib"
640    _BUILD_LDFLAGS_BEGIN_SO="$SCRATCH_FLAGS $CRTBEGIN_SO_O"
641    _BUILD_LDFLAGS_BEGIN_EXE="$SCRATCH_FLAGS $CRTBEGIN_EXE_O"
642
643    _BUILD_LDFLAGS_END_SO="$CRTEND_SO_O"
644    _BUILD_LDFLAGS_END_EXE="$CRTEND_EXE_O"
645
646    case $ABI in
647        armeabi)
648            if [ -z "$LLVM_VERSION" ]; then
649                # add -minline-thumb1-jumptable such that gabi++/stlport/libc++ can be linked
650                # with compiler-rt where helpers __gnu_thumb1_case_* (in libgcc.a) don't exist
651                SCRATCH_FLAGS="-minline-thumb1-jumptable"
652                builder_cflags "$SCRATCH_FLAGS"
653                builder_cxxflags "$SCRATCH_FLAGS"
654            else
655                builder_cflags ""
656                builder_cxxflags ""
657            fi
658            ;;
659        armeabi-v7a|armeabi-v7a-hard)
660            SCRATCH_FLAGS="-march=armv7-a -mfpu=vfpv3-d16"
661            builder_cflags "$SCRATCH_FLAGS"
662            builder_cxxflags "$SCRATCH_FLAGS"
663            builder_ldflags "-march=armv7-a -Wl,--fix-cortex-a8"
664            if [ "$ABI" != "armeabi-v7a-hard" ]; then
665                SCRATCH_FLAGS="-mfloat-abi=softfp"
666                builder_cflags "$SCRATCH_FLAGS"
667                builder_cxxflags "$SCRATCH_FLAGS"
668            else
669                SCRATCH_FLAGS="-mhard-float -D_NDK_MATH_NO_SOFTFP=1"
670                builder_cflags "$SCRATCH_FLAGS"
671                builder_cxxflags "$SCRATCH_FLAGS"
672                builder_ldflags "-Wl,--no-warn-mismatch -lm_hard"
673            fi
674            ;;
675    esac
676}
677
678# $1: Build directory
679# $2: Optional Makefile name
680builder_begin_host ()
681{
682    prepare_host_build
683    builder_begin "$1" "$2"
684    builder_set_prefix "$HOST_TAG "
685}
686