• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
45# Build gdk-pixbuf
46pushd $SRC/gdk-pixbuf
47meson \
48    --prefix=$PREFIX \
49    --libdir=lib \
50    --default-library=static \
51    -Dintrospection=disabled \
52    -Dbuiltin_loaders='all' \
53    _builddir
54ninja -C _builddir
55ninja -C _builddir install
56popd
57
58mv $SRC/{*.zip,*.dict} $OUT
59
60if [ ! -f "${OUT}/gdk-pixbuf_seed_corpus.zip" ]; then
61  echo "missing seed corpus"
62  exit 1
63fi
64
65if [ ! -f "${OUT}/gdk-pixbuf.dict" ]; then
66  echo "missing dictionary"
67  exit 1
68fi
69
70PREDEPS_LDFLAGS="-Wl,-Bdynamic -ldl -lm -lc -pthread -lrt -lpthread"
71DEPS="gmodule-2.0 glib-2.0 gio-2.0 gobject-2.0 gdk-pixbuf-2.0"
72BUILD_CFLAGS="$CFLAGS `pkg-config --static --cflags $DEPS`"
73BUILD_LDFLAGS="-Wl,-static `pkg-config --static --libs $DEPS`"
74
75fuzzers=$(find $SRC/fuzz/ -name "*_fuzzer.c")
76for f in $fuzzers; do
77  fuzzer_name=$(basename $f .c)
78  $CC $CFLAGS $BUILD_CFLAGS -c $f -o $WORK/${fuzzer_name}.o
79  $CXX $CXXFLAGS \
80    $WORK/${fuzzer_name}.o -o $OUT/${fuzzer_name} \
81    $PREDEPS_LDFLAGS \
82    $BUILD_LDFLAGS \
83    $LIB_FUZZING_ENGINE \
84    -Wl,-Bdynamic
85  ln -sf $OUT/gdk-pixbuf_seed_corpus.zip $OUT/${fuzzer_name}_seed_corpus.zip
86  ln -sf $OUT/gdk-pixbuf.dict $OUT/${fuzzer_name}.dict
87done
88