Data Structures and Programming Techniques

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

The make Utility Programming Tools and Environments Winter 2006.
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.
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.
Systems Dev. Tutorial II: Make, utilities, & scripting Recitation Wednesday, Sept 13 th, 2006.
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.
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:
Guide To UNIX Using Linux Third Edition
CS465 - Unix C Programming (cc/make and configuration control)
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.
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.
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.
Linux Operations and Administration
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).
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.
Program in Multiple Files. l all C++ statements are divided into executable and non-executable l executable - some corresponding machine code is generated.
Emacs, Compilation, and Makefile C151 Multi-User Operating Systems.
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.
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).
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
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
Brief Intro to Make CST494/ Gannod.
Makefiles Caryl Rahn.
SEEM3460 Tutorial The Make Utility.
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
Topics Introduction to File Input and Output
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Makefiles and the make utility
Makefiles and Notes on Programming Assignment PA2
Rake 4-Dec-18.
Kyle Fitzpatrick Konstantin Zak 11/29/2004
SCMP Software Development Spring 2018 James Skon
Writing Large Programs
CSc 352: Elementary “make”
GNU Make.
CSc 352 An Introduction to make
Homework K&R chapter 4.
Makefiles and the make utility
Compiler vs linker The compiler translates one .c file into a .o file
Topics Introduction to File Input and Output
SCMP Software Development Spring 2018 James Skon
SPL – PS1 Introduction to C++.
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:

Data Structures and Programming Techniques Makefiles Manolis Koubarakis Data Structures and Programming Techniques

Data Structures and Programming Techniques The Utility make The make utility automatically determines which pieces of a large program need to be recompiled, and issues commands to recompile them. It is useful when we write large programs that are contained in more than one file. Data Structures and Programming Techniques

Preparing and Running make In order to use make, you should create a file named Makefile. This file describes the relationships among files in your program and provides commands for updating each file. In a program, typically, the executable file is updated from object files, which in turn are made by compiling source files. Once a suitable makefile exists, each time you change some source files, the simple shell command make suffices to perform all necessary recompilations. The make program uses the makefile in the current directory and the last-modification times of the files to decide which of the files need to be updated. For each of those files, it issues the recipes recorded in the makefile. Data Structures and Programming Techniques

Data Structures and Programming Techniques Rules A simple makefile consists of rules with the following syntax: target … : prerequisites … recipe … A target or a goal is usually the name of a file that is generated by a program. Examples of targets are executable or object files. A target can also be the name of an action to carry out, such as ‘clean’. A prerequisite is a file that is used as input to create the target. A target often depends on several files. A recipe is an action that make carries out. A recipe may have more than one command. Prerequisites are optional. For example, the rule containing the delete command associated with the target ‘clean’ does not have prerequisites. A rule explains how and when to remake certain files which are the targets of the particular rule. make carries out the recipe on the prerequisites to create or update the target. Data Structures and Programming Techniques

Data Structures and Programming Techniques Example pqsort : sorting.o PQImplementation.o gcc sorting.o PQImplementation.o -o pqsort sorting.o :sorting.c PQInterface.h PQTypes.h gcc -c sorting.c PQImplementation.o :PQImplementation.c PQInterface.h PQTypes.h gcc -c PQImplementation.c clean: rm pqsort sorting.o PQImplementation.o Mind the tabs!!! Data Structures and Programming Techniques

Data Structures and Programming Techniques Comments In this example makefile, the targets include the executable file pqsort, and the object files sorting.o and PQImplementation.o. The prerequisites are files such as sorting.c and PQInterface.h and PQTypes.h Recipes include commands like gcc -c sorting.c and gcc -c PQImplementation.c A recipe may follow each line that contains a target and prerequisites. These recipes say how to update the target file. Important: A tab character must come at the beginning of every line that contains a recipe to distinguish recipes from other lines in the makefile. The target clean is not a file, but merely the name of an action. Notice that clean is not a prerequisite of any other rule. Consequently, make never does anything with it unless you tell it specifically. Note also that the rule for clean does not have any prerequisites, so the only purpose of the rule is to run the specified recipe. Targets that do not refer to files but are just actions are called phony targets. Data Structures and Programming Techniques

Data Structures and Programming Techniques How make is invoked For the previous example, after some of the source .c files have changed, and we would like to create a new executable, we just write make on the command line. Data Structures and Programming Techniques

How make Processes a Makefile When make is called, it reads the makefile in the current directory and starts processing the first rule of the makefile. In our case, this is the rule for the executable file pqsort. However, before make can process this rule, it should process the rules that update the files on which pqsort depends i.e., sorting.o and PQImplementation.o. These in turn depend on files such as sorting.c, PQInterface.h and PQTypes.h which are not the targets of any rule so the recursion stops here. Data Structures and Programming Techniques

Data Structures and Programming Techniques Variables Variables allow a text string to be defined once and substituted in multiple places later. For example, it is standard practice for every makefile to have a variable named objects, which is defined to be a list of all object file names. We can define this variable by writing objects=sorting.o PQImplementation.o Then the variable can be used in the makefile using the notation $(variable). Data Structures and Programming Techniques

Data Structures and Programming Techniques Example (cont’d) objects=sorting.o PQImplementation.o pqsort : $(objects) gcc $(objects) -o pqsort sorting.o :sorting.c PQInterface.h PQTypes.h gcc -c sorting.c PQImplementation.o :PQImplementation.c PQInterface.h PQTypes.h gcc -c PQImplementation.c clean: rm pqsort $(objects) Data Structures and Programming Techniques

Letting make Deduce the Recipes It is not necessary to spell out the recipes for compiling the individual C source files, because make can figure them out. make has an implicit rule for updating a .o file from a correspondingly named .c file using a cc -c command (not gcc). So we can write our example as follows. Data Structures and Programming Techniques

Data Structures and Programming Techniques Example (cont’d) objects=sorting.o PQImplementation.o pqsort : $(objects) gcc $(objects) -o pqsort sorting.o : PQInterface.h PQTypes.h PQImplementation.o : PQInterface.h PQTypes.h clean: rm pqsort $(objects) Data Structures and Programming Techniques

Rules for Cleaning the Directory We can use makefiles to do other things except compiling programs. For example, we can have a recipe that deletes all the object files and executables so that the directory is clean. In our example, this is done by the following rule: clean: rm pqsort $(objects) clean here is called a phony target. To avoid problems with files with the name clean in the same directory, you can write the above rule as follows: .PHONY clean Data Structures and Programming Techniques

Rules for Cleaning the Directory (cont’d) You can execute the above rule by executing the shell command make clean Data Structures and Programming Techniques

Data Structures and Programming Techniques Readings These slides were created by copying (sometimes verbatim!) material from the manual http://www.gnu.org/software/make/manual/make.html . Read this manual for more information (just reading Chapter 2 will suffice). Data Structures and Programming Techniques