prefix = @prefix@
exec_prefix = @exec_prefix@
perl = @with_perl@
# Need a default perl if none specified
ifeq ($(perl), )
perl = /usr/bin/perl
endif

cgidir = @with_cgidir@
# Need a default cgiif none specified
ifeq ($(cgidir), )
cgidir = $(prefix)/cgi-bin
endif


# The directory for installing executable programs that users can run.
bindir = @bindir@

# The directory for object files and libraries of object code.  Do
# not install executables here; they belong in `libexecdir' instead.
libdir = @libdir@

# The directory for installing config files
sysconfdir = @sysconfdir@


default:
	# replace the perl path
	for p in src/bin/* src/cgi-bin/* ; do \
		path=`echo $(perl) | sed 's/\//\\\\\//g'` ; \
		sed 1s/.*/\#\!$$path\ \-w/ < $$p > $$p.old ; \
		mv $$p.old $$p ; \
		chmod +x $$p ; \
	done
	# replace perl lib dirs
	for p in src/bin/* src/cgi-bin/* src/lib/*; do \
		path=`echo $(bindir) | sed 's/\//\\\\\//g'` ; \
		sed s/BINDIR=.*/BINDIR=\"$$path\"\;/ < $$p > $$p.old; \
		mv $$p.old $$p ; \
		path=`echo $(libdir) | sed 's/\//\\\\\//g'` ; \
		sed s/LIBDIR=.*/LIBDIR=\"$$path\"\;/ < $$p > $$p.old; \
		mv $$p.old $$p ; \
		path=`echo $(cgidir) | sed 's/\//\\\\\//g'` ; \
		sed s/CGIDIR=.*/CGIDIR=\"$$path\"\;/ < $$p > $$p.old; \
		mv $$p.old $$p ; \
		path=`echo $(sysconfdir) | sed 's/\//\\\\\//g'` ; \
		sed s/CONFDIR=.*/CONFDIR=\"$$path\"\;/ < $$p > $$p.old; \
		mv $$p.old $$p ; \
		chmod +x $$p ; \
	done

echo:
	echo $(perl)
	echo $(bindir)
	echo $(libdir)
	echo $(cgidir)

### targets required by GNU Coding standards ###

Makefile: Makefile.in config.status
	$(SHELL) ./config.status

install:
	$(SHELL) ./mkinstalldirs $(bindir) $(libdir) $(cgidir)
	for p in src/bin/* ; do \
		cp -f $$p $(bindir)/`basename $$p` ; \
	done
	for p in src/lib/* ; do \
		cp -f $$p $(libdir)/`basename $$p` ; \
	done
	for p in src/cgi-bin/* ; do \
		cp -f $$p $(cgidir)/`basename $$p` ; \
	done

config.status: configure
	$(SHELL) ./config.status --recheck

configure: configure.in
	cd $(srcdir) && $(AUTOCONF)

config.h.in: configure.in
	cd $(srcdir) && $(AUTOHEADER)

config.h: config.h.in
	$(SHELL) ./config.status

src/bin/add_black.cgi:
	echo src/bin/add_black.cgi