60 likes | 84 Views
Makefile and “make” utility. B. Ramamurthy. Compile, load and Link. When we write a program in a high level language such as C, C++ and Java, we compile it and link and load it for execution.
E N D
Makefile and “make” utility B. Ramamurthy Amrita-UB-MSES-cse524-2016-8
Compile, load and Link • When we write a program in a high level language such as C, C++ and Java, we compile it and link and load it for execution. • For example for a C application consisting of counter.h, counter.c, driver.c, we could use these commands: gcc –o counterExedriver.ccounter.c If there are any dependent libraries (Lib) to be linked: gcc –o counterExedriver.ccounter.c –lLib • For complex programs with multiple dependencies the “build” process consists of many such commands • When any of the dependencies change you keep track of which ones to recompile etc. Amrita-UB-MSES-cse524-2016-8
Makefile • You use a “makefile” to streamline the build process during software development. • Makefile consists of the build commands and the “make” utility processes the makefile to accomplishes the build process automatically processing all the necessary dependencies. Amrita-UB-MSES-cse524-2016-8
Dependency chart Driver.c Counter.c Counter.h gcc -c gcc -c gcc -c Counter.o Driver.o gcc -o CounterApp Amrita-UB-MSES-cse524-2016-8
Makefile target: dependencies <tab>: build command CounterApp: Driver.o Counter.o gcc –o CounterApp Driver.o Counter.o Driver.o: Driver.c Counter.h gcc –c Driver.o Driver.c Counter.o: Counter.c Counter.h gcc –c Counter.o Counter.c Amrita-UB-MSES-cse524-2016-8
Make utility • “make” utility on unix systems is a build command • It (by default) processes the commands specified in a file names “Makefile” or “makefile”. • Makefile has targets to build. • Make utility checks • if the target is not present in the folder the command to build the target is executed. • If target is present: it checks the timestamp on the target and the dependencies. If target’s timestamp is earlier than that of any of dependencies it builds target. • It applies the above steps recursively to the dependencies of the target. • Lets look at an example in the demos directory. Amrita-UB-MSES-cse524-2016-8