]> git.lizzy.rs Git - shadowclad.git/blob - Makefile
Implement rudimentary player movement; fix geometry logic bugs
[shadowclad.git] / Makefile
1 PLATFORM ?= x86_64-linux-gnu
2
3 BUILDDIR ?= target/$(PLATFORM)
4 SRCDIR ?= src
5
6 CPPFLAGS ::= -iquotesrc/ $(CPPFLAGS)
7 CFLAGS ::= -g -std=c99 -Wall -Wextra -Wpedantic -Werror \
8            -Wno-error=unused-function -Wno-error=unused-parameter $(CFLAGS)
9 LDFLAGS ::= $(LDFLAGS)
10 LDLIBS ::= -lm -lGL -lGLEW -lglut -lassimp $(LDLIBS)
11
12 # ######
13 # Paths
14 # ######
15
16 sources ::= main.c \
17             engine/asset.c \
18             engine/geometry.c \
19             engine/logger.c \
20             engine/performance.c \
21             engine/render.c \
22             engine/scene.c \
23             engine/tga.c \
24             engine/ui.c \
25             game/input.c \
26             game/level.c \
27             game/player.c
28
29 srcfiles ::= $(addprefix $(SRCDIR)/, $(sources))
30
31 objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(srcfiles)))
32 depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(srcfiles)))
33
34 # Set executable name for the platform
35 # TODO Base this on target platform instead of host OS
36 #ifeq ($(OS),Windows_NT)
37 #       binext ::= .exe
38 #else
39 #       binext ::=
40 #endif
41 binary ::= $(BUILDDIR)/shadowclad #$(binext)
42
43 # ######
44 # Main build rules
45 # ######
46
47 # Default rule: build executable
48 $(binary): $(objects)
49         @mkdir -p $(@D)
50         @echo "Linking executable"
51         @$(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
52
53 # Build C translation units
54 $(objects): $(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk
55         @mkdir -p $(@D)
56         @echo "Building $@"
57         @$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
58
59 # ######
60 # Setup
61 # ######
62
63 # Initialise build environment
64 init:
65         @echo "Creating build directory $(BUILDDIR)"
66         @mkdir -p $(BUILDDIR)
67 .PHONY: init
68
69 # ######
70 # Aliases
71 # ######
72
73 # Build and run
74 run: $(binary)
75         @echo
76         @$(binary)
77 .PHONY: run
78
79 # Build executable
80 shadowclad: $(binary)
81 .PHONY: shadowclad
82
83 # ######
84 # Prerequisites
85 # ######
86
87 # Generate C prerequisite makefiles
88 $(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
89         @mkdir -p $(@D)
90         @echo "Generating prerequisites for $<"
91         @$(CPP) -MM -MT $(BUILDDIR)/$*.c.o -MF $@ $(CPPFLAGS) $<
92 # Give the same prerequisites to the prerequisite makefile,
93 # so that it is regenerated whenever any of said prerequisites change
94         @sed -E -i 's|^([^\s:]+)([ :])|\1 $@\2|' $@
95
96 # Include generated C prerequisites
97 include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(depfile)"))
98
99 # Do not automatically delete generated prerequisites
100 .SECONDARY: $(depfiles)
101
102 # ######
103 # Cleanup rules
104 # ######
105
106 clean:
107         @echo "Removing $(BUILDDIR)"
108         @rm -rf $(BUILDDIR)
109 .PHONY: clean