Introduction Compiling Makefiles Example                         Making makefiles                           Tutorial for CS-...
Introduction Compiling Makefiles ExampleOutline   Introduction       Motivation   Compiling     Object file   Makefiles     M...
Introduction Compiling Makefiles Example   Motivation  The why, what and how of makefiles for you and me.                   ...
Introduction Compiling Makefiles Example   MotivationWhy makefiles?     Lots of source files: foo1.h, foo2.h, foobar1.cpp, fo...
Introduction Compiling Makefiles Example   MotivationWhy makefiles?     Lots of source files: foo1.h, foo2.h, foobar1.cpp, fo...
Introduction Compiling Makefiles Example   MotivationWhat are makefiles?      make - automagically build and manage your pro...
Introduction Compiling Makefiles Example   MotivationHow does it work?      Give targets (usually a file to be created)     ...
Introduction Compiling Makefiles Example   Object file.h and .cpp   .h files contain       declarations.       functions that...
Introduction Compiling Makefiles Example   Object fileBigInt assignment example   The BigInt data type in RSA       BigInt.h...
Introduction Compiling Makefiles Example   Object fileCreating Object file   object file or (.o file)        For creating rsa.o...
Introduction Compiling Makefiles Example   Macros Naming Phony-TargetsMakefiles!   A makefile describes the dependencies betw...
Introduction Compiling Makefiles Example   Macros Naming Phony-TargetsTargets, Dependencies, Commands      Target is usuall...
Introduction Compiling Makefiles Example   Macros Naming Phony-TargetsUse macros!   Like #define   OBJS = rsa.o main.o   CPP...
Introduction Compiling Makefiles Example   Macros Naming Phony-TargetsNaming the file   Naming and running the make file.    ...
Introduction Compiling Makefiles Example    Macros Naming Phony-TargetsPhony targets   Dummy targets to run commands. They ...
Introduction Compiling Makefiles Example   RemarksMakefileOBJS = rsa.o main.o BigInt.oCPP = g++DEBUG = -gCPPFLAGS = -Wall -c...
Introduction Compiling Makefiles Example   RemarksRemarks     Don’t forget to put the TAB before entering the command.     ...
Introduction Compiling Makefiles Example   RemarksQuestions                                    Questions?                  ...
makefiles tutorial
makefiles tutorial
makefiles tutorial
Upcoming SlideShare
Loading in...5
×

makefiles tutorial

2,265

Published on

A quick introduction to makefiles.

Published in: Technology
1 Comment
0 Likes
Statistics
Notes
  • MILLIONS OF THANKS
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total Views
2,265
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
107
Comments
1
Likes
0
Embeds 0
No embeds

No notes for slide

makefiles tutorial

  1. 1. Introduction Compiling Makefiles Example Making makefiles Tutorial for CS-2810 Subhashini V IIT Madras Subhashini V Tutorial on make
  2. 2. Introduction Compiling Makefiles ExampleOutline Introduction Motivation Compiling Object file Makefiles Macros Naming Phony-Targets Example Remarks Subhashini V Tutorial on make
  3. 3. Introduction Compiling Makefiles Example 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. 4. Introduction Compiling Makefiles Example MotivationWhy 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. 5. Introduction Compiling Makefiles Example MotivationWhy 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. 6. Introduction Compiling Makefiles Example MotivationWhat 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. 7. Introduction Compiling Makefiles Example MotivationHow 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. 8. Introduction Compiling Makefiles Example 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. 9. Introduction Compiling Makefiles Example Object fileBigInt 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. 10. Introduction Compiling Makefiles Example Object fileCreating 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. 11. Introduction Compiling Makefiles Example Macros Naming Phony-TargetsMakefiles! A makefile describes the dependencies between files. Figure: Content of a Makefile Subhashini V Tutorial on make
  12. 12. Introduction Compiling Makefiles Example Macros Naming Phony-TargetsTargets, 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. 13. Introduction Compiling Makefiles Example Macros Naming Phony-TargetsUse 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. 14. Introduction Compiling Makefiles Example Macros Naming Phony-TargetsNaming 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. 15. Introduction Compiling Makefiles Example Macros Naming Phony-TargetsPhony 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 *.o *~ rsa rm *.o *~ rsa Subhashini V Tutorial on make
  16. 16. Introduction Compiling Makefiles Example RemarksMakefileOBJS = rsa.o main.o BigInt.oCPP = g++DEBUG = -gCPPFLAGS = -Wall -c $(DEBUG)LDFLAGS = -lmrsa : $(OBJS) $(CPP) $(LDFLAGS) $(OBJS) -o rsamain.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 *.o *~ rsa Subhashini V Tutorial on make
  17. 17. Introduction Compiling Makefiles Example RemarksRemarks 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
  18. 18. Introduction Compiling Makefiles Example RemarksQuestions Questions? Subhashini V Tutorial on make
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×