You are not logged in.

#1 2010-02-14 18:23:42

eyolf
Member
From: Copenhagen
Registered: 2005-11-29
Posts: 339
Website

[SOLVED] Help with sed line in PKGBUILD

I'm trying to make a package for a program which installs just with make all; make install, but where the Makefile contains hardcoded install directories, like so:

INSTALL_PLUGINS_DIR     =       /usr/local/lib/ladspa/
INSTALL_LRDF_DIR        =       /usr/local/share/ladspa/rdf/

...

install: all
    -mkdir -p               $(INSTALL_PLUGINS_DIR)
    cp *.so                 $(INSTALL_PLUGINS_DIR)
    -mkdir -p               $(INSTALL_LRDF_DIR)
    cp *.rdf      $(INSTALL_LRDF_DIR)

I've tried to change "/usr/local" to "${pkgdir}/usr" with a sed line, but if I use single quotes around the sed program, the string ${pkgdir} is used, and with double quotes, I get an error:

sed: -e expression #1, char 17: unknown option to `s'

Can someone with better sed skills than me help me out here?

Last edited by eyolf (2010-02-15 00:31:25)

Offline

#2 2010-02-14 18:30:58

flamelab
Member
From: Athens, Hellas (Greece)
Registered: 2007-12-26
Posts: 2,160

Re: [SOLVED] Help with sed line in PKGBUILD

Try.

sed -i 's/\/usr\/local/${pkgdir}\/usr/g' Makefile

Last edited by flamelab (2010-02-14 18:33:59)

Offline

#3 2010-02-14 18:33:09

jac
Member
From: /home/jac
Registered: 2009-05-19
Posts: 431
Website

Re: [SOLVED] Help with sed line in PKGBUILD

That's rather ugly, may I suggest using _ as a delimiter? Also, I'm not sure if you escaped everything you should have...

sed -i "s_/usr/local_${pkgdir}/usr_g" Makefile

The character immediately after the 's' is used as the delimiter

Last edited by jac (2010-02-14 18:34:22)

Offline

#4 2010-02-14 19:09:00

eyolf
Member
From: Copenhagen
Registered: 2005-11-29
Posts: 339
Website

Re: [SOLVED] Help with sed line in PKGBUILD

Thanks to both of you. It seems that the error was that I had forgotten the "g" at the end. Phew. I'm never going to learn sed....

Offline

#5 2010-02-14 19:17:45

jac
Member
From: /home/jac
Registered: 2009-05-19
Posts: 431
Website

Re: [SOLVED] Help with sed line in PKGBUILD

I don't think that leaving off the 'g' would have given you an error, that just tells sed to apply the change every time it can in a line. Out of curiosity, do you still have the line you were trying to use?

I'm glad it's working now, could you add '[SOLVED]' to the thread title?


Edit: P.S. I learned from here. It was a great resource, and I never even finished it!

Last edited by jac (2010-02-14 19:20:35)

Offline

#6 2010-02-15 00:17:23

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: [SOLVED] Help with sed line in PKGBUILD

I'm very fond of sed. But make is also worth learning too (I went a long time without doing so, but it's worth the investment).

From the snippet you posted, it looks like you could just do this, without needing to do any sed manipulation of the makefile:

make INSTALL_PLUGINS_DIR=${pkgdir}/usr/lib/ladspa/ INSTALL_LRDF_DIR=${pkgdir}/usr/share/ladspa/rdf/

Assignments made on the command-line invocation of make overrule assignments in the makefile of the form "VAR = value". Those in term overrule environment variables. Those in turn overrule assignments in the makefile of the form "VAR ?= value".

Last edited by Profjim (2010-02-15 00:18:15)

Offline

#7 2010-02-15 00:40:43

eyolf
Member
From: Copenhagen
Registered: 2005-11-29
Posts: 339
Website

Re: [SOLVED] Help with sed line in PKGBUILD

@jac: This is the line, which gave the error message in the first post:

sed -i "s/\/usr\/local/${pkgdir}\/usr/"  Makefile

The only difference I can see from the one that worked (the one you posted), is the missing g and the changed delimiter.

@Profjim: Thanks for the tip; I'll make a (mental) note of it until next time I need it. One of these days, I'm going to learn make properly...

Offline

#8 2010-02-15 02:09:24

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: [SOLVED] Help with sed line in PKGBUILD

eyolf wrote:

@jac: This is the line, which gave the error message in the first post:

sed -i "s/\/usr\/local/${pkgdir}\/usr/"  Makefile

The only difference I can see from the one that worked (the one you posted), is the missing g and the changed delimiter.

The changed delimiter is what fixes it. pkgdir is going to be something like "/path/to/here". When it's substituted into the sed expression, sed sees the
command "s/\/usr\/local//path/to/here\/usr/" which it understands as "s/\/usr\/local//<flags and garbage>". The problem is that the /s in your $pkgdir aren't escaped. Using a different delimiter makes it so that they don't need to be escaped anymore. Of course, if your $pkgdir uses "_" or whatever else you used for a delimiter, this problem will rearise.

Offline

#9 2010-02-15 11:00:43

eyolf
Member
From: Copenhagen
Registered: 2005-11-29
Posts: 339
Website

Re: [SOLVED] Help with sed line in PKGBUILD

Does that mean that in order for "/" to work as a delimiter, one would have to double- or triple-escape the "/"s in the file path? "s/\\/usr\\/local" etc.? Not that I would want to use such a monstrosity when a different delimiter solves it -- just curious.

Offline

#10 2010-02-15 11:23:19

jac
Member
From: /home/jac
Registered: 2009-05-19
Posts: 431
Website

Re: [SOLVED] Help with sed line in PKGBUILD

No, you still only need to escape the "/" once. If you "double-escape" it it ends up being "\/" [a backslash an one of sed's delimiters, if you're using /] which will then hopefully not be reinterpreted another time. Underscores do come up in file names, so you could use ":" or any other which comes up less frequently.

Profjim: Thanks for the explanation on how to use make! That avoids all the problems with sed and delimiters

Last edited by jac (2010-02-15 11:25:34)

Offline

#11 2010-02-15 11:59:21

eyolf
Member
From: Copenhagen
Registered: 2005-11-29
Posts: 339
Website

Re: [SOLVED] Help with sed line in PKGBUILD

Profjim: Ah..... I get it now. I didn't read carefully enough the first time around -- too early in the morning, even for a perfectly clear explanation. Thanks a lot!

I wish there were a wiki page with a survey of the different build types (with/without configure, with/wo hard-coded Makefile variables, different make commands, binary installs, etc.) and how to deal with them. When do I need a DESTDIR, when a --prefix=, where do I put $pkgdir, etc. I've built quite a few packages by now, but there has been a lot of trial and error, and grepping through the abs tree for possibly similar PKGBUILDs...

Offline

#12 2010-02-15 17:46:57

Profjim
Member
From: NYC
Registered: 2008-03-24
Posts: 658

Re: [SOLVED] Help with sed line in PKGBUILD

Makefiles themselves aren't standardized, unfortunately. There's a few common patterns---for example, you can expect Makefiles generated by automake to work the same way, you can expect Makefiles generated by cmake to work the same way as each other, somewhat differently than the automake-generated ones, and so on. But in all cases you're going to have to open up the Makefile and look at it to see how it works/what pattern it follows.

Offline

Board footer

Powered by FluxBB