July 29, 2003Serguei Mokhov, 1 Makefile Brief Reference COMP 229, 346, 444, 5201 Revision 1.2 Date: July 18, 2004.

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.
Binghamton University CS-220 Spring 2015 Binghamton University CS-220 Spring 2015 The CS-220 Development Environment.
Understanding Makefiles COMP 2400, Fall 2008 Prof. Chris GauthierDickey.
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.
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)
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
Computer Literacy BASICS: A Comprehensive Guide to IC 3, 5 th Edition Lesson 3 Windows File Management 1 Morrison / Wells / Ruffolo.
8 Shell Programming Mauro Jaskelioff. Introduction Environment variables –How to use and assign them –Your PATH variable Introduction to shell programming.
Unix Makefiles COP 3330 Lecture Notes Dr. David A. Gaitros.
Week 7 Working with the BASH Shell. Objectives  Redirect the input and output of a command  Identify and manipulate common shell environment variables.
Agenda User Profile File (.profile) –Keyword Shell Variables Linux (Unix) filters –Purpose –Commands: grep, sort, awk cut, tr, wc, spell.
Introduction Use of makefiles to manage the build process Declarative, imperative and relational rules Environment variables, phony targets, automatic.
August 7, 2003Serguei A. Mokhov, 1 gcc Tutorial COMP 444/5201 Revision 1.1 Date: January 25, 2004.
July 17, 2003Serguei A. Mokhov, 1 Shells and Shell Scripts COMP 444/5201 Revision 1.3 January 25, 2005.
Scons Writing Solid Code Overview What is scons? scons Basics Other cools scons stuff Resources.
Introduction to C Programming CE Lecture 7 Compiler options and makefiles.
Chapter 6: User-Defined Functions
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).
Setting up Cygwin Computer Organization I 1 May 2010 ©2010 McQuain Cygwin: getting the setup tool Free, almost complete UNIX environment emulation.
Introduction Copyright © Software Carpentry 2010 This work is licensed under the Creative Commons Attribution License See
What is a port The Ports Collection is essentially a set of Makefiles, patches, and description files placed in /usr/ports. The port includes instructions.
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.
Copyright © 2015 Curt Hill Make An Indispensable Developer’s Tool.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
Functions Math library functions Function definition Function invocation Argument passing Scope of an variable Programming 1 DCT 1033.
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.
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.
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
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.
Linux Administration Working with the BASH Shell.
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
CSE 303 Lecture 17 Makefiles reading: Programming in C Ch. 15
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Fall 2015
Bash Introduction (adapted from chapters 1 and 2 of bash Cookbook by Albing, Vossing, & Newham) CPTE 440 John Beckett.
Brief Intro to Make CST494/ Gannod.
Compilation and Debugging
Compilation and Debugging
Shell Scripting March 1st, 2004 Class Meeting 7.
Makefiles Caryl Rahn.
SCMP Special Topic: Software Development Spring 2017 James Skon
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
User-Defined Functions
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
Data Structures and Programming Techniques
CSE 390 Lecture 8 Large Program Management: Make; Ant
SCMP Software Development Spring 2018 James Skon
Cygwin: getting the setup tool
CSc 352 An Introduction to make
CSE 390 Lecture 8 Large Program Management: Make; Ant
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:

July 29, 2003Serguei Mokhov, 1 Makefile Brief Reference COMP 229, 346, 444, 5201 Revision 1.2 Date: July 18, 2004

July 29, 2003Serguei Mokhov, 2 Contents Intro Format Examples

July 29, 2003Serguei Mokhov, 3 Intro Makefiles in conjunction with the make utility ( man make ) provide a very convenient facility to build, install, and uninstall large (and small too) projects in the *nix systems. Makefiles are text files and similar in a way to the shell scripts, which are interpreted by the make utility.

July 29, 2003Serguei Mokhov, 4 Intro (2) A makefile may have some variables declared for convenience then followed by rules on how to build a given target program. The variable part usually declares variables like which compiler to use across all the targets: –which compiler options to use, –where to look for libraries and include files, etc. The rules specify what's needed to build a specific part and how to do it, using shell commands.

July 29, 2003Serguei Mokhov, 5 Intro (3) The make utility avoids re-bulding targets which are up-to-date, thus, saving typing and compiling time a lot. Makefiles largely similar to the Project and Workspace files you might be used to from Visual C++, JBuilder, Eclipse, etc.

July 29, 2003Serguei Mokhov, 6 Specifying Targets When making all the stuff in your program typing make is enough. In certain cases, the make utility assumes target “ all ”, or most often the first target in the list. If you want to build a specific target just supply it as a parameter to make: make mytarget

July 29, 2003Serguei Mokhov, 7 Filenames When you key in make, the make looks for the default filenames in the current directory. For GNU make these are: –GNUMakefile –makefile –Makefile If there more than one of the above in the current directory, the first one according to the above chosen. It is possible to name the makefile anyway you want, then for make to interpret it: make -f

July 29, 2003Serguei Mokhov, 8 Basic Makefile Format Basic Format Summary: # Comments VAR=value(s) # Actually, it is a macro target: list of prerequisites and dependencies command1 to achieve target using $(VAR) [ command2]

July 29, 2003Serguei Mokhov, 9 Basic Makefile Format (2) Comments –Just like for most shell scripts, they start with ‘ # ’ Variables (make calls them macros) –Are assigned the same way as in bash: var=value –Used as: $(var) –Variables can be scalar as well as lists (‘arrays’)

July 29, 2003Serguei Mokhov, 10 Rules Rule or several of then are needed to direct compilation and building, installation, and clean up actions that depend on certain prerequisites. Basic components of a Rule are –Ultimate target of a rule, the goal –List of dependencies needed to be satisfied before this rule can be executed, the prerequisites –List of actions, or command, that are executed once all prerequisites satisfied to arrive to the target goal.

July 29, 2003Serguei Mokhov, 11 Targets Target name can be almost anything: –just a name –a filename –a variable There can be several targets on the same line if they depend on the same things. A target is followed by –a colon “:” –and then by a list of dependencies, separated by spaced The default target make is looking for is either all or first one in the file. Another common target is clean –Developers supply it to clean up their source tree from temporary files, object modules, etc. –Typical invocation is: make clean You are required to supply another target, called run, so that it makes sure your application is compiled and run just by typing: make run.

July 29, 2003Serguei Mokhov, 12 Dependencies The list of dependencies can be: –Filenames –Other target names –Variables Separated by a space. May be empty; means “build always”. Before the target is built: –it’s checked whether it is up-to-date (in case of files) by comparing time stamp of the target of each dependency; if the target file does not exist, it’s automatically considered “old”. –If there are dependencies that are “newer” then the target, then the target is rebuild; else untouched. –If you want to “renew” the target without actually editing the dependencies, “touch” them with the touch command. –If the dependency is a name of another rule, make descends recursively (may be in parallel) to that rule.

July 29, 2003Serguei Mokhov, 13 Actions A list of actions represents the needed operations to be carried out to arrive to the rule’s target. –May be empty. Every action in a rule is usually a typical shell command you would normally type to do the same thing. Every command MUST be preceded with a tab! –This is how make identifies actions as opposed to variable assignments and targets. Do not indent actions with spaces!

July 29, 2003Serguei Mokhov, 14 Line-Oriented Makefile is a line-oriented file. That means by the end of line a new line starts, it is either a new action or target or whatever. If your list of dependencies or a command are too long and you would like for them to span across several lines for clarity and convenience, you may do so, but you will have to escape the end of line by “\” at the end of each such a line. Make sure not to use tabs for such lines.

July 29, 2003Serguei Mokhov, 15 More Advanced Constructs List/array variables/macros can be assignment via the “ := ” operator. It is possible to use control-flow constructs within the actions part of a rule, such as for, if-then-else, test, etc. The syntax is that of bash. Implicit targets for files of specific extensions. “Macros” and “directives” for conditional variable definitions as well as to include other makefiles. Others... Not part of this “study” yet...

July 29, 2003Serguei Mokhov, 16 Examples Off the website.