build - Why does 'touch' ing makefile along with all source file does not rebuild anything? How can I solve this? -


i have source files file1, file2 , file3 , makefile:

tar: file1 file2 file3     @echo hello 

now when touch file1, rebuilds file1 , tar.

but when touch source files , makefile, not rebuild anything. should rebuild source files. why so?

simple solution touch file makefile, becomes difficult when have 20 source files. solution?

the way make works compare timestamp on target , source(s). general format of rule is:

target: source(s)     action(s)         

in case, when run make, @ target's timestamp (tar) , ask whether timstamp older timestamp of source (file, file2, file3). if target older of sources, considered out of date, triggers rule's action(s) run.

the problem rule doesn't except echo output. after runs, tar still has same timestamp had before. next time run make, same thing, because starting condition (the timestamps) did not change.

you can make work expected having rule touch tar file 1 of actions.

tar: file1 file2 file3     @touch tar     @echo hello 

now should behave expected.

$ make make: `tar' date. $ touch file3     $ make hello $ make make: `tar' date. 

of course, in typical makefile, rule more echo. if building something, target of rule (in case tar) modified result of build action, explicitly using touch not required.


Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -