-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
62 lines (54 loc) 路 1.55 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
# Compiler
CC = gcc
# Compiler flags
CFLAGS = -Wall -Wextra -std=c99 -g
DEBUG = -g
# Directories
SRCDIR = src
INCDIR = include
OBJDIR = obj
LIBDIR = build
TESTDIR = test
EXAMDIR = examples
EXAMSRCS = $(wildcard $(EXAMDIR)/*.c)
# Source files
SRCS = $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/components/*.c)
# Object files
OBJS = $(SRCS:$(SRCDIR)/%.c=$(OBJDIR)/%.o)
# Library
LIBNAME = ctermui
LIB = $(LIBDIR)/lib$(LIBNAME).a
# Test files
TESTSRCS = $(wildcard $(TESTDIR)/*.c)
TESTBINS = $(TESTSRCS:$(TESTDIR)/%.c=$(TESTDIR)/%.out)
# Targets
all: $(LIB) $(TESTBINS)
$(TESTDIR)/%.out: $(TESTDIR)/%.c $(LIB)
@mkdir -p $(TESTDIR)
$(CC) $(CFLAGS) -I$(INCDIR) -o $@ $< -L$(LIBDIR) -l$(LIBNAME)
run_tests: $(TESTBINS)
@for testbin in $(TESTBINS); do \
echo "Running $$testbin"; \
$$testbin; \
done
# Rule for creating object files
$(OBJDIR)/%.o: $(SRCDIR)/%.c
@mkdir -p $(OBJDIR)
$(CC) $(CFLAGS) -I$(INCDIR) -c $< -o $(OBJDIR)/$(notdir $@)
# Rule for creating the static library
$(LIB): $(OBJS)
@mkdir -p $(LIBDIR)
#ar rcs $@ $(OBJDIR)/$(notdir $(OBJS))
ar rcs $@ $(addprefix $(OBJDIR)/, $(notdir $(OBJS)))
# ENV run file, take the first argument as the file name
# e.g. make run file=example
run_file: $(LIB)
$(CC) $(CFLAGS) -I$(INCDIR) -o /tmp/$(notdir $(file)).out $(file) -L$(LIBDIR) -l$(LIBNAME) $(args)
/tmp/$(notdir $(file)).out
run_worm: $(LIB)
$(CC) $(CFLAGS) -I$(INCDIR) -o /tmp/worm.out $(EXAMDIR)/worm_game.c -L$(LIBDIR) -l$(LIBNAME)
/tmp/worm.out
# Clean
clean:
rm -rf $(OBJDIR) $(LIBDIR) $(TESTDIR)/*.out $(EXAMDIR)/*.out
.PHONY: all run_tests clean