Question

I am currently trying to install GCC-4.1.2 on my machine: Fedora 20.

In the instruction, the first three commands involve using 'sed' commands, for Makefile modification. However, I am having difficulty in using those commands properly for my case. The website link for GCC-4.1.2.

The commands are:

sed -i 's/install_to_$(INSTALL_DEST) //' libiberty/Makefile.in &&
sed -i 's@\./fixinc\.sh@-c true@' gcc/Makefile.in &&
sed -i 's/@have_mktemp_command@/yes/' gcc/gccbug.in &&

I am trying to understand them by reading the 'sed' man page, but it is not so easy to do so. Any help/tip would be appreciated!

Was it helpful?

Solution

First, the shell part: &&. That just chains the commands together, so each subsequent line will only be run if the prior one is run successfully.

sed -i means "run these commands inline on the file", that is, modify the file directly instead of printing the changed contents to STDOUT. Each sed command here (the string) is a substitute command, which we can tell because the command starts with s.

Substitute looks for a piece of text in the file, and then replaces it. So the order is always s/needle/replacement/. See how the first and last lines have those same forward-slashes? That's the traditional delimiter between the command (substitute), the needle to find in the haystack (install_to_$(INSTALL_DEST), and the text to replace it with ().

So, the first one looks for the string and deletes it (the empty replacement). The last one looks for @have_mktemp_command@ and replaces it with yes.

The middle one is a bit weird. See how it starts with s@ instead of s/? Well, sed will let you use any delimiter you like to separate the needle from the replacement. Since this needle had a / in it (\./fixinc\.sh), it made sense to use a different delimiter than /. It will replace the text ./fixinc.sh with -c true.

Last note: Why does the second needle have \. instead of .? Well, in a Regular Expression like the needle is (but not used in your example), some characters are magical and do magical fairy dust operations. One of those magic characters is .. To avoid the magic, we put a \ in front of it, escaping away from the magic. (The magic is "match any character", and we want a literal period. That's why.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top