-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
106 lines (71 loc) · 2.47 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
CC=gcc
CFLAGS=-Wall -Wextra -lreadline
EXEC=jsh
TEST=test
SRCDIR=src
OBJDIR=obj
TMPDIR=tmp
SRCOBJDIR=$(OBJDIR)/$(SRCDIR)
TESTDIR=tests
TESTOBJDIR=$(OBJDIR)/$(TESTDIR)
SCRIPTSDIR=$(TESTDIR)/scripts
TEST_SCRIPT=$(SCRIPTSDIR)/test.sh
TEST_SETUP=$(SCRIPTSDIR)/test_setup.sh
TEST_VALGRIND=$(SCRIPTSDIR)/test_valgrind.sh
TEST_PROFESSOR=$(SCRIPTSDIR)/test_professor.sh
TEST_TYY=$(SCRIPTSDIR)/test_tyy.sh
CINTA=cinta
CINTAOBJDIR=$(OBJDIR)/cinta
CINTAOBJ=$(CINTAOBJDIR)/cinta.o
SRCFILES := $(shell find $(SRCDIR) -type f -name "*.c")
CINTAFILES := $(shell find $(CINTA) -type f -name "*.c")
TESTFILES := $(shell find $(TESTDIR) -type f -name "*.c")
OBJFILES := $(patsubst $(SRCDIR)/%.c,$(SRCOBJDIR)/%.o,$(SRCFILES))
CINTAOBJFILES := $(patsubst $(CINTA)/%.c,$(CINTAOBJDIR)/%.o,$(CINTAFILES))
TESTOBJFILES := $(patsubst $(TESTDIR)/%.c,$(TESTOBJDIR)/%.o,$(TESTFILES))
ALLFILES := $(SRCFILES) $(TESTFILES) $(shell find $(SRCDIR) $(TESTDIR) -type f -name "*.h")
# Create obj directory at the beginning
$(shell mkdir -p $(SRCOBJDIR))
$(shell mkdir -p $(TESTOBJDIR))
$(shell mkdir -p $(CINTAOBJDIR))
$(SRCOBJDIR)/%.o: $(SRCDIR)/%.c
$(CC) -c -o $@ $< $(CFLAGS)
$(TESTOBJDIR)/%.o: $(TESTDIR)/%.c
$(CC) -c -o $@ $< $(CFLAGS)
$(CINTAOBJDIR)/%.o: $(CINTA)/%.c
$(CC) -c -o $@ $< $(CFLAGS)
.PHONY: all, clean, format, test
all: $(EXEC)
$(EXEC): $(OBJFILES)
$(CC) -o $@ $^ $(CFLAGS)
test-quick: test-unit-quick test-valgrind-quick test-professor
test-unit-quick: compile_tests setup_test_env
./$(TEST_SCRIPT) -q
test-valgrind-quick: compile_tests_valgrind setup_test_env
./$(TEST_VALGRIND) -q
test-valgrind-quick-fds: compile_tests_valgrind setup_test_env
./$(TEST_VALGRIND) -f -q
$(TEST): test-unit test-valgrind test-tyy test-professor
test-unit: compile_tests setup_test_env
./$(TEST_SCRIPT)
test-valgrind: compile_tests_valgrind setup_test_env
./$(TEST_VALGRIND)
test-valgrind-fds: compile_tests_valgrind setup_test_env
./$(TEST_VALGRIND) -f
test-professor:
./$(TEST_PROFESSOR)
test-tyy:
./$(TEST_TYY)
compile_tests_valgrind: $(filter-out $(SRCOBJDIR)/$(EXEC).o, $(OBJFILES)) $(TESTOBJFILES) $(CINTAOBJFILES)
$(CC) -o $(TEST) $^ -g $(CFLAGS)
compile_tests: $(filter-out $(SRCOBJDIR)/$(EXEC).o, $(OBJFILES)) $(TESTOBJFILES) $(CINTAOBJFILES)
$(CC) -o $(TEST) $^ $(CFLAGS)
setup_test_env:
$(shell mkdir -p $(TMPDIR))
./$(TEST_SETUP)
format fmt:
clang-format -i $(ALLFILES)
check-format:
clang-format --dry-run --Werror $(ALLFILES)
clean:
rm -rf $(OBJDIR) $(EXEC) $(TESTOBJDIR) $(TEST) $(TMPDIR)