]> git.lizzy.rs Git - shadowclad.git/blob - Makefile
Rename typedefs.h to geometry.h
[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 $(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         $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
53
54 # ######
55 # Setup
56 # ######
57
58 # Initialise build environment
59 init:
60         mkdir -p $(BUILDDIR)
61 .PHONY: init
62
63 # ######
64 # Aliases
65 # ######
66
67 # Build and run
68 run: $(binary)
69         @echo
70         @LD_LIBRARY_PATH=/usr/local/lib $(binary)
71 .PHONY: run
72
73 # Build executable
74 shadowclad: $(binary)
75 .PHONY: shadowclad
76
77 # ######
78 # Prerequisites
79 # ######
80
81 # Generate C prerequisite makefiles
82 $(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
83         @mkdir -p $(@D)
84         @echo "Generating prerequisites for $<"
85         @$(CPP) -MM -MT $(BUILDDIR)/$*.c.o -MF $@ $(CPPFLAGS) $<
86 # Give the same prerequisites to the prerequisite makefile,
87 # so that it is regenerated whenever any of said prerequisites change
88         @sed -E -i 's|^([^\s:]+)([ :])|\1 $@\2|' $@
89
90 # Include generated C prerequisites
91 include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(depfile)"))
92
93 # Do not automatically delete generated prerequisites
94 .SECONDARY: $(depfiles)
95
96 # ######
97 # Cleanup rules
98 # ######
99
100 clean:
101         rm -rf $(BUILDDIR)
102 .PHONY: clean