-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
57 lines (41 loc) · 1.08 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
CC = gcc
CFLAGS = -Wall -Wextra -Wpedantic -g -Werror -Iinclude
SRC_DIR = src
TEST_DIR = tests
BIN = bin
EXE = lukip
SRCS := $(wildcard $(SRC_DIR)/*.c $(SRC_DIR)/*/*.c $(SRC_DIR)/*/*/*.c)
TESTS := $(wildcard $(TEST_DIR)/*.c $(TEST_DIR)/*/*.c $(TEST_DIR)/*/*/*.c)
ifeq ($(OS), Windows_NT)
EXE = lukip.exe
SRCS := $(subst /,\,$(SRCS))
TESTS := $(subst /,\,$(TESTS))
endif
OBJS = $(SRCS:.c=.o)
TEST_OBJS = $(TESTS:.c=.o)
# "newline" resolves to an actual escape "\n" sequence (hence endef is an extra line down).
define newline
endef
.PHONY: all clean lib tests
all: lib
lib: $(OBJS)
ar rcs liblukip.a $^
tests: $(EXE)
$(EXE): $(BIN) $(OBJS) $(TEST_OBJS)
ifeq ($(OS), Windows_NT)
$(CC) -o $<\$@ $(OBJS) $(TEST_OBJS)
else
$(CC) -o $</$@ $(OBJS) $(TEST_OBJS)
endif
%.o: %.c
$(CC) $(CFLAGS) -c $^ -o $@
$(BIN):
mkdir $(BIN)
clean:
ifeq ($(OS), Windows_NT)
$(foreach obj, $(OBJS) $(TEST_OBJS), if exist $(obj) del /s /q $(obj) > NUL$(newline))
if exist $(BIN) rmdir /s /q $(BIN)
if exist liblukip.a del /s /q liblukip.a > NUL
else
rm -rf $(OBJS) $(TEST_OBJS) $(BIN) liblukip.a
endif