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