1#!/bin/bash -eu 2# Copyright 2020 Google Inc. 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################################################################################ 17 18# For coverage build we need to remove some flags when building protobuf and icu 19if [ "$SANITIZER" = "coverage" ] 20then 21 export OCX=$CXXFLAGS 22 export OC=$CFLAGS 23 CF1=${CFLAGS//-fprofile-instr-generate/} 24 export CFLAGS=${CF1//-fcoverage-mapping/} 25 CXF1=${CXXFLAGS//-fprofile-instr-generate/} 26 export CXXFLAGS=${CXF1//-fcoverage-mapping/} 27fi 28 29# Build Protobuf 30git clone https://github.com/google/protobuf.git 31cd protobuf 32git submodule update --init --recursive 33./autogen.sh 34./configure 35make -j$(nproc) 36make install 37ldconfig 38 39 40# Build icu 41export DEPS_PATH=/src/deps/ 42mkdir $DEPS_PATH 43 44# build ICU for linking statically. 45cd $SRC/icu/source 46./configure --disable-shared --enable-static --disable-layoutex \ 47 --disable-tests --disable-samples --with-data-packaging=static --prefix=$DEPS_PATH 48make install -j$(nproc) 49 50# Ugly ugly hack to get static linking to work for icu. 51cd $DEPS_PATH/lib 52ls *.a | xargs -n1 ar x 53rm *.a 54ar r libicu.a *.{ao,o} 55ln -s libicu.a libicudata.a 56ln -s libicu.a libicuuc.a 57ln -s libicu.a libicui18n.a 58 59if [ "$SANITIZER" = "coverage" ] 60then 61 export CFLAGS=$OC 62 export CXXFLAGS=$OCX 63fi 64 65# Build libphonenumber 66cd $SRC/libphonenumber/cpp 67sed -i 's/set (BUILD_SHARED_LIB true)/set (BUILD_SHARED_LIB false)/g' CMakeLists.txt 68sed -i 's/list (APPEND CMAKE_C_FLAGS "-pthread")/string (APPEND CMAKE_C_FLAGS " -pthread")/g' CMakeLists.txt 69 70mkdir build && cd build 71cmake -DUSE_BOOST=OFF -DBUILD_GEOCODER=OFF \ 72 -DPROTOBUF_LIB="/src/protobuf/src/.libs/libprotobuf.a" \ 73 -DBUILD_STATIC_LIB=ON \ 74 -DICU_UC_INCLUDE_DIR=$SRC/icu/source/comon \ 75 -DICU_UC_LIB=$DEPS_PATH/lib/libicuuc.a \ 76 -DICU_I18N_INCLUDE_DIR=$SRC/icu/source/i18n/ \ 77 -DICU_I18N_LIB=$DEPS_PATH/lib/libicui18n.a \ 78 ../ 79make 80 81# Build our fuzzer 82$CXX -I$SRC/libphonenumber/cpp/src $CXXFLAGS -o phonefuzz.o -c $SRC/phonefuzz.cc 83$CXX $CXXFLAGS $LIB_FUZZING_ENGINE phonefuzz.o -o $OUT/phonefuzz \ 84 ./libphonenumber.a $SRC/protobuf/src/.libs/libprotobuf.a \ 85 $DEPS_PATH/lib/libicu.a -lpthread 86