File indexing completed on 2024-12-15 05:11:24

0001 #!/bin/sh
0002 # Helper for saving time when recompiling, skipping files that haven't
0003 # changed in a meaningful way (e.g. if you only change a comment...)
0004 #
0005 # LGPL v2, David Faure <david@mandrakesoft.com>
0006 
0007 usage()
0008 {
0009   echo "Usage:"
0010   echo " $0 hidechange file    Hides the fact that file was changed (use with care!)"
0011   echo " $0 show               Lists what make currently has to rebuild"
0012   echo " $0 why file           Explains why make must rebuild file"
0013   exit 1;
0014 }
0015 
0016 if [ $# -eq 0 ]; then usage; fi
0017 CDPATH=
0018 builddir=$PWD
0019 
0020 # 'srcdir != builddir' stuff
0021 if test ! -f Makefile && test -n "$OBJ_SUBDIR"; then
0022   builddir=$OBJ_SUBDIR
0023 else
0024   if test ! -f Makefile && test -n "$OBJ_REPLACEMENT"; then
0025      builddir=`pwd | sed -e "$OBJ_REPLACEMENT"`
0026   fi
0027 fi
0028 
0029 if test ! -f Makefile && test -n "$OBJ_SUBDIR"; then
0030    builddir=$OBJ_SUBDIR
0031 fi
0032 cd $builddir
0033 srcdir=`egrep '^srcdir *=' Makefile | sed -e "s#srcdir *= *##"`
0034 UNSERMAKE=`type -p unsermake`
0035 using_unsermake=
0036 if head -n 1 Makefile | grep unsermake >/dev/null; then
0037     using_unsermake=new
0038 fi
0039 if head -n 1 Makefile | grep automake >/dev/null; then
0040     using_unsermake=old
0041 fi
0042 
0043 
0044 case $1 in
0045   hidechange )
0046     if [ $# -ne 2 ]; then usage; fi
0047     ## TODO: unsermake support (or support in unsermake itself)
0048     deps=`make SUBDIRS='' -n | grep '\-o' | sed -e 's/.*-o \([^ ]*\).*/\1/'`;
0049     if [ -n "$deps" ]; then
0050       oldestdep=`ls -t $deps 2>/dev/null | tail -1`
0051       thefile=$2
0052       if [ -f $srcdir/$thefile ]; then
0053           thefile=$srcdir/$thefile
0054       fi
0055       echo
0056       echo "Setting date of $thefile back in time with:"
0057       echo "touch -r $oldestdep $thefile" ; touch -r $oldestdep $thefile
0058     fi
0059     ;;
0060   show )
0061     if [ $# -ne 1 ]; then usage; fi
0062     if test "$using_unsermake" != "new"; then
0063       # Look at the commands that make will issue, and extract "-o output".
0064       # The only trouble, with libtool, is that this gives us .libs/foo.o instead of foo.lo
0065       make SUBDIRS='' -n | grep '\-o' | sed -e 's/.*-o \([^ ]*\).*/\1/'
0066     else
0067       # Solve the above problem (when using new-unsermake) by watching the "echo" lines for creating .lo files
0068       # separately from the rest of the "-o target" lines (for libs and binaries)
0069       # (For libs and bins another way would be to grep for "linking")
0070       # The "ls" is for sorting by date
0071       $UNSERMAKE -n | perl -e 'while(<>) { if (/by libtool/) { s/.*> //; print; } if (m/-o ([^ ]*)/ && $1!~/\.o$/) { print "$1\n"; } }' | xargs -r ls -t -1
0072     fi
0073     ;;
0074   why )
0075     if [ $# -ne 2 ]; then usage; fi
0076     ## TODO: unsermake support (or support in unsermake itself)
0077     make SUBDIRS='' -n -d $2 | egrep -e "(newer than target \`$2'|Must)"
0078     ;;
0079   * ) usage ;;
0080 esac