aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 991fce97e634a0d42384a07149d29199b61ddb11 (plain)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
##
# @file Makefile
# Script to build source files
#
# Copyright (C) 2019 Clyne Sullivan
# Copyright (C) 2019 Belle-Isle, Andrew <drumsetmonkey@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.	If not, see <https://www.gnu.org/licenses/>.
#

#
# VARIABLES
#

CC  = gcc
CXX = g++

EXEC = main
EXECDIR = .

SRCDIR = src
OUTDIR = build
SRCEXT = cpp
OBJEXT = o
DEPEXT = d

LIBDIR = lib
LIBS   = -L$(LIBDIR) -lSDL2 -lpthread -lentityx -lluajit -ldl -lGLEW -lGL \
         -lSDL2_image -lsoil -lfreetype -lopenal -lalut

CXXFLAGS = -ggdb -std=c++17 -Wall -Wextra -Werror -pedantic \
           -Wno-class-memaccess -Wno-implicit-fallthrough -Wno-unused-parameter

CXXINCS = -I$(SRCDIR) \
          -I$(LIBDIR)/entityx \
          -I$(LIBDIR)/luajit/src \
          -I$(LIBDIR)/sol2/include \
          -I$(LIBDIR)/soil \
          -I$(LIBDIR)/cereal/include \
	  -I$(LIBDIR)/freetype

CXXSRC := $(shell find $(SRCDIR) -type f -name *.$(SRCEXT))
CXXOBJ := $(patsubst $(SRCDIR)/%,$(OUTDIR)/%,$(CXXSRC:.$(SRCEXT)=.$(OBJEXT)))

#
# COMPILE STUFF
#

all: resources $(EXEC)

resources: directories

directories:
	@mkdir -p $(EXECDIR)
	@mkdir -p $(OUTDIR)

clean:
	@echo "  CLEAN"
	@$(RM) -rf $(OUTDIR)

cleanall: clean
	@$(RM) -f lib/libentityx.a lib/libluajit.a lib/libsoil.a

cleaner: clean

$(EXEC): lib/libentityx.a lib/libluajit.a lib/libsoil.a $(CXXOBJ)
	@echo "  CXX   " $(EXEC)
	@$(CXX) -o $(EXECDIR)/$(EXEC) $^ $(LIBS)

$(OUTDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT)
	@echo "  CXX   " $<
	@mkdir -p $(dir $@)
	@$(CXX) $(CXXFLAGS) $(CXXINCS) -c -o $@ $<
	@$(CXX) $(CXXFLAGS) $(CXXINCS) $(INCDEP) -MM $(SRCDIR)/$*.$(SRCEXT) > $(OUTDIR)/$*.$(DEPEXT)
	@cp -f $(OUTDIR)/$*.$(DEPEXT) $(OUTDIR)/$*.$(DEPEXT).tmp
	@sed -e 's|.*:|$(OUTDIR)/$*.$(OBJEXT):|' < $(OUTDIR)/$*.$(DEPEXT).tmp > $(OUTDIR)/$*.$(DEPEXT)
	@sed -e 's/.*://' -e 's/\\$$//' < $(OUTDIR)/$*.$(DEPEXT).tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $(OUTDIR)/$*.$(DEPEXT)
	@rm -f $(OUTDIR)/$*.$(DEPEXT).tmp

mem: $(EXEC)
	valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(EXEC)

lib/libentityx.a:
	@cmake -S lib/entityx -B lib/entityx -DENTITYX_BUILD_SHARED=FALSE
	@make -Clib/entityx -j4 entityx
	@cp lib/entityx/libentityx.a lib/libentityx.a

lib/libluajit.a:
	@make -Clib/luajit -j4
	@cp lib/luajit/src/libluajit.a lib/libluajit.a

lib/libsoil.a:
	@make -Clib/soil -j4
	@cp lib/soil/libsoil.a lib/libsoil.a

.PHONY: all remake clean cleaner cleanall resources mem