• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/bin/bash -eu
2# Copyright 2016 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
18export WGET2_DEPS_PATH=$SRC/wget2_deps
19export PKG_CONFIG_PATH=$WGET2_DEPS_PATH/lib64/pkgconfig:$WGET2_DEPS_PATH/lib/pkgconfig
20export CPPFLAGS="-I$WGET2_DEPS_PATH/include"
21export LDFLAGS="-L$WGET2_DEPS_PATH/lib"
22export GNULIB_SRCDIR=$SRC/gnulib
23export LLVM_PROFILE_FILE=/tmp/prof.test
24
25cd $SRC/libunistring
26./autogen.sh
27./configure --enable-static --disable-shared --prefix=$WGET2_DEPS_PATH
28make -j$(nproc)
29make install
30
31cd $SRC/libidn2
32./bootstrap
33./configure --enable-static --disable-shared --disable-doc --disable-gcc-warnings --prefix=$WGET2_DEPS_PATH
34make -j$(nproc)
35make install
36
37cd $SRC/libpsl
38./autogen.sh
39./configure --enable-static --disable-shared --disable-gtk-doc --enable-runtime=libidn2 --enable-builtin=libidn2 --prefix=$WGET2_DEPS_PATH
40make -j$(nproc)
41make install
42
43GNUTLS_CONFIGURE_FLAGS=""
44NETTLE_CONFIGURE_FLAGS=""
45if [[ $CFLAGS = *sanitize=memory* ]]; then
46  GNUTLS_CONFIGURE_FLAGS="--disable-hardware-acceleration"
47  NETTLE_CONFIGURE_FLAGS="--disable-assembler --disable-fat"
48fi
49
50# We could use GMP from git repository to avoid false positives in
51# sanitizers, but GMP doesn't compile with clang. We use gmp-mini
52# instead.
53cd $SRC/nettle
54bash .bootstrap
55./configure --enable-mini-gmp --enable-static --disable-shared --disable-documentation --prefix=$WGET2_DEPS_PATH $NETTLE_CONFIGURE_FLAGS
56( make -j$(nproc) || make -j$(nproc) ) && make install
57if test $? != 0;then
58        echo "Failed to compile nettle"
59        exit 1
60fi
61
62cd $SRC/gnutls
63touch .submodule.stamp
64./bootstrap
65GNUTLS_CFLAGS=`echo $CFLAGS|sed s/-DFUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION//`
66LIBS="-lunistring" \
67CFLAGS="$GNUTLS_CFLAGS" \
68./configure --with-nettle-mini --enable-gcc-warnings --enable-static --disable-shared --with-included-libtasn1 \
69    --with-included-unistring --without-p11-kit --disable-doc --disable-tests --disable-tools --disable-cxx \
70    --disable-maintainer-mode --disable-libdane --disable-gcc-warnings --disable-full-test-suite \
71    --prefix=$WGET2_DEPS_PATH $GNUTLS_CONFIGURE_FLAGS
72make -j$(nproc)
73make install
74
75# avoid iconv() memleak on Ubuntu 16.04 image (breaks test suite)
76export ASAN_OPTIONS=detect_leaks=0
77
78cd $SRC/wget2
79./bootstrap
80
81LIBS="-lgnutls -lhogweed -lnettle -lidn2 -lunistring -lpsl" \
82  ./configure -C --enable-static --disable-shared --disable-doc --without-plugin-support
83make clean
84make -j$(nproc)
85make -j$(nproc) -C unit-tests check
86make -j$(nproc) -C fuzz check
87
88LIBS="-lgnutls -lhogweed -lnettle -lidn2 -lunistring -lpsl" \
89  ./configure -C --enable-fuzzing --enable-static --disable-shared --disable-doc --without-plugin-support
90make clean
91make -j$(nproc) -C lib
92make -j$(nproc) -C include
93make -j$(nproc) -C libwget
94make -j$(nproc) -C src
95
96# Ensure our libraries can be found
97ln -s $WGET2_DEPS_PATH/lib64/libhogweed.a $WGET2_DEPS_PATH/lib/libhogweed.a
98ln -s $WGET2_DEPS_PATH/lib64/libnettle.a  $WGET2_DEPS_PATH/lib/libnettle.a
99
100# build fuzzers
101cd fuzz
102
103CXXFLAGS="$CXXFLAGS -L$WGET2_DEPS_PATH/lib/" make oss-fuzz
104
105find . -name '*_fuzzer' -exec cp -v '{}' $OUT ';'
106find . -name '*_fuzzer.dict' -exec cp -v '{}' $OUT ';'
107find . -name '*_fuzzer.options' -exec cp -v '{}' $OUT ';'
108
109for dir in *_fuzzer.in; do
110  fuzzer=$(basename $dir .in)
111  zip -rj "$OUT/${fuzzer}_seed_corpus.zip" "${dir}/"
112done
113