-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
119 lines (97 loc) · 2.77 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
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
108
109
110
111
112
113
114
115
116
117
118
119
# Copyright 2018-2020 Iwo 'Outfrost' Bujkiewicz
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
PLATFORM ?= x86_64-linux-gnu
BUILDDIR ?= target/$(PLATFORM)
SRCDIR ?= src
CPPFLAGS ::= -iquotesrc/ $(CPPFLAGS)
CFLAGS ::= -g -std=c99 -Wall -Wextra -Wpedantic -Werror \
-Wno-error=unused-function -Wno-error=unused-parameter $(CFLAGS)
LDFLAGS ::= $(LDFLAGS)
LDLIBS ::= -lm -lGL -lGLEW -lglfw -lassimp $(LDLIBS)
# ######
# Paths
# ######
sources ::= main.c \
engine/asset.c \
engine/engine.c \
engine/geometry.c \
engine/input.c \
engine/logger.c \
engine/performance.c \
engine/render.c \
engine/scene.c \
engine/string.c \
engine/tga.c \
engine/ui.c \
game/game.c \
game/input.c \
game/level.c \
game/player.c
srcfiles ::= $(addprefix $(SRCDIR)/, $(sources))
objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(srcfiles)))
depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(srcfiles)))
# Set executable name for the platform
# TODO Base this on target platform instead of host OS
#ifeq ($(OS),Windows_NT)
# binext ::= .exe
#else
# binext ::=
#endif
binary ::= $(BUILDDIR)/shadowclad #$(binext)
# ######
# Main build rules
# ######
# Default rule: build executable
$(binary): $(objects)
@mkdir -p $(@D)
@echo "Linking executable"
@$(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
# Build C translation units
$(objects): $(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk
@mkdir -p $(@D)
@echo "Building $@"
@$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
# ######
# Setup
# ######
# Initialise build environment
init:
@echo "Creating build directory $(BUILDDIR)"
@mkdir -p $(BUILDDIR)
.PHONY: init
# ######
# Aliases
# ######
# Build and run
run: $(binary)
@echo
@$(binary)
.PHONY: run
# Build executable
shadowclad: $(binary)
.PHONY: shadowclad
# ######
# Prerequisites
# ######
# Generate C prerequisite makefiles
$(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
@mkdir -p $(@D)
@echo "Generating prerequisites for $<"
@$(CPP) -MM -MT $(BUILDDIR)/$*.c.o -MF $@ $(CPPFLAGS) $<
# Give the same prerequisites to the prerequisite makefile,
# so that it is regenerated whenever any of said prerequisites change
@sed -E -i 's|^([^\s:]+)([ :])|\1 $@\2|' $@
# Include generated C prerequisites
include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(depfile)"))
# Do not automatically delete generated prerequisites
.SECONDARY: $(depfiles)
# ######
# Cleanup rules
# ######
clean:
@echo "Removing $(BUILDDIR)"
@rm -rf $(BUILDDIR)
.PHONY: clean