-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
78 lines (57 loc) · 1.86 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
CPU := $(shell uname -p)
ifeq ($(CPU),arm)
export LD_LIBRARY_PATH=/opt/homebrew/lib/:$LD_LIBRARY_PATH
INCD = -I /opt/homebrew/include/
LIBD = -L /opt/homebrew/lib/
endif
CC := gcc
SRCD := src
TSTD := tests
AUXD := test_functions
BLDD := build
BIND := bin
INCD += -I include
ALL_SRCF := $(shell find $(SRCD) -type f -name '*.c')
ALL_OBJF := $(patsubst $(SRCD)/%,$(BLDD)/%,$(ALL_SRCF:.c=.o))
TEST_SRC := $(shell find $(TSTD) -type f -name '*.c')
TEST_OBJ := $(patsubst $(TSTD)/%,$(BLDD)/%,$(TEST_SRC:.c=.o))
AUX_SRC := $(shell find $(AUXD) -type f -name '*.c')
TEST := unit_tests
EXEC := MatrixCalculator
AUX_OBJS := $(patsubst $(AUXD)/%,$(BLDD)/%,$(AUX_SRC:.c=.o))
AUX_PGMS := $(patsubst $(AUXD)/%,$(BIND)/%,$(AUX_SRC:.c=))
CFLAGS := -Wall -Wextra -Wshadow -Wdouble-promotion -Wformat=2 -Wundef -pedantic -g
DFLAGS := -g -DDEBUG
PRINT_STATEMENTS := -DERROR -DSUCCESS -DWARN -DINFO
STD := -std=gnu11
TEST_LIB := -lcriterion
LIBS := -lm
CFLAGS += $(STD)
CFLAGS += $(DFLAGS)
TEST_RESULTS := "test_results.json"
MAKEFLAGS := -j
all: setup $(BIND)/$(TEST) $(AUX_PGMS) $(ALL_OBJF)
debug: CFLAGS += $(DFLAGS) $(PRINT_STATEMENTS)
debug: all
setup:
@mkdir -p $(BIND)
@mkdir -p $(BLDD)
$(BIND)/$(TEST): $(ALL_OBJF) $(TEST_OBJ)
$(CC) $(ALL_OBJF) $(TEST_OBJ) $(INCD) $(TEST_LIB) $(LIBD) -o $@ $(LIBS)
$(AUX_PGMS): % : $(AUX_OBJS) $(ALL_OBJF)
$(CC) $(BLDD)/$(@F).o $(ALL_OBJF) -o $@ $(LIBS)
$(BLDD)/%.o: $(AUXD)/%.c
$(CC) $(CFLAGS) $(INCD) -I $(TSTD) -c -o $@ $<
$(BLDD)/%.o: $(TSTD)/%.c
$(CC) $(CFLAGS) $(INCD) -c -o $@ $<
$(BLDD)/%.o: $(SRCD)/%.c
$(CC) $(CFLAGS) $(INCD) -c -o $@ $<
$(BIND)/$(EXEC): $(ALL_OBJF)
$(CC) $(BLDD)/$(EXEC).o -o $@ $(LIBS)
test:
@rm -fr $(TSTD).out
@mkdir -p $(TSTD).out
@$(BIND)/$(TEST) --full-stats --verbose --json=$(TEST_RESULTS)
clean:
rm -fr $(BLDD) $(BIND) $(AUXD)/*.o $(TSTD).out *.out $(TEST_RESULTS)
.PHONY: all clean debug setup test