summaryrefslogtreecommitdiffstats
path: root/doc/build-fastd-android.sh
blob: 3a8623c0c2e919b537aaa4fadf2b23a83ae03fe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Helper script for building fastd-android and its dependencies
#!/bin/bash

if [ x${PWD##*/} == xdoc ]; then
    echo "Warning: it seems you're currently in the doc/ folder. This script needs to run under the top folder of fastd source code."
    echo "See README-Android.md for more info."
    exit 1
fi

echo "This script downloads and builds dependencies for fastd-android, as well as fastd-android itself."
echo "Make sure you have these packages installed:"
echo "  * Android NDK r10d or newer"
echo "  * for Debian/Ubuntu: sudo apt-get install curl build-eseentials automake bison cmake git libtool pkg-config"
echo "    - Ubuntu 12.04 users need to grab cmake 2.8.9 or newer. See README-Android.md for more info."
echo "  * for Mac OS X: brew install automake libtool cmake bison"
echo "Hit ctrl-c now if you don't have all needed stuff yet."
read

SODIUM_VER=1.0.1
UECC_VER=5
LIBUECC_DOWNLOAD_ID=80
LIBSODIUM_PATH=libsodium-${SODIUM_VER}
LIBUECC_PATH=libuecc-${UECC_VER}
ANDROID_NATIVE_LEVEL=16
ARM_TOOLCHAIN=arm-linux-androideabi-4.9
X86_TOOLCHAIN=x86-4.9

if [ x$ANDROID_NDK_HOME == x ]; then
    echo "Set ANDROID_NDK_HOME first"; exit 1;
fi

if [ ! -d "build" ]; then
    mkdir build
fi

pushd build > /dev/null
WORK_DIR=${PWD}

if [ -d "${LIBSODIUM_PATH}" ]; then
    echo "It seems you already have libsodium downloaded.";
else
    echo "Downloading libsodium ${SODIUM_VER}..."
    curl -L https://github.com/jedisct1/libsodium/releases/download/${SODIUM_VER}/libsodium-${SODIUM_VER}.tar.gz | tar zxf - || exit 1
fi

pushd ${LIBSODIUM_PATH} > /dev/null
if [ ! -f "dist-build/android-armv7.sh" ]; then
    echo "Patching libsodium build scripts..."
    sed -i.bak 's/--enable-minimal//' dist-build/android-build.sh
    sed -i "" 's/--arch=/--toolchain="$NDK_TOOLCHAIN" --arch=/' dist-build/android-build.sh
    sed -e 's/-mthumb -marm -march=armv6/-march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16/' dist-build/android-arm.sh > dist-build/android-armv7.sh
    chmod +x dist-build/android-armv7.sh
fi
if [ ! -d "libsodium-android-arm" ]; then
    NDK_PLATFORM=android-${ANDROID_NATIVE_LEVEL} NDK_TOOLCHAIN=${ARM_TOOLCHAIN} dist-build/android-armv7.sh || exit 2
    # for static link using cmake
    rm libsodium-android-arm/lib/libsodium.so
fi
if [ ! -d "libsodium-android-x86" ]; then
    NDK_PLATFORM=android-${ANDROID_NATIVE_LEVEL} NDK_TOOLCHAIN=${X86_TOOLCHAIN} dist-build/android-x86.sh || exit 2
    # for static link using cmake
    rm libsodium-android-x86/lib/libsodium.so
fi
popd > /dev/null

if [ -d "android-cmake" ]; then
    echo "It seems you already have android-cmake downloaded.";
else
    echo "Downloading android-cmake"
    git clone https://github.com/taka-no-me/android-cmake.git;
fi
CMAKE_TOOLCHAIN=${WORK_DIR}/android-cmake/android.toolchain.cmake
ANDROID_CMAKE="cmake -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN}"
echo ">> android-cmake ready."

CMAKE_COMMON_DEFS="-DCMAKE_BUILD_TYPE=Release -DANDROID_NDK=${ANDROID_NDK_HOME} -DANDROID_NATIVE_API_LEVEL=${ANDROID_NATIVE_LEVEL}"

if [ -d "${LIBUECC_PATH}" ]; then
    echo "It seems you already have libuecc downloaded.";
else
    curl -k -L https://projects.universe-factory.net/attachments/download/${LIBUECC_DOWNLOAD_ID}/libuecc-${UECC_VER}.tar.xz | tar Jxf - || exit 4
fi
for ARCH in arm x86; do
    BUILD_DIR=libuecc-${ARCH}
    if [ ! -d "${BUILD_DIR}" ]; then
        mkdir ${BUILD_DIR} && pushd ${BUILD_DIR} > /dev/null
        if [ ${ARCH} == arm ]; then
            _USE_ABI="armeabi-v7a"
        else
            _USE_ABI=${ARCH}
        fi
        ${ANDROID_CMAKE} -DANDROID_ABI="$_USE_ABI" ${CMAKE_COMMON_DEFS} -DCMAKE_INSTALL_PREFIX=`pwd`/output ../${LIBUECC_PATH} || exit 5
        make && make install || exit 6
        # for static link using cmake
        rm output/lib/libuecc.so*
        popd > /dev/null;
        echo ">> libuecc ${ARCH} built."
    fi
done

if [ ! -d "pkgconfig" ]; then
    mkdir pkgconfig
    for ARCH in arm x86; do
        mkdir pkgconfig/${ARCH}
        cp libuecc-${ARCH}/output/lib/pkgconfig/libuecc.pc pkgconfig/${ARCH}
        cp ${LIBSODIUM_PATH}/libsodium-android-${ARCH}/lib/pkgconfig/libsodium.pc pkgconfig/${ARCH}
    done
    echo ">> pkgconfig files prepared."
fi

# detect HomeBrew installed bison for OS X
HOMEBREW_BISON_PATH="/usr/local/opt/bison/bin"
if [ -x "${HOMEBREW_BISON_PATH}/bison" ]; then
    USE_PATH=${HOMEBREW_BISON_PATH}:$PATH
else
    USE_PATH=$PATH
fi

FASTD_ANDROID_DEFS="-DWITH_CAPABILITIES=OFF -DWITH_STATUS_SOCKET=OFF -DWITH_CIPHER_AES128_CTR=FALSE -DWITH_METHOD_XSALSA20_POLY1305=FALSE -DWITH_METHOD_GENERIC_POLY1305=FALSE -DWITH_CMDLINE_COMMANDS=FALSE"

for ARCH in arm x86; do
    BUILD_DIR=fastd-${ARCH}
    if [ ! -d "${BUILD_DIR}" ]; then
        mkdir ${BUILD_DIR}
    fi
    pushd ${BUILD_DIR} > /dev/null
    if [ ! -f "Makefile" ]; then
        if [ ${ARCH} == arm ]; then
            _USE_ABI="armeabi-v7a"
            ADD_DEFS="-DWITH_CIPHER_SALSA2012_NACL=TRUE -DWITH_CIPHER_SALSA20_NACL=TRUE"
        else
            _USE_ABI=${ARCH}
            ADD_DEFS="-DWITH_CIPHER_SALSA2012_NACL=FALSE -DWITH_CIPHER_SALSA20_NACL=FALSE"
        fi

        PATH=${USE_PATH} PKG_CONFIG_LIBDIR=../pkgconfig/${ARCH} \
            ${ANDROID_CMAKE} \
            -DANDROID_ABI="$_USE_ABI" ${CMAKE_COMMON_DEFS} \
            ${FASTD_ANDROID_DEFS} \
            ${ADD_DEFS} -DEXECUTABLE_OUTPUT_PATH=`pwd`/src -DCMAKE_INSTALL_PREFIX=`pwd` \
            ../.. || exit 7
    fi

    make install/strip && echo ">> fastd ${ARCH} build ready in build/${BUILD_DIR}/bin"
    popd > /dev/null
done

popd > /dev/null