#
# Makefile for inetcisd
#

#
# Variable definitions
#
PROGRAM_NAME=inetcisd
MAKEFILE=Makefile
CC=gcc
INCLUDE_DIR=-I $(HOME)/include -I ../include -I .
CFLAGS=-O2 -g -Wall -ansi -pedantic $(INCLUDE_DIR)
LDFLAGS=-L $(HOME)/lib -L ../lib -linetcis -lcud
SRCS=inetcisd.c
OBJS=inetcisd.o
LINKDEP=inetcisd.o ../lib/libinetcis.a
TARGET_FILE=PACKAGE

#
# Rules
#

bad:
	@echo Acceptable targets are production, mhaty, and mhaao.

production: production_define $(PROGRAM_NAME)
	@cp -f $(PROGRAM_NAME) $(PROGRAM_NAME).production
	
production_define:
	@if [ ! -f $(TARGET_FILE) ]; then touch $(TARGET_FILE); fi
	-@if grep -iq production $(TARGET_FILE); then \
		echo Rebuilding target production.; \
	else; \
		rm $(OBJS); echo -n CONFIG_PACKAGE_IS_PRODUCTION \
			 > $(TARGET_FILE); \
	fi


mhaty: mhaty_define $(PROGRAM_NAME)
	@cp -f $(PROGRAM_NAME) $(PROGRAM_NAME).mhaty
	# Automatically copy it over to mhaty.
	rsh -K mhaty mv -f /home/bchatfield/bin/$(PROGRAM_NAME) \
		/home/bchatfield/bin/$(PROGRAM_NAME).0
	cat $(PROGRAM_NAME) | rsh -K mhaty cat ">" /home/bchatfield/bin/$(PROGRAM_NAME)
	rsh -K mhaty chmod a+x /home/bchatfield/bin/$(PROGRAM_NAME)

mhaty_define:
	@if [ ! -f $(TARGET_FILE) ]; then touch $(TARGET_FILE); fi
	-@if grep -iq mhaty $(TARGET_FILE); then \
		echo Rebuilding target mhaty.; \
	else; \
		rm $(OBJS); echo -n CONFIG_PACKAGE_IS_MHATY > $(TARGET_FILE); \
	fi


mhaao: mhaao_define $(PROGRAM_NAME)
	@cp -f $(PROGRAM_NAME) $(PROGRAM_NAME).mhaao
	@if [ -f $(HOME)/bin/$(PROGRAM_NAME) ]; then \
		mv -f $(HOME)/bin/$(PROGRAM_NAME) \
			$(HOME)/bin/$(PROGRAM_NAME).0; \
	fi
	cp -f $(PROGRAM_NAME) $(HOME)/bin/$(PROGRAM_NAME)

mhaao_define:
	@if [ ! -f $(TARGET_FILE) ]; then touch $(TARGET_FILE); fi
	-@if grep -iq mhaao $(TARGET_FILE); then \
		echo Rebuilding target mhaao.; \
	else; \
		rm $(OBJS); echo -n CONFIG_PACKAGE_IS_MHAAO > $(TARGET_FILE); \
	fi


$(PROGRAM_NAME): $(PROGRAM_NAME).o ../lib/libinetcis.a
	$(CC) -o $(PROGRAM_NAME) $(OBJS) $(LDFLAGS)

.c.o:
	$(CC) $(CFLAGS) -D`cat $(TARGET_FILE)` -c $<

tags:
	@echo Generating TAGS file for emacs.
	@etags *.c ../lib/*.c *.h ../include/*.h


clean:
	-rm $(OBJS) $(PROGRAM_NAME) *~ *.log TAGS $(TARGET_FILE)

depend:
	@grep -q '^# DO NOT DELETE THIS LINE' $(MAKEFILE)
	@if [ $? ]; then \
		echo '/^# DO NOT DELETE THIS LINE/+1,$d|w' | ex $(MAKEFILE) \
	else \
		echo '\n# DO NOT DELETE THIS LINE - make depend requires it.' \
			>> $(MAKEFILE); \
	fi
	$(CC) -M $(CFLAGS) $(SRCS) >> $(MAKEFILE)


# DO NOT DELETE THIS LINE -- make depend requires it.
inetcisd.o : inetcisd.c /usr/include/sys/types.h /usr/include/machine/ansi.h \
  /usr/include/machine/types.h /usr/include/machine/endian.h /usr/include/sys/cdefs.h \
  /usr/include/sys/socket.h /usr/include/netinet/in.h /usr/include/arpa/inet.h \
  /usr/include/sys/param.h /usr/include/sys/syslimits.h /usr/include/sys/signal.h \
  /usr/include/machine/trap.h /usr/include/machine/param.h /usr/include/machine/vmlayout.h \
  /usr/include/machine/limits.h /usr/include/sys/errno.h /usr/include/sys/ioctl.h \
  /usr/include/sys/stat.h /usr/include/stdlib.h /usr/include/stdio.h /usr/include/fcntl.h \
  /usr/include/unistd.h /usr/include/sys/unistd.h /usr/include/sys/time.h /usr/include/time.h \
  /usr/include/termios.h /usr/include/sys/ttydefaults.h /usr/include/signal.h \
  /usr/include/setjmp.h /usr/include/ctype.h /usr/include/runetype.h /usr/include/syslog.h \
  /usr/include/stdarg.h /usr/include/machine/stdarg.h /usr/include/string.h /usr/include/limits.h \
  /home/mhaad/u4/bchatfield/include/comdef.h /home/mhaad/u4/bchatfield/include/pppcudint.h \
  ../include/x25io.h ../include/sockio.h ../include/misc.h ../include/log.h ../include/poserr.h \
  ./config.h 
