110 likes | 253 Views
Makefile Tutorial CIS5027 . Prof: Dr. Shu-Ching Chen TA: Hsin -Yu Ha. 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 .
E N D
Makefile TutorialCIS5027 Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
What’s make? • Autility thatautomatically 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
Compiling by hand • Build Process • Files: main.c foo1.c foo2.c • gccmain.c foo1.c foo2.c –o main • gccmain.c foo1.c foo2.c –c gccmain.o foo1.o foo2.o –o main • With make and makefile, you only need to type make
Makefile Format • Target: The file we want to create • Dependencies: Check before creating the target file • Commands: Consider as shell script. Target : dependencies <Tab> system commands
First Makefile make gccmain.c –c gcc foo1.c –c gccmain.ofool.o –o main
Change one source file touch foo1.c make gcc foo1.c –c gccmain.ofool.o –o main
Variables • $(VAR) or ${VAR} • For example Targets = foo ${Targets}: common.h gcc –o ${Targets} foo.c foo: common.h gcc –o foofoo.c
Difference between :=, = and += x = fooy = $(x) barx = xyz# The value of y would be xyz bar x := fooy := $(x) barx := xyz# The value of y would be foo bar CFLAGS= -c CFLAGS+= -Wall
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