# $Id: Makefile.unx,v 1.9.2.1 2004/11/18 22:38:10 j_ali Exp $
# Copyright (c) Slash'EM Development Team 2001-2004
# NetHack may be freely redistributed.  See license for details.
#
# This makefile is for maintainer use. It is not needed when building the game.

AWK = awk

CFLAGS = -g -I../../include -pthread
#RPCLIB = -lrpclib

# ----------------------------------------
#
# Nothing below this line should have to be changed.

# timestamps for primary header files, matching src/Makefile
CONFIG_H = ../../src/config.h-t
HACK_H  = ../../src/hack.h-t

CSRC = nhxdr.c nhext.c nhextxdr.c nhextio.c nhextnb.c test_com.c

all:	tests

FORCE:

tests:	test_xdr rpcgen-test_xdr test_ext test_io FORCE
	@echo ""
	@echo Testing NhExt XDR routines...
	@echo The output of these two tests should be identical:
	@echo ============================
	- ./test_xdr -w | ./rpcgen-test_xdr -r
	@echo ============================
	- ./rpcgen-test_xdr -w | ./test_xdr -r
	@echo ============================
	@echo ""
	@echo Testing NhExt sub-protocol 1 support routines...
	@echo ============================
	- ./test_ext
	@echo ============================
	@echo ""
	@echo Testing NhExt I/O buffering routines...
	@echo ============================
	- ./test_io
	@echo ============================

test_xdr:	test_xdr.c nhxdr.o nhextxdr.o nhextio.o nhextnb.o
	$(CC) $(CFLAGS) -URPCGEN -o test_xdr test_xdr.c nhxdr.o nhextxdr.o \
		nhextio.c nhextnb.c

rpcgen-test_xdr:	test_xdr.c
	$(CC) $(CFLAGS) -DRPCGEN -o rpcgen-test_xdr test_xdr.c $(RPCLIB)

rpcgen-nhext.h rpcgen-nhext_xdr.c:	rpcgen-nhext.x
	rpcgen rpcgen-nhext.x

rpcgen-nhext.x:	ext_protocol.html
	$(AWK) '/<h3>init<\/h3>/ { init=1; } /^<pre>$$/ { if (init) output=1; next;} /^<\/pre>$$/ { output=0; } { if (output) print }' < ext_protocol.html > rpcgen-nhext.x

test_ext:	test_ext.c test_com.o nhext.o nhxdr.o nhextxdr.o nhextio.o \
	nhextnb.o
	$(CC) $(CFLAGS) -o test_ext test_ext.c test_com.o nhext.o nhxdr.o \
		nhextxdr.o nhextio.o nhextnb.o

test_io:	test_io.c test_com.o nhextio.o nhextnb.o
	$(CC) $(CFLAGS) -o test_io test_io.c test_com.o nhextio.o nhextnb.o

clean:
	$(RM) *.o test_xdr rpcgen-test_xdr test_ext test_io

spotless:	clean
	$(RM) rpcgen-nhext.h rpcgen-nhext_xdr.c rpcgen-nhext.x

depend: ../../sys/unix/depend.awk $(CSRC)
	$(AWK) -f ../../sys/unix/depend.awk ../../include/*.h $(CSRC) | \
	sed -e 's:\.\./include:\.\./\.\./include:g' \
	  -e 's:touch:@echo /**/ >>:' > makedep
	@echo '/^# DO NOT DELETE THIS LINE OR CHANGE ANYTHING BEYOND IT/+2,$$d' >eddep
	@echo '$$r makedep' >>eddep
	@echo 'w' >>eddep
	@cp Makefile.unx Makefile.bak
	ed - Makefile.unx < eddep
	ed - Makefile.w32 < eddep
	@rm -f eddep makedep
	@echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile.unx
	@echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile.unx
	@echo '# see make depend above' >> Makefile.unx
	@echo '# DEPENDENCIES MUST END AT END OF FILE' >> Makefile.w32
	@echo '# IF YOU PUT STUFF HERE IT WILL GO AWAY' >> Makefile.w32
	@echo '# see Makefile.unx' >> Makefile.w32
	- diff Makefile.bak Makefile.unx
	@rm -f Makefile.bak

# DO NOT DELETE THIS LINE OR CHANGE ANYTHING BEYOND IT

# config.h timestamp
$(CONFIG_H): ../../include/config.h
	touch $(CONFIG_H)
# hack.h timestamp
$(HACK_H): ../../include/hack.h
	touch $(HACK_H)
#
nhxdr.o: nhxdr.c ../../include/nhxdr.h
nhext.o: nhext.c ../../include/nhxdr.h ../../include/proxycom.h
nhextxdr.o: nhextxdr.c ../../include/nhxdr.h
nhextio.o: nhextio.c ../../include/nhxdr.h ../../include/proxycom.h
nhextnb.o: nhextnb.c ../../include/nhxdr.h ../../include/proxycom.h
test_com.o: test_com.c test_com.h
# DEPENDENCIES MUST END AT END OF FILE
# IF YOU PUT STUFF HERE IT WILL GO AWAY
# see make depend above
