1#!/bin/bash -e 2 3# Copyright (C) 2019 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 17ELFUTILS_VERSION=elfutils-0.178 18ABIGAIL_VERSION=4752d416 19 20NUM_CORES=$(cat /proc/cpuinfo | grep -c proc) 21BASE_DIR=$(readlink -f $(dirname $0)) 22OUT_DIR="${BASE_DIR}/abigail-inst/${ABIGAIL_VERSION}" 23 24ELFUTILS_SRC="${BASE_DIR}/elfutils-src" 25LIBABIGAIL_SRC="${BASE_DIR}/abigail-src" 26 27# Check output dir. 28if [ -e "${OUT_DIR}" ]; then 29 echo "WARN: ${OUT_DIR} exists. Press enter to continue or Ctrl-C to abort." 30 read 31fi 32 33# Clear out the OUT_DIR 34rm -rf "${OUT_DIR}" 35 36# Add the future PATHs to the environment for the builds to pick up 37export PATH="${OUT_DIR}/bin:${PATH}" 38export LD_LIBRARY_PATH="${OUT_DIR}/lib:${OUT_DIR}/lib/elfutils:${LD_LIBRARY_PATH}" 39 40PACKAGES="autoconf libtool libxml2-dev pkg-config python3" 41# Install the dependencies. 42if ! ( hash dpkg 2>/dev/null ); then 43 echo "WARN: not running on a Debian compatible system!" 44 echo " Please be sure you have the required packages installed on" 45 echo " your system before continuing." 46 echo "" 47 echo " The list of required packages is, at the minimum:" 48 echo " ${PACKAGES}" 49 echo " but some distributions may require more." 50 echo " You are on your own here, be careful." 51 echo "" 52 echo "Press enter to continue or Ctrl-C to abort." 53 read 54elif ! dpkg -s ${PACKAGES} > /dev/null 2>&1 ; then 55 set -x 56 sudo apt-get install --yes ${PACKAGES} 57fi 58set -x 59 60# Acquire elfutils sources 61if [ ! -d "${ELFUTILS_SRC}" ]; then 62 git clone git://sourceware.org/git/elfutils.git "${ELFUTILS_SRC}" 63else 64 git -C ${ELFUTILS_SRC} fetch 65fi 66 67git -C ${ELFUTILS_SRC} checkout ${ELFUTILS_VERSION} 68 69# Build elfutils 70pushd "${ELFUTILS_SRC}" 71 #git clean -dfx 72 autoreconf -i --force 73 mkdir -p build/ 74 pushd build/ 75 ../configure --prefix="${OUT_DIR}" \ 76 --enable-maintainer-mode \ 77 --disable-debuginfod 78 make -j${NUM_CORES} 79 make -j${NUM_CORES} install 80 popd 81popd 82 83# Acquire libabigail sources 84if [ ! -d "${LIBABIGAIL_SRC}" ]; then 85 git clone git://sourceware.org/git/libabigail.git "${LIBABIGAIL_SRC}" 86else 87 git -C ${LIBABIGAIL_SRC} fetch 88fi 89 90git -C ${LIBABIGAIL_SRC} checkout ${ABIGAIL_VERSION} 91 92# Build libabigail 93pushd "${LIBABIGAIL_SRC}" 94 #git clean -dfx 95 autoreconf -i --force 96 mkdir -p build/ 97 pushd build/ 98 ../configure VERSION_SUFFIX="-${ABIGAIL_VERSION}-android" \ 99 --prefix="${OUT_DIR}" \ 100 --enable-cxx11=yes \ 101 --disable-shared \ 102 "CPPFLAGS=-I${OUT_DIR}/include" \ 103 "LDFLAGS=-L${OUT_DIR}/lib" 104 make -j${NUM_CORES} 105 make -j${NUM_CORES} install 106 popd 107popd 108 109set +x 110 111echo 112echo "Note: Export following environment before running the executables:" 113echo 114echo "export PATH=\"${OUT_DIR}/bin:\${PATH}\"" 115echo "export LD_LIBRARY_PATH=\"${OUT_DIR}/lib:${OUT_DIR}/lib/elfutils:\${LD_LIBRARY_PATH}\"" 116echo 117echo 118