1.3 Minimizing Rebuilds

     

When we run our program, we discover that aside from printing fees, fies, foes, and fums, it also prints text from the input file. This is not what we want. The problem is that we have forgotten some rules in our lexical analyzer and flex is passing this unrecognized text to its output. To solve this problem we simply add an "any character" rule and a newline rule:

 int fee_count = 0;         int fie_count = 0;         int foe_count = 0;         int fum_count = 0; %% fee     fee_count++; fie     fie_count++; foe     foe_count++; fum     fum_count++; . \n 

After editing this file we need to rebuild the application to test our fix:

 $  make  flex -t lexer.l > lexer.c gcc -c lexer.c gcc count_words.o lexer.o -lfl -ocount_words 

Notice this time the file count_words.c was not recompiled. When make analyzed the rule, it discovered that count_words.o existed and was newer than its prerequisite count_words.c so no action was necessary to bring the file up to date. While analyzing lexer.c , however, make saw that the prerequisite lexer.l was newer than its target lexer.c so make must update lexer.c . This, in turn , caused the update of lexer.o and then count_words . Now our word counting program is fixed:

 $  count_words < lexer.l  3 3 3 3 



Managing Projects with GNU make
Managing Projects with GNU Make (Nutshell Handbooks)
ISBN: 0596006101
EAN: 2147483647
Year: 2003
Pages: 131

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net