-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
61 lines (43 loc) · 1.31 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
CC = cc
CFLAGS += -Wextra -Wall -Wdouble-promotion
pgnview test: CFLAGS += -fsanitize=address,undefined -g3
release: CFLAGS += -O2 -g
LDFLAGS += -g
pgnview test: LDFLAGS += -fsanitize=address,undefined -g3
release: LDFLAGS += -g
CHESS_OBJS = bitboard.o board.o movegen.o
PGN_OBJS = pgn.o pgn_ext.o
OBJS = $(CHESS_OBJS) $(PGN_OBJS) termbox2.o main.o
EXE = pgnview
RELEASE_DIR = release
RELEASE_EXE = $(RELEASE_DIR)/$(EXE)
TEST_DIR = tests
TEST_SRCS = $(wildcard $(TEST_DIR)/*.c)
TEST_EXES = $(patsubst %.c,%,$(TEST_SRCS))
TESTS = $(wildcard $(TEST_DIR)/*.test)
TEST_RESULTS = $(addsuffix .res, $(TESTS))
.Phony: all
all: pgnview
pgnview: $(OBJS)
$(CC) -o $(EXE) $(OBJS) $(LDFLAGS)
main.o: termbox2.h chess.h pgn.h pgn_ext.h
$(CHESS_OBJS): chess.h
$(PGN_OBJS): pgn.h
pgn_ext.o: pgn_ext.h chess.h
termbox2.o: termbox2.h
release: mkdir $(RELEASE_EXE)
$(RELEASE_EXE): $(addprefix $(RELEASE_DIR)/, $(OBJS))
$(CC) -o $(RELEASE_EXE) $^ $(LDFLAGS)
$(RELEASE_DIR)/%.o: %.c
$(CC) -c $(CFLAGS) -o $@ $<
mkdir:
@mkdir -p $(RELEASE_DIR)
.Phony: clean
clean:
rm -rf $(RELEASE_DIR) $(EXE) test_* $(OBJS)
.Phony: test $(TESTS)
$(TEST_DIR)/%: $(TEST_DIR)/%.c $(PGN_OBJS) $(CHESS_OBJS)
$(CC) $< $(CFLAGS) $(LDFLAGS) $(PGN_OBJS) $(CHESS_OBJS) -o $@
$(TEST_DIR)/%.test.res: $(TEST_DIR)/%.test
./$<
test: $(TEST_EXES) $(TEST_RESULTS)