Download presentation
Presentation is loading. Please wait.
Published byCalvin Webb Modified over 9 years ago
1
Prof: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015 Makefile Tutorial CIS5027
2
What’s make? A utility that automatically builds executable programs and libraries from source code by reading files called makefile which specify how to derive the target program. Make allows you to manage large programs and keep track of which portion of the entire program have been changed. Makefile tells make how to generate an execution file make make –f MyMakefile
3
Compiling by hand Build Process Files: main.c foo1.c foo2.c 1) gcc main.c foo1.c foo2.c –o main 2) gcc main.c foo1.c foo2.c –c gcc main.o foo1.o foo2.o –o main With make and makefile, you only need to type make
4
Makefile Format Target: The file we want to create Dependencies: Check before creating the target file Commands: Consider as shell script. Please note: you need to put a tab character at the beginning of every recipe line! Target : dependencies(or prerequisites ) system commands(or recipe )
5
Dependency graph
6
First Makefile make gcc main.c –c gcc foo1.c –c gcc main.o fool.o –o main
7
Change one source file touch foo1.c make gcc foo1.c –c gcc main.o fool.o –o main
8
Variables $(VAR) or ${VAR} For example Targets = foo ${Targets}: common.h gcc –o ${Targets} foo.c foo: common.h gcc –o foo foo.c
9
Variables example edit : main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o cc -o edit main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o objects = main.o kbd.o command.o display.o \ insert.o search.o files.o utils.o edit : $(objects) cc -o edit $(objects). clean : rm edit $(objects)
10
Difference between :=, = and += x = foo y = $(x) bar x = xyz # The value of y would be xyz bar x := foo y := $(x) bar x := xyz # The value of y would be foo bar CFLAGS= -c CFLAGS+= -Wall
11
Makefile Example
12
Makefile Tutorial Make manual http://www.gnu.org/software/make/manual/make.html 8 functions for transforming text http://www.gnu.org/software/make/manual/html_node/Functions.html comma:=, empty:= space:= $(empty) $(empty) foo:= a b c bar:= $(subst $(space),$(comma),$(foo)) # bar is now ‘a,b,c’.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.