[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

shell and sed vs awk perl and python (Re: checklib ;)



* From: Manoj Srivastava
* Date: Fri, 01 Jun 2007 16:24:20 -0500

> On Fri, 1 Jun 2007 20:53:10 +0000 (UTC), Oleg Verych
><olecom@flower.upol.cz> said:  
>
>> Notes about original:
>> - `basename' doesn't work,
>
>         Why? It seems to work perfectly fine here.
> __> basename /usr/local/src/arch/packages--debian/kernel-package/kernel-package/debian/common/checklibs
> checklibs

olecom@flower:/tmp/ck$ bash ./checklibs
checklibs"
olecom@flower:/tmp/ck$ sh ./checklibs
checklibs"
olecom@flower:/tmp/ck$ sh ./checklibs...
checklibs...
olecom@flower:/tmp/ck$ bash ./checklibs...
checklibs...
olecom@flower:/tmp/ck$

# I use
APPNAME="${0##*/}"
echo $APPNAME

>
>> - unlink early, rather than that "trap" bloat,
>
>         You do not seem to understand what trap does.  I unlink temp
>  files the moment I am done with them.  Traps are set to handle
>  exceptions, and to clean up when those occur.

# In this case i meant something like this
#
O=/tmp/chklib_libs_dyn_symbols.sh
echo "# generated by $APPNAME" >$O
exec 4<$O 5>>$O # redirect and unlink early
rm $O; I=4; O=5

# descriptors sometimes aren't flexible, nevertheless this is one of
# the solutions for concurrency, races     and unconditional killing

>         Please read up on signal handling; your remark seems to indicate
>  you don't know what it is all about.

Ok ;)

>> - "progname" isn't used anyway,
>
>         Right. It is standard boilerplate for my scripts; I usually use
>  it in diagnostic messages; of which none seemed to have survived into
>  production. 
>
>> - awk, perl overkill, (there could be `python' easyly ;)
>
>         awk and Perl are essential packages; python would mean a
>  dependency.  I also don''t like python, so I am unlikely to add python
>  code to my build system.

Well, at least awk-style field access in the shell you can do like that:

field() {
# $1 field #
# $2 data
#
    shift $1 ; echo $1
}

foo=`field 3 $bar`

>> - `objdump' can handle one file at time (and not buggy).
>
>         I don't understand that comment.
> ,----[  Manual page objdump(1) ]
>| SYNOPSIS
>|        objdump [-a|--archive-headers] <<SNIP>>  objfile...
>| DESCRIPTION
>|        objdump  displays  information  about  one  or  more object files. 
> `----

`readelf' failed, this one is working -- no problem.

But i meant, that to get need libraries and undefined symbols from (not)
one file(s), one run of `objdump' is needed:

2>/dev/null objdump -T --private-headers -- * | sed -n -e '
# Matching needed libraries:
#,-
#|Dynamic Section:
#|NEEDED      libc.so.6
#`-
# Making output like (for further parsing, thus making unique names):
#,-
#|L=$L" libc.so.6";
#`-
/NEEDED/{
s_^[^lib]*\([^.]*\)\(.*\)$_L=$L" \1\2";_;
p;
};

# Matching needed dynamic symbols:
#,-
#|DYNAMIC SYMBOL TABLE:
#|0000000      DF *UND*	0000000000000148  GLIBC_2.2.5 __libc_start_main
#|...
#|0000000  w   D  *UND*	0000000000000000              __gmon_start__
#`-
# Output is:
#,-
#|S=$S" __libc_start_main";
#|S=$S" __gmon_start__";
#`-
/\*UND\*/{   # prefix symbol with "||", add script
s_\([^\t ]*\)$_||S=$S" \1";_
s_[^|]*||__; # remove all up-to and marker
p;
};'

>> + i would suggest $PATH compatible EXTRA_.... syntax
>
>         I don't understand this comment either.

The way `EXTRA_LIBRARY_PATHS' variable is assignd, isn't it bad idea
to have compatible PATH assigments?

CHLPATH=/lib:/usr/lib:$EXTRA_LIBRARY_PATHS:
CHLPATH=`echo $CHLPATH | sed -e 's_/*:_:_g;s_:_ _g;s_/$__'`
# bad path test case: `echo /lib//:::/usr/lib///:/jj/kk/`

Anyway thanks for your feedback, i've placed chunks of the script here
for reference.
____




Reply to: