Professional Documents
Culture Documents
Dum Ka Biryani Make For Each Other
Dum Ka Biryani Make For Each Other
Dum Ka Biryani Make For Each Other
Version 1.0
February 2011
GNU Free Documentation License
Shakthi Kannan
shakthimaan@gmail.com
http://www.shakthimaan.com
()
1/1
Dum Ka Biryani
()
2/1
Makefile
target : prerequisites ...
recipe
...
...
3/1
()
4/1
5/1
Makefile
objects = masala.o rice.o onion.o curd.o coriander.o meat.o
biryani : $(objects)
cc -o biryani $(objects)
masala.o : masala.h defs.h
rice.o : rice.h defs.h
onion.o : defs.h
curd.o : defs.h
coriander.o : defs.h
meat.o : defs.h
clean:
rm biryani $(objects)
()
6/1
()
7/1
()
8/1
* Implicit rule
masala.o : masala.h
* Variable definition
objects = masala.o rice.o onion.o curd.o coriander.o meat.o
* Directive
ifeq ($(CC), gcc)
libs=$(libs for gcc)
else
libs=$(normal libs)
endif
* Comments
# This is a comment
()
9/1
Default
* GNUMakefile
* makefile
* Makefile
()
10 / 1
Default
* GNUMakefile
* makefile
* Makefile
$ make
$ make -f myMakefile
$ make --file=myMakefile
()
10 / 1
* Syntax
include filenames...
()
11 / 1
* Syntax
include filenames...
$ make
$ make -I
$ make --include-dir
()
11 / 1
GNUmakefile
meat:
cc -c vegetables.c
%: force
@$(MAKE) -f Makefile $@
force: ;
()
12 / 1
GNUmakefile
meat:
cc -c vegetables.c
%: force
@$(MAKE) -f Makefile $@
force: ;
$ make
$ make meat
()
12 / 1
First phase
* Reads all makefiles
* Reads included makefiles
* Internalize variables, values, implicit and explicit rules
* Constructs dependency graph of targets and pre-requisites
* immediate: expansion in phase one
Second phase
* Determines which targets need to be re-built
* Invokes the necessary rules
* deferred: expansion in phase two
()
13 / 1
()
14 / 1
()
15 / 1
()
16 / 1
Makefile
clean :
rm -f *.o
Wildcard expansion does not happen in variable definition
Makefile
objects = *.o
Use Wildcard function!
Makefile
objects = $(wildcard *.o)
()
17 / 1
()
18 / 1
Automatic variables
$
all prerequisites
$@ target
$< first prerequisite
Makefile
coriander.o : coriander.c
cc -c $(CFLAGS) $^ -o $@
Makefile
masala.o : masala.c masala.h defs.h
cc -c $(CFLAGS) $< -o $@
()
19 / 1
20 / 1
()
21 / 1
()
22 / 1
22 / 1
Makefile
LIST = masala rice onion
all:
for i in $(LIST); do \
echo $$i; \
done
()
23 / 1
Makefile
LIST = masala rice onion
all:
for i in $(LIST); do \
echo $$i; \
done
$ make
masala
rice
onion
()
23 / 1
()
24 / 1
()
24 / 1
()
25 / 1
()
26 / 1
()
27 / 1
()
28 / 1
$ make
$ make
Adding
Adding
Adding
Adding
Adding
mix
green chillies
ginger garlic paste
cinnamon, cardamom
fried onions
coriander and mint leaves
()
28 / 1
()
29 / 1
()
29 / 1
()
30 / 1
()
30 / 1
()
31 / 1
Makefile
masala := chillies.o onions.o garlic.o ginger.o
biryani := $(masala:.o=.c)
Makefile
masala := chillies.o onions.o garlic.o ginger.o
biryani := $(masala:%.o=%.c)
* biryani is set to chillies.c onions.c garlic.c ginger.c
()
32 / 1
Makefile
greeny = coriander
coriander = green coriander leaves
leaves := $($(greeny))
all:
@echo $(leaves)
()
33 / 1
Makefile
greeny = coriander
coriander = green coriander leaves
leaves := $($(greeny))
all:
@echo $(leaves)
$ make
green coriander leaves
()
33 / 1
Makefile
objects = masala.o rice.o onion.o curd.o
...
objects += coriander.o
Makefile
CFLAGS = $(includes) -O
...
CFLAGS += -pg
()
34 / 1
()
35 / 1
Makefile
water := saffron water
leaves = mint leaves
undefine water
undefine leaves
Makefile
override undefine CFLAGS
()
36 / 1
Makefile
target ... : variable-assignment
Makefile
prog : CFLAGS = -g
prog : masala.o rice.o onion.o
()
37 / 1
()
38 / 1
Makefile
libs for gcc = -lgnu
normal libs =
biryani : $(objects)
ifeq ($(CC), gcc)
libs=$(libs for gcc)
else
libs=$(normal libs)
endif
()
39 / 1
Makefile
conditional-directive
text-if-true
else
text-if-false endif
Makefile
conditional-directive
text-if-one-is-true
endif
else conditional-directive
text-if-true
else
text-if-false endif
()
40 / 1
* ifneq
ifneq ($(STRIP), strip)
* ifdef
ifdef $(LIBS)
* ifndef
ifndef $(CFLAGS)
()
41 / 1
()
42 / 1
()
43 / 1
()
44 / 1
Makefile
$(if condition,then-part[,else-part] )
$(or condition1[,condition2[,condition3...]] )
$(and condition1[,condition2[,condition3...]] )
()
45 / 1
Makefile
$(foreach var,list,text )
Makefile
find files = $(wildcard $(dir)/*)
dirs := masala rice leaves
files := $(foreach dir, $(dirs), $(find files))
()
46 / 1
Makefile
$(call variable,param,param,... )
Makefile
reverse = $(2) $(1)
make = $(call reverse,cook,mix)
make contains mix cook
()
47 / 1
Makefile
LIST = $PATH
all:
@echo $(LIST)
@echo $(value LIST)
()
48 / 1
Makefile
LIST = $PATH
all:
@echo $(LIST)
@echo $(value LIST)
$ make
ATH
/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
()
48 / 1
Makefile
$(origin variable )
()
49 / 1
Makefile
$(flavor variable )
()
50 / 1
Makefile
contents := $(shell cat onion.c)
Makefile
files := $(shell echo *.c)
()
51 / 1
References
GNU Make:
http://www.gnu.org/software/make/
GNU Make Manual:
http://www.gnu.org/software/make/manual/
Dum Ka Biryani, Make for each other (sources):
http://www.shakthimaan.com/downloads.html#dum-ka-biryani-make-for-each-other
Symbols in LaTeX and HTML:
http://newton.ex.ac.uk/research/qsystems/people/sque/symbols/
()
52 / 1