-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
88 lines (60 loc) · 2.13 KB
/
Makefile
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# Make manual: https://www.gnu.org/software/make/manual/make.html
# GCC Options: https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html
# mmv
# -------------------------------------------------------------------
# files and directories
# -------------------------------------------------------------------
bin_name = mmv
man_name = $(bin_name).1.gz
prefix = /usr/local
bin_dir = $(prefix)/bin
man_dir = $(prefix)/man/man1
src_dir = src
test_dir = test
debug_dir = debug
build_dir = build
src_files := $(wildcard $(src_dir)/*)
def_files := $(wildcard $(src_dir)/*.c)
test_def_files := $(patsubst $(src_dir)/%.c, $(test_dir)/test_%.c, $(def_files))
# -------------------------------------------------------------------
# flags
# -------------------------------------------------------------------
optim_flags = -O2
w-arith = -Wdouble-promotion -Wfloat-equal
w-basic = -pedantic -Wall -Wextra
w-extra = -Wcast-align=strict -Wconversion -Wpadded -Wshadow -Wstrict-prototypes -Wvla
w-fmt = -Wformat=2 -Wformat-overflow=2 -Wformat-truncation
warn_flags = $(w-basic) $(w-extra) $(w-arith) $(w-fmt)
CFLAGS = $(warn_flags) $(optim_flags)
# -------------------------------------------------------------------
# targets
# -------------------------------------------------------------------
.PHONY: all test debug clean test_clean install uninstall
all:
$(CC) $(CFLAGS) main.c $(src_files) -o $(bin_name)
test:
mkdir -p ./test/bin
$(CC) ./test/test_utils.c ./test/unity.c -o ./test/bin/test_utils
$(CC) ./test/test_set.c ./test/unity.c -o ./test/bin/test_set
$(CC) -D DEBUG=1 ./test/test_mmv.c ./test/unity.c -o ./test/bin/test_mmv
./test/bin/test_utils
./test/bin/test_set
./test/bin/test_mmv
debug:
$(CC) $(CFLAGS) -D DEBUG=1 main.c $(src_files) -o debug_$(bin_name)
# clean target: remove all object files and binary
clean:
rm $(bin_name)
test_clean:
rm -rf ./test/bin
debug_clean:
rm debug_$(bin_name)
# install target for "sudo make install"
install:
$(NORMAL_INSTALL)
install -m 007 $(bin_name) $(bin_dir)
cp ./man/$(man_name) $(man_dir)/$(man_name)
uninstall:
$(NORMAL_UNINSTALL)
rm $(bin_dir)/$(bin_name)
rm $(man_dir)/$(man_name)