update credits
[LibreOffice.git] / bin / oss-fuzz-build.sh
blobc7c5133bbf01e22360d1212de3a8c5eb716d6f6c
1 #!/usr/bin/env bash
3 set -e
5 if [ -z "${OUT}" ] || [ -z "${SRC}" ] || [ -z "${WORK}" ]; then
6 echo "OUT, SRC or WORK not set - script expects to be called inside oss-fuzz build env"
7 exit 1
8 fi
10 print_stamp()
12 local do_df="$1"; shift
13 echo "[[" `date -u` "]]" "build -" "$@"
14 if [ "$do_df" != "0" ]; then
15 df -h $OUT $WORK
19 print_stamp 1 start
20 echo git: `git -C $SRC/libreoffice log -1 --pretty=reference`
22 #shuffle CXXFLAGS -stdlib=libc++ arg into CXX as well because we use
23 #the CXX as the linker and need to pass -stdlib=libc++ to build
24 export CXX="$CXX -stdlib=libc++ -fsanitize-blacklist=$SRC/libreoffice/bin/sanitize-excludelist.txt"
25 export CXX_FOR_BUILD="$CXX"
26 export CC="$CC -fsanitize-blacklist=$SRC/libreoffice/bin/sanitize-excludelist.txt"
27 export CC_FOR_BUILD="$CC"
28 #similarly force the -fsanitize etc args in as well as pthread to get
29 #things to link successfully during the build
30 export LDFLAGS="$CFLAGS -Wl,--compress-debug-sections,zlib -lpthread"
31 #build-time concat-deps tool leaks a titch
32 export ASAN_OPTIONS="detect_leaks=0"
34 cd $WORK
35 if [ -f Makefile ]; then
36 print_stamp 0 clean
37 make clean
40 print_stamp 0 autogen.sh
41 $SRC/libreoffice/autogen.sh --with-distro=LibreOfficeOssFuzz --with-external-tar=$SRC/external-tar
43 print_stamp 1 make
44 make
46 print_stamp 1 prepare '$OUT'
48 pushd instdir/program
49 # skip last 14 bytes of 1st, and first 85 of 2nd to just skip the
50 # xml tags to merge these into a single xml file
51 head -c -14 services.rdb > templateservices.rdb
52 tail -c +85 ./services/services.rdb >> templateservices.rdb
53 for a in *fuzzer; do
54 #some minimal fonts required
55 mv $a $OUT
56 mkdir -p $OUT/$a.fonts
57 tar -x -C $OUT/$a.fonts --strip-components=1 --wildcards --no-anchored '*.ttf' -f $SRC/external-tar/liberation-fonts-ttf*
58 cp $SRC/external-tar/*opens___.ttf $OUT/$a.fonts
59 #minimal runtime requirements
60 cp templateservices.rdb $OUT/$a.services.rdb
61 cp types.rdb $OUT/$a.types.rdb
62 cp types/offapi.rdb $OUT/$a.moretypes.rdb
63 cat > $OUT/$a.unorc << EOF
64 [Bootstrap]
65 URE_INTERNAL_LIB_DIR=\${ORIGIN}
66 UNO_TYPES=\${ORIGIN}/$a.types.rdb \${ORIGIN}/$a.moretypes.rdb
67 UNO_SERVICES=\${ORIGIN}/$a.services.rdb
68 EOF
69 done
70 popd
72 #starting corpuses
73 for zip_file in $SRC/*_seed_corpus.zip; do
74 cp $zip_file $OUT
75 done
77 #fuzzing dictionaries
78 cp $SRC/*.dict $OUT
80 #options files
81 cp $SRC/libreoffice/vcl/workben/*.options $OUT
83 print_stamp 1 end