~showard314/ubuntu/karmic/r-base/remove_start_comments

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#! /bin/sh

# This script writes an export file, assembling the exported symbols
# by reading the output of nm.  This file is needed on AIX (4.2 and
# later) to compile shared libs.
#
# For the (main) executable add "-bE:lib.exp" to the linker options
# and for the shared libs add "-bI:lib.exp" (maybe with a path) if
# you call the export file "lib.exp".

#set -x

usage="Usage: `basename $0` [-o <expfile>] <object files and libs>"

if [ ${1-"-h"} = "-h" ]; then
	echo 1>&2 "$usage"
	exit 1
fi

# Check for name of export file
case $1 in
    -o)
	mainexp=${2?$usage}
	shift 2
	;;
    -o*)
	mainexp=$1
	mainexp=${mainexp#-o}
	shift
	;;
    *)
	mainexp="lib.exp"
	;;
esac

# Check for object or archive files
ofiles=""
for arg; do
    case $arg in *.o | *.lo | *.a) ofiles="$ofiles $arg";; esac
done

# Call nm so that it prints only global symbols (unsorted, w/o header)
nm=nm
nmopts="-p -g -h"

# Replace "varname B adr1 adr2" with "varname bss"
regex1='s,^\([a-zA-Z][a-zA-Z0-9_]*\)  *B .*$,\1 bss,p'

# Replace "varname D adr1 adr2" with "varname"
regex2='s,^\([a-zA-Z][a-zA-Z0-9_]*\)  *D .*$,\1,p'

# Note that functions appear as ".funname T" for the text section
# and as "funname D" for the initialized data section (the function
# name is a pointer).

## # Replace ".funname T adr1 adr2" with "funname"
## regex1='s,^\.\([a-zA-Z][a-zA-Z0-9_]*\)  *T .*$,\1,p'

echo "#! ." > $mainexp
$nm $nmopts $ofiles | sed -n -e "$regex1" -e "$regex2" | \
    sort | uniq >> $mainexp

exit $?