# Makefile for urlredir

# Please read the README file before compiling or installing this software.

#### Start of system configuration section. ####

CC = @CC@

INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)\" @DEBUG@ @NOREGEX@ @NOSAVESKIP@
LIBS = @LIBS@

CFLAGS = -Wall -O3

prefix = @prefix@
exec_prefix = $(prefix)

bindir = @bindir@
sysconfdir = @sysconfdir@
mandir = @mandir@

# Prefix to be prepended to each installed program, normally empty or `g'.
binprefix = 


#### End of system configuration section. ####

SHELL = /bin/sh

SRCS = main.c redir.c utils.c buildconf.l buildconf.y
OBJS = main.o redir.o utils.o lex.yy.o y.tab.o
HDRS = main.h redir.h buildconf.h utils.h
DISTFILES = $(SRCS) $(HDRS) urlredir.conf Makefile.in README \
            GPL.gz configure configure.in examples \
            install-sh version.c urlredir.1 urlredir.conf.5

all: urlredir
.PHONY: all

.c.o:
	$(CC) -c $(CPPFLAGS) $(DEFS) $(CFLAGS) $<

.PHONY: install
install:
	$(INSTALL_PROGRAM) -d $(bindir)
	-$(INSTALL_PROGRAM) -d $(sysconfdir)
	-$(INSTALL_PROGRAM) -d $(mandir)/man1 $(mandir)/man5
	-$(INSTALL_PROGRAM) urlredir $(bindir)/$(binprefix)urlredir
	-$(INSTALL_PROGRAM) -m644 urlredir.conf $(sysconfdir)/urlredir.conf
	-$(INSTALL_PROGRAM) -m644 urlredir.conf.5 $(mandir)/man5/urlredir.conf.5
	sed -e "s!_sysconfdir_!$(sysconfdir)!" urlredir.1 > $(mandir)/man1/$(binprefix)urlredir.1
	chmod 0644 $(mandir)/man1/$(binprefix)urlredir.1

urlredir: $(OBJS)
	$(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)

lex.yy.c: buildconf.l
	lex buildconf.l

y.tab.c y.tab.h: buildconf.y
	yacc -d buildconf.y

main.o redir.o: main.h redir.h buildconf.h utils.h
y.tab.o: main.h buildconf.h utils.h buildconf.y
lex.yy.o: buildconf.h main.h utils.h y.tab.h buildconf.l
utils.o: utils.h

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

config.status: configure
	./configure --no-create

.PHONY: clobber
clobber: clean

.PHONY: clean 
clean:
	rm -f urlredir *.o core y.tab.c y.tab.h lex.yy.c

.PHONY: distclean
distclean: clean
	rm -f Makefile config.status config.log config.cache

.PHONY: dist
dist: $(DISTFILES)
	echo urlredir-`sed -e '/version/!d' -e 's/[^0-9.]*\([0-9A-Za-z.]*\).*/\1/' -e q version.c` > .dname
	echo urlredir_`sed -e '/version/!d' -e 's/[^0-9.]*\([0-9A-Za-z.]*\).*/\1/' -e q version.c` > .fname
	rm -rf `cat .dname`
	mkdir `cat .dname`
	cd `cat .dname`; for file in $(DISTFILES); do ln -s ../$$file .; done
	tar chzf `cat .fname`.tar.gz `cat .dname`
	rm -rf `cat .dname` .dname .fname

# Prevent GNU make v3 from overflowing arg limit on SysV.
.NOEXPORT:
