1#!/bin/bash -eu 2# Copyright 2018 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################################################################################ 17PREFIX=$WORK/prefix 18mkdir -p $PREFIX 19 20export PKG_CONFIG="`which pkg-config` --static" 21export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig 22export PATH=$PREFIX/bin:$PATH 23 24BUILD=$WORK/build 25 26rm -rf $WORK/* 27rm -rf $BUILD 28mkdir -p $BUILD 29 30# Build glib 31pushd $SRC/glib-2.64.2 32meson \ 33 --prefix=$PREFIX \ 34 --libdir=lib \ 35 --default-library=static \ 36 -Db_lundef=false \ 37 -Doss_fuzz=enabled \ 38 -Dlibmount=disabled \ 39 -Dinternal_pcre=true \ 40 _builddir 41ninja -C _builddir 42ninja -C _builddir install 43popd 44 45pushd $SRC/freetype2 46./autogen.sh 47./configure --prefix="$PREFIX" --disable-shared PKG_CONFIG_PATH="$PKG_CONFIG_PATH" 48make -j$(nproc) 49make install 50 51# Build cairo 52pushd $SRC/cairo 53meson \ 54 --prefix=$PREFIX \ 55 --libdir=lib \ 56 --default-library=static \ 57 _builddir 58ninja -C _builddir 59ninja -C _builddir install 60popd 61 62mv $SRC/{*.zip,*.dict} $OUT 63 64if [ ! -f "${OUT}/cairo_seed_corpus.zip" ]; then 65 echo "missing seed corpus" 66 exit 1 67fi 68 69if [ ! -f "${OUT}/cairo.dict" ]; then 70 echo "missing dictionary" 71 exit 1 72fi 73 74PREDEPS_LDFLAGS="-Wl,-Bdynamic -ldl -lm -lc -pthread -lrt -lpthread" 75DEPS="gmodule-2.0 glib-2.0 gio-2.0 gobject-2.0 freetype2 cairo cairo-gobject" 76BUILD_CFLAGS="$CFLAGS `pkg-config --static --cflags $DEPS`" 77BUILD_LDFLAGS="-Wl,-static `pkg-config --static --libs $DEPS`" 78 79fuzzers=$(find $SRC/fuzz/ -name "*_fuzzer.c") 80for f in $fuzzers; do 81 fuzzer_name=$(basename $f .c) 82 $CC $CFLAGS $BUILD_CFLAGS \ 83 -c $f -o $WORK/${fuzzer_name}.o 84 $CXX $CXXFLAGS \ 85 $WORK/${fuzzer_name}.o -o $OUT/${fuzzer_name} \ 86 $PREDEPS_LDFLAGS \ 87 $BUILD_LDFLAGS \ 88 $LIB_FUZZING_ENGINE \ 89 -Wl,-Bdynamic 90 ln -sf $SRC/cairo_seed_corpus.zip $OUT/${fuzzer_name}_seed_corpus.zip 91 ln -sf $SRC/cairo.dict $OUT/${fuzzer_name}.dict 92done 93