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 -lglut -lassimp $(LDLIBS)
20 engine/performance.c \
29 srcfiles ::= $(addprefix $(SRCDIR)/, $(sources))
31 objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(srcfiles)))
32 depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(srcfiles)))
34 # Set executable name for the platform
35 # TODO Base this on target platform instead of host OS
36 #ifeq ($(OS),Windows_NT)
41 binary ::= $(BUILDDIR)/shadowclad #$(binext)
47 # Default rule: build executable
50 @echo "Linking executable"
51 @$(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
53 # Build C translation units
54 $(objects): $(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk
57 @$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
63 # Initialise build environment
65 @echo "Creating build directory $(BUILDDIR)"
87 # Generate C prerequisite makefiles
88 $(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
90 @echo "Generating prerequisites for $<"
91 @$(CPP) -MM -MT $(BUILDDIR)/$*.c.o -MF $@ $(CPPFLAGS) $<
92 # Give the same prerequisites to the prerequisite makefile,
93 # so that it is regenerated whenever any of said prerequisites change
94 @sed -E -i 's|^([^\s:]+)([ :])|\1 $@\2|' $@
96 # Include generated C prerequisites
97 include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(depfile)"))
99 # Do not automatically delete generated prerequisites
100 .SECONDARY: $(depfiles)
107 @echo "Removing $(BUILDDIR)"