bump product version to 5.0.4.1
[LibreOffice.git] / bin / update_pch.sh
blob9f423d643d009cc9fead6194ef1d23a71de5c9f3
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]
11 # Invoke: make cmd cmd="./bin/update_pch.sh [..]"
13 root=`dirname $0`
14 root=`cd $root/.. && pwd`
16 if test -z "$1"; then
17 headers=`ls $root/*/inc/pch/precompiled_*.hxx`
18 else
19 headers="$1"
22 # Split the headers into an array.
23 IFS=' ' read -a aheaders <<< $headers
24 hlen=${#aheaders[@]};
25 if [ $hlen -gt 1 ]; then
26 if [ -z "$PARALLELISM" ]; then
27 PARALLELISM=0 # Let xargs decide
29 echo $headers | xargs -n 1 -P $PARALLELISM $0
30 exit $?
33 for x in $headers; do
34 header=$x
35 echo updating `echo $header | sed -e s%$root/%%`
36 module=`readlink -f $header | sed -e s%$root/%% -e s%/.*%%`
37 name=`echo $header | sed -e s/.*precompiled_// -e s/\.hxx//`
38 makefile="Library_$name.mk"
40 tmpfile=`mktemp`
42 cat "$root/$module/$makefile" | sed 's#\\$##' | \
44 inobjects=
45 ifstack=0
46 while read line ; do
47 if test "$line" = "))" ; then
48 inobjects=
49 elif echo $line | grep -q -e add_exception_objects -e add_cxxobject -e add_cxxobjects ; then
50 inobjects=1
51 if test $ifstack -ne 0 ; then
52 echo Sources in a conditional, ignoring for now. >&2
54 elif echo $line | grep -q ^if ; then
55 ifstack=$((ifstack + 1))
56 elif echo $line | grep -q ^endif ; then
57 ifstack=$((ifstack - 1))
58 elif test -n "$inobjects" -a $ifstack -eq 0; then
59 file=$line
60 if echo $line | grep -q ", "; then
61 true # $if() probably, or something similar
62 elif ! test -f "$root/$file".cxx ; then
63 echo No file $file in $module/$makefile >&2
64 else
66 function list_file_includes()
68 ifdepth=0
69 # filter out only preprocessor lines, get the first and second "words" after the #,
70 # also replace " with @ (would cause trouble when doing echo of the line)
71 cat "$1" | grep -E '^\s*#' | sed 's/^\s*#/#/' | sed 's/^\(#\w*\s+\w*\)\s+.*/\1/' | sed 's/"/@/g' | \
72 while read line; do
73 # skip everything surrounded by any #if
74 if echo "$line" | grep -q "#if" ; then
75 ifdepth=$((ifdepth + 1))
76 lastif="$line"
77 elif echo "$line" | grep -q "#endif" ; then
78 ifdepth=$((ifdepth - 1))
79 lastif="#if"
80 elif echo "$line" | grep -q "#include"; then
81 if test $ifdepth -eq 0; then
82 echo $line | sed 's/@/"/g'
83 else
84 echo "#include in $lastif : $line" | sed 's/@/"/g' >&2
87 done
90 list_file_includes "$root/$file".cxx | sed 's/\(#include [<@][^>@]*[>@]\).*/\1/' | sed 's#\.\./##g#' >>$tmpfile
93 done
96 cat >$header <<EOF
97 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
99 * This file is part of the LibreOffice project.
101 * This Source Code Form is subject to the terms of the Mozilla Public
102 * License, v. 2.0. If a copy of the MPL was not distributed with this
103 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
107 This file has been autogenerated by update_pch.sh . It is possible to edit it
108 manually (such as when an include file has been moved/renamed/removed. All such
109 manual changes will be rewritten by the next run of update_pch.sh (which presumably
110 also fixes all possible problems, so it's usually better to use it).
115 # Library_svx needs this (sendreportw32.cxx)
116 if test "$makefile" = Library_svx.mk ; then
117 cat >>$header <<EOF
118 #ifdef WNT
119 #define UNICODE
120 #define _UNICODE
121 #endif
126 function local_file()
128 file="$1"
129 echo "$file" | grep -q ^"$module"/ && exit 0
130 # find "$root/$module" -type f | grep -v "$root/$module/inc/" | grep /"$file"'$' && exit 0
131 find "$root/$module" -type f | grep /"$file"'$' -q && exit 0
132 if echo "$file" | grep -F . -q; then
133 find "$root/$module" -type f | grep -q /`echo "$file" | sed 's/\.hxx$/.sdi/'` && exit 0
135 # not local
136 exit 1
139 function filter_ignore()
141 # - filter out all files that are not normal headers
142 # - unicode/datefm.h is a icu header, clashes with DateFormat definition
143 # - gperffasttoken.hxx is not a proper header
144 # - comphelper/servicedecl.hxx ignore for now
145 # - sores.hxx provides BMP_PLUGIN, which is redefined
146 # - some sources play ugly #define tricks with editeng/eeitemid.hxx
147 # - objbase.h and oledb.h break ado
148 # - NSS cert.h may need to be mangled by nssrenam.h
149 # - xmlreader.h breaks cppuhelper
150 # - jerror.h and jpeglib.h are not self-contained
151 # - service1.hxx/service2.hxx are inside comments in frameworks/
152 grep -E -e '\.h[">]$' -e '\.hpp[">]$' -e '\.hdl[">]$' -e '\.hxx[">]$' -e '^[^\.]*>$' | \
153 grep -v -F -e '#include <vcl/opengl/OpenGLContext.hxx>' | \
154 grep -v -F -e '#include <unicode/datefmt.h>' | \
155 grep -v -F -e '#include "gperffasttoken.hxx"' | \
156 grep -v -F -e '#include <comphelper/servicedecl.hxx>' | \
157 grep -v -F -e '#include <svtools/sores.hxx>' | \
158 grep -v -F -e '#include <editeng/eeitemid.hxx>' | \
159 grep -v -F -e '#include <service1.hxx>' | \
160 grep -v -F -e '#include <service2.hxx>' | \
161 grep -v -F -e '#include <objbase.h>' | \
162 grep -v -F -e '#include <oledb.h>' | \
163 grep -v -F -e '#include <cert.h>' | \
164 grep -v -F -e '#include <xmlreader/xmlreader.hxx>' | \
165 grep -v -e '#include [<"]jerror.h[">]' | \
166 grep -v -e '#include [<"]jpeglib.h[">]'
169 # " in #include "foo" breaks echo down below, so " -> @
170 cat $tmpfile | LC_ALL=C sort -u | filter_ignore | sed 's/"/@/g' | \
172 while read line; do
173 file=`echo $line | sed 's/.*[<"@]\([^>"@]*\)[>"@].*/\1/'`
174 if ! local_file "$file"; then
175 echo $line | sed 's/@/"/g' >>$header
177 done
180 cat >>$header <<EOF
182 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
185 rm $tmpfile
186 done
188 #echo Done.
189 exit 0