1 PLATFORM ?= x86_64-linux-gnu
3 BUILDDIR ?= target/$(PLATFORM)
6 CPPFLAGS ::= -iquotesrc/ $(CPPFLAGS)
7 CFLAGS ::= -g -std=c99 -Wall -Wextra -Wpedantic -Werror \
8 -Wno-error=unused-function -Wno-error=unused-parameter $(CFLAGS)
10 LDLIBS ::= -lm -lGL -lGLEW -lglfw -lassimp $(LDLIBS)
20 engine/performance.c \
30 srcfiles ::= $(addprefix $(SRCDIR)/, $(sources))
32 objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(srcfiles)))
33 depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(srcfiles)))
35 # Set executable name for the platform
36 # TODO Base this on target platform instead of host OS
37 #ifeq ($(OS),Windows_NT)
42 binary ::= $(BUILDDIR)/shadowclad #$(binext)
48 # Default rule: build executable
51 @echo "Linking executable"
52 @$(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
54 # Build C translation units
55 $(objects): $(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk
58 @$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
64 # Initialise build environment
66 @echo "Creating build directory $(BUILDDIR)"
88 # Generate C prerequisite makefiles
89 $(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
91 @echo "Generating prerequisites for $<"
92 @$(CPP) -MM -MT $(BUILDDIR)/$*.c.o -MF $@ $(CPPFLAGS) $<
93 # Give the same prerequisites to the prerequisite makefile,
94 # so that it is regenerated whenever any of said prerequisites change
95 @sed -E -i 's|^([^\s:]+)([ :])|\1 $@\2|' $@
97 # Include generated C prerequisites
98 include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(depfile)"))
100 # Do not automatically delete generated prerequisites
101 .SECONDARY: $(depfiles)
108 @echo "Removing $(BUILDDIR)"