#!/usr/bin/sh
# Revised to compile under Cygwin 1.5.12-1 and gcc 3.3.3, but
# probably will compile under other Cygwin releases.
# This makefile is based on the original makefiles supplied with
# the ping implementation from Mike Muuss.

# The BINDIR is the directory in which the ping executable will 
# be installed and the MANDIR is the directory in which the ping 
# manual page will be installed.

prefix = /usr
BINDIR = ${prefix}/bin
MANDIR = ${prefix}/share/man/man1
DOCDIR = ${prefix}/share/doc/ping

# You shouldn't need to change anything below this line.

CC= gcc
CFLAGS = -O2
CPPFLAGS = -I/usr/include
LDFLAGS = -s
G = -g
INCL = -I.
LIBS = 

# Script (or program) that returns the machine and os types.
# You can also edit in the name yourself.
MD=`uname -m`
OS=`uname -o`

# Script (or program) that returns the user and and group,
# or just edit in the name yourself. In case the user belongs
# to several groups, it will be returned only the first.
# You can edit the name and group to one of your preference.
MY_USER = `whoami`
MY_GROUP = `groups | awk '{print $$1}'`


all:
	-@dir=$(MD)-$(OS); set -x; \
	if [ ! -d $$dir ]; then ${MAKE} ${MFLAGS} config; fi; \
	if [ -n "`find Makefile -newer $$dir/Makefile -print`" ]; \
	  then ${MAKE} ${MFLAGS} config; fi; \
	cd $$dir; ${MAKE} ${MFLAGS} ping

ping:
	$(CC) $(CPPFLAGS) $(INCL) $(G) $(CFLAGS) $(LDFLAGS)  -o ping ping.c $(LIBS)


# N.B.- symbolic links are used in the subdirectory rather than VPATH
# because at least one Sun cc compiler puts the .o in the wrong place
# when using VPATH and it's almost impossible to get "make depend" to
# do the right thing.

config:
	-@dir=$(MD)-$(OS); set -x; \
	mkdir $$dir; chmod ug+w $$dir; \
	ln -s ../ping.c $$dir; ln -s ../ping.1 $$dir; \
	sed -e "/^all:/d" Makefile >$$dir/Makefile; \
	chmod ug+w $$dir/Makefile; \

install:
	-@dir=$(MD)-$(OS); set -x; \
	install -c -o $(MY_USER) -g $(MY_GROUP) -m 755 -D $$dir/ping.exe ${DESTDIR}${BINDIR}/ping.exe; \
	install -c -o $(MY_USER) -g $(MY_GROUP) -m 664 -D $$dir/ping.1 ${DESTDIR}${MANDIR}/ping.1
	install -c -o $(MY_USER) -g $(MY_GROUP) -m 664 -D AUTHORS ${DESTDIR}${DOCDIR}/AUTHORS
	install -c -o $(MY_USER) -g $(MY_GROUP) -m 664 -D LICENSE ${DESTDIR}${DOCDIR}/LICENSE
	install -c -o $(MY_USER) -g $(MY_GROUP) -m 664 -D CHANGELOG ${DESTDIR}${DOCDIR}/CHANGELOG

clean:
	-@dir=$(MD)-$(OS); set -x; rm -rf $$dir

distclean:
	-@dir=$(MD)-$(OS); set -x; rm -rf $$dir

uninstall:
	-@dir=$(MD)-$(OS); set -x; \
	rm ${DESTDIR}${BINDIR}/ping.exe; \
	rm ${DESTDIR}${MANDIR}/ping.1; \
	rm ${DESTDIR}${DOCDIR}/AUTHORS \
	rm ${DESTDIR}${DOCDIR}/LICENSE \
	rm ${DESTDIR}${DOCDIR}/CHANGELOG \
	rm -rf $$dir; 

