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