1 PLATFORM ?= x86_64-linux-gnu
3 BUILDDIR ?= target/$(PLATFORM)
6 CPPFLAGS ::= -iquotesrc/ $(CPPFLAGS)
7 CFLAGS ::= -g -std=c99 -Wall -Wextra -Wpedantic -Werror $(CFLAGS)
9 LDLIBS ::= -lGL -lGLEW -lglut -lassimp $(LDLIBS)
18 engine/performance.c \
26 srcfiles ::= $(addprefix $(SRCDIR)/, $(sources))
28 objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(srcfiles)))
29 depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(srcfiles)))
31 # Set executable name for the platform
32 # TODO Base this on target platform instead of host OS
33 #ifeq ($(OS),Windows_NT)
38 binary ::= $(BUILDDIR)/shadowclad #$(binext)
44 # Default rule: build executable
47 @echo "Linking executable"
48 @$(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
50 # Build C translation units
51 $(objects): $(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk
54 @$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
60 # Initialise build environment
62 @echo "Creating build directory $(BUILDDIR)"
84 # Generate C prerequisite makefiles
85 $(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
87 @echo "Generating prerequisites for $<"
88 @$(CPP) -MM -MT $(BUILDDIR)/$*.c.o -MF $@ $(CPPFLAGS) $<
89 # Give the same prerequisites to the prerequisite makefile,
90 # so that it is regenerated whenever any of said prerequisites change
91 @sed -E -i 's|^([^\s:]+)([ :])|\1 $@\2|' $@
93 # Include generated C prerequisites
94 include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(depfile)"))
96 # Do not automatically delete generated prerequisites
97 .SECONDARY: $(depfiles)
104 @echo "Removing $(BUILDDIR)"