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