CMSC 341 Makefile Review. 1 Make Overview make is a program that automates the compilation of programs whose files are dependent on each other A program.

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.
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.
Understanding Makefiles COMP 2400, Fall 2008 Prof. Chris GauthierDickey.
1 CSE 390 Lecture 8 Large Program Management: Make; Ant slides created by Marty Stepp, modified by Josh Goodwin
1 The Makefile Utility ABC – Chapter 11,
Declarative Languages. Declarative languages In an imperative programming language, a program specifies how to solve a problem In a declarative language,
CS 211 Recitation 1 TA: Ishani Chakraborty. Admin stuff Office hours: 5:00-6:00 pm, Tuesdays at Core.
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
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.
Guide To UNIX Using Linux Third Edition
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.
Other Features Index and table of contents Macros and VBA.
C++ / G4MICE Course Session 3 Introduction to Classes Pointers and References Makefiles Standard Template Library.
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.
Introduction Use of makefiles to manage the build process Declarative, imperative and relational rules Environment variables, phony targets, automatic.
The Structure of a C++ Program. Outline 1. Separate Compilation 2. The # Preprocessor 3. Declarations and Definitions 4. Organizing Decls & Defs into.
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.
July 2011CMSC 341 CVS/Ant 1 CMSC 341 Java Packages Ant CVS Project Submission.
Chapter 13. Procedural programming vs OOP  Procedural programming focuses on accomplishing tasks (“verbs” are important).  Object-oriented programming.
Copyright © Curt Hill Generic Classes Template Classes or Container Classes.
C Tutorial - Program Organization CS Introduction to Operating Systems.
ADTs and C++ Classes Classes and Members Constructors The header file and the implementation file Classes and Parameters Operator Overloading.
1 CSE 390 Lecture 8 Large Program Management: Make; Ant slides created by Marty Stepp, modified by Jessica Miller and Ruth Anderson
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.
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
Separate Compilation make and makefiles
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 7: Macros in SAS  Macros provide for more flexible programming in SAS  Macros make SAS more “object-oriented”, like R 1 © Fall 2011 John Grego.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
Modular Programming. Introduction As programs grow larger and larger, it is more desirable to split them into sections or modules. C allows programs to.
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.
Problem Solving With C++ Recitation – make February 2016.
Multiple File Compilation and linking By Bhumik Sapara.
Brandon Packard. Why make? So far, you have probably worked on relatively small projects Coding projects can become huge My research consists of 1600.
L071 Introduction to C Topics Compilation Using the gcc Compiler The Anatomy of a C Program Reading Sections
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.
Large Program Management: Make; Ant
Makefiles Caryl Rahn.
Introduction to C Topics Compilation Using the gcc Compiler
Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Hector Cen Fall 2017
Chapter 7: Macros in SAS Macros provide for more flexible programming in SAS Macros make SAS more “object-oriented”, like R Not a strong suit of text ©
Large Program Management: Make; Ant
Makefiles and the make utility
Large Program Management: Make; Ant
Data Structures and Programming Techniques
CSE 390 Lecture 8 Large Program Management: Make; Ant
CMSC 202 Additional Lecture – Makefiles
Large Program Management: Make; Ant
CSCE-221 Makefile Introduction
CSc 352: Elementary “make”
Large Program Management: Make; Ant
Large Program Management: Make; Ant
Makefiles and the make utility
Compiler vs linker The compiler translates one .c file into a .o file
CSE 390 Lecture 8 Large Program Management: Make; Ant
Large Program Management: Make; Ant
The make utility (original presentation courtesy of Alark Joshi)
Presentation transcript:

CMSC 341 Makefile Review

1 Make Overview make is a program that automates the compilation of programs whose files are dependent on each other A program typically consists of several files, and a programmer usually only works on a few of them at a time –Typically vast majority of files remain unchanged and thus do not need to be recompiled

2 Make Overview make will only recompile the files that need to be updated (files that depend on modified files), which is much faster than simply recompiling the whole program each time make looks at the timestamps of source files (*.C, *.H) that are required to generate an object file (*.o) –If a source is newer then the object file, the object file needs to be recompiled –Likewise if an object file is newer than the executable it needs to be re-linked

3 Makefile Structure A makefile is a list of rules of what files are required to generate an object or an executable file –File typically called makefile or Makefile Each rule consists of 4 parts: –Target: the name of the object or executable to create –Dependency List: the list of files that the target is dependent upon –TAB: used to set off an action –Action(s): a list of actions to take in order to create the target (i.e. g++ …)

4 Makefile Rule Foobar.o: Foobar.C Foobar.H g++ -ansi -Wall -c Foobar.C Target The file to create. In this case an object file: Foobar.o Dependency List The files that are required to create the object file. In this case Foobar.C and Foobar.H Used to signal what follows as an action Action(s) What needs to be done to create the target. In this case it is the separate compilation of Foobar.C

5 A simple makefile Project1: Project1.o Inventory.o Cd.o Date.o g++ -ansi -Wall -o proj1 Project1.o Inventory.o Cd.o Date.o Project1.o: Project1.c Inventory.h g++ -ansi -Wall -c Project1.c Inventory.o: Inventory.c Inventory.h Cd.h g++ -ansi -Wall -c Inventory.c Cd.o: Cd.c Cd.h Date.h g++ -ansi -Wall -c Cd.c Date.o: Date.c Date.h g++ -ansi -Wall -c Date.c

6 Target Specification You can automatically create any of the targets by typing make If you omit a target as a parameter to make, it assumes that you want the first target in the makefile –This target is known as the default target and is almost always the name of the executable that you want to create

7 Dependency Graph Discussed in class

8 Makefile Macros Similar to a #define or alias – use when you need the same thing over and over Syntax to define macro is: – MACRO_NAME = content to be substituted for MACRO_NAME Benefits: easy to make changes – simply change in 1 place rather than on all targets, etc… DIR1 = /afs/umbc.edu/users/y/p/ypeng/pub/CMSC341/Proj1/ PROJ = Proj1 CC = g++ CCFLAGS = -g -ansi -Wall -I. -I $(DIR1) OBJECTS = Project1.o Inventory.o Cd.o Date.o

9 Makefile Macros To access a declared macro simply put the name of the macro inside parenthesis after a dollar sign Syntax to recall macro: –$(MACRO_NAME) Project1: $(OBJECTS) $(CC) $(CCFLAGS) -o $(PROJ).c $(OBJECTS) Project1.o: Project1.c Inventory.h $(CC) $(CCFLAGS) -c Project1.c

10 Phony Targets You can specify targets that do auxiliary tasks and do not actually compile code –Remove object and executable files –Print source code –Submit all code These tasks do not require looking at the timestamps on files and thus it is good practice to let make know that there is no “real” target for a rule, and that it should just execute the action list

11 Phony Targets The syntax is just like any other rule except the rule is proceeds a.PHONY declaration Syntax is:.PHONY: target.PHONY: submit submit: submit cs341 $(PROJ) $(SOURCES) Makefile *.txt.PHONY: print Print: enscript -G2rE $(SOURCES) Makefile *.txt

12 PROJ = Proj1 CC = g++ CCFLAGS = -g -ansi –Wall SOURCES = $(PROJ).c Inventory.h Inventory.c Cd.h Cd.c Date.h Date.c OBJECTS = $(PROJ).o Inventory.o Cd.o Date.o $(PROJ): $OBJECTS $(CC) $(CCFLAGS) -o $(PROJ) $(OBJECTS) $(PROJ).o: $(PROJ).c Inventory.h $(CC) $(CCFLAGS) -c $(PROJ).c Inventory.o: Inventory.c Inventory.h Cd.h $(CC) $(CCFLAGS) -c Inventory.c Cd.o: Cd.c Cd.h Date.h $(CC) $(CCFLAGS) -c Cd.c Date.o: Date.c Date.h $(CC) $(CCFLAGS) -c Date.c.PHONY: submit submit: submit cs341 $(PROJ) $(SOURCES) Makefile *.txt.PHONY: print Print: enscript -G2rE $(SOURCES) Makefile *.txt Advanced Makefile

13 Templates As mentioned in class you should never explicitly compile template classes when using g++ What implications does this have on makefiles? –Do not create a target for a template class You will never make a myTemplateClass.o object file, as template code automatically gets compiled when it is seen declared –Since object files are not created, they do not be listed in the OBJECTS target dependency list –Do list template class files as dependencies for an target (object) when the files that create that target (object) reference them