Lecture 8  make. Using make for compilation  With medium to large software projects containing many files, it’s difficult to: Type commands to compile.

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.
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.
1 The Makefile Utility ABC – Chapter 11,
Systems Dev. Tutorial II: Make, utilities, & scripting Recitation Wednesday, Sept 13 th, 2006.
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
Basic linux shell commands and Makefiles. Log on to engsoft.rutgers.edu Open SSH Secure Shell – Quick Connect Hostname: engsoft.rutgers.edu Username/password:
Introduction to Make Updated by Prasad Spring 2000.
The Makefile Utility ABC – Chapter 11, Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.
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.
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.
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.
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.
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.
Object Oriented Programming COP3330 / CGS5409.  Assignment Submission Overview  Compiling with g++  Using Makefiles  Misc. Review.
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.
Multiple File Compilation and linking By Bhumik Sapara.
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.
Object Oriented Programming COP3330 / CGS5409.  Compiling with g++  Using Makefiles  Debugging.
Brandon Packard. Why make? So far, you have probably worked on relatively small projects Coding projects can become huge My research consists of 1600.
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.
Object Oriented Programming COP3330 / CGS5409.  Assignment Submission Overview  Compiling with g++  Using Makefiles  Misc. Review.
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
Makefiles CSSE 332 Operating Systems
The make utility (original presentation courtesy of Alark Joshi)
CSE 303 Lecture 17 Makefiles reading: Programming in C Ch. 15
Brief Intro to Make CST494/ Gannod.
Compilation and Debugging
Compilation and Debugging
Large Program Management: Make; Ant
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: Samira Pouyanfar Hector Cen Fall 2017
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
CMPSC 60: Week 4 Discussion
CMSC 202 Additional Lecture – Makefiles
SCMP Software Development Spring 2018 James Skon
Large Program Management: Make; Ant
CSc 352: Elementary “make”
Large Program Management: Make; Ant
Makefiles and the make utility
CSE 390 Lecture 8 Large Program Management: Make; Ant
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.
g++ features, better makefiles
The make utility (original presentation courtesy of Alark Joshi)
Presentation transcript:

Lecture 8  make

Using make for compilation  With medium to large software projects containing many files, it’s difficult to: Type commands to compile all the files correctly each time Type commands to compile all the files correctly each time Keep track of which files have been changed Keep track of which files have been changed Keep track of files’ dependencies on other files Keep track of files’ dependencies on other files  The make utility automates this process

How make works  Reads a file called [Mm]akefile, which contains rules for building a “target”  If the target depends on a file, then that file is built If that file depends on a third file, then the third file is built, and so on… If that file depends on a third file, then the third file is built, and so on… Works backward through the chain of dependencies Works backward through the chain of dependencies  Targets only built if they are older than the files they depend on

Types of lines in Makefiles  Dependency or rules lines  Commands  Macro assignments  Comments

Dependency/rules lines  Specify a target and a list of prerequisites (optional) for that target target : prereq1 prereq2 prereq3 …

Command lines  Follow dependency lines  MUST start with a TAB!  Any command that can be run in the shell can be placed here target : prereq1 prereq2 command1command2  Special variables in commands: represents the target represents the target $? represents prereqs that are newer than target $? represents prereqs that are newer than target

Simplified Makefile example program : main.o iodat.o dorun.o g++ -o main.o iodat.o dorun.o main.o : main.cc g++ -c $? iodat.o : iodat.cc g++ -c $? dorun.o : $? g++ -c dorun.cc

Macro (variable) assignments  You can use macros to represent text in a Makefile Saves typing Saves typing Allows you to easily change the action of the Makefile Allows you to easily change the action of the Makefile  Assignment: MACRONAME = macro value  Usage: ${MACRONAME}

Simplified Example Makefile with macros OBJS = main.o iodat.o dorun.o CC = /usr/bin/g++ program : ${OBJS} ${CC} -o ${OBJS} main.o : main.cpp ${CC} -c $? iodat.o : iodat.cpp ${CC} -c $? ${CC} -c $? dorun.o : dorun.cpp ${CC} -c $? ${CC} -c $?

Comments and other Makefile notes  Comments begin with a ‘#’  Lines that are too long can be continued on the next line by placing a ‘\’ at the end of the first line

Invoking make  Be sure that your description file: is called makefile or Makefile is called makefile or Makefile is in the directory with the source files (to simplify) is in the directory with the source files (to simplify)  make (builds the first target in the file)  make target(s) (builds target(s))  Important options: -n : don’t run the commands, just list them -n : don’t run the commands, just list them -f file : use file instead of [Mm]akefile -f file : use file instead of [Mm]akefile

Other useful Makefile tips  Include a way to clean up your mess: %make clean No dependencies! No dependencies!clean: /bin/rm -f *.o core

Makefile example b : c d rm echo $? > a : c rm echo $? > target : a b rm echo $? > cat $? >> all : a b c d target start : rm `ls | egrep –v ‘\ ’` ; echo D > d ; echo C > c echo B > b ; echo A > a ; echo Target > target