#  Das Password Manager
#  Copyright (C) 2013  Daniel Gröber <dxld ÄT darkboxed DOT org>
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.

include config.mk

all: pmenu output-trigger

configure: config.sed

config.sed: config.mk
	@echo "s|@PREFIX@|${PREFIX}|" > $@
	@echo "s|@BINDIR@|${BINDIR}|" >> $@
	@echo "s|@DATADIR@|${DATADIR}|" >> $@
	@echo "s|@LIBEXECDIR@|${LIBEXECDIR}|" >> $@

output-trigger: config.mk output-trigger.c
	@echo CC -o $@
	@${CC} -o $@ output-trigger.c


pmenu_SRC = pmenu.c draw.c
pmenu_OBJ = ${pmenu_SRC:.c=.o}

.c.o:
	@echo CC -c $<
	@${CC} -c $< ${pmenu_CFLAGS}

${pmenu_OBJ}: config.mk draw.h

pmenu: ${pmenu_OBJ}
	@echo CC -o $@
	@${CC} -o $@ pmenu.o draw.o ${pmenu_LDFLAGS}


install: config.sed pmenu output-trigger
	mkdir -p ${DESTDIR}${BINDIR}
	mkdir -p ${DESTDIR}${LIBEXECDIR}/dpw

	sed -f config.sed dpw > ${DESTDIR}${BINDIR}/dpw
	chmod 0755 ${DESTDIR}${BINDIR}/dpw

	install -m 0755 pmenu ${DESTDIR}${LIBEXECDIR}/dpw
	install -m 0755 output-trigger ${DESTDIR}${LIBEXECDIR}/dpw

clean:
	rm -f config.sed output-trigger pmenu ${pmenu_OBJ}

.PHONY: clean dist configure install uninstall
