LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Gentoo (https://www.linuxquestions.org/questions/gentoo-87/)
-   -   help concerning sed command: (https://www.linuxquestions.org/questions/gentoo-87/help-concerning-sed-command-4175607693/)

nobodino 06-10-2017 12:45 PM

help concerning sed command:
 
Can someone help me undertand what is doing the following command, it's called for building xfsdump:
------------------
sed -i -e "s:enable_curses=[a-z]*:enable_curses=$(usex ncurses):" -e "s:libcurses="[^"]*":libcurses='$(use ncurses && $(tc-getPKG_CONFIG) --libs ncurses)':" configure || die
-------------------

Turbocapitalist 06-10-2017 01:08 PM

The normal delimiters for search and replace are slashes, as in s/// but they can be any character as long as they are three of a kind. So here you have s::: instead.

Then you have double quotes so that means the shell is interpreting the contents before passing them on to sed. That brings you to the command substitution indicated by $( ... )

Then the logical OR operator || means that if sed fails, then die will be run. Maybe die is a function defined earlier in the script. I'm not sure at all under which conditions sed would fail.

It also looks like a pair of double quotes needed to be escaped:

Code:

sed    -i \
        -e "s:enable_curses=[a-z]*:enable_curses=$(usex ncurses):" \
        -e "s:libcurses=\"[^"]*\":libcurses='$(use ncurses && $(tc-getPKG_CONFIG) --libs ncurses)':" \                                                       
        configure \                                                           
|| die


pan64 06-10-2017 01:11 PM

what part is unclear?
Code:

sed    is the command
-i    inline editing, the processed file will be overwritten (see man page)
-e 'expression'  a sed script to execute
-e 'expression'  another one
configure        looks like a filename here
that's all
both expressions are:
s      substitute
:      separator
search string
:      separator
replacement
:


rknichols 06-10-2017 01:18 PM

Quote:

Originally Posted by nobodino (Post 5721337)
sed -i -e "s:enable_curses=[a-z]*:enable_curses=$(usex ncurses):" -e "s:libcurses="[^"]*":libcurses='$(use ncurses && $(tc-getPKG_CONFIG) --libs ncurses)':" configure || die

In the config file, where it finds "enable_curses=something" it replaces the "something" with the output from the "usex ncurses" command.

Where it finds "libcurses=something" it replaces the "something" with the output from the command string, "use ncurses && $(tc-getPKG_CONFIG) --libs ncurses", which presumably gives the installed version of the ncurses library.

nobodino 06-10-2017 02:06 PM

well I tried to use it in a 'slackware' script and it doesn't recognize 'usex ncurses' and 'use ncurses'?

rknichols 06-10-2017 02:47 PM

Are you sure those functions are not defined somewhere above in the configure script, or perhaps in some file sourced by the configure script? If not, then that script was apparently intended for a build environment where those commands exist. Maybe there is a README file that tells what is required.

Didier Spaier 06-10-2017 06:13 PM

Quote:

Originally Posted by nobodino (Post 5721360)
well I tried to use it in a 'slackware' script and it doesn't recognize 'usex ncurses' and 'use ncurses'?

This is because you sed command is wrong. If I write it this way it works
Code:

sed -i \
-e 's:enable_curses=[a-z]*:enable_curses=$(usex ncurses):' \
-e 's:libcurses="[^"]*":libcurses=$(use ncurses && $(tc-getPKG_CONFIG) --libs ncurses):' configure || die

This is what it does:
Code:

didier[/storage/slackware64-14.2/source/ap/xfsdump/xfsdump-3.1.6]$ diff -u configure.orig configure
--- configure.orig      2017-06-11 00:57:10.177180799 +0200
+++ configure  2017-06-11 01:03:50.758182005 +0200
@@ -12795,7 +12795,7 @@
 
    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for bad glibc/ncurses header interaction" >&5
 $as_echo_n "checking for bad glibc/ncurses header interaction... " >&6; }
-    libcurses="-lncurses"
+    libcurses=''
    LIBS="$LIBS $libcurses"
    CFLAGS="$CFLAGS -D_GNU_SOURCE"
    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
@@ -12812,10 +12812,10 @@
 }
 _ACEOF
 if ac_fn_c_try_link "$LINENO"; then :
-  enable_curses=yes; { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5
+  enable_curses=$(usex ncurses); { $as_echo "$as_me:${as_lineno-$LINENO}: result: ok" >&5
 $as_echo "ok" >&6; }
 else
-  enable_curses=no; libcurses=""; { $as_echo "$as_me:${as_lineno-$LINENO}: result: disabling curses" >&5
+  enable_curses=$(usex ncurses); libcurses=''; { $as_echo "$as_me:${as_lineno-$LINENO}: result: disabling curses" >&5
 $as_echo "disabling curses" >&6; }
 fi
 rm -f core conftest.err conftest.$ac_objext \
didier[/storage/slackware64-14.2/source/ap/xfsdump/xfsdump-3.1.6]$

But I am not sure it is the intended effect, and I don't understand why it is needed as in Slackware the package is built OK without it. Where does that come from? And why post that in the Gentoo forum if you try it on Slackware?

nobodino 06-11-2017 01:33 AM

Well, I'm trying to solve the xfdsdump building in slackware-current (for Slackware From Scratch), and for the time being, I've not found a way to solve it.
So I pick ideas and patches in every distribution (gentoo, debian, fedora, archlinux...) to try to solve the problem.

Thanks for you answer, I'll try to see if it solves my problem.

Didier Spaier 06-11-2017 01:45 AM

Quote:

Originally Posted by nobodino (Post 5721483)
Well, I'm trying to solve the xfdsdump building in slackware-current (for Slackware From Scratch), and for the time being, I've not found a way to solve it.

xfsdump builds fine on a regular Slackware 14.2 without any patch. That's all I know.

Quote:

So I pick ideas and patches in every distribution (gentoo, debian, fedora, archlinux...) to try to solve the
Applying blindly (not knowing what they do and why they are needed) patches at random out of context is a receipt for failure.

Good luck, though.

nobodino 06-11-2017 02:30 AM

You're right it builds fine in stable (14.2), not in -current.
I didn't say anything else.

ThanXX


All times are GMT -5. The time now is 03:09 PM.