The make Utility Programming Tools and Environments Winter 2006.

Slides:



Advertisements
Similar presentations
Makefiles. makefiles Problem: You are working on one part of a large programming project (e. g., MS Word).  It consists of hundreds of individual.c files.
Advertisements

Make. A simple make file $ make program Strength of make is its sensitivity to dependency hierarchies. Specify such dependencies in a description file.
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.
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.
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,
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 12 Separate Compilation Namespaces Simple Make Files (Ignore all class references.
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
26-Jun-15 Rake. rake and make A program can consist of many source code files This is always true in Rails! The files may need to be compiled in a certain.
Basic linux shell commands and Makefiles. Log on to engsoft.rutgers.edu Open SSH Secure Shell – Quick Connect Hostname: engsoft.rutgers.edu Username/password:
2000 Copyrights, Danielle S. Lahmani UNIX Tools G , Fall 2000 Danielle S. Lahmani Lecture 9.
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.
G++ and make Dan Wilson CS193 02/01/06. The g++ Compiler What happens when you call g++ to build your program? Phase 1, Compilation:.cpp files are compiled.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
Makefiles. makefiles Problem: You are working on one part of a large programming project (e. g., MS Word).  It consists of hundreds of individual.c files.
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.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
Makefiles. makefiles Problem: You are working on one part of a large programming project (e. g., MS Word).  It consists of hundreds of individual.cpp.
Introduction Use of makefiles to manage the build process Declarative, imperative and relational rules Environment variables, phony targets, automatic.
Jump to first page (C) 1998, Arun Lakhotia 1 Software Configuration Management: Build Control Arun Lakhotia University of Southwestern Louisiana Po Box.
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.
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
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).
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.
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;
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
Data Display Debugger (DDD)
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.
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
CSI605 Introduction to make. Advantages of Make Significantly reduces the amount of time spent compiling a program. Insures that programs are compiled.
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
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)
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
Brief Intro to Make CST494/ Gannod.
Makefiles Caryl Rahn.
SCMP Special Topic: Software Development Spring 2017 James Skon
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
Rake 4-Dec-18.
Data Structures and Programming Techniques
CMPSC 60: Week 4 Discussion
SCMP Software Development Spring 2018 James Skon
Build Tools (make) CSE 333 Autumn 2018
CSc 352: Elementary “make”
GNU Make.
CSc 352 An Introduction to make
Makefiles and the make utility
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:

The make Utility Programming Tools and Environments Winter 2006

make The make utility automates certain tasks (usually simple command-line stuff) compiling multi-file programs archiving/extracting installation Often used to manage builds runs the compiler only when necessary uses file modify times to decide when it is necessary

Makefiles A basic makefile contains targets A target consists of: Target name – file to be built List of dependencies (if any) Command to build the target

Rules target : dependencies command1 command2 … Each command executed in its own subshell Each command must start w/a tab These MUST be tabs!!!

Dependency List A list of files that the target depends upon Target is only built if it doesn't not exist, or if it exists, but is older than all of the dependencies. A dependency may also appear as a target in the same makefile; these are then intermediate targets This relationship is checked recursively, down the dependency tree

Simple Example linecount : foo.c wc –l foo.c > linecount This rule would tell make that the file linecount depends on the file foo.c To build linecount the command “ wc –l foo.c > linecount ” should be run If linecount doesn't exist, or foo.c is newer (modified more recently than linecount ), the wc command will be executed

(cont) $ make target main check dependencies, main.o & subs.o 1. main.o check its dependenies, main.cc & subs.h 2. subs.o etc. Does main exist? If so, is it newer than its dependencies? If no, execute command-line

Input Files Specify a makefile using the -f option to make make -f myMakefile If not specified, make looks in the current directory for (in order): 1. makefile 2. Makefile

Simple Makefile for building a program. main: main.o subs.o gcc –o main main.o subs.o subs.o: subs.c subs.h gcc –c subs.c main.o: main.c subs.h gcc –c main.c TABS!

Make command line (simplified) make [options] [targets] options include “-f filename” use filename as the Makefile “-n” don’t do anything – just print what needs to be done. targets are what should be built (if needed).

Specifying a target Just specify the target after the make command: make subs.o If no target is specified, the first target listed in the file is created

Revisit Example A target doesn't need dependencies, nor does its command-line need to make create the target: clean : - \rm *.o - \rm main $ make clean will cause those files to be removed (assuming there is no file called clean in the directory. See next slide.)

Phony targets (GNU only) A target can be specified as phony, so that it is always executed:.PHONY : clean clean : - \rm *.o - \rm main The dash in front of the commands tells make to ignore the return values; to continue executing, even if an error is returned.

Macros You can create macros (make variables) OBJS = subs.o main.o main: $(OBJS) gcc –o main $(OBJS)

Command Modifiers If a command starts it won't be echoed to “Hello there A preceding - will tell make to ignore return status clean: -\rm foo -\rm bar

Fancy Stuff – Macro Substitution Evaluates to the value of a macro after some substitutions: SOURCE = main.c subs.c OBJS = ${SOURCE:.c=.o} now OBJS is main.o subs.o

Automatic Variables of current target $<Name of first prerequisite $^ Name of all prerequisites, with spaces in between $?Name of all prerequisites newer than the target

Suffix Rules General rules for building files that end with some suffix from files with the same name but a different suffix For example, how to build a.o file from a.c file %.o : %.c $(cc) $< -o

Example Suffix Rule.c.o: gcc –c $< This rule tells Make how to create a.o file any time is has a.c file (and needs the.o file to build a target).

A Complete Example.c.o: gcc –c $< SOURCE = main.c subs.c OBJS = ${SOURCE:.c=.o} main: $(OBJS) gcc –o main $(OBJS)

Comments and other Makefile notes Comments begin with a ‘#’ Can be placed at the beginning of a line or after a non-comment line Lines that are too long can be continued on the next line by placing a ‘\’ at the end of the first line

Basic Makefile example program : main.o iodat.o dorun.o gcc -o program main.o iodat.o dorun.o main.o : main.c gcc -c main.c iodat.o : iodat.c gcc -c iodat.c dorun.o : dorun.c gcc -c dorun.c

Simplifying the example Makefile with macros OBJS = main.o iodat.o dorun.o CC = /usr/bin/gcc program : ${OBJS} ${CC} -o ${OBJS} main.o : main.c ${CC} -c $? iodat.o : iodat.c ${CC} -c $? dorun.o : dorun.c ${CC} -c $?

Simplifying the example Makefile again OBJS = main.o iodat.o dorun.o CC = /usr/bin/gcc program : ${OBJS} ${CC} -o ${OBJS}

Other useful Makefile tips Include a way to clean up your mess clean: /bin/rm -f *.o core Include a target to build multiple programs all: program1 program2 program3

Epilogue We've looked at rather basic makefiles, but you already have a useful working knowledge. If you need it, make is capable of a good bit more. Read gnu's site. nual/make.html