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