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