home *** CD-ROM | disk | FTP | other *** search
/ PC World 2000 February / PCWorld_2000-02_cd.bin / live / usr / X11R6 / bin / gccmakedep < prev    next >
Text File  |  1999-09-03  |  3KB  |  149 lines

  1. #!/bin/sh
  2.  
  3. #
  4. # makedepend which uses 'gcc -M'
  5. #
  6. # $XFree86: xc/config/util/gccmdep.cpp,v 3.3.4.2 1999/08/02 08:37:52 hohndel Exp $
  7. #
  8. # Based on mdepend.cpp and code supplied by Hongjiu Lu <hjl@nynexst.com>
  9. #
  10.  
  11. TMP=${TMPDIR-/tmp}/mdep$$
  12. CC="gcc"
  13. RM="rm -f"
  14. LN="ln -s"
  15. MV="mv -f"
  16.  
  17. # Security: if $tmp exists exit immediately
  18. rm -f ${TMP}
  19. if [ -e ${TMP} ] ; then
  20.     echo "$0: ${TMP} exists already, exit." 1>&2
  21.     exit 1;
  22. fi
  23.  
  24. if [ -n "`type -p mktemp`" ] ; then
  25.     TMP="`mktemp ${TMP}.XXXXXX`" || exit 1
  26. fi
  27.  
  28.  
  29. trap "$RM ${TMP}*; exit 1" 1 2 15
  30. trap "$RM ${TMP}*; exit 0" 1 2 13
  31.  
  32. files=
  33. makefile=
  34. endmarker=
  35. magic_string='# DO NOT DELETE'
  36. append=n
  37. args=
  38. asmfiles=
  39.  
  40. while [ $# != 0 ]; do
  41.     if [ "$endmarker"x != x -a "$endmarker" = "$1" ]; then
  42.     endmarker=
  43.     else
  44.     case "$1" in
  45.         -D*|-I*)
  46.         args="$args '$1'"
  47.         ;;
  48.         -g|-o)
  49.         ;;
  50.         *)
  51.         if [ "$endmarker"x = x ]; then
  52.             case $1 in
  53. # ignore these flags
  54.             -w|-o|-cc)
  55.                 shift
  56.                 ;;
  57.             -v)
  58.                 ;;
  59.             -s)
  60.                 magic_string="$2"
  61.                 shift
  62.                 ;;
  63.             -f-)
  64.                 makefile="-"
  65.                 ;;
  66.             -f)
  67.                 makefile="$2"
  68.                 shift
  69.                 ;;
  70.             --*)
  71.                 endmarker=`echo $1 | sed 's/^\-\-//'`
  72.                 if [ "$endmarker"x = x ]; then
  73.                 endmarker="--"
  74.                 fi
  75.                 ;;
  76.             -a)
  77.                 append=y
  78.                 ;;
  79.             -*)
  80.                 echo "Unknown option '$1' ignored" 1>&2
  81.                 ;;
  82.             *)
  83.                 files="$files $1"
  84.                 ;;
  85.             esac
  86.         fi
  87.         ;;
  88.     esac
  89.     fi
  90.     shift
  91. done
  92.  
  93. if [ x"$files" = x ]; then
  94. # Nothing to do
  95.     exit 0
  96. fi
  97.  
  98. case "$makefile" in
  99.     '')
  100.     if [ -r makefile ]; then
  101.         makefile=makefile
  102.     elif [ -r Makefile ]; then
  103.         makefile=Makefile
  104.     else
  105.         echo 'no makefile or Makefile found' 1>&2
  106.         exit 1
  107.     fi
  108.     ;;
  109. esac
  110.  
  111. if [ X"$makefile" != X- ]; then
  112.     if [ x"$append" = xn ]; then
  113.         sed -e "/^$magic_string/,\$d" < $makefile > $TMP
  114.         echo "$magic_string" >> $TMP
  115.     else
  116.         cp $makefile $TMP
  117.     fi
  118. fi
  119.  
  120. # need to link .s files to .S
  121. for i in $files; do
  122.     case $i in
  123.     *.s)
  124.         dir=`dirname $i`
  125.         base=`basename $i .s`
  126.         (cd $dir; $RM ${base}.S; $LN ${base}.s ${base}.S)
  127.         asmfiles="$asmfiles ${base}.S"
  128.         ;;
  129.     esac
  130. done
  131.  
  132. CMD="$CC -M $args `echo $files | sed -e 's,\.s$,\.S,g' -e 's,\.s ,\.S ,g'` |     sed -e 's,\.S$,\.s,g' -e 's,\.S ,\.s ,g'"
  133.  
  134. if [ X"$makefile" != X- ]; then
  135.     CMD="$CMD >> $TMP"
  136. fi
  137. eval $CMD
  138. if [ X"$makefile" != X- ]; then
  139.     $RM ${makefile}.bak
  140.     $MV $makefile ${makefile}.bak
  141.     $MV $TMP $makefile
  142. fi
  143.  
  144. if [ x"$asmfiles" != x ]; then
  145.     $RM $asmfiles
  146. fi
  147. $RM ${TMP}*
  148. exit 0
  149.