I'm trying to create a build script for GCC (which works, for now), but I would like to be able to skip rebuilding all the prereq libraries when I'm only updating GCC/binutils for example. I thought of making the script create a file in the main build directory containing all the steps to skip. How would I do that (something with the cat command and find to see if a step is in the file?). This would allow me, albeit manually, to enable a rebuild of certain parts when needed.

UPDATE: The answers posted seem to assume that I need a makefile, while I find that very troublesome and don't want it; the build procedure consists of many cd, configure, make, make install steps that I simply don't want in a makefile. The script is near-finished, this is the last step I need for it...

UPDATE2: as I said in the comment below, I'm on windows, using MSYS bash as shell.


PS: this "skipping completed steps" needs to be performed each time the script is run.

  • Why are you building gcc & co. Wouldn't it be better to use it from system repositories? – Maciej Piechotka Sep 19 '10 at 14:25
  • I live on Windows x64, which a) doesn't have system repositories, and b) I'm experimenting and would like to build a x64 MinGW-w64 compiler with GCC 4.6 – rubenvb Sep 19 '10 at 14:26
  • 1
    Despite your saying that you don't want to use Make, it seems that what you're doing is exactly what Make is built for --- it's a dependency resolution system ... which it looks like you're wanting to build yourself. – Eric Smith Sep 19 '10 at 15:56
  • @Eric, no... I'm trying to create a BASH shell script, which runs a given set of commands, like TDM has for his GCC builds, and many others also use. That's what I want a variation of, not a makefile. – rubenvb Sep 19 '10 at 16:44

So, it looks like you're not really asking a question around build frameworks, but rather a specific question about how to determine if a certain line exists in a text file?

If you want to find out if the string foo exists in a file, then:

if grep -q foo thefile; then
   # it's there
   # otherwise

should do the trick.

  • Great, that's already half of it. I did mention Bash in my questionnot anything CMake/Make/Scons or something like that... Would an echo "foo\n" > thefile do the job for creating the file? Will it append "foo" to the file, or create a new one and overwrite the previous? Thanks – rubenvb Sep 19 '10 at 18:27
  • Never mind: I have what I wanted: echo "foo" >> test with your magic should do the trick! – rubenvb Sep 19 '10 at 18:35

It sounds like you need an introduction to make, produced by our friends over at GNU, I believe.

Make can look at a bunch of intermediate files and determine which ones need to be recompiled. And based on which one(s) of those, also figure out which ones need their supporting files rebuilt, thus recursing.

You will need to set it up in advance by creating a Makefile, but this is something which it sounds like you are willing to do.

For more information, I would check out this URL: http://www.gnu.org/software/make/. Actually, bullet point number 2 sounds like it does a better job of describing it than anything I could do.


You might want to look into CMake. For what you've described, it's probably overkill and make would be a better fit, but if you start getting into the autotools stuff, it could make your life a lot easier.

  • CMake and autotools don't fit the same niche... autotools will make the program compile (when used correctly) on any platform with sh, wherease CMake will require CMake on all the platforms, which is fine if your not going to want full portability. I would list CMake and autotools as different options for similar tasks. – mathepic Sep 20 '10 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.