-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
59 lines (46 loc) · 1.28 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
######################################
## WILL'S ULTIMATE MAKEFILE ##
## DATE: FEB 2016 ##
######################################
# Compiler
CC = g++
OPTS = -c -g -Wall
# Project name
PROJECT = $(EXECDIR)/game
TESTS = $(EXECDIR)/tests
# Directories
EXECDIR = bin
OBJDIR = obj
SRCDIR = src
INCDIR = include
TESTDIR = tests
# Libraries
LIBS = -L /usr/lib -lSDL2 -lSDL2_image -lSDL2_ttf -lSDL2_mixer
INC = -I /usr/include -I $(INCDIR)
# Files and folders
SRCS = $(shell find $(SRCDIR) -name '*.cc' -not -path '*tests*')
TESTSRCS = $(shell find $(SRCDIR) -name '*.cc' ! -name '*main.cc')
SRCDIRS = $(shell find . -name '*.cc' | dirname {} | sort | uniq | sed 's/\/$(SRCDIR)//g' )
OBJS = $(patsubst $(SRCDIR)/%.cc,$(OBJDIR)/%.o,$(SRCS))
TESTOBJS = $(patsubst $(SRCDIR)/%.cc,$(OBJDIR)/%.o,$(TESTSRCS))
# Targets
$(PROJECT): buildrepo $(OBJS)
$(CC) $(OBJS) $(LIBS) -o $@
$(TESTS): $(TESTOBJS)
$(CC) $(TESTOBJS) $(LIBS) -o $@
$(OBJDIR)/%.o: $(SRCDIR)/%.cc
$(CC) $(OPTS) $(INC) -c $< -o $@
clean:
rm $(PROJECT) $(OBJDIR) $(TESTS) -Rf
buildrepo:
@$(call make-repo)
tests: buildrepo $(TESTS)
# Create obj directory structure
define make-repo
mkdir -p $(OBJDIR)
mkdir -p $(OBJDIR)/$(TESTDIR)
for dir in $(SRCDIRS); \
do \
mkdir -p $(OBJDIR)/$$dir; \
done
endef