makefile
Download
Skip this Video
Download Presentation
Makefile

Loading in 2 Seconds...

play fullscreen
1 / 12

Makefile - PowerPoint PPT Presentation


  • 95 Views
  • Uploaded on

Makefile. Ansuman Banerjee Arijit Bishnu Debapriyo Majumdar Data and File Structures Lab M.Tech . Computer Science 1 st Year, Semester I Indian Statistical Institute Kolkata August 26, 2014. Compilation stages. Compiler stage: C file  lower level assembly language code

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Makefile' - melvin-taylor


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
makefile

Makefile

AnsumanBanerjee

ArijitBishnu

Debapriyo Majumdar

Data and File Structures Lab

M.Tech. Computer Science 1st Year, Semester I

Indian Statistical Institute Kolkata

August 26, 2014

compilation stages
Compilation stages
  • Compiler stage:

C file lower level assembly language code

  • Assembler stage:

Assembly language code  Object code (machine directly understands) [.o files]

  • Linker stage:

Object codes  Linked to produce an executable file

May also link with some built in functions

the codebase
The Codebase
  • Download:

http://www.isical.ac.in/~pdslab/ProgramsForMakefile.tar.gz

  • Trivial compilation:

$ gccmain.cadd.cmean.c -o prog

  • Create object files, and compile

$ gcc-c add.c -o add.o

$ gcc –c mean.c -o mean.o

$ gcc-c main.c-o main.o

$ gccmain.omean.oadd.o -o prog

dependencies
Dependencies
  • $ gcc -c add.c -o add.o
  • $ gcc –c mean.c -o mean.o
  • $ gcc -c main.c -o main.o
  • $ gccmain.omean.oadd.o -o prog
the mean function
The mean function

Arithmetic mean

Geometric mean

Which object and executable files should change?

  • #include "mean.h"
  • int mean(intn1, intn2) {
  • return (n1+n2)/2;
  • }
  • #include "mean.h"
  • #include <math.h>
  • int mean(intn1, intn2) {
  • return sqrt(n1*n2);
  • }
recompiling
Recompiling

# Recompiling only mean.o and the prog

$ gcc –c mean.c -o mean.o

$ gccmain.omean.oadd.o -o prog

  • A Makefile
    • Define dependencies and compilation instructions beforehand
    • When parts of a large codebase is changed, the make command recompiles selectively and builds the program
a simple makefile
A Simple Makefile

# comment

target: dependency1 dependency2 ...

<tab> build instruction / command

The format

prog: main.omean.oadd.o

gcc -Wall main.omean.oadd.o -o prog

main.o: main.cadd.hmean.h

gcc -c -Wall main.c -o main.o

mean.o: mean.cmean.h

gcc -c -Wall mean.c -o mean.o

add.o: add.cadd.h

gcc -c -Wall add.c -o add.o

Makefile

a simple makefile1
A Simple Makefile

$ make

$ make prog

Command

prog: main.omean.oadd.o

gcc -Wall main.omean.oadd.o -o prog -lm

main.o: main.cadd.hmean.h

gcc -c -Wall main.c -o main.o

mean.o: mean.cmean.h

gcc -c -Wall mean.c -o mean.o

add.o: add.cadd.h

gcc -c -Wall add.c -o add.o

Specifying the Target

Makefile

defining more targets
Defining more targets

default: prog

all: prog

prog: main.omean.oadd.o

gcc -Wall main.omean.oadd.o -o prog -lm

main.o: main.cadd.hmean.h

gcc -c -Wall main.c -o main.o

mean.o: mean.cmean.h

gcc -c -Wall mean.c -o mean.o

add.o: add.cadd.h

gcc -c -Wall add.c -o add.o

Makefile

If there were more executable files, prog1 prog2 … or the object files

variables
Variables

default: prog

all: prog

prog: main.omean.oadd.o

gcc -Wall main.omean.oadd.o -o prog -lm

main.o: main.cadd.hmean.h

gcc -c -Wall main.c -o main.o

mean.o: mean.cmean.h

gcc -c -Wall mean.c -o mean.o

add.o: add.cadd.h

gcc -c -Wall add.c -o add.o

Makefile

Objects

Command

Flags

variables1
Variables

CC=gcc

CFLAGS=-c –Wall

LDFLAGS=-lm

OBJECTS=main.oadd.omean.o

default: prog

all: prog

prog: $(OBJECTS)

$(CC) $(OBJECTS) -o prog $(LDFLAGS)

main.o: main.cadd.hmean.h

$(CC) $(CFLAGS) main.c-o main.o

mean.o: mean.cmean.h

$(CC) $(CFLAGS) mean.c-o mean.o

add.o: add.cadd.h

$(CC) $(CFLAGS) add.c-o add.o

clean:

rm -f $(OBJECTS)

Makefile

experiments for yourself
Experiments for yourself
  • Make clean and then run make
  • Change the file add.h and run make
  • Change the file main.c and run make
ad