update_pch.sh 5.2 KB
Newer Older
1 2 3 4 5 6 7 8 9
#! /bin/bash
#
# This file is part of the LibreOffice project.
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#

10 11
# Usage: update_pch.sh [precompiled_xxx.hxx]

12
root=`dirname $0`
13
root=`cd $root/.. && pwd`
14

Luboš Luňák's avatar
Luboš Luňák committed
15
if test -z "$1"; then
Luboš Luňák's avatar
Luboš Luňák committed
16
    headers=`ls $root/*/inc/pch/precompiled_*.hxx`
17
else
Luboš Luňák's avatar
Luboš Luňák committed
18
    headers="$1"
19 20 21
fi

for x in $headers; do
Luboš Luňák's avatar
Luboš Luňák committed
22 23
    header=$x
    echo updating `echo $header | sed -e s%$root/%%`
24
    module=`readlink -f $header | sed -e s%$root/%% -e s%/.*%%`
Luboš Luňák's avatar
Luboš Luňák committed
25 26
    name=`echo $header | sed -e s/.*precompiled_// -e s/\.hxx//`
    makefile="Library_$name.mk"
27

Luboš Luňák's avatar
Luboš Luňák committed
28 29 30 31 32 33 34
    tmpfile=`mktemp`

    cat "$root/$module/$makefile" | sed 's#\\$##' | \
        (
        inobjects=
        ifstack=0
        while read line ; do
35
            if test "$line" = "))" ; then
Luboš Luňák's avatar
Luboš Luňák committed
36 37 38 39 40 41 42 43 44 45 46 47
                inobjects=
            elif echo $line | grep -q -e add_exception_objects -e add_noexception_objects -e add_cxxobject -e add_cxxobjects ; then
                inobjects=1
                if test $ifstack -ne 0 ; then
                    echo Sources in a conditional, ignoring for now. >&2
                fi
            elif echo $line | grep -q ^if ; then
                ifstack=$((ifstack + 1))
            elif echo $line | grep -q ^endif ; then
                ifstack=$((ifstack - 1))
            elif test -n "$inobjects" -a $ifstack -eq 0; then
                file=$line
48 49 50
                if echo $line | grep -q ", "; then
                    true # $if() probably, or something similar
                elif ! test -f "$root/$file".cxx ; then
Luboš Luňák's avatar
Luboš Luňák committed
51 52
                    echo No file $file in $module/$makefile >&2
                else
Lubos Lunak's avatar
Lubos Lunak committed
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

function list_file_includes()
(
    ifdepth=0
    # filter out only preprocessor lines, get the first and second "words" after the #,
    # also replace " with @ (would cause trouble when doing echo of the line)
    cat "$1" | grep '^\s*#' | sed 's/^\s*#/#/' | sed 's/^\(#\w*\s+\w*\)\s+.*/\1/' | sed 's/"/@/g' | \
        while read line; do
            # skip everything surrounded by any #if
            if echo "$line" | grep -q "#if" ; then
                ifdepth=$((ifdepth + 1))
                lastif="$line"
            elif echo "$line" | grep -q "#endif" ; then
                ifdepth=$((ifdepth - 1))
                lastif="#if"
            elif echo "$line" | grep -q "#include"; then
                if test $ifdepth -eq 0; then
                    echo $line | sed 's/@/"/g'
                else
                    echo "#include in $lastif : $line" | sed 's/@/"/g' >&2
                fi
            fi
        done
)

                    list_file_includes "$root/$file".cxx | sed 's/\(#include [<@][^>@]*[>@]\).*/\1/' | sed 's#\.\./##g#' >>$tmpfile
Luboš Luňák's avatar
Luboš Luňák committed
79 80 81 82 83 84
                fi
            fi
        done
        )

    cat >$header <<EOF
85 86 87 88 89 90 91 92 93
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

94 95 96 97 98 99 100
/*
 This file has been autogenerated by update_pch.sh . It is possible to edit it
 manually (such as when an include file has been moved/renamed/removed. All such
 manual changes will be rewritten by the next run of update_pch.sh (which presumably
 also fixes all possible problems, so it's usually better to use it).
*/

101 102
EOF

Luboš Luňák's avatar
Luboš Luňák committed
103 104 105
    # Library_svx needs this (sendreportw32.cxx)
    if test "$makefile" = Library_svx.mk ; then
        cat >>$header <<EOF
Luboš Luňák's avatar
Luboš Luňák committed
106 107 108 109 110 111
#ifdef WNT
#define UNICODE
#define _UNICODE
#endif

EOF
Luboš Luňák's avatar
Luboš Luňák committed
112
    fi
113 114 115 116

function local_file()
(
    file="$1"
Luboš Luňák's avatar
Luboš Luňák committed
117 118 119 120 121 122 123 124
    echo "$file" | grep -q ^"$module"/ && exit 0
#    find "$root/$module" -type f | grep -v "$root/$module/inc/" | grep /"$file"'$' && exit 0
    find "$root/$module" -type f | grep /"$file"'$' -q && exit 0
    if echo "$file" | grep -F . -q; then
        find "$root/$module" -type f | grep -q /`echo "$file" | sed 's/\.hxx$/.sdi/'` && exit 0
    fi
    # not local
    exit 1
125 126
)

Luboš Luňák's avatar
Luboš Luňák committed
127
function filter_ignore()
128
(
Luboš Luňák's avatar
Luboš Luňák committed
129
# - filter out all files that are not normal headers
Lubos Lunak's avatar
Lubos Lunak committed
130
# - gperffasttoken.hxx is not a proper header
Luboš Luňák's avatar
Luboš Luňák committed
131 132
# - sores.hxx provides BMP_PLUGIN, which is redefined
# - some sources play ugly #define tricks with editeng/eeitemid.hxx
Lubos Lunak's avatar
Lubos Lunak committed
133
# - jerror.h and jpeglib.h are not self-contained
Luboš Luňák's avatar
Luboš Luňák committed
134 135 136
    grep -e '\.h[">]$' -e '\.hpp[">]$' -e '\.hdl[">]$' -e '\.hxx[">]$' -e '^[^\.]*>$' | \
    grep -v -F -e '#include "gperffasttoken.hxx"' | \
    grep -v -F -e '#include <svtools/sores.hxx>' | \
Lubos Lunak's avatar
Lubos Lunak committed
137 138
    grep -v -F -e '#include <editeng/eeitemid.hxx>' | \
    grep -v -F -e '#include "jerror.h"' | \
Lubos Lunak's avatar
Lubos Lunak committed
139
    grep -v -F -e '#include "jpeglib.h"'
140 141
)

Luboš Luňák's avatar
Luboš Luňák committed
142
    # " in #include "foo" breaks echo down below, so " -> @
143
    cat $tmpfile | LC_ALL=C sort -u | filter_ignore | sed 's/"/@/g' | \
Luboš Luňák's avatar
Luboš Luňák committed
144 145 146 147 148 149 150 151
        (
        while read line; do
            file=`echo $line | sed 's/.*[<"@]\([^>"@]*\)[>"@].*/\1/'`
            if ! local_file "$file"; then
                echo $line | sed 's/@/"/g' >>$header
            fi
        done
        )
152

Luboš Luňák's avatar
Luboš Luňák committed
153
    cat >>$header <<EOF
154 155 156 157

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
EOF

Luboš Luňák's avatar
Luboš Luňák committed
158
    rm $tmpfile
159
done
Luboš Luňák's avatar
Luboš Luňák committed
160

161 162
#echo Done.
exit 0