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

Similar documents
Program Development Tools

Chapter 2: An Introduction to Makeles 5 2 An Introduction to Makeles You need a le called a makele to tell make what to do. Most often, the makele tel

Basic Compilation Control with Make

Build. System building

GNU Make. A Program for Directing Recompilation GNU make Version 3.79 April Richard M. Stallman and Roland McGrath

@shorttitlepage GNU Make Copyright (C) 1988, '89, '90, '91, '92, '93 Free Software Foundation, Inc.

GNU Make. A Program for Directing Recompilation. Edition 0.51, for make Version 3.75 Beta. May Richard M. Stallman and Roland McGrath

GNU Make. A Program for Directing Recompilation GNU make Version 3.82 July Richard M. Stallman, Roland McGrath, Paul D.

Outline. Configuration management. Main Phases MOTIVATION

COSC345 Software Engineering. Make

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

CS240: Programming in C. Lecture 2: Overview

2 Compiling a C program

CS240: Programming in C

GNUPro Toolkit User s Guide for Altera for ARM and ARM/ Thumb Development

Makefiles SE 2XA3. Term I, 2018/19

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

The make utility. Alark Joshi COMPSCI 253

Intermediate Programming, Spring 2017*

Multiple file project management & Makefile

Introduction to System Programming : makefile

Using GNU make C HAPTER 4

Kurt Schmidt. May 23, 2018

CS11 Advanced C++ Fall Lecture 4

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

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

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

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

CS 473: Algorithms. Chandra Chekuri 3228 Siebel Center. Fall University of Illinois, Urbana-Champaign

CSE 333 Interlude - make and build tools

HPC User Environment

Make: a build automation tool

Software Building (Sestavování aplikací)

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

CSE 374 Programming Concepts & Tools

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

Make: a build automation tool 1/23

Laboratory: Computer Organization

Reviewing gcc, make, gdb, and Linux Editors 1

Depth First Search (DFS)

CS11 Intro C++ Spring 2018 Lecture 4

Build Systems, Version Control, Integrated Development Environment

Systems Programming. laboratory. Compilation automation. make ceedling

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

Depth First Search (DFS)

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

CS Basics 15) Compiling a C prog.

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

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

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

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

independent compilation and Make

Maemo Diablo GNU Make and makefiles Training Material

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

Introduction to Supercomputing

Makefile Brief Reference

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

Separate Compilation of Multi-File Programs

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

The Linux Programming Environment. Computer Science Department Texas State University

Chris' Makefile Tutorial

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

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

How to learn C? CSCI [4 6]730: A C Refresher or Introduction. Diving In: A Simple C Program 1-hello-word.c

Lab 2.2. Out: 9 February 2005

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

Make. Dependency Graphs

15213 Recitation Section C

Make was originally a Unix tool from 1976, but it has been re-implemented several times, notably as GNU Make.

AN 834: Developing for the Intel HLS Compiler with an IDE

Programming in the Large Steps

The CS-220 Development Environment

Projects and Make Files

UNIX Makefile. C Project Library Distribution and Installation.

C/C++ Programming. Session 10

Using the Unix system. UNIX Introduction

Personal SE. C Struct & Typedef Make

make and makefile CS 211

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

CS 261 Recitation 1 Compiling C on UNIX

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

Goals for This Lecture:

LSF Make. Platform Computing Corporation

Compiling Code using Makefiles and GNUstep. 2501ICT Nathan

CS Students Linux User's Guide

Building a Salvo Application with GNU's avr-gcc C Compiler, WinAVR and AVRStudio

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

Lab #3 Automating Installation & Introduction to Make Due in Lab, September 15, 2004

CSC 2500: Unix Lab Fall 2016

CS Lab 1 Linux/Shell Basic commands Introduction. Teaching Assistant Henrique Potter

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

Workspace for '3-ctips' Page 1 (row 1, column 1)

Introduction to Supercomputing

Make A Program for Maintaining Computer Programs

C / C++ Coding Rules

Introduction to Linux

COMP Lecture Notes The Compiler

Data and File Structures Laboratory

The make Utility in Unix SEEM

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

Transcription:

1 The make utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them. Make can be used with any programming language whose compiler can be run with a shell command. Make is not limited to programs. It can be used to describe any task where some files must be updated automatically from others whenever the others change. We will use make to automatically generate executable images (*.hex files) for downloading from our *.c and *.h files. 1 material adapted from GNU Make by Richard Stallman

Here is a dependency graph for a program called edit. Make works by building a source file dependency graph and checking file creation times to determine which files are now out of date and recompiling only as needed. For example, if command.h was changed, its timestamp would be newer than the *.c and *.h files that depend on it. Thus make would recompile kbd.c and files.c and relink all the object files to produce edit. No other files would be compiled as there is no need.

Make is controlled by a makefile which describes dependencies and actions to take to rebuild the executable image. The makefile is usually called either Makefile or makefile. Advantages of using a makefile to build a project: The makefile documents exactly how to rebuild the executable It reduces rebuilding a complex project to a single command It can be used to build the other files you need:.eeprom,.lst,.hex... It is very general purpose: VHDL, Verilog, LaTeX, etc. One makefile can be used reused for other projects with minor edits

make looks for a makefile in the current directory. The makefile describes the dependencies and actions using makefile rules A rule is formed as follows: target : prerequisites <hard tab> commands target: usually the name of a file generated by the command below. It can also be the name of an action to carry out. (phony target) prerequisites: file(s) that used as input to create the target. A target usually depends on several files. commands : usually shell command(s) used to create the target. Can also specify commands for a target that does not depend on any prerequisites. (e.g.; clean)

An example rule: sr.o : sr.c avr-gcc -g -c -Wall -O2 -mmcu=atmega128 -o sr.o sr.c This rule tells make that: sr.o is dependent on sr.c if sr.c is newer than sr.o, recreate sr.o by executing avr-gcc A rule then, explains how and when to remake certain files which are the targets of the particular rule. make carries out the commands on the prerequisites to create or update the target.

make does its work in two phases: 1. Include needed files, initialize variables, rules, build dependency graph 2. Determine which targets to rebuild, and invoke commands to do so The order of the rules is insignificant, except for determining the default goal. Rules tell make when targets are out of date and how to update them if necessary. Targets are out of date if they do not exist or if they are older than any of its prerequisities.

A simple makefile for edit edit : main.o kbd.o command.o display.o insert.o search.o files. utils.o cc -o edit main.o kbd.o command.o display.o insert.o search.o\ files.o utils.o files.o : utils.o main.o : main.c defs.h cc -c main.c kbd.o : kbd.c defs.h command.h cc -c kbd.c command.o : command.c defs.h command.h cc -c command. c display.o : display.c defs.h buffer.h cc -c display. c insert.o : insert.c defs.h buffer.h cc -c insert. c search.o : search.c defs.h buffer.h cc -c search. c files.o : files.c defs.h buffer.h command.h cc -c files. c utils.o : utils.c defs.h cc utils.c clean : rm edit main.o kbd.o command.o display.o insert.o search.

A simple make file for sr.c including variables Listing goes here

We can make the makefile more general purpose with some new rules. Implicit rules - make implicitly knows how to make some files. Its has implicit rules for updating *.o files from a corresponding *.c file using gcc. We can thus omit commands for making *.o files from the object file rules. Pattern rules - You can define an implicit rule by writing a pattern rule. Pattern rules contain the character %. The target is considered a pattern for matching names. The pattern rule: %.o : %.c command Says to create any file ending with.o from a file ending with.c execute command.

Automatic variables These are variables that are computed afresh for each rule that is executed based on the target and prerequisites of the rule. The scope of automatic variables is thus very limited. They only have values within the command script. They cannot be used in the target or prerequisite lists. Some automatic variables we will use: $@ The file name of the target of the rule $< The name of the first prerequisite $? The names of all the prerequisites newer than the target $^ The names of all the prerequisites

Big make file goes here

Generally, translational units are turned into object files. But header files are not standalone translational units, make has no way of knowing that it needs to rebuild a.c file when a.h file changes. gcc is able to read your source file and generate a list of prerequisite files for it with the -MM switch. We can take this output and create another makefile from it using some shell commands. There will be one makefile for each source file. Each makefile is then included in our top level makefile so that the dependencies are taken care of. Here is the makefile code for this: %.d: %.c @set -e; rm -f $@; \ $(CC) -M $( CFLAGS ) $< > $@. $$$$ ; \ sed s,\( $ *\)\. o[ :]*,\1. o $@ :,g < $@. $$$$ > $@; \ rm -f $@. $$$$ - include ( $SRCS :.c =.d)