prefix = $(DESTDIR)@prefix@
mandir = ${prefix}/share/man
sysconfdir = $(DESTDIR)/etc

INSTALL=install
CFLAGS=-Wl,-z,now -O2 -Wall -Wstrict-prototypes -Werror -g \
	-DDCHROOT_VERSION="\"@DCHROOT_VERSION@\""

all: dchroot

docs: dchroot.1

dchroot : dchroot.c
	$(CC) $(CFLAGS) $@.c -o $@

install: all
	$(INSTALL) -d $(prefix)/bin
	$(INSTALL) --mode=4755 dchroot $(prefix)/bin
	$(INSTALL) -d $(sysconfdir)
	$(INSTALL) --mode=0644 dchroot.conf $(sysconfdir)
	$(INSTALL) -d $(prefix)/share/man/man1
	$(INSTALL) dchroot.1 $(prefix)/share/man/man1

clean:
	$(RM) dchroot.1 dchroot *~ *.o

dchroot.1: dchroot dchroot.inc
	help2man --manual="User Commands" \
		--name="Execute a command under a different root filesystem." \
		--section=1 \
		--source=Debian \
		--output=dchroot.1 \
		--include=dchroot.inc \
		--no-info \
		-h "-h" \
		-v "-V" \
		./dchroot

distclean: clean
	$(RM) config.log config.cache config.status Makefile
