1 PLATFORM ?= x86_64-linux-gnu
3 BUILDDIR ?= target/$(PLATFORM)
6 CPPFLAGS ::= -iquotesrc/ $(CPPFLAGS)
7 CFLAGS ::= -g -std=c99 -Wall -Wextra -Wpedantic $(CFLAGS)
9 LDLIBS ::= -L/usr/local/lib -lGL -lGLEW -lglut -lassimp $(LDLIBS)
18 engine/performance.c \
25 srcfiles ::= $(addprefix $(SRCDIR)/, $(sources))
27 objects ::= $(addprefix $(BUILDDIR)/, $(addsuffix .o, $(srcfiles)))
28 depfiles ::= $(addprefix $(BUILDDIR)/, $(addsuffix .mk, $(srcfiles)))
30 # Set executable name for the platform
31 # TODO Base this on target platform instead of host OS
32 #ifeq ($(OS),Windows_NT)
37 binary ::= $(BUILDDIR)/shadowclad #$(binext)
43 # Default rule: build executable
46 @echo "###### Linking executable..."
47 $(CC) $(LDFLAGS) -o $(binary) $^ $(LOADLIBES) $(LDLIBS)
49 # Build C translation units
50 $(objects): $(BUILDDIR)/%.c.o: %.c $(BUILDDIR)/%.c.mk
52 $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
58 # Initialise build environment
70 @LD_LIBRARY_PATH=/usr/local/lib $(binary)
81 # Generate C prerequisite makefiles
82 $(depfiles): $(BUILDDIR)/%.c.mk: %.c Makefile
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|' $@
90 # Include generated C prerequisites
91 include $(foreach depfile, $(depfiles), $(shell [ -r "$(depfile)" ] && echo "$(depfile)"))
93 # Do not automatically delete generated prerequisites
94 .SECONDARY: $(depfiles)