--- MITgcm/tools/xmakedepend 2002/02/11 23:15:24 1.1.2.1 +++ MITgcm/tools/xmakedepend 2016/12/30 23:56:52 1.13 @@ -1,4 +1,7 @@ -#!/usr/bin/sh +#! /usr/bin/env sh +# +# $Header: /home/ubuntu/mnt/e9_copy/MITgcm/tools/xmakedepend,v 1.13 2016/12/30 23:56:52 jmc Exp $ +# $Name: $ # # $TOG: mdepend.cpp /main/13 1997/06/20 21:12:18 kaleb $ # @@ -23,17 +26,33 @@ # "-" (at least, that is what the documentation implies). # # $XFree86: xc/config/util/mdepend.cpp,v 3.2 1997/06/29 07:54:20 dawes Exp $ -# -CC="cpp -traditional -Dlinux -D__i386__ -D_POSIX_C_SOURCE=199309L -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_GNU_SOURCE " +CPPARGS="-Dlinux -D__i386__ -D_POSIX_C_SOURCE=199309L -D_POSIX_SOURCE -D_XOPEN_SOURCE -D_BSD_SOURCE -D_SVID_SOURCE -D_GNU_SOURCE " +CPPARGS="-traditional $CPPARGS" + +CC="cpp $CPPARGS" +if test -x /lib/cpp ; then + CC="/lib/cpp $CPPARGS" +fi silent='-' -TMP=./mdep$$ +#TMP=./mdep$$ +#- try to put temporary files in system-local /tmp dir +TMP=/tmp/mdep$$ +touch $TMP ; retVal=$? +if [ $retVal -eq 0 ] ; then + if test ! -r $TMP ; then TMP=./mdep$$ ; fi +else + TMP=./mdep$$ +fi +rm -f $TMP +#echo "temp files: $TMP" + CPPCMD=${TMP}a DEPENDLINES=${TMP}b TMPMAKEFILE=${TMP}c -MAGICLINE=${TMP}d +HEAD_MKFILE=${TMP}d ARGS=${TMP}e trap "rm -f ${TMP}*; exit 1" 1 2 15 @@ -118,6 +137,11 @@ shift ;; + -cpp) + CC="$2 $CPPARGS" + shift + ;; + -*) echo "Unknown option '$1' ignored" 1>&2 ;; @@ -156,7 +180,7 @@ ;; esac -if [ "$verbose"x = "y"x ]; then +if [ "$verbose"x = "y"x ]; then cat $CPPCMD fi @@ -165,18 +189,15 @@ do $CPPCMD $i | sed -n "/^#/s;^;$i ;p" -done | sed -e 's|/[^/.][^/]*/\.\.||g' -e 's|/\.[^.][^/]*/\.\.||g' -e 's|"||g' -e 's| \./| |' | awk '{ +done | sed -e 's|/[^/.][^/]*/\.\.||g' -e 's|/\.[^.][^/]*/\.\.||g' -e 's|"||g' -e 's| \./| |' | awk '!/<.*>/{ if ($1 != $4 && $2 != "#ident" && $2 != "#pragma") - - { ofile = substr ($1, 1, length ($1) - 2) "'"$objsuffix"'" print ofile, $4 } }' | sort -u | awk ' - { newrec = rec " " $2 if ($1 != old1) @@ -200,7 +221,6 @@ print rec }' | egrep -v '^[^:]*:[ ]*$' >> $DEPENDLINES - trap "" 1 2 13 15 # Now we are committed case "$makefile" in $TMPMAKEFILE) @@ -212,12 +232,10 @@ ;; esac -# # If not -a, append the magic string and a blank line so that # /^$magic_string/+1,\$d can be used to delete everything from after # the magic string to the end of the file. Then, append a blank # line again and then the dependencies. -# if [ "$append" = "n" ] then cat >> $makefile << END_OF_APPEND @@ -225,11 +243,21 @@ $magic_string END_OF_APPEND +# ed -h > /dev/null 2>&1 + which ed > /dev/null 2>&1 + RETVAL=$? + if test x"$RETVAL" = x0 ; then + if [ $verbose = y ]; then echo ' using line editor "ed"' ; fi ed $silent $makefile << END_OF_ED_SCRIPT /^$magic_string/+1,\$d w q END_OF_ED_SCRIPT + else + if [ $verbose = y ]; then echo ' using sed command' ; fi + sed -n "1,/^$magic_string/p" $makefile > $HEAD_MKFILE + mv $HEAD_MKFILE $makefile + fi echo '' >>$makefile fi @@ -239,7 +267,6 @@ $TMPMAKEFILE) cat $TMPMAKEFILE ;; - esac rm -f ${TMP}*