-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
102 lines (77 loc) · 2.44 KB
/
Copy pathMakefile
File metadata and controls
102 lines (77 loc) · 2.44 KB
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
# Disable built-in rules, automatically parallelize
MAKEFLAGS += --no-builtin-variables --no-builtin-rules
MAKEFLAGS += --jobs=$(shell nproc)
.PHONY: all clean run test_%
modules := err utils types common rnd pthfind entity
objs := main png_wrap
tests := rnd
CXX = clang++
# Common flags for compiling & linking steps
FLAGS = -std=c++2c -I$(pdir) -fprebuilt-module-path=$(bdir)/
FLAGS += -Wall -Wextra -O3 -flto -ggdb3 #-pg
CXXFLAGS += $(FLAGS)
LDFLAGS += $(FLAGS)
LDLIBS = $(shell pkg-config libpng --libs)
# LDLIBS = -Ldeps/libpng -l:libpng.a -lz
CXXFLAGS += -DDEBUG
LDFLAGS += -DDEBUG
# build directory
bdir := .build
# project directory
pdir := mmo
# tests directory
tdir := tests
define pcm
$(addprefix $(bdir)/,$(addsuffix .pcm,$(1)))
endef
define obj
$(addprefix $(bdir)/,$(addsuffix .o,$(1)))
endef
define tst
$(addprefix $(tdir)/test_,$(addsuffix .cpp,$(1)))
endef
pcm_modules := $(call pcm,$(modules))
obj_files := $(call obj,$(objs))
all: | $(bdir)/main main
# Test dependencies
$(bdir)/test_entity: $(call pcm,entity)
$(bdir)/test_pthfind: $(call pcm,err types utils common pthfind) $(call obj,png_wrap)
$(bdir)/test_path: $(call pcm,types)
$(bdir)/test_rnd: $(call pcm,rnd)
$(bdir)/test_binmask: $(call obj,png_wrap) $(call pcm,utils common err)
$(bdir)/test_png: $(call obj,png_wrap) $(call pcm,err utils)
# Intermodule dependencies
$(call pcm,entity): | $(call pcm,err)
$(call pcm,types): | $(call pcm,err)
$(call pcm,common): | $(call obj,png_wrap) $(call pcm,types utils)
$(call pcm,pthfind): | $(call pcm,common)
$(call pcm,utils): | $(call pcm,err)
$(call obj,png_wrap): $(call pcm,err)
# General dependencies
$(bdir)/main.o: $(pcm_modules)
$(bdir)/main: LDFLAGS +=
$(bdir)/main: $(obj_files) $(pcm_modules) | $(bdir)
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
$(bdir)/png_wrap.o: CXXFLAGS += $(shell pkg-config libpng --cflags)
#$(bdir)/png_wrap: LDFLAGS += $(shell pkg-config libpng --libs)
#$(bdir)/png_wrap: $(bdir)/png_wrap.o $(bdir)/utils.o
# $(CXX) $(LDFLAGS) -o $@ $^
# FIXME: header dependencies
$(call obj,utils): $(pdir)/utils.hpp
$(bdir):
mkdir $@
clean:
test -n "$(bdir)" && rm -rf "$(bdir)"
main: $(bdir)/main
run: $(bdir)/main
@./$<
$(bdir)/%.pcm: $(pdir)/%.cppm | $(bdir)
$(CXX) $(CXXFLAGS) --precompile -o $@ -c $^ $(EXTRAFLAGS)
$(bdir)/%.o: $(pdir)/%.cpp | $(bdir)
$(CXX) $(CXXFLAGS) -c -o $@ $<
# Tests
$(bdir)/test_%: $(call tst, %) | $(bdir)
$(CXX) $(LDFLAGS) -o $@ $^ $(LDLIBS)
test_%: $(bdir)/test_%
@echo -n "Running "
$<