VectorLinux

Please login or register.

Login with username, password and session length
Advanced search  

News:

Visit our home page for VL info. For support and documentation, visit the Vector Linux Knowledge Center or search the Knowledge Center and this Forum using the search box above.

Author Topic: [Solved]CLI command question  (Read 2455 times)

budulay

  • Packager
  • Vectorian
  • ****
  • Posts: 568
  • NewComer
[Solved]CLI command question
« on: August 13, 2008, 06:09:43 pm »

Hi
I am now trying to edit .SlackBuild to correct an error in fltk2's makefile.( http://www.fltk.org/str.php?L1701 )
What I need to do is to replace
Code: [Select]
$(bindir)/fltk2-config with
Code: [Select]
$(DESTDIR)$(bindir)/fltk2-config in the  /$NAME/$VERSION/tmp/$NAME-$VERSION/fluid/Makefile
and I am stuck here.
Code: [Select]
sed 's/$(bindir)/fltk2-config/$(DESTDIR)$(bindir)/g' /$NAME/$VERSION/tmp/$NAME-$VERSION/fluid/Makefiledoesn't work, because there is to much '/' there.
Also a question - will it write $(bindir) as $(bindir), not as varuable's value?
Here I need $(bindir)/fltk2-config and $(DESTDIR)$(bindir)/fltk2-config to be writen as it looks now, and all the variables from /$NAME/$VERSION/tmp/$NAME-$VERSION/fluid/Makefile to get their value.
Thanks in advance
« Last Edit: August 13, 2008, 08:40:09 pm by budulay »
Logged
VL6.0-Light@MSI MS-1652(AMD TurionX2 ZM-84 2300 MHZ, 4 GB RAM, 250 GB HDD, Nvidia GForce 9600M GT, GIGABYTE AirCruiser N300)
Registered Linux user #473602
SlackBuild Repository for VL7.Not much but it's a start. Join in!

wcs

  • Packager
  • Vectorian
  • ****
  • Posts: 1144
Re: CLI command question
« Reply #1 on: August 13, 2008, 06:34:21 pm »

I would do "diff -c" with the new Makefile, put the Makefile.patch in /src, and put the patch command in the SlackBuild:
Code: [Select]
#APPLY PATCHES
#-----------------------------------------------------
echo "Applying patches..."
cp $CWD/filename.patch ./
patch -c -b -z .old < filename.patch
#-----------------------------------------------------

Would that work?
Logged

budulay

  • Packager
  • Vectorian
  • ****
  • Posts: 568
  • NewComer
Re: CLI command question
« Reply #2 on: August 13, 2008, 06:47:26 pm »

Thank you wcs for your quick reply.
Unfortunatelly I don't really understand what you are talking about...
I looked at "diff --help" for -c option, but didn't understand a thing...
Also I don't know how to apply patches.
Could you, please explain it a little.
Now I am reading sed howto - http://www.grymoire.com/Unix/Sed.htm , maybe I could find something useful there...
and I also found that if $variable is put in single quotes, it will not expand - http://www.linuxquestions.org/questions/showthread.php?p=2929923#post2929923 , right? if so, that's an answear to one of my questions:
Quote
Also a question - will it write $(bindir) as $(bindir), not as varuable's value?

ADDED:
Seems like I found a solution:
Code: [Select]
sed 's_$(bindir)/fltk2-config_$(DESTDIR)$(bindir)_g' /$NAME/$VERSION/tmp/$NAME-$VERSION/fluid/Makefilewill try it out and post the result
« Last Edit: August 13, 2008, 06:59:47 pm by budulay »
Logged
VL6.0-Light@MSI MS-1652(AMD TurionX2 ZM-84 2300 MHZ, 4 GB RAM, 250 GB HDD, Nvidia GForce 9600M GT, GIGABYTE AirCruiser N300)
Registered Linux user #473602
SlackBuild Repository for VL7.Not much but it's a start. Join in!

wcs

  • Packager
  • Vectorian
  • ****
  • Posts: 1144
Re: CLI command question
« Reply #3 on: August 13, 2008, 06:59:33 pm »

No prob...
I only started doing this two weeks ago, so I'm no expert.  :)

First, edit the Makefile and change whatever you want.
Save it as Makefile.patched or Makefile.new (whatever).
Then do:
Code: [Select]
diff -c Makefile Makefile.patched > Makefile.patch
This will produce a patch file that says what is different between the original and the patched version.
The -c option is there to give the context: the lines above and below what is changed, for easy reading.

Then delete the new version of the file and put the Makefile.patch together with the SlackBuild and the source tarball.

In the Slackbuild the patch command above will copy the patch to the current directory (should be the extracted sources), apply the patch, and change the original Makefile before compiling (I put it just before the configure & make section of the SlackBuild). The -c option is to say that this is a "context" patch, the -b is to make a backup of the original, and "-z .old" is to name the original "Makefile.old".

I prefer it this way than applying the changes in the SlackBuild, so that changes to the source code are easily documented inside the /src directory without one having to go inside the SlackBuild to find out if there are any changes at all.

If anyone cares to correct me on this stuff, I'll be glad... it works, but there might be better ways.
Logged

exeterdad

  • Packager
  • Vectorian
  • ****
  • Posts: 2046
Re: CLI command question
« Reply #4 on: August 13, 2008, 07:29:18 pm »

sed -i 's|$(bindir)|$(DESTDIR)$(bindir)|g' path/to/Makefile


Edit:
The above is wrong. Should be:
sed -i 's|$(bindir)/fltk2-config|$(DESTDIR)$(bindir)|g' path/to/Makefile

I forgot to type in the /fltk2-config part.  Also, if there is only one edit you don't need the "g" Without it, one match will be replaced. With it, all matches will be replaced.  Often in sed "/" is used.  But as you found it causes problems since the regex contains a /. It can be swapped out with almost anything, as long as it doesn't occur in your regex, or the replacement text.  I use "|" in those cases since it's easy for me to read.  Some people like "@"

HTH
« Last Edit: August 13, 2008, 08:26:53 pm by exeterdad »
Logged

exeterdad

  • Packager
  • Vectorian
  • ****
  • Posts: 2046
Re: CLI command question
« Reply #5 on: August 13, 2008, 08:28:30 pm »

Heh, heh.  How come I didn't notice you found a sed solution and edited?  ::)
Logged

Triarius Fidelis

  • Vecteloper
  • Vectorian
  • ****
  • Posts: 2399
  • Domine, exaudi vocem meam
    • my website
Re: CLI command question
« Reply #6 on: August 13, 2008, 08:34:43 pm »

If you find sed handy, try Perl.
Logged
"Leatherface, you BITCH! Ho Chi Minh, hah hah hah!"

Formerly known as "Epic Fail Guy" and "Döden" in recent months

budulay

  • Packager
  • Vectorian
  • ****
  • Posts: 568
  • NewComer
Re: CLI command question
« Reply #7 on: August 13, 2008, 08:39:43 pm »

Thank you very much, extendad and wcs for your replies.
I read about patches and fount that really interesting. Will experiment with this next time I'll need to fix something, but I already spend about 2 hours trying to make sed work, so it's late to retreat ;)

Quote from: extendad
sed -i 's|$(bindir)|$(DESTDIR)$(bindir)|g' path/to/Makefile
Despite I have already found that / could be replaced with anything, the great thing is that your post gave me is that it pointed out about that  "-i" thing!
I was wandering all the time, why my changes are shown in shell, but didn't in the file I edit. The -i option fixed that.
Also there is typo in my last post, I forgot to include fltk2-config into the second part of the script.
So, here is the script I'm using:
Code: [Select]
sed -i 's_$(bindir)/fltk2-config_$(DESTDIR)$(bindir)/fltk2-config_g' /$NAME/$VERSION/tmp/$NAME-$VERSION/fluid/MakefileOnce again, thank you for help.

It worked! Package is now ready. Will upload it to my vectorcintrib.

If you find sed handy, try Perl.
Well, that sounds even less familiar than sed for me, but thank you for reply, I think I will remember this some day :D
Logged
VL6.0-Light@MSI MS-1652(AMD TurionX2 ZM-84 2300 MHZ, 4 GB RAM, 250 GB HDD, Nvidia GForce 9600M GT, GIGABYTE AirCruiser N300)
Registered Linux user #473602
SlackBuild Repository for VL7.Not much but it's a start. Join in!

exeterdad

  • Packager
  • Vectorian
  • ****
  • Posts: 2046
Re: [Solved]CLI command question
« Reply #8 on: August 14, 2008, 05:36:49 am »

Glad you got it working. Sed is pretty daunting at first, and there are cool things about it that I will never know.  But I've learned enough that I can accomplish some pretty fun things and don't need to hit Google as much to find a solution. To really understand the commands you are seeing, and want to write better sed commands (this applies to perl as well), you really should take some time and study regex (regular expressions). Then it won't be like you are trying to decipher Greek.
If you are interested, you can check this:
http://sed.sourceforge.net/sed1line.txt
It's "sed one liners" You can really do some magic. If you forget the URL, just remember to Google "sed one liners", there are copies all over the web.

If perl is more then you want to tackle, you might like messing with awk.  Sed is powerful, but limited to editing.  Perl edits text well, but since it's a programming language, the sky is the limit what you can do with that text.  Awk is not as powerful as perl, but is a language as well that can do much of what perl can do without investing a ton of time into learning it.

Just my two cents.
Logged

budulay

  • Packager
  • Vectorian
  • ****
  • Posts: 568
  • NewComer
Re: [Solved]CLI command question
« Reply #9 on: August 14, 2008, 06:19:28 am »

Thank you for information. Bookmarked the likn - It looks like a pretty useful one. More my Linux experience will grow, more time I'll invest in studying some cool stuff.
Thank you once again for advice.
Logged
VL6.0-Light@MSI MS-1652(AMD TurionX2 ZM-84 2300 MHZ, 4 GB RAM, 250 GB HDD, Nvidia GForce 9600M GT, GIGABYTE AirCruiser N300)
Registered Linux user #473602
SlackBuild Repository for VL7.Not much but it's a start. Join in!