1#! /bin/sh
2#
3# Check for accurate dependencies in gcc/Makefile.in.
4#
5# Copyright (C) 2008, 2012 Free Software Foundation, Inc.
6# Written by Ralf Wildenhues <Ralf.Wildenhues@gmx.de>.
7#
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
11#
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.
14
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.
18start_after=
19
20# Skip some objects unconditionally; make sure each name in this list is
21# surrounded by spaces.
22skip=" crtbegin.o crtbeginS.o crtbeginT.o crtend.o crtendS.o crtfastmath.o crtprec64.o crtprec80.o crtprec32.o ecrti.o ecrtn.o ncrti.o ncrtn.o "
23
24# Files which show up as dependencies other than through unconditional #include.
25# This is an egrep pattern.
26hidden_dep_files='(BASE-VER|DATESTAMP|DEV-PHASE|Makefile|xcoffout\.h|basic-block\.h|bconfig\.h)$'
27
28: ${MAKE=make}
29: ${EGREP="grep -E"}
30
31# -------------------------------------------------------------------------
32# There should be no need for changes beyond this point.
33
34set -e
35st=0
36
37if test -f c-family/c-common.o; then :; else
38  echo "$0: rerun in an up to date build-tree/gcc directory" >&2
39  exit 1
40fi
41
42for obj in *.o
43do
44  if test -n "$start_after"; then
45    if test $obj = $start_after; then
46      start_after=
47    fi
48    continue
49  fi
50  case $skip in *\ $obj\ *) continue ;; esac
51
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 | \\ | /* ) ;;
61      *)
62        echo $hdr ;;
63    esac
64  done < depfile |
65  LC_ALL=C sort -u > hdrs
66
67
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
75  fi
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/^/  /'
85  fi
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/^/  /'
90  fi
91done
92exit $st
93
94# vi:sw=2:
95