PROGRAMS = ipinfo ipmatch

BINDIR = /usr/local/bin
MANDIR = /usr/local/man/man1

MAKE = /usr/bin/make
MKDIR = /bin/mkdir
RM = /bin/rm
CC = /usr/bin/gcc
INSTALL = /usr/bin/install
POD2MAN = /usr/bin/pod2man -c '' -r ''

CFLAGS = 
LIBS = -lm
DEFINES = 

all: $(PROGRAMS)

ipinfo:
	$(CC) $(DEFINES) $(CFLAGS) ipinfo.c -o ipinfo $(LIBS)

ipmatch:
	$(CC) $(DEFINES) $(CFLAGS) ipmatch.c -o ipmatch $(LIBS)

clean:
	$(RM) -f $(PROGRAMS)

install:
	@test -d $(BINDIR) || $(MKDIR) -p $(BINDIR) || exit 1
	@test -d $(MANDIR) || $(MKDIR) -p $(MANDIR) || exit 1
	@for P in $(PROGRAMS); do \
		if [ ! -s "$${P}" ]; then $(MAKE) $${P} || exit 1; fi; \
		echo $(INSTALL) $${P} $(BINDIR); \
		$(INSTALL) $${P} $(BINDIR) || exit 1; \
		if [ ! -s "$${P}.1" ]; then echo "Manpage $${P}.1 does not exist"; exit 1; fi; \
		echo $(INSTALL) $${P}.1 $(MANDIR); \
		$(INSTALL) $${P}.1 $(MANDIR) || exit 1; \
	done

uninstall:
	@for P in $(PROGRAMS); do \
		echo $(RM) -f $(BINDIR)/$${P} $(MANDIR)/$${P}.1; \
		test -f $(BINDIR)/$${P} && $(RM) -f $(BINDIR)/$${P}; \
		test -f $(MANDIR)/$${P}.1 && $(RM) -f $(MANDIR)/$${P}.1; \
	done

man:
	@for P in $(PROGRAMS); do \
		if [ ! -s "$${P}.pod" ]; then echo "Pod file $${P}.pod does not exist"; exit 1; fi; \
		echo $(POD2MAN) $${P}.pod $${P}.1; \
		$(POD2MAN) $${P}.pod $${P}.1 || exit 1; \
	done

clean-all: clean clean-man

clean-man:
	@for P in $(PROGRAMS); do \
		echo $(RM) -f $${P}.1; \
		$(RM) -f $${P}.1; \
	done

