Back to home page

MITgcm

 
 

    


Warning, /tools/xmakedepend is written in an unsupported language. File is not indexed.

view on githubraw file Latest commit f79ba37a on 2024-09-26 16:30:15 UTC
f610331bb1 Ed H*0001 #! /usr/bin/env sh
d0a0fb6eb0 Patr*0002 #
97ed5a6d28 Jean*0003 #
d0a0fb6eb0 Patr*0004 # $TOG: mdepend.cpp /main/13 1997/06/20 21:12:18 kaleb $
                0005 #
                0006 #       Do the equivalent of the 'makedepend' program, but do it right.
                0007 #
                0008 #       Usage:
                0009 #
                0010 #       makedepend [cpp-flags] [-w width] [-s magic-string] [-f makefile]
                0011 #         [-o object-suffix]
                0012 #
                0013 #       Notes:
                0014 #
                0015 #       The C compiler used can be overridden with the environment
                0016 #       variable "CC".
                0017 #
                0018 #       The "-v" switch of the "makedepend" program is not supported.
                0019 #
                0020 #
                0021 #       This script should
                0022 #       work on both USG and BSD systems.  However, when System V.4 comes out,
                0023 #       USG users will probably have to change "silent" to "-s" instead of
                0024 #       "-" (at least, that is what the documentation implies).
                0025 #
                0026 # $XFree86: xc/config/util/mdepend.cpp,v 3.2 1997/06/29 07:54:20 dawes Exp $
                0027 
d07dbd7f61 Mart*0028 CPPARGS="-Dlinux -D__i386__ -D_POSIX_C_SOURCE=199309L -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE  -D_GNU_SOURCE  "
b0c9d94a44 Jean*0029 CPPARGS="-traditional $CPPARGS"
c419bc9ed8 Ed H*0030 
c52c4842c7 Ed H*0031 CC="cpp $CPPARGS"
                0032 if test -x /lib/cpp ; then
                0033     CC="/lib/cpp $CPPARGS"
c419bc9ed8 Ed H*0034 fi
d0a0fb6eb0 Patr*0035 
                0036 silent='-'
                0037 
4965aa2630 Jean*0038 #TMP=./mdep$$
42bfdc9294 Jean*0039 #- try to put temporary files in system-local /tmp dir
4965aa2630 Jean*0040 TMP=/tmp/mdep$$
                0041 touch $TMP ; retVal=$?
                0042 if [ $retVal -eq 0 ] ; then
                0043   if test ! -r $TMP ; then TMP=./mdep$$ ; fi
                0044 else
                0045   TMP=./mdep$$
                0046 fi
                0047 rm -f $TMP
                0048 #echo "temp files: $TMP"
42bfdc9294 Jean*0049 
d0a0fb6eb0 Patr*0050 CPPCMD=${TMP}a
                0051 DEPENDLINES=${TMP}b
                0052 TMPMAKEFILE=${TMP}c
873777c38b Jean*0053 HEAD_MKFILE=${TMP}d
d0a0fb6eb0 Patr*0054 ARGS=${TMP}e
                0055 
                0056 trap "rm -f ${TMP}*; exit 1" 1 2 15
                0057 trap "rm -f ${TMP}*; exit 0" 1 2 13
                0058 
                0059 echo " \c" > $CPPCMD
                0060 if [ `wc -c < $CPPCMD` -eq 1 ]
                0061 then
                0062     c="\c"
                0063     n=
                0064 else
                0065     c=
                0066     n="-n"
                0067 fi
                0068 
                0069 echo $n "$c" >$ARGS
                0070 
                0071 files=
                0072 makefile=
                0073 magic_string='# DO NOT DELETE'
                0074 objsuffix='.o'
                0075 width=78
                0076 endmarker=""
                0077 verbose=n
                0078 append=n
                0079 
                0080 while [ $# != 0 ]
                0081 do
                0082     if [ "$endmarker"x != x ] && [ "$endmarker" = "$1" ]; then
                0083         endmarker=""
                0084     else
                0085         case "$1" in
                0086             -D*|-I*)
                0087                 echo $n " '$1'$c" >> $ARGS
                0088                 ;;
                0089 
                0090             -g|-O)      # ignore so we can just pass $(CFLAGS) in
                0091                 ;;
                0092 
                0093             *)
                0094                 if [ "$endmarker"x = x ]; then
f79ba37af1 Mart*0095                     case "$1" in
d0a0fb6eb0 Patr*0096                         -w)
                0097                             width="$2"
                0098                             shift
                0099                             ;;
                0100                         -s)
                0101                             magic_string="$2"
                0102                             shift
                0103                             ;;
                0104                         -f*)
                0105                             if [ "$1" = "-f-" ]; then
                0106                                 makefile="-"
                0107                             else
                0108                                 makefile="$2"
                0109                                 shift
                0110                             fi
                0111                             ;;
                0112                         -o)
                0113                             objsuffix="$2"
                0114                             shift
                0115                             ;;
f79ba37af1 Mart*0116 
d0a0fb6eb0 Patr*0117                         --*)
                0118                             echo "$1" | sed 's/^\-\-//' >${TMP}end
                0119                             endmarker="`cat ${TMP}end`"
                0120                             rm -f ${TMP}end
                0121                             if [ "$endmarker"x = x ]; then
                0122                                 endmarker="--"
                0123                             fi
                0124                             ;;
                0125                         -v)
                0126                             verbose="y"
                0127                             ;;
                0128 
                0129                         -a)
                0130                             append="y"
                0131                             ;;
                0132 
                0133                         -cc)
                0134                             CC="$2"
                0135                             shift
                0136                             ;;
                0137 
44c7d828c4 Alis*0138                         -cpp)
                0139                             CC="$2 $CPPARGS"
                0140                             shift
                0141                             ;;
                0142 
d0a0fb6eb0 Patr*0143                         -*)
                0144                             echo "Unknown option '$1' ignored" 1>&2
                0145                             ;;
                0146                         *)
                0147                             files="$files $1"
                0148                             ;;
                0149                     esac
                0150                 fi
                0151                 ;;
                0152         esac
                0153     fi
                0154     shift
                0155 done
                0156 echo ' $*' >> $ARGS
                0157 
                0158 echo "#!/bin/sh" > $CPPCMD
                0159 echo "exec $CC `cat $ARGS`" >> $CPPCMD
                0160 chmod +x $CPPCMD
                0161 rm $ARGS
                0162 
                0163 case "$makefile" in
                0164     '')
                0165         if [ -r makefile ]
                0166         then
                0167             makefile=makefile
                0168         elif [ -r Makefile ]
                0169         then
                0170             makefile=Makefile
                0171         else
                0172             echo 'no makefile or Makefile found' 1>&2
                0173             exit 1
                0174         fi
                0175         ;;
                0176     -)
                0177         makefile=$TMPMAKEFILE
                0178         ;;
                0179 esac
                0180 
97ed5a6d28 Jean*0181 if [ "$verbose"x = "y"x ]; then
d0a0fb6eb0 Patr*0182     cat $CPPCMD
                0183 fi
                0184 
                0185 echo '' > $DEPENDLINES
                0186 for i in $files
                0187 do
                0188     $CPPCMD $i       | sed -n "/^#/s;^;$i ;p"
                0189 
05cb9e7836 Oliv*0190 done   | sed -e 's|/[^/.][^/]*/\.\.||g' -e 's|/\.[^.][^/]*/\.\.||g'     -e 's|"||g' -e 's| \./| |'   | awk '!/<.*>/{
d0a0fb6eb0 Patr*0191         if ($1 != $4  &&  $2 != "#ident" && $2 != "#pragma")
                0192 
                0193             {
f79ba37af1 Mart*0194             ofile = $1
                0195             sub(/\.[^.]*$/, "'"$objsuffix"'", ofile)
d0a0fb6eb0 Patr*0196             print ofile, $4
                0197             }
                0198         }'   | sort -u   | awk '
                0199 
                0200             {
                0201             newrec = rec " " $2
                0202             if ($1 != old1)
                0203                 {
                0204                 old1 = $1
                0205                 if (rec != "")
                0206                     print rec
                0207                 rec = $1 ": " $2
                0208                 }
                0209             else if (length (newrec) > '"$width"')
                0210                 {
                0211                 print rec
                0212                 rec = $1 ": " $2
                0213                 }
                0214             else
                0215                 rec = newrec
                0216             }
                0217         END         {
                0218 
                0219             if (rec != "")
                0220                 print rec
                0221             }'   | egrep -v '^[^:]*:[   ]*$' >> $DEPENDLINES
                0222 
                0223 trap "" 1 2 13 15       # Now we are committed
                0224 case "$makefile" in
                0225     $TMPMAKEFILE)
                0226         ;;
                0227     *)
f79ba37af1 Mart*0228         if [ "$append" = "n" ]
                0229         then
                0230           rm -f $makefile.bak
                0231           cp $makefile $makefile.bak
                0232         fi
d0a0fb6eb0 Patr*0233         echo "Appending dependencies to $makefile"
                0234         ;;
                0235 esac
                0236 
                0237 # If not -a, append the magic string and a blank line so that
                0238 # /^$magic_string/+1,\$d can be used to delete everything from after
                0239 # the magic string to the end of the file.  Then, append a blank
                0240 # line again and then the dependencies.
                0241 if [ "$append" = "n" ]
                0242 then
                0243     cat >> $makefile << END_OF_APPEND
                0244 
                0245 $magic_string
                0246 
                0247 END_OF_APPEND
873777c38b Jean*0248 # ed -h > /dev/null 2>&1
                0249   which ed > /dev/null 2>&1
                0250   RETVAL=$?
                0251   if test x"$RETVAL" = x0 ; then
                0252     if [ $verbose = y ]; then echo ' using line editor "ed"' ; fi
d0a0fb6eb0 Patr*0253     ed $silent $makefile << END_OF_ED_SCRIPT
                0254 /^$magic_string/+1,\$d
                0255 w
                0256 q
                0257 END_OF_ED_SCRIPT
873777c38b Jean*0258   else
                0259     if [ $verbose = y ]; then echo ' using sed command' ; fi
                0260     sed -n "1,/^$magic_string/p" $makefile > $HEAD_MKFILE
                0261     mv $HEAD_MKFILE $makefile
                0262   fi
d0a0fb6eb0 Patr*0263     echo '' >>$makefile
                0264 fi
                0265 
                0266 cat $DEPENDLINES >>$makefile
                0267 
                0268 case "$makefile" in
                0269     $TMPMAKEFILE)
                0270         cat $TMPMAKEFILE
                0271         ;;
                0272 esac
                0273 
                0274 rm -f ${TMP}*
                0275 exit 0