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.

Slides:



Advertisements
Similar presentations
The make Utility Programming Tools and Environments Winter 2006.
Advertisements

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.
Makefiles  Provide a way for separate compilation.  Describe the dependencies among the project files.  The make utility.
Programming Logic and Design Fourth Edition, Introductory
CS201 – Makefile Tutorial. A Trivial Makefile # Trivial Makefile for puzzle1.c # Ray S. Babcock, CS201, MSU-Bozeman # 1/5/05 # puzzle1: puzzle1.c gcc.
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.
Introduction to Make Updated by Prasad Spring 2000.
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.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
Make: the good, the bad, and the ugly Dan Berger Titus Winters
Unix Makefiles COP 3330 Lecture Notes Dr. David A. Gaitros.
July 29, 2003Serguei Mokhov, 1 Makefile Brief Reference COMP 229, 346, 444, 5201 Revision 1.2 Date: July 18, 2004.
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.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
System Programming - LAB 1 Programming Environments.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
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).
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;
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
CSE 251 Dr. Charles B. Owen Programming in C1 Compilation and Makefiles.
Copyright © 2015 Curt Hill Make An Indispensable Developer’s Tool.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015 Makefile Tutorial CIS5027.
Lecture 8  make. Using make for compilation  With medium to large software projects containing many files, it’s difficult to: Type commands to compile.
COP 3530 Spring 12 Discussion Session 1. Agenda 1.Introduction 2.Remote programming 3.Separate code 4.Compile -- g++,makefile 5.Debug -- gdb 6.Questions?
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
Multiple File Compilation and linking By Bhumik Sapara.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
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:
Object Oriented Programming COP3330 / CGS5409.  Compiling with g++  Using Makefiles  Debugging.
Brandon Packard. Why make? So far, you have probably worked on relatively small projects Coding projects can become huge My research consists of 1600.
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.
Multiple file project management & Makefile
Makefiles CSSE 332 Operating Systems
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
What Is? function predefined, programmer-defined
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
Editor, Compiler, Linker, Debugger, Makefiles
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
CMSC 202 Additional Lecture – Makefiles
C Programming Basic – week 9
SCMP Software Development Spring 2018 James Skon
Vocabulary Algorithm - A precise sequence of instructions for processes that can be executed by a computer Low level programming language: A programming.
CSc 352: Elementary “make”
What Is? function predefined, programmer-defined
Makefiles and the make utility
Compiler vs linker The compiler translates one .c file into a .o file
CSC 253 Lecture 15.
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.
Presentation transcript:

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 Require coordination of files to build

Motivation – continued Problems: Long files are harder to manage (for both programmers and machines) Every change requires compilation of all constituent files? Many programmers can not modify the same file simultaneously Large projects are not implemented in a single module/file

Motivation – continued Solution : Separation of Concerns Targets: Proper and optimal division of components Minimum compilation when something is changed Easy maintenance of project structure, dependencies and creation

Project maintenance Performed in Unix by the Make utility A makefile is a file (script) containing: Project structure (files, dependencies) Instructions for creation of object code, executables, other tasks Note:A makefile script is not limited to C++ programs

Project structure Project structure and dependencies can be represented as a DAG (= Directed Acyclic Graph) Example : Date class: contains 3 files Date.h, Date.cpp, TestDate.cpp Date.h included in both.cpp files Executable should be named testdate

testdate (exe) Date.o TestDate.o Date.cppDate.h TestDate.cpp

Makefile Rules: Targets, Dependencies, and Associated Commands testdate: Date.o TestDate.o g++ -o testdate TestDate.o Date.o TestDate.o: TestDate.cpp Date.h g++ -c TestDate.cpp Date.o: Date.cpp Date.h g++ -c Date.cpp

Rule syntax Target TestDate.o: TestDate.cpp Date.h g++ -c TestDate.cpp tab dependencies action This rule compiles TestDate.cpp, but does NOT create any executable,just TestDate.o Rule

Macros Macros are used to simplify and automate Often used like constants in programs We can compress identical dependencies and use built- in macros to get another (shorter) equivalent makefile : testdate: TestDate.o Date.o g++ –o TestDate.o Date.o TestDate.o Date.o: Date.h g++ –c $*.cpp Macro represents rule target: = testdate Macro $* represents prefixes shared by target and dependant files: $* = TestDate, if target is TestDate.o Date, if target is Date.o

make operation Project’s dependency tree is constructed Target of first rule is to be created Go down the dependency tree to see if there is a target that should be recreated: target file is older than one of its dependencies recreate the target file according to the action specified, on our way up the tree. Consequently, more files may need to be recreated If something is changed, linking is usually necessary Top target in dependency tree

make operation - continued make operation ensures minimum compilation, when the project structure is written properly Do not write something like: testdate: TestDate.cpp Date.cpp Date.h g++ –o testdate TestDate.cpp Date.cpp which requires compilation of all files when something is changed Example: If Date.cpp changes, why compile TestDate.cpp?

Passing parameters to makefile Parameters can be passed to a makefile by specifying them along with their values in the command line. For example: make PAR1=1 PAR2=soft1 will call the makefile with 2 parameters: PAR1 is assigned the value “1” and PAR2 is assigned the value “soft1”. The same names should be used within the makefile to access these variables (using the usual “$(VAR_NAME)” syntax)

Passing parameters - continued Note that assigning a value to a variable within the makefile overrides any value passed from the command line. For example: command line : make PAR=1 in the makefile: PAR = 2 PAR value within the makefile will be 2, overriding the value sent from the command line

Conditional statements Simple conditional statements can be included in a makefile. Usual syntax is: ifeq (value1, value2) body of if else body of else endif

Conditional statements - example sum: main.o sum.o gcc –o sum main.o sum.o main.o: main.c sum.h gcc –c main.c #deciding which file to compile to create sum.o ifeq ($(USE_SUM), 1) sum.o: sum1.c sum.h gcc –c sum1.c –o else sum.o: sum2.c sum.h gcc –c sum2.c –o endif

Reference GNU Project’s Tutorial for makefiles