# Makefile for MinorHack. Automatically compiles all entries in a directory
# and reports which ones failed.
# Windows users, you must have MINGDIR set, otherwise the Makefile will try to
# to compile for UNIX.

entry_SOURCES = $(wildcard *.cpp) $(wildcard *.c)

ifneq ($(MINGDIR),)
PLATFORM = Windows
entries = $(patsubst %.c,%.exe,$(patsubst %.cpp,%.exe,$(entry_SOURCES)))
LDLIBS = -lalleg
CC = gcc
CXX = g++

# MinGW doesn't have default rules?
%.exe: %.c
	$(CC) $(CFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS)
	echo $(DDA)

%.exe: %.cpp
	$(CXX) $(CXXFLAGS) $(LDFLAGS) $^ -o $@ $(LDLIBS)
else
PLATFORM = UNIX
entries = $(patsubst %.c,%,$(patsubst %.cpp,%,$(entry_SOURCES)))
LDLIBS = `allegro-config --libs`
endif

.PHONY: all post-compile 

all:
	@echo Compiling for $(PLATFORM)
	-$(MAKE) -k $(entries)
	$(MAKE) post-compile

post-compile:
	@$(if $(filter-out $(wildcard $(addprefix *,$(entries))), $(entries)), echo The following entries failed to compile: $(filter-out $(wildcard $(addprefix *,$(entries))), $(entries)), echo All entries compiled successfully)
