version 1.9, 1998/11/22 00:11:08 |
version 1.10, 1999/05/21 01:24:04 |
|
|
#!/bin/sh - |
#!/bin/sh - |
# $OpenBSD$ |
# $OpenBSD$ |
# $NetBSD: lorder.sh,v 1.3 1995/04/24 07:38:52 cgd Exp $ |
# $NetBSD: lorder.sh.gnm,v 1.3 1995/12/20 04:45:11 cgd Exp $ |
# |
# |
# Copyright (c) 1990, 1993 |
# Copyright (c) 1990, 1993 |
# The Regents of the University of California. All rights reserved. |
# The Regents of the University of California. All rights reserved. |
|
|
# @(#)lorder.sh 8.1 (Berkeley) 6/6/93 |
# @(#)lorder.sh 8.1 (Berkeley) 6/6/93 |
# |
# |
|
|
# only one argument is a special case, just output the name twice |
# one argument can be optimized: put out the filename twice |
case $# in |
case $# in |
0) |
0) |
echo "usage: lorder file ..."; |
echo "usage: lorder file ..."; |
|
|
# remove temporary files on HUP, INT, QUIT, PIPE, TERM |
# remove temporary files on HUP, INT, QUIT, PIPE, TERM |
trap "rm -rf $TDIR; trap 2 ; kill -2 $$" 1 2 3 13 15 |
trap "rm -rf $TDIR; trap 2 ; kill -2 $$" 1 2 3 13 15 |
|
|
# if the line ends in a colon, assume it's the first occurrence of a new |
# make sure files depend on themselves |
# object file. Echo it twice, just to make sure it gets into the output. |
for file in "$@"; do echo "$file $file" ; done |
|
# if the line has " T ", " D ", " G ", " R ", it's a globally defined |
|
# symbol, put it into the symbol file. |
# |
# |
# if the line has " T " or " D " it's a globally defined symbol, put it |
|
# into the symbol file. |
|
# |
|
# if the line has " U " it's a globally undefined symbol, put it into |
# if the line has " U " it's a globally undefined symbol, put it into |
# the reference file. |
# the reference file. |
${NM:-nm} -go "$@" | sed " |
${NM:-nm} -go "$@" | sed " |
/:$/ { |
/ [TDGR] / { |
s/:// |
s/:.* [TDGR] / / |
s/.*/& &/ |
|
p |
|
d |
|
} |
|
/ [TD] / { |
|
s/:.* [TD] / / |
|
w $S |
w $S |
d |
d |
} |
} |
|
|
" |
" |
|
|
# sort symbols and references on the first field (the symbol) |
# sort symbols and references on the first field (the symbol) |
# join on that field, and print out the file names. |
# join on that field, and print out the file names (dependencies). |
sort +1 $R -o $R |
sort +1 $R -o $R |
sort +1 $S -o $S |
sort +1 $S -o $S |
join -j 2 -o 1.1 2.1 $R $S |
join -j 2 -o 1.1 2.1 $R $S |