sed translate link arguments into make dependency

This is a discussion on sed translate link arguments into make dependency within the awk forums in Programming Languages category; The following test script shows what I'm attempting to do. It will end up in a make file translating a make macro for library list into a macro for target dependency. pre_fix=lib suffix=.so echo Starting with: echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe | sed -r \ -e 's|(-l)([^ ]+)|'$pre_fix'\2'$suffix'|g' \ -e ':a;s|(([ ]*-L)([^ ]+))+([ ]+)+('$pre_fix'[^ ]+)+|\1 \3/\5|g;ta' # Use lines below if not GNU sed and -r option #-e 's|\(-l\)\([^ ]\+\)|'$pre_fix'\2'$suffix'|g' \ #-e 's|\(\([ ]*-L\)\([^ ]\+\)\)\+\([ ]\+\)\+\('$pre_fix'[^ ]\+\)\+| \3/\5|g' Current output is: sh junk.txt Starting with: -L/usr/local/lib -ltom -ldick -lharry ...

Go Back   Application Development Forum > Programming Languages > awk

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-15-2008, 12:23 AM
dhighley
Guest
 
Default sed translate link arguments into make dependency

The following test script shows what I'm attempting to do. It will end
up in a make file translating a make macro for library list into a
macro for target dependency.

pre_fix=lib
suffix=.so
echo Starting with:
echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe
echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe |
sed -r \
-e 's|(-l)([^ ]+)|'$pre_fix'\2'$suffix'|g' \
-e ':a;s|(([ ]*-L)([^ ]+))+([ ]+)+('$pre_fix'[^ ]+)+|\1 \3/\5|g;ta'

# Use lines below if not GNU sed and -r option
#-e 's|\(-l\)\([^ ]\+\)|'$pre_fix'\2'$suffix'|g' \
#-e 's|\(\([ ]*-L\)\([^ ]\+\)\)\+\([ ]\+\)\+\('$pre_fix'[^ ]\+\)\+|
\3/\5|g'

Current output is:
sh junk.txt
Starting with:
-L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe
-L/usr/local/lib /usr/local/lib/libtom.so libdick.so libharry.so -L/
usr/lib /usr/lib/libjane.so libdoe.so

should look like this when done:
/usr/local/lib/libtom.so /usr/local/lib/libdick.so /usr/local/lib/
libharry.so /usr/lib/libjane.so /usr/lib/libdoe.so
Reply With Quote
  #2  
Old 08-15-2008, 03:17 AM
Kenny McCormack
Guest
 
Default Re: sed translate link arguments into make dependency

In article <070ce6c5-620e-40bb-b1d8-85e07eb9bf69@v16g2000prc.googlegroups.com>,
dhighley <dhighley@highley-recommended.com> wrote:
>The following test script shows what I'm attempting to do. It will end
>up in a make file translating a make macro for library list into a
>macro for target dependency.
>
>pre_fix=lib
>suffix=.so
>echo Starting with:
>echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe
>echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe |
>sed -r \
>-e 's|(-l)([^ ]+)|'$pre_fix'\2'$suffix'|g' \
>-e ':a;s|(([ ]*-L)([^ ]+))+([ ]+)+('$pre_fix'[^ ]+)+|\1 \3/\5|g;ta'
>
># Use lines below if not GNU sed and -r option
>#-e 's|\(-l\)\([^ ]\+\)|'$pre_fix'\2'$suffix'|g' \
>#-e 's|\(\([ ]*-L\)\([^ ]\+\)\)\+\([ ]\+\)\+\('$pre_fix'[^ ]\+\)\+|
>\3/\5|g'


What part of comp.lang.AWK don't you understand?

Reply With Quote
  #3  
Old 08-15-2008, 09:17 AM
dhighley
Guest
 
Default Re: sed translate link arguments into make dependency

On Aug 15, 12:17*am, gaze...@shell.xmission.com (Kenny McCormack)
wrote:
> In article <070ce6c5-620e-40bb-b1d8-85e07eb9b...@v16g2000prc.googlegroups..com>,
>
>
>
> dhighley *<dhigh...@highley-recommended.com> wrote:
> >The following test script shows what I'm attempting to do. It will end
> >up in a make file translating a make macro for library list into a
> >macro for target dependency.

>
> >pre_fix=lib
> >suffix=.so
> >echo Starting with:
> >echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe
> >echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe |
> >sed -r \
> >-e 's|(-l)([^ ]+)|'$pre_fix'\2'$suffix'|g' \
> >-e ':a;s|(([ ]*-L)([^ ]+))+([ ]+)+('$pre_fix'[^ ]+)+|\1 \3/\5|g;ta'

>
> ># Use lines below if not GNU sed and -r option
> >#-e 's|\(-l\)\([^ ]\+\)|'$pre_fix'\2'$suffix'|g' \
> >#-e 's|\(\([ ]*-L\)\([^ ]\+\)\)\+\([ ]\+\)\+\('$pre_fix'[^ ]\+\)\+|
> >\3/\5|g'

>
> What part of comp.lang.AWK don't you understand?


Not meaning to stir the pot I did a search before to see where sed
type questions were being asked. There is no sed group and I had
posted on comp.editors before. Many books do combine sed and awk. But
programming both I do know that they are not that close together as
languages.
Reply With Quote
  #4  
Old 08-16-2008, 03:07 PM
Claudio
Guest
 
Default Re: sed translate link arguments into make dependency

On 2008-08-15, dhighley <dhighley@highley-recommended.com> wrote:
> The following test script shows what I'm attempting to do. It will end
> up in a make file translating a make macro for library list into a
> macro for target dependency.
>
> pre_fix=lib
> suffix=.so
> echo Starting with:
> echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe
> echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe |
> sed -r \
> -e 's|(-l)([^ ]+)|'$pre_fix'\2'$suffix'|g' \
> -e ':a;s|(([ ]*-L)([^ ]+))+([ ]+)+('$pre_fix'[^ ]+)+|\1 \3/\5|g;ta'
>
> # Use lines below if not GNU sed and -r option
> #-e 's|\(-l\)\([^ ]\+\)|'$pre_fix'\2'$suffix'|g' \
> #-e 's|\(\([ ]*-L\)\([^ ]\+\)\)\+\([ ]\+\)\+\('$pre_fix'[^ ]\+\)\+|
> \3/\5|g'
>
> Current output is:
> sh junk.txt
> Starting with:
> -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe
> -L/usr/local/lib /usr/local/lib/libtom.so libdick.so libharry.so -L/
> usr/lib /usr/lib/libjane.so libdoe.so
>
> should look like this when done:
> /usr/local/lib/libtom.so /usr/local/lib/libdick.so /usr/local/lib/
> libharry.so /usr/lib/libjane.so /usr/lib/libdoe.so


Use awk instead:

echo -LAndTheRestOfTheLine | tr ' ' \\n | awk '....(see below)...'

And the awk command:

awk '$0 ~ /^-L/ {path=$0}
$0 ~ /^-l/ {print path "/lib" lib ".so"}'

Use an awk function (substr perhaps) in the path=$0 to eliminate the -L

You can omit the "tr" command: awk -F' '

Hope it helps you.

Best regars,
Claudio.

Reply With Quote
  #5  
Old 08-19-2008, 10:39 AM
dhighley
Guest
 
Default Re: sed translate link arguments into make dependency

On Aug 16, 12:07*pm, Claudio <clau...@example.org> wrote:
> On 2008-08-15, dhighley <dhigh...@highley-recommended.com> wrote:
>
>
>
> > The following test script shows what I'm attempting to do. It will end
> > up in a make file translating a make macro for library list into a
> > macro for target dependency.

>
> > pre_fix=lib
> > suffix=.so
> > echo Starting with:
> > echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe
> > echo -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe |
> > sed -r \
> > -e 's|(-l)([^ ]+)|'$pre_fix'\2'$suffix'|g' \
> > -e ':a;s|(([ ]*-L)([^ ]+))+([ ]+)+('$pre_fix'[^ ]+)+|\1 \3/\5|g;ta'

>
> > # Use lines below if not GNU sed and -r option
> > #-e 's|\(-l\)\([^ ]\+\)|'$pre_fix'\2'$suffix'|g' \
> > #-e 's|\(\([ ]*-L\)\([^ ]\+\)\)\+\([ ]\+\)\+\('$pre_fix'[^ ]\+\)\+|
> > \3/\5|g'

>
> > Current output is:
> > sh junk.txt
> > Starting with:
> > -L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe
> > -L/usr/local/lib /usr/local/lib/libtom.so libdick.so libharry.so -L/
> > usr/lib /usr/lib/libjane.so libdoe.so

>
> > should look like this when done:
> > /usr/local/lib/libtom.so /usr/local/lib/libdick.so /usr/local/lib/
> > libharry.so /usr/lib/libjane.so /usr/lib/libdoe.so

>
> Use awk instead:
>
> echo -LAndTheRestOfTheLine | tr ' ' \\n | awk '....(see below)...'
>
> And the awk command:
>
> awk '$0 ~ /^-L/ {path=$0}
> $0 ~ /^-l/ {print path "/lib" lib ".so"}'
>
> Use an awk function (substr perhaps) in the path=$0 to eliminate the -L
>
> You can omit the "tr" command: awk -F' '
>
> Hope it helps you.
>
> Best regars,
> Claudio.


Not quite. Below is a working example:

#!/bin/sh
LIBS='-L/usr/local/lib -ltom -ldick -lharry -L/usr/lib -ljane -ldoe'
echo Starting with:
echo $LIBS
echo
echo what did we get?:

echo $LIBS |
awk -F' ' '
BEGIN{pre_fix="lib"; suffix=".so";out=""}
{
for(i=1; i<=NF; i++)
{
if($i ~ /^-L/) {path=substr($i,3)}
if($i ~ /^-l/) {out=out path "/" pre_fix substr($i,3) suffix "
"}
}
}
END{print out}'
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 08:51 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.