#!/usr/bin/env make
# marcille - a dungeon generator.

#############################
# shell used by this Makefile
#############################

SHELL= bash


#######################
# common tool locations
#######################

CC= cc
CHMOD= chmod
CLANG= clang
GCC= gcc
GINDENT= gindent
MV= mv
RM= rm
TRUE= true


#####################
# C compiler settings
#####################

# Common C compiler warnings to silence
#
CSILENCE= -Wno-poison-system-directories

# Attempt to silence unknown warnings
#
CUNKNOWN= -Wno-unknown-warning-option

# Common C compiler warning flags
#
CWARN= -Wall -Wextra -pedantic ${CSILENCE} ${CUNKNOWN}

# The standard to compile against
#
CSTD= -std=gnu17

# Compiler bit architecture
#
ARCH=

# Defines that are needed to compile
#
CDEFINE=

# Include files that are needed to compile
#
CINCLUDE=

# Other flags to pass to the C compiler
#
COTHER=

# Optimization
#
OPT= -O3

# Default flags for ANSI C compilation
#
CFLAGS= ${CSTD} ${CWARN} ${ARCH} ${CDEFINE} ${CINCLUDE} ${COTHER} ${OPT}

# Libraries needed to build
#
LDFLAGS=

# C compiler to use
#
CC= cc

# Compiler add-ons or replacements for clang only
#
ifeq "$(findstring $(CLANG),${CC})" "$(CLANG)"
#
CSILENCE+=
#
CWARN+= -Weverything
#
endif

# Specific add-ons or replacements for gcc only
#
ifeq "$(findstring $(GCC),${CC})" "$(GCC)"
#
CSILENCE+=
#
CWARN+=
#
endif


###########################################
# Special Makefile variables for this entry
###########################################

# what to build
#
PROG= prog
OBJ= ${PROG}.o
TARGET= ${PROG}

# If you have alternate code, uncomment the next two lines and
# remove the rest of the comments:
# ALT_OBJ= ${PROG}.alt.o
# ALT_TARGET= ${PROG}.alt
ALT_OBJ=
ALT_TARGET=

# list any data files supplied with the submission
#
DATA=

#################
# build the entry
#################

all: data ${TARGET}

.PHONY: all data try clean clobber install

# how to compile
#
${PROG}: ${PROG}.c
	${CC} ${CFLAGS} ${PROG}.c -o $@ ${LDFLAGS}

# suggested way to run the program
try: ${PROG} ${DATA}
	./try.sh


# alternative executable
#
alt: data ${ALT_TARGET}
	@${TRUE}

${PROG}.alt: ${PROG}.alt.c
	${CC} ${CFLAGS} ${PROG}.alt.c -o $@ ${LDFLAGS}

# suggested way(s) to run alt code, if you include a prog.alt.c
#
try.alt: ${PROG}.alt ${DATA}
	@${TRUE}


# data files
#
data: ${DATA}

# both all and alt
#
everything: all alt


###############
# utility rules
###############

clean:
	${RM} -f ${OBJ} ${ALT_OBJ}
	@-if [[ -f indent.c ]]; then \
	    echo ${RM} -f indent.c; \
	    ${RM} -f indent.c; \
	fi

clobber: clean
	${RM} -f ${TARGET} ${ALT_TARGET} *.dSYM walking_mushroom.png
	@-if [[ -e sandwich ]]; then \
	    ${RM} -f sandwich; \
	    echo 'ate sandwich'; \
	fi


######################################
# optional include of 1337 hacker rulz
######################################

-include 1337.mk ../1337.mk ../../1337.mk
