# -----------------------------------------------------------------------
#  Set USER and GROUP to the values you pass to the -u and -g options of
#  prospero

USER=www
GROUP=www

# Set WEBSOCKET to the appropriate path for Prospero for forward WebSocket
# requests.  See the prospero manual for details.

WEBSOCKET=/websocket/

# Set PUBLIC to the location of your public website.  A subdirectory named
# "house" will be created in ${PUBLIC} to hold house's HTML and SVG files.

PUBLIC=/usr/local/www/mammothcheese.ca

# Set FONTDIR to the directory where you want the fonts installed.  if you
# want to install the fonts into the "house" subdirectory, then use
# FONTDIR=${PUBLIC}/house/

FONTDIR=/usr/local/www/mammothcheese.ca

# Set WEBFONT to the web path to the fonts.  This is not the local
# directory (that's FONTDIR).  This is the path that will be concatenated
# with the font names in the stylesheet in index.html.

WEBFONT=/

# -----------------------------------------------------------------------

PREFIX?=/usr/local

BINDIR=${PREFIX}/bin
INCDIR=${PREFIX}/include
LIBDIR=${PREFIX}/lib
ETCDIR=${PREFIX}/etc/

INSTALL_PROGRAM?=/usr/bin/install -c -s -m550 -o root -g wheel
INSTALL_SCRIPT?=/usr/bin/install -c -m500 -o root -g wheel
INSTALL_MAN?=/usr/bin/install -c -m440 -o root -g wheel
INSTALL_DATA?=/usr/bin/install -c -m440 -o ${USER} -g ${GROUP}

MKDIR?=/bin/mkdir -p
RM?=/bin/rm -f
RMDIR?=/bin/rmdir
SED?=/usr/bin/sed
CP?=/bin/cp
GZIP_CMD?=/usr/bin/gzip
CHOWN?=/usr/sbin/chown
CHMOD?=/bin/chmod

VERSION=\"8.15\"
HTML=index.html dark_circles.svg circles.svg
FONTS=SourceSansPro-Regular.ttf SourceSansPro-Bold.ttf 

CFLAGS+=-Wall -DVERSION=${VERSION} -DPUBLIC=\"${PUBLIC}\" -DWEBSOCKET=\'${WEBSOCKET}\'

.if defined(SELFIES)
CFLAGS+= -DSELFIES
.endif

.PHONY: all
all: house

house: house.c
	${CC} ${CFLAGS} -o house house.c

.PHONY: start
start:
	${ETCDIR}/rc.d/house forcerestart

.PHONY: stop
stop:
	${ETCDIR}/rc.d/house forcestop

.PHONY: install
install: all
	${MKDIR} ${ETCDIR}/rc.d ${BINDIR} ${PUBLIC}/house/ ${FONTDIR}
	${CHOWN} ${USER}:${GROUP} ${PUBLIC}/house
	${CHMOD} 750 ${PUBLIC}/house
	${INSTALL_PROGRAM} house ${BINDIR}
	${SED} -e 's|%%WEBFONT%%|${WEBFONT}|1' -e 's|%%WEBSOCKET%%|${WEBSOCKET}|1' index.template > index.html
	${INSTALL_DATA} ${HTML} ${PUBLIC}/house/
	${INSTALL_DATA} ${FONTS} ${FONTDIR}
	${SED} -e 's|%%PREFIX%%|${PREFIX}|1' house.rcfile > house.rc
	${INSTALL_SCRIPT} house.rc ${ETCDIR}/rc.d/house

.PHONY: deinstall
deinstall:
	${RM} ${BINDIR}/house
	${RM} -r ${PUBLIC}/house/

.PHONY: debug
debug:
	${CC} ${CFLAGS} -O0 -g -o house house.c

.PHONY: clean
clean:

	rm -f house index.html *.rc *.o *tmp *backup *gz
