Make: File Dependency System Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: 818-677-4954 “UNIX for Programmers and Users” Third.

Slides:



Advertisements
Similar presentations
Compiling. Your C, C++ or Fortran program won’t work unless you compile it The compiler will build your program as an executable file (typically in the.
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.
C Programming Tools Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition,
Gdb: GNU Debugger Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
The Makefile utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
David Notkin Autumn 2009 CSE303 Lecture 20 static make.
Makefiles Tutorial adapted from and myMakeTutorial.txt.
Understanding Makefiles COMP 2400, Fall 2008 Prof. Chris GauthierDickey.
1 The Makefile Utility ABC – Chapter 11,
Ar: Unix Archiver Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
Introduction to Make Updated by Prasad Spring 2000.
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.
Unix Makefiles COP 3330 Lecture Notes Dr. David A. Gaitros.
리눅스 : 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.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
Perl Challenge Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
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.
SEEM3460 Tutorial Multi-module programming in C. Copy the material Create the directory mkdir c_multi cd c_multi mkdir ask cd ask Copy files cp ~seem3460/distribute/c_multi-module/ask/ask_reverse.c.
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.
Chapter 12 C Programming Tools Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, Original Notes.
Tools – Ant-MakeEtc 1 CSCE 747 Fall 2013 CSCE 747 Software Testing and Quality Assurance Tools 12 – Hamcrest 10/02/
CVS: Concurrent Version System Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third.
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.
Modular Programming. Introduction As programs grow larger and larger, it is more desirable to split them into sections or modules. C allows programs to.
cs33201 Chapter 12 C Programming Tools Graham Glass and King Ables, UNIX for Programmers and Users, Third Edition, Pearson Prentice Hall, 2003.
C code organization CSE 2451 Rong Shi. Topics C code organization Linking Header files Makefiles.
C P ROGRAMMING T OOLS. C OMPILING AND R UNNING S INGLE M ODULE P ROGRAM.
Advanced UNIX progamming Fall 2002 Instructor: Ashok Srinivasan Lecture 2 Class web site:
Brandon Packard. Why make? So far, you have probably worked on relatively small projects Coding projects can become huge My research consists of 1600.
UNIX Development: g++ and make CS 2204 Class meeting 8 Created by Doug Bowman, 2001 Modified by Mir Farooq Ali, 2002.
Ar: Unix Archiver Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall,
The make utility (original presentation courtesy of Alark Joshi)
Large Program Management: Make; Ant
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.
Multi-module programming in C
Computer Systems and Networks
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
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
Multi-module programming in C
Rake 4-Dec-18.
CSE 390 Lecture 8 Large Program Management: Make; Ant
Multi-module programming in C
Kyle Fitzpatrick Konstantin Zak 11/29/2004
Large Program Management: Make; Ant
Large Program Management: Make; Ant
Build Tools (make) CSE 333 Autumn 2018
Large Program Management: Make; Ant
Large Program Management: Make; Ant
Makefiles and the make utility
CSE 390 Lecture 8 Large Program Management: Make; Ant
Large Program Management: Make; Ant
Presentation transcript:

make: File Dependency System Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third Edition, Prentice-Hall, GRAHAM GLASS, KING ABLES Slides partially adapted from Kumoh National University of Technology (Korea) and NYU

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone:  THE UNIX FILE-DEPENDENCY SYSTEM: MAKE - In order to update the two main program executables “main1” and “main2” manually, 1. Recompile “reverse.c” 2. Link “reverse.o” and “main1.o” to produce a new version of “main1”. 3. Link “reverse.o” and “main2.o” to produce a new version of “main2”. - imagine a system with 1000 object modules and 50 executable programs.  a nightmare.

make: File Dependency System One way to avoid these problems to use the UNIX make utility, which allows you to create a makefile that contains a list of all file interdependencies for each executable. Developed at Bell Labs around 1978 by S. Feldman (now at IBM)

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone:  THE UNIX FILE-DEPENDENCY SYSTEM: MAKE - Once such a file is created, to re-create the executable is easy: $ make -f makefile - synopsis of make Utility: make [ -f makefile ] make is a utility that updates a file based on a series of dependency rules stored in a special-format “make file”. The -f option allows you to specify your own make -filename; if none is specified, the name “makefile” is assumed.

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone:  Make Files - To use the make utility to maintain an executable file,  create a make file. - contains a list of all of the interdependencies that exist between the files that are used to create the executable. Example: the name of the make file for “main1”, “main1.make” - a make file contains make rules of the form targetList: dependencyList commandList targetList : a list of target files dependencyList : a list of files on which the files in targetList depend. commandList : a list of zero or more commands, separated by new lines,

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone:  Make Files - For example, “main1.make” main1: main1.o reverse.o cc main1.o reverse.o -o main1 main1.o : main1.c reverse.h cc -c main1.c reverse.o : reverse.c reverse.h cc -c reverse.c

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone:  The Order of Make Rules - The make utility creates a “tree” of interdependencies. Each target file in the first rule is a root node of a dependency tree, Each file in its dependency list is added as a leaf of each root node. In example, main1 main1.o reverse.o

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone:  The Order of Make Rules - In example, the final tree main1 main1.o reverse.o main1.c reverse.h reverse.c reverse.h

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone:  Make Ordering main1 main1.o reverse.o main1.c reverse.h reverse.c reverse.h

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone:  Executing a Make - Once a make file has been created, the make process is set into action by using the make utility as follows: make [ -f makeFileName ] - To re-create the executable file whose dependency information is stored in the file makeFileName. If the “-f” option is omitted, the default make-file name “makefile” is used. $ make -f main1.make cc -c main1.c cc -c reverse.c cc main1.o reverse.o -o main1 $ _

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone:  A second make file, called “main2.make” main2: main2.o reverse.o palindrome.o cc main2.o reverse.o palindrome.o -o main2 main2.o: main2.c palindrome.h cc -c main2.c reverse.o: reverse.c reverse.h cc -c reverse.c palindrome.o: palindrome.c palindrome.h reverse.h cc -c palindrome.c $ make -f main2.make cc -c main2.c cc -c palindrome.c cc main2.o reverse.o palindrome.o -o main2 $ _

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone:  Make Rules - Note that several of the rules are of the form xxx.o : reverse.c reverse.h cc -c xxx.c where xxx varies between rules. main2:main2.o reverse.o palindrome.o cc main2.o reverse.o palindrome.o -o main2 main2.o:main2.c palindrome.h reverse.o:reverse.c reverse.h palindrome.o:palindrome.c palindrome.h reverse.h

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone:  Make Rules - a sleeker version of “main2.make” main2: main2.o reverse.o palindrome.o cc main2.o reverse.o palindrome.o -o main2 main2.o: palindrome.h reverse.o: reverse.h palindrome.o: palindrome.h reverse.h This makefile uses one of the build-in compilation rules:.c.o: $(CC) $(CFLAGS) $(CPPFLAGS) -c $< $< is a built-in variable whose value is the filename of the dependency (i.e., “main2”, “reverse”, “palindrome”, and so on)

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone: More Advanced Makefile SUPPORT_DIR = /home/whatever CC=gcc CFALGS=-g -Wall -DDEBUG CPPFLAGS = -I $(SUPPORT_DIR) LDFLAGS = -L $(SUPPORT_DIR) LDLIBS =---> none here all:main1 main2 main1:main1.o reverse.o $(CC) $(CFALGS) $(CPPFLAGS) main1.o reverse.o -o main1 $(LDLIBS) main1.o :main1.c reverse.h $(CC) $(CFALGS) $(CPPFLAGS) -c main1.c reverse.o :reverse.c reverse.h $(CC) $(CFALGS) $(CPPFLAGS) -c reverse.c main2:main2.o reverse.o palindrome.o $(CC) $(CFALGS) $(CPPFLAGS) main2.o reverse.o palindrome.o -o main2 main2.o:palindrome.h reverse.o:reverse.h palindrome.o:palindrome.h reverse.h lint : lint $(CPPFLAGS) *.c clean: rm palindrome reverse *.o

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone:  Touch - To confirm that the new version of the make file worked, we executed make and obtained the following output: $ make -f main2.make ‘main2’ is up to date. $ - - make uses the last modification time of all of the named files - compiles those that have time stamps less or equal to the current system time. Utility : touch -c { fileName }+ touch updates the last modification and access times of the named files to the current time.

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone:  Touch - we touched the file “reverse.h”, which subsequently caused the recompilation of several source files: $ touch reverse.h $ make -f main2.make /bin/cc -c -O reverse.c /bin/cc -c -O palindrome.c cc main2.o reverse.o palindrome.o -o main2 $ _

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone:  Touch - To recompile the suite of programs, we can use the touch utility to force recompilation of all of the source files: $ touch *.c---> force make to recompile everything. $ make -f main2.make /bin/cc -c -p main2.c /bin/cc -c -p palindrome.c /bin/cc -c -p reverse.c cc -p main2.o reverse.o palindrome.o -o main2 $ _

make: File Dependency System Prof. Andrzej (AJ) Bieszczad Phone: Better Make Tools gmake –GNU make, from free software foundation –Support for parallel building –More flexibility with macros nmake –From AT&T and Bell Labs –Uses state files instead of time stamps –Dynamic dependency checking Steps can alter dependency graph Includes rules for C header files, several others