SlideShare ist ein Scribd-Unternehmen logo
1 von 21
Downloaden Sie, um offline zu lesen
Introduction Compiling Makefiles Example Extras




                                Making makefiles
                                  Tutorial for CS-2810


                                       Subhashini V

                                          IIT Madras




                                  Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras



Outline
   Introduction
       Motivation
   Compiling
     Object file
   Makefiles
     Macros
     Naming
     Phony-Targets
   Example
   Extras
      Default-rules
      Remarks

                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Motivation




         The why, what and how of makefiles for you and me.




                                        Figure: xkcd


                (comic is for sudo, but who cares, it has ‘make’)


                                  Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Motivation



Why makefiles?




         Lots of source files: foo1.h, foo2.h, foobar1.cpp, foobar2.cpp
         How to manage them all?
         Compiling is complicated!!!




                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Motivation



Why makefiles?




         Lots of source files: foo1.h, foo2.h, foobar1.cpp, foobar2.cpp
         How to manage them all?
         Compiling is complicated!!!
         Solution: make




                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Motivation



What are makefiles?




         make - automagically build and manage your programs.
         compile quickly with a single command
         recompile is even quicker




                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Motivation



How does it work?



         Give targets (usually a file to be created)
         Specify dependencies for each target.
         Give command to create target from dependencies.
         ‘make’ recursively builds the targets from the set of
         dependencies.
         recompilation - time-stamp of modification




                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Object file



.h and .cpp



   .h files contain
         declarations.
         functions that the class promises.
   .cpp files contain
         definitions
         implementations of the promised methods.
         other functions that are not a part of any class.




                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Object file



BigInt assignment example




   The BigInt data type in RSA
         BigInt.h - with proposed methods : +, -, *, /, !
         BigInt.cpp - with implementation of methods
         rsa.cpp - ONLY needs #include “BigInt.h”.
         Don’t need BigInt.cpp.




                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Object file



Creating Object file

   object file or (.o file)
         For creating rsa.o, no need to include BigInt.cpp!
         Eventually need BigInt.cpp for running.
         Link later.
         You also don’t need main()
   Command:

         g++ -Wall -c rsa.cpp

     * -Wall : all warnings turned on
     * -c : Compiles but doesn’t link



                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Macros Naming Phony-Targets



Makefiles!
   A makefile describes the dependencies between files.




                               Figure: Content of a Makefile


                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Macros Naming Phony-Targets



Targets, Dependencies, Commands




         Target is usually a file. Remember “:”
         Dependencies : .cpp, corresponding .h and other .h files
         Determining dependencies.
         the all important [tab]
         Commands : can be multiple




                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Macros Naming Phony-Targets



Use macros!

   Like #define

   OBJS = rsa.o main.o
   CPP = g++
   DEBUG = -g
   CPPFLAGS = -Wall -c $(DEBUG)
   LDFLAGS = -lm

   Usage: $(variable)
   rsa : $(OBJS)
             $(CPP) $(LDFLAGS) $(OBJS) -o rsa
         Automatic variables : $@ , $<, $^ ...



                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Macros Naming Phony-Targets



Naming the file



   Naming and running the make file.
         makefile - run with make
         Makefile - run with make
         give any filename - run as make -f < filename >
   make picks the first target in the file and executes the commands
   if the dependencies are more recent than the target.




                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras    Macros Naming Phony-Targets



Phony targets


   Dummy targets to run commands. They don’t actually create files.
         make all
         make clean
         make tar
   Use .PHONY or directly the name.

.PHONY: clean
                                                    Or           clean:
clean:
                                                                      rm -f *.o *~ rsa
     rm -f *.o *~ rsa




                                     Subhashini V    Tutorial on make
Introduction Compiling Makefiles Example Extras



Makefile

OBJS = rsa.o main.o BigInt.o
CPP = g++
DEBUG = -g
CPPFLAGS = -Wall -c $(DEBUG)
LDFLAGS = -lm

rsa :   $(OBJS)
          $(CPP) $(LDFLAGS) $(OBJS) -o rsa
main.o : main.cpp BigInt.h rsa.h
          $(CPP) $(CPPFLAGS) main.cpp -o $@
rsa.o : rsa.cpp rsa.h BigInt.h
          $(CPP) $(CPPFLAGS) rsa.cpp -o $@
BigInt.o : BigInt.cpp BigInt.h
          $(CPP) $(CPPFLAGS) BigInt.cpp -o $@
clean :
          rm -f *.o *~ rsa

                                  Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Default-rules Remarks



Automatic Variables




   $@ , $<, $^
         $@ : used for the target variable.
         $< : the 1st prerequisite.
         $^ : is like “all the above” - all the prerequisites.




                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Default-rules Remarks



Default automatic rules to compile

   Example-1
   prog: foo.o foobar.o ...
   <TAB> (nothing)

                 $(CPP) $(LDFLAGS) $^ -o $@
   (if prog.o (or prog.c) is one of the prerequisites.)
   Example-2
   prog: prog.c prog.h
   <TAB> (nothing)

            $(CPP) $(CPPFLAGS) -c $< -o $@
   Check these.


                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Default-rules Remarks



‘make’ from within the editor


   Some editors like Vim allow you to call ‘make’ while still editing
   the makefile :)
         :make - to run the Makefile.
   To navigate through the errors and fix compilation issues fast, try
         :copen - Opens the quickfix window, to show the results of
         the compilation.
         :cnext or :cn - jump to the next error in source code.
         :cprev or :cp - jump to the previous error in source code.




                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Default-rules Remarks



Remarks




         Don’t forget to put the TAB before entering the command.
         Look at examples of Makefiles.
         Lots of tutorials and resources available online.




                                     Subhashini V   Tutorial on make
Introduction Compiling Makefiles Example Extras   Default-rules Remarks



Questions?




                                         Just make it.




                                     Subhashini V   Tutorial on make

Weitere ähnliche Inhalte

Was ist angesagt?

Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programmingsudhir singh yadav
 
Introduction to Vim
Introduction to VimIntroduction to Vim
Introduction to VimBrandon Liu
 
linux file sysytem& input and output
linux file sysytem& input and outputlinux file sysytem& input and output
linux file sysytem& input and outputMythiliA5
 
Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examplesabclearnn
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in LinuxAnu Chaudhry
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell ScriptingRaghu nath
 
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例National Cheng Kung University
 
Introduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsIntroduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsQUONTRASOLUTIONS
 
Valgrind tutorial
Valgrind tutorialValgrind tutorial
Valgrind tutorialSatabdi Das
 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utilityNirajan Pant
 
Introduction to yocto
Introduction to yoctoIntroduction to yocto
Introduction to yoctoAlex Gonzalez
 
Linux Directory Structure
Linux Directory StructureLinux Directory Structure
Linux Directory StructureKevin OBrien
 

Was ist angesagt? (20)

Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Shell programming
Shell programmingShell programming
Shell programming
 
Complete Guide for Linux shell programming
Complete Guide for Linux shell programmingComplete Guide for Linux shell programming
Complete Guide for Linux shell programming
 
Introduction to Vim
Introduction to VimIntroduction to Vim
Introduction to Vim
 
Shell Scripting
Shell ScriptingShell Scripting
Shell Scripting
 
linux file sysytem& input and output
linux file sysytem& input and outputlinux file sysytem& input and output
linux file sysytem& input and output
 
Linux basic commands with examples
Linux basic commands with examplesLinux basic commands with examples
Linux basic commands with examples
 
Shell Scripting in Linux
Shell Scripting in LinuxShell Scripting in Linux
Shell Scripting in Linux
 
Bash Shell Scripting
Bash Shell ScriptingBash Shell Scripting
Bash Shell Scripting
 
Basics of shell programming
Basics of shell programmingBasics of shell programming
Basics of shell programming
 
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
LLVM 總是打開你的心:從電玩模擬器看編譯器應用實例
 
Introduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra SolutionsIntroduction to Linux Kernel by Quontra Solutions
Introduction to Linux Kernel by Quontra Solutions
 
Valgrind tutorial
Valgrind tutorialValgrind tutorial
Valgrind tutorial
 
GCC compiler
GCC compilerGCC compiler
GCC compiler
 
from Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Worksfrom Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Works
 
Grep - A powerful search utility
Grep - A powerful search utilityGrep - A powerful search utility
Grep - A powerful search utility
 
Embedded linux network device driver development
Embedded linux network device driver developmentEmbedded linux network device driver development
Embedded linux network device driver development
 
Introduction to yocto
Introduction to yoctoIntroduction to yocto
Introduction to yocto
 
Linux Programming
Linux ProgrammingLinux Programming
Linux Programming
 
Linux Directory Structure
Linux Directory StructureLinux Directory Structure
Linux Directory Structure
 

Andere mochten auch

Makefiles Intro
Makefiles IntroMakefiles Intro
Makefiles IntroYnon Perek
 
Makefile
MakefileMakefile
MakefileIonela
 
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介Wen Liao
 
Introduction to makefile
Introduction to makefileIntroduction to makefile
Introduction to makefileRay Song
 
Open Budget Format: Issues on Development of Specification and Converter Impl...
Open Budget Format: Issues on Development of Specification and Converter Impl...Open Budget Format: Issues on Development of Specification and Converter Impl...
Open Budget Format: Issues on Development of Specification and Converter Impl...Olya Parkhimovich
 
Physics 1
Physics 1Physics 1
Physics 1Manulat
 
भारतीय मानसून
भारतीय मानसूनभारतीय मानसून
भारतीय मानसूनDinesh Gaekwad
 
Bhikshuk (भिक्षुक)
Bhikshuk (भिक्षुक)Bhikshuk (भिक्षुक)
Bhikshuk (भिक्षुक)Hindijyan
 
ppt of our Solar system in hindi
ppt of our Solar system in hindippt of our Solar system in hindi
ppt of our Solar system in hindivethics
 
GENERAL PHYSICS 1 TEACHING GUIDE
GENERAL PHYSICS 1 TEACHING GUIDEGENERAL PHYSICS 1 TEACHING GUIDE
GENERAL PHYSICS 1 TEACHING GUIDEPRINTDESK by Dan
 
force and laws of motion
force and laws of motionforce and laws of motion
force and laws of motionashutoshrockx
 
Hindi Workshop हिंदी कार्यशाला
 Hindi Workshop हिंदी कार्यशाला Hindi Workshop हिंदी कार्यशाला
Hindi Workshop हिंदी कार्यशालाVijay Nagarkar
 

Andere mochten auch (20)

Makefiles Intro
Makefiles IntroMakefiles Intro
Makefiles Intro
 
Makefile
MakefileMakefile
Makefile
 
Makefiles Bioinfo
Makefiles BioinfoMakefiles Bioinfo
Makefiles Bioinfo
 
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
 
Introduction to makefile
Introduction to makefileIntroduction to makefile
Introduction to makefile
 
Open Budget Format: Issues on Development of Specification and Converter Impl...
Open Budget Format: Issues on Development of Specification and Converter Impl...Open Budget Format: Issues on Development of Specification and Converter Impl...
Open Budget Format: Issues on Development of Specification and Converter Impl...
 
Physics 1
Physics 1Physics 1
Physics 1
 
भारतीय मानसून
भारतीय मानसूनभारतीय मानसून
भारतीय मानसून
 
Bhikshuk (भिक्षुक)
Bhikshuk (भिक्षुक)Bhikshuk (भिक्षुक)
Bhikshuk (भिक्षुक)
 
Hindi ppt
Hindi pptHindi ppt
Hindi ppt
 
ppt of our Solar system in hindi
ppt of our Solar system in hindippt of our Solar system in hindi
ppt of our Solar system in hindi
 
जलवायु
जलवायुजलवायु
जलवायु
 
Physics and its laws in anaesthesia
Physics and its laws in anaesthesiaPhysics and its laws in anaesthesia
Physics and its laws in anaesthesia
 
Water In Hindi
Water In HindiWater In Hindi
Water In Hindi
 
GENERAL PHYSICS 1 TEACHING GUIDE
GENERAL PHYSICS 1 TEACHING GUIDEGENERAL PHYSICS 1 TEACHING GUIDE
GENERAL PHYSICS 1 TEACHING GUIDE
 
Impacts of water pollution hindi
Impacts of water pollution hindiImpacts of water pollution hindi
Impacts of water pollution hindi
 
force and laws of motion
force and laws of motionforce and laws of motion
force and laws of motion
 
Photo electric effect
Photo electric effectPhoto electric effect
Photo electric effect
 
Hindi Workshop हिंदी कार्यशाला
 Hindi Workshop हिंदी कार्यशाला Hindi Workshop हिंदी कार्यशाला
Hindi Workshop हिंदी कार्यशाला
 
Atoms
AtomsAtoms
Atoms
 

Ähnlich wie makefiles tutorial

How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)Matthias Noback
 
How Symfony Changed My Life
How Symfony Changed My LifeHow Symfony Changed My Life
How Symfony Changed My LifeMatthias Noback
 
GNU Parallel: Lab meeting—technical talk
GNU Parallel: Lab meeting—technical talkGNU Parallel: Lab meeting—technical talk
GNU Parallel: Lab meeting—technical talkHoffman Lab
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projectsMpho Mphego
 
All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$Joe Ferguson
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using SwiftDiego Freniche Brito
 
PowerShell: Automation for everyone
PowerShell: Automation for everyonePowerShell: Automation for everyone
PowerShell: Automation for everyoneGavin Barron
 
PowerShell: Automation for Everyone
PowerShell: Automation for EveryonePowerShell: Automation for Everyone
PowerShell: Automation for EveryoneIntergen
 
Pharo foreign function interface (FFI) by example by Esteban Lorenzano
Pharo foreign function interface (FFI) by example by Esteban LorenzanoPharo foreign function interface (FFI) by example by Esteban Lorenzano
Pharo foreign function interface (FFI) by example by Esteban LorenzanoFAST
 
Using Doctrine Migrations to Synchronize Databases
Using Doctrine Migrations to Synchronize DatabasesUsing Doctrine Migrations to Synchronize Databases
Using Doctrine Migrations to Synchronize DatabasesBryce Embry
 
Writing Rust Command Line Applications
Writing Rust Command Line ApplicationsWriting Rust Command Line Applications
Writing Rust Command Line ApplicationsAll Things Open
 
Build Systems with autoconf, automake and libtool [updated]
Build Systems with autoconf, automake and libtool [updated]Build Systems with autoconf, automake and libtool [updated]
Build Systems with autoconf, automake and libtool [updated]Benny Siegert
 
Reusando componentes Zope fuera de Zope
Reusando componentes Zope fuera de ZopeReusando componentes Zope fuera de Zope
Reusando componentes Zope fuera de Zopementtes
 
PHP Programming: Intro
PHP Programming: IntroPHP Programming: Intro
PHP Programming: IntroThings Lab
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generatorsdantleech
 
3. build your own php extension ai ti aptech
3. build your own php extension   ai ti aptech3. build your own php extension   ai ti aptech
3. build your own php extension ai ti aptechQuang Anh Le
 
07 build your-own_php_extension
07 build your-own_php_extension07 build your-own_php_extension
07 build your-own_php_extensionNguyen Duc Phu
 
Build your own PHP extension
Build your own PHP extensionBuild your own PHP extension
Build your own PHP extensionVõ Duy Tuấn
 

Ähnlich wie makefiles tutorial (20)

How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)How Symfony changed my life (#SfPot, Paris, 19th November 2015)
How Symfony changed my life (#SfPot, Paris, 19th November 2015)
 
How Symfony Changed My Life
How Symfony Changed My LifeHow Symfony Changed My Life
How Symfony Changed My Life
 
GNU Parallel: Lab meeting—technical talk
GNU Parallel: Lab meeting—technical talkGNU Parallel: Lab meeting—technical talk
GNU Parallel: Lab meeting—technical talk
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projects
 
All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$
 
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides:  Let's build macOS CLI Utilities using SwiftMobileConf 2021 Slides:  Let's build macOS CLI Utilities using Swift
MobileConf 2021 Slides: Let's build macOS CLI Utilities using Swift
 
PowerShell: Automation for everyone
PowerShell: Automation for everyonePowerShell: Automation for everyone
PowerShell: Automation for everyone
 
PowerShell: Automation for Everyone
PowerShell: Automation for EveryonePowerShell: Automation for Everyone
PowerShell: Automation for Everyone
 
Pharo foreign function interface (FFI) by example by Esteban Lorenzano
Pharo foreign function interface (FFI) by example by Esteban LorenzanoPharo foreign function interface (FFI) by example by Esteban Lorenzano
Pharo foreign function interface (FFI) by example by Esteban Lorenzano
 
Using Doctrine Migrations to Synchronize Databases
Using Doctrine Migrations to Synchronize DatabasesUsing Doctrine Migrations to Synchronize Databases
Using Doctrine Migrations to Synchronize Databases
 
Writing Rust Command Line Applications
Writing Rust Command Line ApplicationsWriting Rust Command Line Applications
Writing Rust Command Line Applications
 
Doit apac-2010-1.0
Doit apac-2010-1.0Doit apac-2010-1.0
Doit apac-2010-1.0
 
Build Systems with autoconf, automake and libtool [updated]
Build Systems with autoconf, automake and libtool [updated]Build Systems with autoconf, automake and libtool [updated]
Build Systems with autoconf, automake and libtool [updated]
 
Reusando componentes Zope fuera de Zope
Reusando componentes Zope fuera de ZopeReusando componentes Zope fuera de Zope
Reusando componentes Zope fuera de Zope
 
C# tutorial
C# tutorialC# tutorial
C# tutorial
 
PHP Programming: Intro
PHP Programming: IntroPHP Programming: Intro
PHP Programming: Intro
 
Incredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and GeneratorsIncredible Machine with Pipelines and Generators
Incredible Machine with Pipelines and Generators
 
3. build your own php extension ai ti aptech
3. build your own php extension   ai ti aptech3. build your own php extension   ai ti aptech
3. build your own php extension ai ti aptech
 
07 build your-own_php_extension
07 build your-own_php_extension07 build your-own_php_extension
07 build your-own_php_extension
 
Build your own PHP extension
Build your own PHP extensionBuild your own PHP extension
Build your own PHP extension
 

Kürzlich hochgeladen

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...AliaaTarek5
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dashnarutouzumaki53779
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 

Kürzlich hochgeladen (20)

From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
(How to Program) Paul Deitel, Harvey Deitel-Java How to Program, Early Object...
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Visualising and forecasting stocks using Dash
Visualising and forecasting stocks using DashVisualising and forecasting stocks using Dash
Visualising and forecasting stocks using Dash
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 

makefiles tutorial

  • 1. Introduction Compiling Makefiles Example Extras Making makefiles Tutorial for CS-2810 Subhashini V IIT Madras Subhashini V Tutorial on make
  • 2. Introduction Compiling Makefiles Example Extras Outline Introduction Motivation Compiling Object file Makefiles Macros Naming Phony-Targets Example Extras Default-rules Remarks Subhashini V Tutorial on make
  • 3. Introduction Compiling Makefiles Example Extras Motivation The why, what and how of makefiles for you and me. Figure: xkcd (comic is for sudo, but who cares, it has ‘make’) Subhashini V Tutorial on make
  • 4. Introduction Compiling Makefiles Example Extras Motivation Why makefiles? Lots of source files: foo1.h, foo2.h, foobar1.cpp, foobar2.cpp How to manage them all? Compiling is complicated!!! Subhashini V Tutorial on make
  • 5. Introduction Compiling Makefiles Example Extras Motivation Why makefiles? Lots of source files: foo1.h, foo2.h, foobar1.cpp, foobar2.cpp How to manage them all? Compiling is complicated!!! Solution: make Subhashini V Tutorial on make
  • 6. Introduction Compiling Makefiles Example Extras Motivation What are makefiles? make - automagically build and manage your programs. compile quickly with a single command recompile is even quicker Subhashini V Tutorial on make
  • 7. Introduction Compiling Makefiles Example Extras Motivation How does it work? Give targets (usually a file to be created) Specify dependencies for each target. Give command to create target from dependencies. ‘make’ recursively builds the targets from the set of dependencies. recompilation - time-stamp of modification Subhashini V Tutorial on make
  • 8. Introduction Compiling Makefiles Example Extras Object file .h and .cpp .h files contain declarations. functions that the class promises. .cpp files contain definitions implementations of the promised methods. other functions that are not a part of any class. Subhashini V Tutorial on make
  • 9. Introduction Compiling Makefiles Example Extras Object file BigInt assignment example The BigInt data type in RSA BigInt.h - with proposed methods : +, -, *, /, ! BigInt.cpp - with implementation of methods rsa.cpp - ONLY needs #include “BigInt.h”. Don’t need BigInt.cpp. Subhashini V Tutorial on make
  • 10. Introduction Compiling Makefiles Example Extras Object file Creating Object file object file or (.o file) For creating rsa.o, no need to include BigInt.cpp! Eventually need BigInt.cpp for running. Link later. You also don’t need main() Command: g++ -Wall -c rsa.cpp * -Wall : all warnings turned on * -c : Compiles but doesn’t link Subhashini V Tutorial on make
  • 11. Introduction Compiling Makefiles Example Extras Macros Naming Phony-Targets Makefiles! A makefile describes the dependencies between files. Figure: Content of a Makefile Subhashini V Tutorial on make
  • 12. Introduction Compiling Makefiles Example Extras Macros Naming Phony-Targets Targets, Dependencies, Commands Target is usually a file. Remember “:” Dependencies : .cpp, corresponding .h and other .h files Determining dependencies. the all important [tab] Commands : can be multiple Subhashini V Tutorial on make
  • 13. Introduction Compiling Makefiles Example Extras Macros Naming Phony-Targets Use macros! Like #define OBJS = rsa.o main.o CPP = g++ DEBUG = -g CPPFLAGS = -Wall -c $(DEBUG) LDFLAGS = -lm Usage: $(variable) rsa : $(OBJS) $(CPP) $(LDFLAGS) $(OBJS) -o rsa Automatic variables : $@ , $<, $^ ... Subhashini V Tutorial on make
  • 14. Introduction Compiling Makefiles Example Extras Macros Naming Phony-Targets Naming the file Naming and running the make file. makefile - run with make Makefile - run with make give any filename - run as make -f < filename > make picks the first target in the file and executes the commands if the dependencies are more recent than the target. Subhashini V Tutorial on make
  • 15. Introduction Compiling Makefiles Example Extras Macros Naming Phony-Targets Phony targets Dummy targets to run commands. They don’t actually create files. make all make clean make tar Use .PHONY or directly the name. .PHONY: clean Or clean: clean: rm -f *.o *~ rsa rm -f *.o *~ rsa Subhashini V Tutorial on make
  • 16. Introduction Compiling Makefiles Example Extras Makefile OBJS = rsa.o main.o BigInt.o CPP = g++ DEBUG = -g CPPFLAGS = -Wall -c $(DEBUG) LDFLAGS = -lm rsa : $(OBJS) $(CPP) $(LDFLAGS) $(OBJS) -o rsa main.o : main.cpp BigInt.h rsa.h $(CPP) $(CPPFLAGS) main.cpp -o $@ rsa.o : rsa.cpp rsa.h BigInt.h $(CPP) $(CPPFLAGS) rsa.cpp -o $@ BigInt.o : BigInt.cpp BigInt.h $(CPP) $(CPPFLAGS) BigInt.cpp -o $@ clean : rm -f *.o *~ rsa Subhashini V Tutorial on make
  • 17. Introduction Compiling Makefiles Example Extras Default-rules Remarks Automatic Variables $@ , $<, $^ $@ : used for the target variable. $< : the 1st prerequisite. $^ : is like “all the above” - all the prerequisites. Subhashini V Tutorial on make
  • 18. Introduction Compiling Makefiles Example Extras Default-rules Remarks Default automatic rules to compile Example-1 prog: foo.o foobar.o ... <TAB> (nothing) $(CPP) $(LDFLAGS) $^ -o $@ (if prog.o (or prog.c) is one of the prerequisites.) Example-2 prog: prog.c prog.h <TAB> (nothing) $(CPP) $(CPPFLAGS) -c $< -o $@ Check these. Subhashini V Tutorial on make
  • 19. Introduction Compiling Makefiles Example Extras Default-rules Remarks ‘make’ from within the editor Some editors like Vim allow you to call ‘make’ while still editing the makefile :) :make - to run the Makefile. To navigate through the errors and fix compilation issues fast, try :copen - Opens the quickfix window, to show the results of the compilation. :cnext or :cn - jump to the next error in source code. :cprev or :cp - jump to the previous error in source code. Subhashini V Tutorial on make
  • 20. Introduction Compiling Makefiles Example Extras Default-rules Remarks Remarks Don’t forget to put the TAB before entering the command. Look at examples of Makefiles. Lots of tutorials and resources available online. Subhashini V Tutorial on make
  • 21. Introduction Compiling Makefiles Example Extras Default-rules Remarks Questions? Just make it. Subhashini V Tutorial on make