1 / 6

Makefile and “make” utility

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.

mblanco
Download Presentation

Makefile and “make” utility

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Makefile and “make” utility B. Ramamurthy Amrita-UB-MSES-cse524-2016-8

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

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

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

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

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

More Related