PR middle-end/48973
[official-gcc.git] / contrib / check_makefile_deps.sh
blob60b9c1757fd7241d593fc351dc3c0bf1768caee0
1 #! /bin/sh
3 # Check for accurate dependencies in gcc/Makefile.in.
5 # Copyright (C) 2008 Free Software Foundation, Inc.
6 # Written by Ralf Wildenhues <Ralf.Wildenhues@gmx.de>.
8 # This script is Free Software, and it can be copied, distributed and
9 # modified as defined in the GNU General Public License. A copy of
10 # its license can be downloaded from http://www.gnu.org/copyleft/gpl.html
12 # Start this script in an up to date build-tree/gcc directory.
13 # Using it in stage1 only works if the host compiler is GCC.
15 # To continue an interrupted check, make sure there are no *.o.backup
16 # files lying around (i.e., move them back to their original name),
17 # and set $start_after to the name of the last object that should be skipped.
18 start_after=
20 # Skip some objects unconditionally; make sure each name in this list is
21 # surrounded by spaces.
22 skip=" crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o crtfastmath.o crtprec64.o crtprec80.o crtprec32.o "
24 # Files which show up as dependencies other than through unconditional #include.
25 # This is an egrep pattern.
26 hidden_dep_files='(BASE-VER|DATESTAMP|DEV-PHASE|Makefile|xcoffout\.h|basic-block\.h|bconfig\.h)$'
28 : ${MAKE=make}
29 : ${EGREP="grep -E"}
31 # -------------------------------------------------------------------------
32 # There should be no need for changes beyond this point.
34 set -e
35 st=0
37 if test -f c-common.o; then :; else
38 echo "$0: rerun in an up to date build-tree/gcc directory" >&2
39 exit 1
42 for obj in *.o
44 if test -n "$start_after"; then
45 if test $obj = $start_after; then
46 start_after=
48 continue
50 case $skip in *\ $obj\ *) continue ;; esac
52 mv -f $obj $obj.backup
53 ${MAKE} $obj CFLAGS='-MM -MF depfile'
54 mv -f $obj.backup $obj
55 ${MAKE} -t
56 LC_ALL=C ${MAKE} -d $obj >make-d-log
57 hdrs=`cat depfile`
58 for hdr in $hdrs; do
59 case $hdr in
60 *: | *.o | \\ | /* ) ;;
62 echo $hdr ;;
63 esac
64 done < depfile |
65 LC_ALL=C sort -u > hdrs
68 sed -n '/.*Prerequisite..\([^ ]*\). is newer than target .'"$obj"'.*/s//\1/p' \
69 < make-d-log |
70 LC_ALL=C sort -u > not-up-to-date
71 if test -s not-up-to-date; then
72 st=1
73 echo "$0: error: prerequisites for $obj are not up to date:" >&2
74 cat not-up-to-date >&2
76 sed -n '/.*Prerequisite..\([^ ]*\). is older than target .'"$obj"'.*/s//\1/p' \
77 < make-d-log |
78 LC_ALL=C sort -u > deps
79 missing_deps=`LC_ALL=C join -v 1 hdrs deps`
80 unneeded_deps=`LC_ALL=C join -v 2 hdrs deps | $EGREP -v "$hidden_dep_files" || :`
81 if test -n "$missing_deps"; then
82 st=1
83 echo "missing deps for $obj:"
84 echo "$missing_deps" | sed 's/^/ /'
86 if test -n "$unneeded_deps"; then
87 # unneeded dependencies are not a big problem, so they cause no failure.
88 echo "unneeded deps for $obj:"
89 echo "$unneeded_deps" | sed 's/^/ /'
91 done
92 exit $st
94 # vi:sw=2: