Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha

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.
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.
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.
Introduction to Make Updated by Prasad Spring 2000.
Guide To UNIX Using Linux Third Edition
2000 Copyrights, Danielle S. Lahmani UNIX Tools G , Fall 2000 Danielle S. Lahmani Lecture 9.
CS465 - Unix C Programming (cc/make and configuration control)
Lecture 8  make. Overview: Development process  Creation of source files (.c,.h,.cpp)  Compilation (e.g. *.c  *.o) and linking  Running and testing.
1 Introduction to Tool chains. 2 Tool chain for the Sitara Family (but it is true for other ARM based devices as well) A tool chain is a collection of.
Make: the good, the bad, and the ugly Dan Berger Titus Winters
July 29, 2003Serguei Mokhov, 1 Makefile Brief Reference COMP 229, 346, 444, 5201 Revision 1.2 Date: July 18, 2004.
Jump to first page (C) 1998, Arun Lakhotia 1 Software Configuration Management: Build Control Arun Lakhotia University of Southwestern Louisiana Po Box.
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.
The LC-3 – Chapter 7 COMP 2620 Dr. James Money COMP
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.
Makefiles. Multiple Source Files (1) u Obviously, large programs are not going to be contained within single files. u C provides several techniques to.
CSE 251 Dr. Charles B. Owen Programming in C1 Compilation and Makefiles.
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.
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.
Problem Solving With C++ Recitation – make February 2016.
Multiple File Compilation and linking By Bhumik Sapara.
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.
LECTURE 3 Translation. PROCESS MEMORY There are four general areas of memory in a process. The text area contains the instructions for the application.
Makefiles Manolis Koubarakis Data Structures and Programming Techniques 1.
Makefiles CSSE 332 Operating Systems
Lecture 3 Translation.
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
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2017
Computer Science 210 Computer Organization
Brief Intro to Make CST494/ Gannod.
Makefiles Caryl Rahn.
SCMP Special Topic: Software Development Spring 2017 James Skon
Computer Science 210 Computer Organization
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
Makefiles and the make utility
Makefiles and Notes on Programming Assignment PA2
USER CENTRIC VIEW AND SYSTEM CENTRIC VIEW OF SYSTEM SOFTWARE
Computer Science 210 Computer Organization
Data Structures and Programming Techniques
Kyle Fitzpatrick Konstantin Zak 11/29/2004
SCMP Software Development Spring 2018 James Skon
Stata Basic Course Lab 2.
Writing Large Programs
Build Tools (make) CSE 333 Autumn 2018
CSc 352: Elementary “make”
GNU Make.
CSc 352 An Introduction to make
Makefiles and the make utility
Compiler vs linker The compiler translates one .c file into a .o file
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:

Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha Makefile Tutorial CIS5027 Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha

What’s make? A utility that automatically builds executable programs and libraries from source code by reading files called makefile which specify how to derive the target program. Make allows you to manage large programs and keep track of which portion of the entire program have been changed. Makefile tells make how to generate an execution file make executes commands in the makefile to update one or more target names, where name is typically a program. If no -f option is present, make will look for the makefiles GNUmakefile,makefile, and Makefile, in that order. The purpose of the make utility is to determine automatically which pieces of a large program need to be recompiled, and issue the commands to recompile them. The manual describes the GNU implementation of make, which was written by Richard Stallman and Roland McGrath. Our examples show C programs, since they are most common, but you can use make with any programming language whose compiler can be run with a shell command. In fact, make is not limited to programs. You can use it to describe any task where some files must be updated automatically from others whenever the others change. To prepare to use make, you must write a file called the makefile that describes the relationships among files in your program, and the states the commands for updating each file. In a program, typically the executable file is updated from object files, which are in turn made by compiling source files. Once a suitable makefile exists, each time you change some source files, this simple shell command: make ``When should I use a Makefile?'' When there is more than one file to handle. If the code is expected to be built on different machines. There are special handling steps. If you consider your time to be valuable. If you expect to rebuild your executable at some later point - the Makefile retains the memory of the needed steps. make make –f MyMakefile

Compiling by hand Build Process Files: main.c foo1.c foo2.c gcc main.c foo1.c foo2.c –o main gcc main.c foo1.c foo2.c –c gcc main.o foo1.o foo2.o –o main With make and makefile, you only need to type -c Compile and assemble, but do not link -o <file> Place the output into <file> -Wa,<options> Pass comma-separated <options> on to the assembler GCC: GNU Compiler Collection Referrers to all the different languages that are supported by the GNU compiler. gcc: GNU C      Compiler g++: GNU C++ Compiler The main differences: gcc will compile: *.c/*.cpp files as C and C++ respectively. g++ will compile: *.c/*.cpp files but they will all be treated as C++ files. Also if you use g++ to link the object files it automatically links in the std C++ libraries (gcc does not do this). gcc compiling C files has less predefined macros. gcc compiling *.cpp and g++ compiling *.c/*.cpp files has a few extra macros. make

Makefile Format Target: The file we want to create Dependencies: Check before creating the target file Commands: Consider as shell script. Target : dependencies <Tab> system commands If there are no dependencies for target, make will safely executes the system commands specified.

Dependency graph Four entries appear in the file. Each contains a dependency line that shows how a file is built. Thus the first line says that project1 (the name before the colon) is built from the two object files main.o and io.o (the names after the colon). What this line tells make is that it should execute the following gcc line whenever one of those object files change. The lines containing commands have to begin with tabs (not spaces). It doesn't matter what order the three entries are within the makefile. make figures out which files depend on which and executes all the commands in the right order.

First Makefile make gcc main.c –c gcc foo1.c –c gcc main.o fool.o –o main

Change one source file touch foo1.c make gcc foo1.c –c gcc main.o fool.o –o main Changes the date/time stamp of the file filename to the current time.

Variables $(VAR) or ${VAR} For example Targets = foo ${Targets}: common.h gcc –o ${Targets} foo.c foo: common.h gcc –o foo foo.c You can also use variables when writing Makefiles. It comes in handy in situations where you want to change the compiler, or the compiler options. When people use a filename or other string more than once in a makefile, they tend to assign it to a macro. That's simply a string that make expands to another string.

Difference between :=, = and += x = foo y = $(x) bar x = xyz # The value of y would be xyz bar x := foo y := $(x) bar x := xyz # The value of y would be foo bar In short, variables defined with := are expanded once, but variables defined with = are expanded whenever they are used. += adds the option –Wall to CFLAGS CFLAGS= -c CFLAGS+= -Wall

Makefile Example

Makefile Tutorial Make manual 8 functions for transforming text http://www.gnu.org/software/make/manual/make.html 8 functions for transforming text http://www.gnu.org/software/make/manual/html_node/Functions.html Functions allow you to do text processing in the makefile to compute the files to operate on or the commands to use in recipes. You use a function in a function call, where you give the name of the function and some text (the arguments) for the function to operate on. The result of the function's processing is substituted into the makefile at the point of the call, just as a variable might be substituted.