# Makefile Recompilation - Unix makefile

## What is Makefile Recompilation?

The make program is a bright utility and works based on the changes you do in your source files. If you have four files main.cpp, hello.cpp, factorial.cpp and functions’, then all the enduring files are reliant on functions’, and main.cpp is dependent on both hello.cpp and factorial.cpp.

Therefore if you make any change in functions’, then the make recompiles all the source files to produce new object files. However if you make any modify in main.cpp, as this is not dependent of any other file, then only main.cpp file is recompiled, and help.cpp and factorial.cpp are not.

While compiling a file, the make checks its entity file and compare the time stamps. If source file has a newer time stamp than the entity file, then it generate new entity file assume that the source file has been transformed.

### Avoiding Recompilation

There may be a scheme consisting of thousands of files. Sometimes you may have altered a source file but you may not want to recompile all the files that depend on it. For instance, expect you add a macro or a declaration to a header file, on which the other files depend. Being traditional, make assumes that any modify in the header file requires recompilation of all dependent files, but you know that they do not require recompilation and you would rather not waste your time waiting for them to accumulate.

If you expect the problem before altering the header file, you can use the -t' flag. This flag tells make not to run the directions in the rules, but rather to mark the target up to date by change its last-modification date. You need to follow this process −

• 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.

If you have already transformed the header file at a time when some files do need recompilation, it is too late to do this. as an alternative, you can use the -o file' flag, which marks a particular file as "old". This means, the file itself will not be remade, and nothing else will be remade on its explanation. You want to follow this method −

• Recompile the source files that need compilation for reasons independent of the particular header file, with make -o header file'. If several header files are involved, use a separate -o' option for each header file.
• Update all the object files with `make -t'.