bump product version to 4.1.6.2
[LibreOffice.git] / bin / update_pch.sh
blob4d9456969d3b6b67150299046faa8674f880b3e7
1 #! /bin/bash
3 # This file is part of the LibreOffice project.
5 # This Source Code Form is subject to the terms of the Mozilla Public
6 # License, v. 2.0. If a copy of the MPL was not distributed with this
7 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
10 # Usage: update_pch.sh [precompiled_xxx.hxx]
12 root=`dirname $0`
13 root=`cd $root/.. && pwd`
15 if test -z "$1"; then
16 headers=`ls $root/*/inc/pch/precompiled_*.hxx`
17 else
18 headers="$1"
21 for x in $headers; do
22 header=$x
23 echo updating `echo $header | sed -e s%$root/%%`
24 module=`readlink -f $header | sed -e s%$root/%% -e s%/.*%%`
25 name=`echo $header | sed -e s/.*precompiled_// -e s/\.hxx//`
26 makefile="Library_$name.mk"
28 tmpfile=`mktemp`
30 cat "$root/$module/$makefile" | sed 's#\\$##' | \
32 inobjects=
33 ifstack=0
34 while read line ; do
35 if test "$line" = "))" ; then
36 inobjects=
37 elif echo $line | grep -q -e add_exception_objects -e add_noexception_objects -e add_cxxobject -e add_cxxobjects ; then
38 inobjects=1
39 if test $ifstack -ne 0 ; then
40 echo Sources in a conditional, ignoring for now. >&2
42 elif echo $line | grep -q ^if ; then
43 ifstack=$((ifstack + 1))
44 elif echo $line | grep -q ^endif ; then
45 ifstack=$((ifstack - 1))
46 elif test -n "$inobjects" -a $ifstack -eq 0; then
47 file=$line
48 if echo $line | grep -q ", "; then
49 true # $if() probably, or something similar
50 elif ! test -f "$root/$file".cxx ; then
51 echo No file $file in $module/$makefile >&2
52 else
54 function list_file_includes()
56 ifdepth=0
57 # filter out only preprocessor lines, get the first and second "words" after the #,
58 # also replace " with @ (would cause trouble when doing echo of the line)
59 cat "$1" | grep '^\s*#' | sed 's/^\s*#/#/' | sed 's/^\(#\w*\s+\w*\)\s+.*/\1/' | sed 's/"/@/g' | \
60 while read line; do
61 # skip everything surrounded by any #if
62 if echo "$line" | grep -q "#if" ; then
63 ifdepth=$((ifdepth + 1))
64 lastif="$line"
65 elif echo "$line" | grep -q "#endif" ; then
66 ifdepth=$((ifdepth - 1))
67 lastif="#if"
68 elif echo "$line" | grep -q "#include"; then
69 if test $ifdepth -eq 0; then
70 echo $line | sed 's/@/"/g'
71 else
72 echo "#include in $lastif : $line" | sed 's/@/"/g' >&2
75 done
78 list_file_includes "$root/$file".cxx | sed 's/\(#include [<@][^>@]*[>@]\).*/\1/' | sed 's#\.\./##g#' >>$tmpfile
81 done
84 cat >$header <<EOF
85 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
87 * This file is part of the LibreOffice project.
89 * This Source Code Form is subject to the terms of the Mozilla Public
90 * License, v. 2.0. If a copy of the MPL was not distributed with this
91 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
95 This file has been autogenerated by update_pch.sh . It is possible to edit it
96 manually (such as when an include file has been moved/renamed/removed. All such
97 manual changes will be rewritten by the next run of update_pch.sh (which presumably
98 also fixes all possible problems, so it's usually better to use it).
103 # Library_svx needs this (sendreportw32.cxx)
104 if test "$makefile" = Library_svx.mk ; then
105 cat >>$header <<EOF
106 #ifdef WNT
107 #define UNICODE
108 #define _UNICODE
109 #endif
114 function local_file()
116 file="$1"
117 echo "$file" | grep -q ^"$module"/ && exit 0
118 # find "$root/$module" -type f | grep -v "$root/$module/inc/" | grep /"$file"'$' && exit 0
119 find "$root/$module" -type f | grep /"$file"'$' -q && exit 0
120 if echo "$file" | grep -F . -q; then
121 find "$root/$module" -type f | grep -q /`echo "$file" | sed 's/\.hxx$/.sdi/'` && exit 0
123 # not local
124 exit 1
127 function filter_ignore()
129 # - filter out all files that are not normal headers
130 # - gperffasttoken.hxx is not a proper header
131 # - sores.hxx provides BMP_PLUGIN, which is redefined
132 # - some sources play ugly #define tricks with editeng/eeitemid.hxx
133 # - jerror.h and jpeglib.h are not self-contained
134 grep -e '\.h[">]$' -e '\.hpp[">]$' -e '\.hdl[">]$' -e '\.hxx[">]$' -e '^[^\.]*>$' | \
135 grep -v -F -e '#include "gperffasttoken.hxx"' | \
136 grep -v -F -e '#include <svtools/sores.hxx>' | \
137 grep -v -F -e '#include <editeng/eeitemid.hxx>' | \
138 grep -v -F -e '#include "jerror.h"' | \
139 grep -v -F -e '#include "jpeglib.h"'
142 # " in #include "foo" breaks echo down below, so " -> @
143 cat $tmpfile | LC_ALL=C sort -u | filter_ignore | sed 's/"/@/g' | \
145 while read line; do
146 file=`echo $line | sed 's/.*[<"@]\([^>"@]*\)[>"@].*/\1/'`
147 if ! local_file "$file"; then
148 echo $line | sed 's/@/"/g' >>$header
150 done
153 cat >>$header <<EOF
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
158 rm $tmpfile
159 done
161 #echo Done.
162 exit 0