]> git.lizzy.rs Git - shadowclad.git/blob - Makefile
Implement transform math to rotate movement direction
[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/level.c \
26             game/player.c
27
28 srcfiles ::= $(addprefix $(SRCDIR)/, $(sources))
29
30 objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(srcfiles)))
31 depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(srcfiles)))
32
33 # Set executable name for the platform
34 # TODO Base this on target platform instead of host OS
35 #ifeq ($(OS),Windows_NT)
36 #       binext ::= .exe
37 #else
38 #       binext ::=
39 #endif
40 binary ::= $(BUILDDIR)/shadowclad #$(binext)
41
42 # ######
43 # Main build rules
44 # ######
45
46 # Default rule: build executable
47 $(binary): $(objects)
48         @mkdir -p $(@D)
49         @echo "Linking executable"
50         @$(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
51
52 # Build C translation units
53 $(objects): $(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk
54         @mkdir -p $(@D)
55         @echo "Building $@"
56         @$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
57
58 # ######
59 # Setup
60 # ######
61
62 # Initialise build environment
63 init:
64         @echo "Creating build directory $(BUILDDIR)"
65         @mkdir -p $(BUILDDIR)
66 .PHONY: init
67
68 # ######
69 # Aliases
70 # ######
71
72 # Build and run
73 run: $(binary)
74         @echo
75         @$(binary)
76 .PHONY: run
77
78 # Build executable
79 shadowclad: $(binary)
80 .PHONY: shadowclad
81
82 # ######
83 # Prerequisites
84 # ######
85
86 # Generate C prerequisite makefiles
87 $(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
88         @mkdir -p $(@D)
89         @echo "Generating prerequisites for $<"
90         @$(CPP) -MM -MT $(BUILDDIR)/$*.c.o -MF $@ $(CPPFLAGS) $<
91 # Give the same prerequisites to the prerequisite makefile,
92 # so that it is regenerated whenever any of said prerequisites change
93         @sed -E -i 's|^([^\s:]+)([ :])|\1 $@\2|' $@
94
95 # Include generated C prerequisites
96 include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(depfile)"))
97
98 # Do not automatically delete generated prerequisites
99 .SECONDARY: $(depfiles)
100
101 # ######
102 # Cleanup rules
103 # ######
104
105 clean:
106         @echo "Removing $(BUILDDIR)"
107         @rm -rf $(BUILDDIR)
108 .PHONY: clean