The make utility (original presentation courtesy of Alark Joshi)

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.
Compilation & linkage.h read.h.c read.c.c main.c.c list.c.h list.h prog1 Linkage: g++ read.o main.o list.o –o prog1.o main.o.o list.o.o read.o Compilation:
1 The Makefile Utility ABC – Chapter 11,
Declarative Languages. Declarative languages In an imperative programming language, a program specifies how to solve a problem In a declarative language,
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
1 CS 201 Makefile Debzani Deb. 2 Remember this? 3 What is a Makefile? A Makefile is a collection of instructions that is used to compile your program.
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.
1 Building. 2 Goals of this Lecture Help you learn about: The build process for multi-file programs Partial builds of multi-file programs make, a popular.
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.
Introduction Use of makefiles to manage the build process Declarative, imperative and relational rules Environment variables, phony targets, automatic.
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Scons Writing Solid Code Overview What is scons? scons Basics Other cools scons stuff Resources.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
GNU Make Computer Organization II 1 © McQuain What is make ? make is a system utility for managing the build process (compilation/linking/etc).
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
1 Building Jennifer Rexford. 2 Goals of this Lecture Help you learn about: The build process for multi-file programs Partial builds of multi-file programs.
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.
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.
Multiple File Compilation and linking By Bhumik Sapara.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
CSc 352 An Introduction to make Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
Makefile Script file to automate program compilation and linking (making) 1. Write the "makefile" 2. Write your programs 3. Run "make" or "make -f makefile"
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.
Multiple file project management & Makefile
The make utility (original presentation courtesy of Alark Joshi)
Automating Builds with Makefiles
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.
Large Program Management: Make; Ant
Makefiles Caryl Rahn.
SEEM3460 Tutorial The Make Utility.
SCMP Special Topic: Software Development Spring 2017 James Skon
Compiling from source code
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
Large Program Management: Make; Ant
Makefiles and the make utility
Large Program Management: Make; Ant
Data Structures and Programming Techniques
CSE 390 Lecture 8 Large Program Management: Make; Ant
CMPSC 60: Week 4 Discussion
CMSC 202 Additional Lecture – Makefiles
Kyle Fitzpatrick Konstantin Zak 11/29/2004
SCMP Software Development Spring 2018 James Skon
Build Tools (make) CSE 333 Autumn 2018
CSCE-221 Makefile Introduction
CSc 352: Elementary “make”
Large Program Management: Make; Ant
GNU Make.
Large Program Management: Make; Ant
CSc 352 An Introduction to make
Makefiles and the make utility
Compiler vs linker The compiler translates one .c file into a .o file
CSE 390 Lecture 8 Large Program Management: Make; Ant
SCMP Software Development Spring 2018 James Skon
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.
Large Program Management: Make; Ant
Presentation transcript:

The make utility (original presentation courtesy of Alark Joshi) Make is a utility that is included with Linux/Unix operating systems It is a command generator It is designed to help you compile large projects

What is make? Make is non-procedural You tell make what you want (e.g. a particular class file or executable) You provide a set of rules showing dependencies between files Make uses the rules to get the job done

of the program can be very resource intensive Why use make? For large programs, recompiling all the pieces of the program can be very resource intensive But if the program is complex, determining exactly what needs to be recompiled can be a time-consuming (and error-prone) task The make utility was written to assist with this process

What does make do? Make uses a file called Makefile (or makefile) to determine what needs to be recompiled Makefile contains a set of rules When you run make, it uses the rules in the Makefile to determine what needs to be done Make does the minimum amount of work needed to get the job done

Rules in a Makefile A typical rule has the form target: dependency list command list target can be the name of a file that needs to be created (or a “phony” name that can be used to specify which command to execute) The dependency list is a space separated list of files that the target depends on in some way The command list is one or more linux commands needed to accomplish the task of creating the target

Rules in a Makefile Each command must be indented with a tab Both dependency lists and commands can be continued onto another line by putting a \ at the end of the first line A # is used to start a comment in a makefile – The comment consists of the remainder of the line

Example Dependencies for a “list” program: TestList.c includes List.h, Node.h, Job.h, and common.h List.c includes List.h, Node.h, Job.h, and common.h Node.c includes Node.h, Job.h, and common.h Job.c includes Job.h and common.h

Rules for the “list” program Brute-force approach

How make works When you type make without a target name will assume you mean to make the first real target in the makefile When you type make target, the make utility will look at the rule for target make will recursively search through the rules for all the dependencies to determine what has been modified

How make works If the current version of target is newer than all the files it depends on, make will do nothing. If a target file is older than any of the files that it depends on, the command following the rule will be executed

Macros Sometimes, you find yourself using the same stuff in lots of command actions---macros simplify things Define macro CC = gcc CFLAGS = -O –Wall –g PROGS = list TestList Then use the macro by typing $(macroname) $(CC) $(CFLAGS) –c List.c

# File "makefile" used to build "ola207" executable CXX = g++ -std=c++11 –pedantic ola207: bakery.o bakeryPrint.o $(CXX) -g bakery.o bakeryPrint.o -o ola207 bakery.o: bakery.cpp bakeryPrint.h bakeryConstants.h $(CXX) -g -c bakery.cpp bakeryPrint.o: bakeryPrint.cpp bakeryPrint.h bakeryConstants.h $(CXX) -g -c bakeryPrint.cpp

Phony Targets Phony targets are targets that do not correspond to a file clean: rm –f *.o

Example all: subdirs subdirs: cd bad; make cd almost-generic; make cd generic-with-library; make cd generic; make clean: cd bad; make clean almost-generic; make clean generic-with-library/; make clean generic; make clean

(Optional) Advanced Stuff follows:

Substitution Rules Often, you will find that your Makefile has many similar commands You can use patterns to define rules and commands for such cases For example, we could use the rule %.o : %.c $(CC) $(CFLAGS) –c $< Which says that every .o file depends on the corresponding .c file and can be created from it with the command below the rule

Substitution Rules - Internal macros % - any name (the same in all occurrences) $@ - The name of the current target $< - The first dependency for the current target $^ - All the dependencies for the current target %.o : %.c $(CC) $(CFLAGS) –c $< hello: $(CC) hello.o $(CFLAGS) $< -o $@

Suffix Rules A suffix rule identifies suffixes that make should recognizes .SUFFIXES: .o .c Another rule shows how files with suffixes are related .c.o : $(CC) $(CFLAGS) –c $< Think of this as saying the .o file is created from the corresponding .c file using the given command

A More Advanced Example With macros, suffix rules and phony targets

Taking the drudgery out of dependencies Dependencies for a .o file should include all the user written header files that it includes For a big project, getting all of these right can take some time The gcc command has an option -MMD which tells it to compute the dependencies. These are stored in a file with the suffix .d Include the .d file into the Makefile using -include *.d

Multiple rules for a target If there is more that one rule for a given target, make will combine them. The rules can be specified in any order in the Makefile