The make utility. Alark Joshi COMPSCI 253

Similar documents
Make: a build automation tool

Make: a build automation tool 1/23

[Software Development] Makefiles. Davide Balzarotti. Eurecom Sophia Antipolis, France

Chris' Makefile Tutorial

GNU Make 1. 1 material adapted from GNU Make by Richard Stallman

Makefile Tutorial. Eric S. Missimer. December 6, 2013

CS Basics 15) Compiling a C prog.

Berner Fachhochschule Haute cole spcialise bernoise Berne University of Applied Sciences 2

Using GNU make C HAPTER 4

Makefiles SE 2XA3. Term I, 2018/19

Software Building (Sestavování aplikací)

Introduction to System Programming : makefile

CSE 333 Interlude - make and build tools

Multiple file project management & Makefile

independent compilation and Make

COSC345 Software Engineering. Make

CSE 374 Programming Concepts & Tools

Reviewing gcc, make, gdb, and Linux Editors 1

We d like to hear your suggestions for improving our indexes. Send to

Maemo Diablo GNU Make and makefiles Training Material

Intermediate Programming, Spring 2017*

Programming in the Large Steps

Make! CSC230: C and Software Tools. N.C. State Department of Computer Science. Some examples adapted from

HPC User Environment

Kurt Schmidt. May 23, 2018

GDB and Makefile. Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

The Make Utility. Independent compilation. Large programs are difficult to maintain. Problem solved by breaking the program into separate files

The Linux Programming Environment. Computer Science Department Texas State University

The make utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them.

CS11 Intro C++ Spring 2018 Lecture 4

CS11 Advanced C++ Fall Lecture 4

C / C++ Coding Rules

2 Compiling a C program

Compilation & linkage. Compilation & linkage. Make. Compilation & linkage. Explicit rules. What makefile contains

LSF Make. Platform Computing Corporation

area.o perimeter.o formatting.o geometry.c gcc -o geometry area.o perimeter.o formatting.o geometry.c

The Make Utility. Independent compilation. Large programs are difficult to maintain. Problem solved by breaking the program into separate files

DAY 4. CS3600, Northeastern University. Alan Mislove

Makefiles are a simple way to organize code compilation. Using a makefile it is possible to compile several source files to produce an executable;

Lab 2.2. Out: 9 February 2005

UNIX Makefile. C Project Library Distribution and Installation.

Outline. COMP 2718: Software Development Tools: gcc and make. C and Java 3/28/16

INTERMEDIATE SOFTWARE DESIGN SPRING 2011 ACCESS SPECIFIER: SOURCE FILE

CS Students Linux User's Guide

PCICC32 Linux Driver Quick Installation and Usage Guide

GNU make. Michal Koutný. Software development and monitoring tools (NSWI126)

CS240: Programming in C. Lecture 2: Overview

GNU make... Martin Ohlerich, Parallel Programming of High Performance Systems

Oregon State University School of Electrical Engineering and Computer Science. CS 261 Recitation 1. Spring 2011

Projects and Make Files

CAAM 420 Fall 2012 Lecture 15. Roman Schutski

CSC 2500: Unix Lab Fall 2016

COMP 2400 UNIX Tools

CS 247: Software Engineering Principles. Modules

CS2141 Software Development using C/C++ Compiling a C++ Program

CMPT 300. Operating Systems. Brief Intro to UNIX and C

The CS-220 Development Environment

CS240: Programming in C

The makeutility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them.

Linking and Loading. ICS312 - Spring 2010 Machine-Level and Systems Programming. Henri Casanova

CSE 390 Lecture 8. Large Program Management: Make; Ant

CSCi 4061: Intro to Operating Systems Spring 2017 Instructor: Jon Weissman Assignment 1: Simple Make Due: Feb. 15, 11:55 pm

CMake & Ninja. by István Papp

Reliable C++ development - session 1: From C to C++ (and some C++ features)

Using Platform LSF Make

Tutorial: Compiling, Makefile, Parallel jobs

Basic Compilation Control with Make

UNIVERSITY OF CALIFORNIA Department of Electrical Engineering and Computer Sciences Computer Science Division. P. N. Hilfinger

Computer Science 322 Operating Systems Mount Holyoke College Spring Topic Notes: C and Unix Overview

{C} Tools of the Trade

Workshop Agenda Feb 25 th 2015

11.1 Modular Organization and makefiles.

Overview of today s lecture. Quick recap of previous C lectures. Introduction to C programming, lecture 2. Abstract data type - Stack example

Dalhousie University CSCI 2132 Software Development Winter 2018 Lab 8, March 22

CMPSC 311- Introduction to Systems Programming Module: Build Processing

Compiler Drivers = GCC

COMP Lecture Notes The Compiler

Systems Programming. laboratory. Compilation automation. make ceedling

Introduction. Introduction to gcc and Makefiles. Stef Nychka. September 21, Department of Computing Science University of Alberta

Program Development Tools

CMPSC 311- Introduction to Systems Programming Module: Build Processing

Make. Dependency Graphs

PROGRAM COMPILATION MAKEFILES. Problem Solving with Computers-I

CMPS 12M Winter 2018 Lab 1 Due: Monday January 11:59pm

Embedded Software TI2726 B. 3. C tools. Koen Langendoen. Embedded Software Group

CS480. Compilers Eclipse, SVN, Makefile examples

Laboratorio di Tecnologie dell'informazione

/visualc/vcug/_asug_overview.3a_.nmake_reference.htm

The Makefile utility. (Extract from the slides by Terrance E. Boult

Autotools Tutorial. Mengke HU. ASPITRG Group Meeting. ECE Department Drexel University

Continue: How do I learn C? C Primer Continued (Makefiles, debugging, and more ) Last Time: A Simple(st) C Program 1-hello-world.c!

Makefile Brief Reference

PRINCIPLES OF OPERATING SYSTEMS

ITST Searching, Extracting & Archiving Data

Chapter 6: The C Preprocessor

Compiling Code using Makefiles and GNUstep. 2501ICT Nathan

Project Build Process. Abhijit Bhosale M.Tech (IT) School of Information Technology, IIT Kharagpur

Laboratorio di Programmazione. Prof. Marco Bertini

cc is really a front-end program to a number of passes or phases of the whole activity of "converting" our C source files to executable programs:

And You Thought There Couldn t be More C++ Fundamentals of Computer Science

Transcription:

The make utility Alark Joshi COMPSCI 253

What is make? 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 It can be useful whenever you have long sequences of commands which need to accomplish a particular task or a set of related tasks

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

Why use make? For large programs, recompiling all the pieces of the program can be very time consuming But if the program is complex, determining exactly what needs to be recompiled too can be difficult 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 the doubly-linked list Main.c and TestList.c include 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 common.h

Rules for Doubly-Linked List 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 sequence of command line options in lots of commands Define macro CC = gcc CFLAGS = -O Wall g PROGS = list TestList Then use the macro by typing $(macroname) $(CC) $(CFLAGS) c List.c

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: hello.o $(CC) $(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

Phony Targets Phony targets are targets that do not correspond to a file progs: list Testlist clean: rm force *.o $(PROGS)

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

Doubly Linked List Example With macros, suffix rules and phone 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

Useful functions See man pages for more information dir, notdir suffix, basename addsuffix, addprefix foreach call, eval