forked from anhvir/c203
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile.ver1_explained
60 lines (48 loc) · 1.86 KB
/
Makefile.ver1_explained
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# define C compiler & flags
CC = gcc
CFLAGS = -Wall
# just like #define in C, here:
# CC becomes a symbolic name, and is equivalent to "gcc"
# CFLAGS is equivalent to "-Wall"
# use CFLAGS = -g -Wall
# if you want to run debugging tools such as valgrind and gdb
# but note that the flag "-g" makes the excutable code slower.
# define libraries to be linked (for example -lm)
LIB =
# LIB is equivalent to "" (empty),
# if we want to compile with "-lm" we should write:
# LIB = -lm
HDR = factorial.h
SRC = main.c factorial.c
# HDR, SRC are symbolic names,
# each of them is a string containing several file names
# HDR contains all .h files of the project
# SRC contains all .c files of the project
# OBJ is the same as SRC, just sustitute ".c" with ".o"
OBJ = $(SRC:.c=.o)
# so, OBJ becomes "main.o factorial.o"
# recall that "factorial.o" stands for the object file
# translated by "gcc" from "factorial.c", ie. it is the product of command:
# gcc -c factorial.c
# the executable name
EXE = factorial
$(EXE): $(HDR) $(OBJ) Makefile
$(CC) $(CFLAGS) -o $(EXE) $(OBJ) $(LIB)
# so, factorial (ie EXE) depends on
# main.o factorial.o
# and is associated with command:
# gcc -Wall -o main.o factorial.o
clean:
rm -f $(OBJ) $(EXE)
# The target "clean" helps to remove all files "make" created, include
# all `.o` files ( which are in OBJ)
# end the file factorial (whic is EXE).
# The purpose running "make clean" is:
# - for you to be able to recompile the project
# (for example, after copying the project to a different computers)
# - to clean the non-essential files so that you can economically
# copy the whole project to an archive.
$(OBJ): $(HDR)
# The last lines just state the dependencies for the objects .o files
# It means that when one of the file in the list HDR changed,
# "make" must rebuild the .o files (ie. recompile them).