Professional Documents
Culture Documents
Dum Ka Biryani
Dum Ka Biryani
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
()
4/1
Makele 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 denition
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
() Dum Ka Biryani, Make for each other 9/1
()
10 / 1
()
10 / 1
* Syntax
include lenames...
()
11 / 1
* Syntax
include lenames...
()
11 / 1
()
12 / 1
GNUmakele meat: cc -c vegetables.c %: force @$(MAKE) -f Makele $@ force: ; $ make $ make meat
()
12 / 1
First phase * Reads all makeles * Reads included makeles * 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
Makele clean : rm -f *.o Wildcard expansion does not happen in variable denition Makele objects = *.o Use Wildcard function! Makele objects = $(wildcard *.o)
()
17 / 1
()
18 / 1
Automatic variables $ all prerequisites $@ target $< rst prerequisite Makele coriander.o : coriander.c cc -c $(CFLAGS) $^ -o $@ Makele masala.o : masala.c masala.h defs.h cc -c $(CFLAGS) $< -o $@
()
19 / 1
()
21 / 1
()
22 / 1
Makele LIST = masala rice onion all: for i in $(LIST); do \ echo $$i; \ done
()
23 / 1
Makele LIST = masala rice onion all: for i in $(LIST); do \ echo $$i; \ done $ make masala rice onion
()
23 / 1
* -j number, number of recipies to execute in parallel. * -l number, number (limit) of jobs to run in parallel.
()
24 / 1
* -j number, number of recipies to execute in parallel. * -l number, number (limit) of jobs to run in parallel. $ make $ make -j $ make --jobs $ make -l $ make --max-load
()
24 / 1
()
25 / 1
* Recursive make commands should always use the variable MAKE. Makele subsystem : cd subdir && $(MAKE) Makele subsystem : $(MAKE) -C subdir
()
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
* Recursively Expanded variable Makele spice = $(chillies) chillies = $(both) both = green chillies and red chillie powder all: ; echo $(spice)
()
29 / 1
* Recursively Expanded variable Makele spice = $(chillies) chillies = $(both) both = green chillies and red chillie powder all: ; echo $(spice) $ make green chillies and red chillie powder
()
29 / 1
()
30 / 1
()
30 / 1
* Conditional Variable assignment operator Makele ifeq ($(origin RICE), undefined) RICE = Basmati rice endif Makele RICE ?= Basmati rice
()
31 / 1
Makele masala := chillies.o onions.o garlic.o ginger.o biryani := $(masala:.o=.c) Makele 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
Makele greeny = coriander coriander = green coriander leaves leaves := $($(greeny)) all: @echo $(leaves)
()
33 / 1
Makele greeny = coriander coriander = green coriander leaves leaves := $($(greeny)) all: @echo $(leaves) $ make green coriander leaves
()
33 / 1
Makele objects = masala.o rice.o onion.o curd.o ... objects += coriander.o Makele CFLAGS = $(includes) -O ... CFLAGS += -pg
()
34 / 1
()
35 / 1
Makele water := saffron water leaves = mint leaves undefine water undefine leaves Makele override undefine CFLAGS
()
36 / 1
Makele target ... : variable-assignment Makele prog : CFLAGS = -g prog : masala.o rice.o onion.o
()
37 / 1
()
38 / 1
Makele libs for gcc = -lgnu normal libs = biryani : $(objects) ifeq ($(CC), gcc) libs=$(libs for gcc) else libs=$(normal libs) endif
()
39 / 1
Makele 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
()
45 / 1
Makele find files = $(wildcard $(dir)/*) dirs := masala rice leaves files := $(foreach dir, $(dirs), $(find files))
()
46 / 1
Makele reverse = $(2) $(1) make = $(call reverse,cook,mix) make contains mix cook
()
47 / 1
()
48 / 1
Makele LIST = $PATH all: @echo $(LIST) @echo $(value LIST) $ make ATH /usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
()
48 / 1
How the variable was dened: * undened * default * environment * environment override * le * command line * automatic
()
49 / 1
Flavor of the variable: * undened * recursively expanded variable * simply expanded variable
()
50 / 1
()
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