The Makefile Utility ABC – Chapter 11, 483-489. Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components.

Slides:



Advertisements
Similar presentations
Makefile Ansuman Banerjee Arijit Bishnu Debapriyo Majumdar Data and File Structures Lab M.Tech. Computer Science 1 st Year, Semester I Indian Statistical.
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.
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.
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.
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.
Makefiles, and.h files, and.c files, and.o files, OH MY! For projects with more complexity. (Great.. Just what we needed)
Unix Makefiles COP 3330 Lecture Notes Dr. David A. Gaitros.
Programming Tools gcc make utility Open Source code Static and Shared Libraries gdb Memory debugging tools.
Makefiles CISC/QCSE 810. BeamApp and Tests in C++ 5 source code files After any modification, changed source needs to be recompiled all object files need.
리눅스 : Lecture 5 UNIX 유틸리티 : text editor, compilation (make), …
Adv. UNIX: large/131 Advanced UNIX v Objectives of these slides: –learn how to write/manage large programs consisting of multiple files, which.
Old Chapter 10: Programming Tools A Developer’s Candy Store.
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.
Homework K&R chapter 4. HW3: ASCII Hex to Integer int axtoi (char s[ ]) { int i, n, flag; n = 0; flag = 1; for ( i = 0; flag; i++) /* for (i = 0; ; i++)
Chapter Ten g++ and make1 System Programming Software Development: g++ and make.
System Programming - LAB 1 Programming Environments.
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.
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.
Tools – Ant-MakeEtc 1 CSCE 747 Fall 2013 CSCE 747 Software Testing and Quality Assurance Tools 12 – Hamcrest 10/02/
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.
Lecture 8  make. Using make for compilation  With medium to large software projects containing many files, it’s difficult to: Type commands to compile.
Make: File Dependency System Lecturer: Prof. Andrzej (AJ) Bieszczad Phone: “UNIX for Programmers and Users” Third.
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.
Makefiles & Project 1 Q&A Recitation Staff.
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
Lecture 1: Introduction UNIX programming environment –Editors –Remote shell setup –C compilers –Debugger –make.
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)
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.
Makefiles Caryl Rahn.
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
Makefiles and the make utility
Rake 4-Dec-18.
CMPSC 60: Week 4 Discussion
CMSC 202 Additional Lecture – Makefiles
C Programming Basic – week 9
Build Tools (make) CSE 333 Autumn 2018
Makefiles and the make utility
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)
Presentation transcript:

The Makefile Utility ABC – Chapter 11,

Motivation Small programs single file “Not so small” programs : –Many lines of code –Multiple components –More than one programmer

Motivation – continued Problems: –Long files are harder to manage (for both programmers and machines) –Every change requires long compilation –Many programmers cannot modify the same file simultaneously

Motivation – continued Solution : divide project to multiple files Targets: –Good division to components –Minimum compilation when something is changed –Easy maintenance of project structure, dependencies and creation

Project maintenance Done in Unix by the Makefile mechanism A makefile is a file (script) containing : –Project structure (files, dependencies) –Instructions for files creation The make command reads a makefile, understands the project structure and makes up the executable Note that the Makefile mechanism is not limited to C programs

Project structure Project structure and dependencies can be represented as a DAG (= Directed Acyclic Graph) Example : –Program contains 3 files –main.c., sum.c, sum.h –sum.h included in both.c files –Executable should be the file sum

sum (exe) sum.o main.o sum.csum.h main.c

makefile sum: main.o sum.o gcc –o sum main.o sum.o main.o: main.c sum.h gcc –c main.c sum.o: sum.c sum.h gcc –c sum.c

Rule syntax main.o: main.c sum.h gcc –c main.c tab dependency action Rule

Equivalent makefiles.o depends (by default) on corresponding.c file. Therefore, equivalent makefile is : sum: main.o sum.o gcc –o sum main.o sum.o main.o: sum.h gcc –c main.c sum.o: sum.h gcc –c sum.c

Equivalent makefiles - continued We can compress identical dependencies and use built-in macros to get another (shorter) equivalent makefile : sum: main.o sum.o gcc –o main.o sum.o main.o sum.o: sum.h gcc –c $*.c

make operation Project dependencies tree is constructed Target of first rule should be created We go down the tree to see if there is a target that should be recreated. This is required when the target file is older than one of its dependencies In this case we recreate the target file according to the action specified, on our way up the tree. Consequently, more files may need to be recreated If something was changed, linking is performed

make operation - continued make operation ensures minimum compilation, when the project structure is written properly Do not write something like: prog: main.c sum1.c sum2.c gcc –o prog main.c sum1.c sum2.c which requires compilation of all project when something is changed

Make operation - example File Last Modified sum 10:03 main.o09:56 sum.o 09:35 main.c 10:45 sum.c 09:14 sum.h 08:39

Make operation - example Operations performed: gcc –c main.c gcc –o sum main.o sum.o main.o should be recompiled (main.c is newer). Consequently, main.o is newer than sum and therefore sum should be recreated (by re-linking).

Useful gcc Options Include: -I Define: -D Optimization: -O Example: gcc –DDEBUG –O2 –I/usr/include example.c –o example -lm

Another makefile example # Makefile to compare sorting routines BASE = /home/blufox/base CC = gcc CFLAGS = -O –Wall EFILE = $(BASE)/bin/compare_sorts INCLS = -I$(LOC)/include LIBS = $(LOC)/lib/g_lib.a \ $(LOC)/lib/h_lib.a LOC = /usr/local OBJS = main.o another_qsort.o chk_order.o \ compare.o quicksort.o $(EFILE): “linking $(CFLAGS) –o $(OBJS) $(LIBS) $(OBJS): compare_sorts.h $(CC) $(CFLAGS) $(INCLS) –c $*.c # Clean intermediate files clean: rm *~ $(OBJS)

Example - continued We can define multiple targets in a makefile Target clean – has an empty set of dependencies. Used to clean intermediate files. make –Will create the compare_sorts executable make clean –Will remove intermediate files

Reference Good tutorial for makefiles make.html