Makefiles and the make utility

Slides:



Advertisements
Similar presentations
Makefiles. makefiles Problem: You are working on one part of a large programming project (e. g., MS Word).  It consists of hundreds of individual.c files.
Advertisements

The make Utility Programming Tools and Environments Winter 2006.
CMSC 341 Makefile Review. 1 Make Overview make is a program that automates the compilation of programs whose files are dependent on each other A program.
Separate compilation Large programs are generally separated into multiple files, e.g. tuples.h, ray.h, ray.c, tuples.c main.c With several files, we can.
The Makefile utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
Understanding Makefiles COMP 2400, Fall 2008 Prof. Chris GauthierDickey.
1 The Makefile Utility ABC – Chapter 11,
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
CS465 - Unix C Programming (cc/make and configuration control)
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
G++ and make Dan Wilson CS193 02/01/06. The g++ Compiler What happens when you call g++ to build your program? Phase 1, Compilation:.cpp files are compiled.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
Unix Makefiles COP 3330 Lecture Notes Dr. David A. Gaitros.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
Makefiles CISC/QCSE 810. BeamApp and Tests in C++ 5 source code files After any modification, changed source needs to be recompiled all object files need.
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
Makefile M.A Doman. Compiling multiple objects Card.cpp -> Card.o Deck.cpp -> Deck.o main.cpp -> main.o main.o Deck.o Card.o -> Dealer.exe.
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
The Make utility. Motivation Small programs all in single cpp file “Not so small” programs : Many lines of code Multiple components More than one programmer.
Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
Week 2-3 Control flow (review) Conditional statements If, else, else if, switch-case, break Loop constructs for, while, do-while, break, continue, label--go;
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
Separate Compilation make and makefiles
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
Lecture 8  make. Using make for compilation  With medium to large software projects containing many files, it’s difficult to: Type commands to compile.
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
Make Make is a system utility that automatically compiles your programs for you Make looks for a file named Makefile (or makefile) in the current directory.
Problem Solving With C++ Recitation – make February 2016.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
CSI605 Introduction to make. Advantages of Make Significantly reduces the amount of time spent compiling a program. Insures that programs are compiled.
Build Tools 1. Building a program for a large project is usually managed by a build tool that controls the various steps involved. These steps may include:
Brandon Packard. Why make? So far, you have probably worked on relatively small projects Coding projects can become huge My research consists of 1600.
CSc 352 An Introduction to make Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
Makefiles CSSE 332 Operating Systems
The make utility (original presentation courtesy of Alark Joshi)
CSE 303 Lecture 17 Makefiles reading: Programming in C Ch. 15
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
Brief Intro to Make CST494/ Gannod.
Compilation and Debugging
Compilation and Debugging
Makefiles Caryl Rahn.
SEEM3460 Tutorial The Make Utility.
SCMP Special Topic: Software Development Spring 2017 James Skon
CS 201 A Whirlwind Tour of C Programming
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
Prof: Dr. Shu-Ching Chen TA: Yimin Yang
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Makefiles and the make utility
Makefiles and Notes on Programming Assignment PA2
Rake 4-Dec-18.
Data Structures and Programming Techniques
CMPSC 60: Week 4 Discussion
CMSC 202 Additional Lecture – Makefiles
SCMP Software Development Spring 2018 James Skon
CSCE-221 Makefile Introduction
CSc 352: Elementary “make”
CSc 352 An Introduction to make
Compiler vs linker The compiler translates one .c file into a .o file
Makefiles, GDB, Valgrind
SCMP Software Development Spring 2018 James Skon
SPL – PS1 Introduction to C++.
What is make? make is a system utility for managing the build process (compilation/linking/etc). There are various versions of make; these notes discuss.
The make utility (original presentation courtesy of Alark Joshi)
Presentation transcript:

Makefiles and the make utility make is a unix utility Organizes command-based tasks Uses file timestamps to keep targeted files up to date Useful for automating compilation of software projects makefiles are used by make Define which commands need to be run (and their syntax) To establish dependencies between files Macros can be defined and used for global options Rules can be defined to simplify commands

Makefiles Consists of targets, dependencies, and commands Basic syntax: target: depend1 depend2 … command [arg1] [arg2] … [additional commands] Note: command must be preceded by a tab (not spaces)! For each target in the makefile the timestamp of the target is compared to those of the dependencies If a dependent file is newer than the target, the commands get executed Dependent files may be targets themselves Could trigger multiple commands as files get updated

Makefile flow example testdate depends on Date.o and TestDate.o Date.o, in turn, depends on Date.cpp and Date.h If, for example, Date.cpp is changed and make is executed Date.o will be out of date Causes execution of: g++ -c Date.cpp $(DB) Produces updated Date.o Which then, causes execution of: g++ -o testdate TestDate.o Date.o $(DB) Result: recompiled testdate Only the code necessary for updating is recompiled (TestDate.o is not changed) DB=-g testdate: Date.o TestDate.o g++ -o testdate TestDate.o Date.o $(DB) TestDate.o: TestDate.cpp Date.h g++ -c TestDate.cpp $(DB) Date.o: Date.cpp Date.h g++ -c Date.cpp $(DB) clean: rm -f *.o testdate lie: echo "This is a great lecture"

Running make Execute “make” at the command prompt By default, it will run command in a file called makefile or Makefile To run any other file name, use the –f option make –f somefile By default, make will attempt to update the first target it encounters in the makefile To select a different target, simply add it to the argument list make target1 [target2 …] Multiple targets are permitted Commands will be echoed to the terminal as they are run

Makefile macros DB is a macro make clean It is invoked as $(DB) DB=-g testdate: Date.o TestDate.o g++ -o testdate TestDate.o Date.o $(DB) TestDate.o: TestDate.cpp Date.h g++ -c TestDate.cpp $(DB) Date.o: Date.cpp Date.h g++ -c Date.cpp $(DB) clean: rm -f *.o testdate lie: echo "This is a great lecture" DB is a macro It is invoked as $(DB) Resulting command for Date.o target is: g++ -c Date.cpp –g which compiles for debugging make clean Does not create/update a file called clean It simply runs the rm command to remove all compiled results Similar behavior for make lie!

Makefile rules rule: %.o: %.cpp … Built-in macros: For any .cpp file, make the corresponding .o with the given rule Built-in macros: $@: left side of “:” separator $^: right side of “:” separator $<: first argument on right side CC=g++ CFLAGS=-g DEPS = Date.h OBJ = Date.o TestDate.o %.o: %.cpp $(DEPS) $(CC) -c -o $@ $< $(CFLAGS) testdate: $(OBJ) $(CC) -o $@ $^ $(CFLAGS)