1 # Copyright 2018-2020 Iwo 'Outfrost' Bujkiewicz
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 PLATFORM ?= x86_64-linux-gnu
9 BUILDDIR ?= target/$(PLATFORM)
12 CPPFLAGS ::= -iquotesrc/ $(CPPFLAGS)
13 CFLAGS ::= -g -std=c99 -Wall -Wextra -Wpedantic -Werror \
14 -Wno-error=unused-function -Wno-error=unused-parameter $(CFLAGS)
15 LDFLAGS ::= $(LDFLAGS)
16 LDLIBS ::= -lm -lGL -lGLEW -lglfw -lassimp $(LDLIBS)
28 engine/performance.c \
39 srcfiles ::= $(addprefix $(SRCDIR)/, $(sources))
41 objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(srcfiles)))
42 depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(srcfiles)))
44 # Set executable name for the platform
45 # TODO Base this on target platform instead of host OS
46 #ifeq ($(OS),Windows_NT)
51 binary ::= $(BUILDDIR)/shadowclad #$(binext)
57 # Default rule: build executable
60 @echo "Linking executable"
61 @$(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
63 # Build C translation units
64 $(objects): $(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk
67 @$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
73 # Initialise build environment
75 @echo "Creating build directory $(BUILDDIR)"
97 # Generate C prerequisite makefiles
98 $(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
100 @echo "Generating prerequisites for $<"
101 @$(CPP) -MM -MT $(BUILDDIR)/$*.c.o -MF $@ $(CPPFLAGS) $<
102 # Give the same prerequisites to the prerequisite makefile,
103 # so that it is regenerated whenever any of said prerequisites change
104 @sed -E -i 's|^([^\s:]+)([ :])|\1 $@\2|' $@
106 # Include generated C prerequisites
107 include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(depfile)"))
109 # Do not automatically delete generated prerequisites
110 .SECONDARY: $(depfiles)
117 @echo "Removing $(BUILDDIR)"