Just out of curiosity, how does Makefile know that a file changed (and then recompile it)? Is it up to make
? Is it up to the compiler? If so, is it language dependent?
Use the command `make' to recompile the source files that really need recompilation. Make the changes in the header files. Use the command `make -t' to mark all the object files as up to date. The next time you run make, the changes in the header files do not cause any recompilation.
How does make know that a source code file needs to be recompiled? Freshness Check: Speed is the reason we use make. For maximum speed, make does the least amount of work to determine the freshness of the compiled object code.
The make utility requires a file, Makefile (or makefile ), which defines set of tasks to be executed. You may have used make to compile a program from source code. Most open source projects use make to compile a final executable binary, which can then be installed using make install .
The makefile is read by the make command, which determines the target file or files that are to be made and then compares the dates and times of the source files to decide which rules need to be invoked to construct the target.
It looks at the file time-stamp - simple as that. If a dependency is newer that the target, the target is rebuilt.
Make works by inspecting information about files, not their contents.
Make works out dependencies between targets and their dependencies, and then looks to see whether the files exist. If they do, it asks the operating system for the time and date the file was last modified. This is the 'timestamp' for this purpose, although the term can have other meanings.
If a target file either does not exist, or exists and is earlier than its dependent file, then Make rebuilds the target from the dependent by applying a rule.
If the dependent does not exist, Make signals an error.
A consequence of this is that you can force a rebuild by deleting the target, or by 'touching' the dependent to make it later than the target. You can avoid a rebuild by 'touching' the target. Touching simply updates the timestamp to now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With