CSc 352: Elementary “make”

Slides:



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

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.
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.
1 The Makefile Utility ABC – Chapter 11,
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.
Introduction to Make Updated by Prasad Spring 2000.
CSc 352 Shell Scripts Saumya Debray Dept. of Computer Science
Guide To UNIX Using Linux Third Edition
CS465 - Unix C Programming (cc/make and configuration control)
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
July 29, 2003Serguei Mokhov, 1 Makefile Brief Reference COMP 229, 346, 444, 5201 Revision 1.2 Date: July 18, 2004.
Introduction Use of makefiles to manage the build process Declarative, imperative and relational rules Environment variables, phony targets, automatic.
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Makefile Introduction Jia – Wei Lin 1. Outline Why we use make ? Create a Description File Rules of Makefile How make Processes a Makefile? GCC Flags.
Scons Writing Solid Code Overview What is scons? scons Basics Other cools scons stuff Resources.
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).
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
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
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.
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.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
An Introduction to the UNIX Make Utility Introduction: Although make can be used in conjunction with most programming languages all examples given here.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 2 Class web site:
Announcements Assignment 1 will be regraded for all who’s score (not percentage) is less than 6 (out of 65). If your score is 6 or higher, but you feel.
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.
Multiple file project management & Makefile
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
C – Multi-file development and make
Computer Science 210 Computer Organization
Brief Intro to Make CST494/ Gannod.
Makefiles Caryl Rahn.
SEEM3460 Tutorial The Make Utility.
SCMP Special Topic: Software Development Spring 2017 James Skon
Computer Science 210 Computer Organization
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
Introduction to the C Language
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Makefiles and the make utility
Data Structures and Programming Techniques
CSc 352: Testing and Code Coverage
CSc 352 Debugging Tools Saumya Debray Dept. of Computer Science
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
Appendix F C Programming Environment on UNIX Systems
GNU Make.
CSc 352 An Introduction to make
Makefiles and the make utility
Compiler vs linker The compiler translates one .c file into a .o file
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.
The make utility (original presentation courtesy of Alark Joshi)
Presentation transcript:

CSc 352: Elementary “make” Saumya Debray Dept. of Computer Science The University of Arizona, Tucson debray@cs.arizona.edu

What is “make”? make is a Unix tool that simplifies the task of compiling large and complex software projects the programmer creates a Makefile that speficies: which files depend on which other files what commands to run when a file changes and needs to be (re)compiled make reads Makefile and runs commands as necessary not such a big deal for small single-source-file programs very helpful when a large number of files involved can be used for many tasks that involve running some commands on files that have changed

Example Suppose we have four C programs: We fix a bug in palindromes.c need to recompile palindromes.c but not the remaining files! We can do this using make

Example Makefile What it means mayan : mayan.c gcc –Wall mayan.c –o mayan palindromes : palindromes.c gcc –Wall palindromes.c –o palindromes rotstr : rotstr.c gcc –Wall rotstr.c –o rotstr vowels : vowels.c gcc –Wall vowels.c –o vowels The file mayan is built from the file mayan.c To build mayan from mayan.c, execute this command (and similarly for the other files) \t \t \t \t

Makefile structure: rules “target” Makefile mayan : mayan.c gcc –Wall mayan.c –o mayan file(s) the target depends on ( ≥ 0 ) (“prerequisites”) if any of these files is changed, the target must be recompiled. “rule” command ( ≥ 0 ) to execute if target is out of date w.r.t. the files it depends on In general, a makefile will have many rules: typically, one for each target

How make works Makefile Behavior of make if target does not exist: target : prerequisite1 … prerequisiten command if target does not exist: run command else: if target is older than any of its prerequisites: else: /* (target is up to date) */ do nothing If make is invoked without specifying a target, it uses the first target in the makefile by default

Example to run make, type the command make Makefile make prints out the commands it executes as it executes them when make is re-run, only the commands for the updated prerequisites are executed

Creating a makefile What are the targets? For each target foo: figure out which files are created from other files and which need to be re-created when any of those files change. For each target foo: what are the files which, if changed, would require us to re-create foo? These are the prerequisites for foo (let’s say bar1 ... barn) What commands do we use to (re-)create foo? say: cmd1 ... cmdm

Creating a makefile The resulting rule for foo is: or: foo: bar1 bar2 ... barn cmd1 cmd2 ... cmdm tab tab tab or: foo: bar1 bar2 ... barn cmd1 ; cmd2 ; ... cmdm tab

Another example We can use make to build a program in different ways: # 32-bit executables mayan-32: gcc –m32 mayan.c –o mayan # 64-bit executables mayan-64: gcc –m64 mayan.c –o mayan # unoptimized mayan: gcc mayan.c –o mayan # optimized mayan-opt: gcc –O3 mayan.c –o mayan

Phony Targets Makefile We don’t really intend to “build” the targets all, clean Such “targets” are called phony targets The rules would not work if we accidentally introduced files named all, clean to prevent this problem, declare them to be phony targets This rule has no command! This rule has no prerequisites!

Phony targets

Variables A variable is a name that represents a text string (its value) also called “macros” defined as: XYZ = value used as: $(XYZ) makes it easier to write, understand makefiles Example: Part of a makefile from a CSC 453 assignment: variable definitions variable uses

Summary of concepts Rules Phony targets Variables represent dependencies between files specified using targets, prerequisites, commands Phony targets Variables