Brief Intro to Make CST494/598 -- Gannod.

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.
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.
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,
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:
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.
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.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
Scons Writing Solid Code Overview What is scons? scons Basics Other cools scons stuff Resources.
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).
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.
CSE 251 Dr. Charles B. Owen Programming in C1 Compilation and Makefiles.
Makefiles CARYL RAHN. Separate compilation Large programs are generally separated into multiple files, e.g. main.c addmoney.c removemoney.c money.h With.
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.
Multiple File Compilation and linking By Bhumik Sapara.
An Introduction to the UNIX Make Utility Introduction: Although make can be used in conjunction with most programming languages all examples given here.
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.
CSc 352 An Introduction to make Saumya Debray Dept. of Computer Science The University of Arizona, Tucson
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.
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
Multiple file project management & Makefile
Makefiles CSSE 332 Operating Systems
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
Compilation and Debugging
Compilation and Debugging
Makefiles Caryl Rahn.
SEEM3460 Tutorial The Make Utility.
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
Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
Large Program Management: Make; Ant
Makefiles and the make utility
Makefiles and Notes on Programming Assignment PA2
Data Structures and Programming Techniques
CMPSC 60: Week 4 Discussion
CMSC 202 Additional Lecture – Makefiles
Kyle Fitzpatrick Konstantin Zak 11/29/2004
Large Program Management: Make; Ant
CSc 352: Elementary “make”
Large Program Management: Make; Ant
GNU Make.
Makefiles and the make utility
Compiler vs linker The compiler translates one .c file into a .o file
Makefiles, GDB, Valgrind
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)
Large Program Management: Make, Ant
Presentation transcript:

Brief Intro to Make CST494/598 -- Gannod

Harry Koehnemann, Computing Studies The make utility The make utility is a tool for managing computer projects make uses a descriptor file called a makefile that contains all the dependency information rules for building/creating targets Most often, the makefile tells make how to compile and link a program Harry Koehnemann, Computing Studies

Harry Koehnemann, Computing Studies Makefile rules rules have the following form: target ... : prerequisites ... <tab> command <tab> ... A target is usually the name of a file that is generated by a program A prerequisite is a file that is used as input to create the target A command is an action that make carries out Harry Koehnemann, Computing Studies

Harry Koehnemann, Computing Studies Prerequisites A normal prerequisite says 2 things: order of execution of build commands: any commands necessary to build any of a target's prerequisites will be fully executed before any commands necessary to build the target. dependency relationship: if any prerequisite is newer than the target, then the target is considered out-of-date and must be rebuilt. Harry Koehnemann, Computing Studies

Harry Koehnemann, Computing Studies Simple Example prog1 : file1.o file2.o file3.o  CC -o prog1 file1.o file2.o file3.o  file1.o : file1.cc mydefs.h  CC -c file1.cc  file2.o : file2.cc mydefs.h  CC -c file2.cc  file3.o : file3.cc  CC -c file3.cc  Harry Koehnemann, Computing Studies

Harry Koehnemann, Computing Studies Phony Targets Phony targets allow “scripts” to be included in a makefile. .PHONY tells Make which targets are not files. This avoids conflict with files of the same name, and improves performance. If a phony target is included as a prerequisite for another target, it will be run every time that other target is required. Phony targets are never up-to-date. Harry Koehnemann, Computing Studies

Harry Koehnemann, Computing Studies Example # Naming our phony targets .PHONY: clean install # Removing the executable and the object files clean: rm sample main.o example.o echo clean: make complete # Installing the final product install: cp sample /usr/local echo install: make complete Harry Koehnemann, Computing Studies

Harry Koehnemann, Computing Studies Makefile variables The syntax for declaring and setting a makefile variable is varname = variable contents To call the variable, use $(varname). # Defining the object files OBJ = main.o example.o # Linking object files sample: $(OBJ) cc -o sample $(OBJ) Harry Koehnemann, Computing Studies

Predefined make variables CC Compiler, defaults to cc. CFLAGS Passed to $(CC) LD Loader, defaults to ld LDFLAGS Passed to $(LD) $@ Full name of the current target. $? Files for current dependency which are out-of-date $< The source file of the current (single) dependency http://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html Harry Koehnemann, Computing Studies

Harry Koehnemann, Computing Studies Variable example # Basic Makefile with variables CC = g++ CFLAGS = -Wall -O2 COMPILE = $(CC) $(CFLAGS) -c all: myprog myprog: main.o file.o $(CC) -o myprog main.o file.o main.o: main.cpp $(COMPILE) -o main.o main.cpp file.o: file.cpp $(COMPILE) -o file.o file.cpp Harry Koehnemann, Computing Studies

Harry Koehnemann, Computing Studies Predefined Rules some common rules are built into make. for example, make knows that in order to create a .o file, it must use $(CC) -c on the corresponding .c file OBJECTS = data.o main.o io.o project1: $(OBJECTS) cc $(OBJECTS) -o project1 data.o: data.h main.o: data.h io.h io.o: io.h Harry Koehnemann, Computing Studies

Harry Koehnemann, Computing Studies Multiple targets you can put more than one file in the target section of the dependency rules CFLAGS = -Aa -D_HPUX_SOURCE OBJECTS = data.o main.o io.o project1: $(OBJECTS) cc $(OBJECTS) -o project1 data.o main.o: data.h io.o main.o: io.h Harry Koehnemann, Computing Studies

Harry Koehnemann, Computing Studies Pattern Rules A pattern rule is a concise way of specifying a rule for many files at once. You specify a pattern by using the % wildcard The following pattern rule will take any .c file and compile it into a .o file: Rule can be overridden in makefile %.o: %.c $(CC) $(CFLAGS) $(INCLUDES) -c <input> -o <output> Harry Koehnemann, Computing Studies

Another Variable Example # Variables only – uses defaults! CC=gcc CFLAGS=-O0 LDFLAGS=-s -L /usr/lib -- assume nothing up-to-date $ make SocketExample.o gcc -O0 -c -o SocketExample.o SocketExample.c $ make SocketExample gcc -O0 -s -L . SocketExample.c -o SocketExample Harry Koehnemann, Computing Studies

Interesting Make Arguments -d print debug information -f <file> use <file> instead of {mM}akefile -n list what would be made; do not execute -t ‘touch’ files to make them up-to-date; do not execute -e env variables override makefile variables Harry Koehnemann, Computing Studies

Harry Koehnemann, Computing Studies References GNU make http://www.gnu.org/software/make/manual/html_node/ http://www.eng.hawaii.edu/Tutor/Make/index.html http://www.delorie.com/gnu/docs/make/make.html#SEC_Top http://www.linuxdevcenter.com/pub/a/linux/2002/01/31/make_intro.html http://www.metalshell.com/view/tutorial/120/ http://makepp.sourceforge.net/1.18/t_index.html Harry Koehnemann, Computing Studies