less, makedepend
Chris Torek
chris at mimsy.UUCP
Wed Jul 13 07:37:00 AEST 1988
Here is Berkeley's mkdep (/usr/src/usr.bin/mkdep.sh, /usr/bin/mkdep),
and a shell script of my own (`getdep') to try if you do not have a
`-M' option or equivalent.
: Run this shell script with "sh" not "csh"
PATH=/bin:/usr/bin:/usr/ucb:/etc:$PATH
export PATH
all=false
if [ x$1 = x-a ]; then
all=true
fi
echo Extracting getdep.sh
sed 's/^X//' <<'//go.sysin dd *' >getdep.sh
X#! /bin/sh
X#
X# getdep - get dependency lists.
X
X# find cpp
Xcpp=/lib/cpp
X
X# handle arguments
Xincl=
Xfor i
Xdo
X case "$i" in
X -I*)
X incl="$incl $i";;
X -O|-c|-M|-D*|-U*)
X ;;
X *)
X # assume source file
X # put '$dep' in front of dependencies
X dep=`echo "$i" | sed -e 's,/,\\\\/,g' -e 's/\.c$/.o/'`
X # Find includes, remove leading numerics, remove ./,
X # remove double quotes, and remove trailing numerics.
X # Sort that, discarding duplicates, and add '$dep'.
X $cpp $incl "$i" | grep "^#" |
X sed -e 's/# [0-9]* //' -e 's,"./,",' -e 's/"\(.*\)"/\1/' \
X -e 's/ [ 0-9]*$//' |
X sort -u | sed -e "s/^/$dep: /";;
X esac
Xdone
//go.sysin dd *
if [ `wc -c < getdep.sh` != 625 ]; then
made=false
echo error transmitting getdep.sh --
echo length should be 625, not `wc -c < getdep.sh`
else
made=true
fi
if $made; then
chmod 644 getdep.sh
echo -n ' '; ls -ld getdep.sh
fi
echo Extracting mkdep.sh
sed 's/^X//' <<'//go.sysin dd *' >mkdep.sh
X#!/bin/sh -
X#
X# Copyright (c) 1987 Regents of the University of California.
X# All rights reserved.
X#
X# Redistribution and use in source and binary forms are permitted
X# provided that the above copyright notice and this paragraph are
X# duplicated in all such forms and that any documentation,
X# advertising materials, and other materials related to such
X# distribution and use acknowledge that the software was developed
X# by the University of California, Berkeley. The name of the
X# University may not be used to endorse or promote products derived
X# from this software without specific prior written permission.
X# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
X# IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
X# WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
X#
X# @(#)mkdep.sh 5.12 (Berkeley) 6/30/88
X#
XPATH=/bin:/usr/bin:/usr/ucb
Xexport PATH
X
XMAKE=Makefile # default makefile name is "Makefile"
X
Xwhile :
X do case "$1" in
X # -f allows you to select a makefile name
X -f)
X MAKE=$2
X shift; shift ;;
X
X # the -p flag produces "program: program.c" style dependencies
X # so .o's don't get produced
X -p)
X SED='s;\.o;;'
X shift ;;
X *)
X break ;;
X esac
Xdone
X
Xif [ $# = 0 ] ; then
X echo 'usage: mkdep [-p] [-f makefile] [flags] file ...'
X exit 1
Xfi
X
Xif [ ! -w $MAKE ]; then
X echo "mkdep: no writeable file \"$MAKE\""
X exit 1
Xfi
X
XTMP=/tmp/mkdep$$
X
Xtrap 'rm -f $TMP ; exit 1' 1 2 3 13 15
X
Xcp $MAKE ${MAKE}.bak
X
Xsed -e '/DO NOT DELETE THIS LINE/,$d' < $MAKE > $TMP
X
Xcat << _EOF_ >> $TMP
X# DO NOT DELETE THIS LINE -- mkdep uses it.
X# DO NOT PUT ANYTHING AFTER THIS LINE, IT WILL GO AWAY.
X
X_EOF_
X
X# If your compiler doesn't have -M, add it. If you can't, the next two
X# lines will try and replace the "cc -M". The real problem is that this
X# hack can't deal with anything that requires a search path, and doesn't
X# even try for anything using bracket (<>) syntax.
X#
X# egrep '^#include[ ]*".*"' /dev/null $* |
X# sed -e 's/:[^"]*"\([^"]*\)".*/: \1/' -e 's/\.c/.o/' |
X
Xcc -M $* |
Xsed "
X s; \./; ;g
X $SED" |
Xawk '{
X if ($1 != prev) {
X if (rec != "")
X print rec;
X rec = $0;
X prev = $1;
X }
X else {
X if (length(rec $2) > 78) {
X print rec;
X rec = $0;
X }
X else
X rec = rec " " $2
X }
X}
XEND {
X print rec
X}' >> $TMP
X
Xcat << _EOF_ >> $TMP
X
X# IF YOU PUT ANYTHING HERE IT WILL GO AWAY
X_EOF_
X
X# copy to preserve permissions
Xcp $TMP $MAKE
Xrm -f ${MAKE}.bak $TMP
Xexit 0
//go.sysin dd *
if [ `wc -c < mkdep.sh` != 2422 ]; then
made=false
echo error transmitting mkdep.sh --
echo length should be 2422, not `wc -c < mkdep.sh`
else
made=true
fi
if $made; then
chmod 444 mkdep.sh
echo -n ' '; ls -ld mkdep.sh
fi
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.unix.questions
mailing list