#-----------------------------------------------------------------------------
#
# SocketIO makefile for the platform @OS@, on the host @host@.
#
#-----------------------------------------------------------------------------
VER=6.0.2
CC=@CC@
CFLAGS=@CFLAGS@
#CFLAGS=-O2 -g -W -Wall -Wimplicit -Wstrict-prototypes -Wmissing-prototypes
VPATH=@srcdir@
CPPFLAGS=@CPPFLAGS@
LDFLAGS=@LDFLAGS@
LIBS=@LIBS@
DEFS=@DEFS@@NDEFS@
PREFIX=@prefix@
LIB=libsio.a
LIBSO=libsio.so.5
LIBSOS=libsio.so
STRIP=strip

OBJS=\
PRead.o		  PWrite.o	    SAcceptA.o	      SAcceptS.o \
SBind.o		  SClose.o	    SConnect.o	      SConnectByName.o \
SNew.o		  SRead.o	    SReadline.o       SRecv.o \
SRecvfrom.o	  SRecvmsg.o	    SSelect.o	      SSend.o \
SSendto.o	  SSendtoByName.o   SWrite.o	      SocketUtil.o \
StrAddr.o	  UAcceptA.o	    UAcceptS.o	      UBind.o \
UConnect.o	  UConnectByName.o  UNew.o	      URecvfrom.o \
USendto.o	  USendtoByName.o   SError.o          main.o \
SWait.o

SOBJS=\
PRead.so	   PWrite.so	      SAcceptA.so	 SAcceptS.so \
SBind.so	   SClose.so	      SConnect.so	 SConnectByName.so \
SNew.so		   SRead.so	      SReadline.so	 SRecv.so \
SRecvfrom.so	   SRecvmsg.so	      SSelect.so	 SSend.so \
SSendto.so	   SSendtoByName.so   SWrite.so		 SocketUtil.so \
StrAddr.so	   UAcceptA.so	      UAcceptS.so	 UBind.so \
UConnect.so	   UConnectByName.so  UNew.so		 URecvfrom.so \
USendto.so	   USendtoByName.so   SError.so          main.so \
SWait.so

all: $(LIB)
	-@/bin/ls -l $(LIB)
	-@echo 'Done.'

$(LIB): $(OBJS)
	/bin/rm -f $(LIB)
	ar rv $(LIB) $(OBJS)
	-@RANLIB@ $(LIB)
	chmod a+r $(LIB) sio.h usio.h

install: $(LIB)
	cp $(LIB) $(PREFIX)/lib/$(LIB)
	cp sio.h usio.h $(PREFIX)/include
	chmod a+r $(PREFIX)/lib/$(LIB) $(PREFIX)/include/sio.h $(PREFIX)/include/usio.h
	-@/bin/ls -l $(PREFIX)/lib/$(LIB) $(PREFIX)/include/sio.h $(PREFIX)/include/usio.h

shared: $(LIBSO)

so: $(LIBSO)

$(LIBSO): $(SOBJS)
	/bin/rm -f $(LIBSO)
	gcc -shared -Wl,-soname,$(LIBSO) -o $(LIBSO) $(SOBJS)
	chmod a+r $(LIB) sio.h usio.h
	-@/bin/ls -l $(LIBSO)

soinstall: $(LIBSO)
	cp $(LIBSO) $(PREFIX)/lib/$(LIBSO)
	/bin/rm -f $(PREFIX)/lib/$(LIBSOS)
	( cd $(PREFIX)/lib ; /bin/ln -s $(LIBSO) $(LIBSOS) )
	cp sio.h usio.h $(PREFIX)/include
	chmod a+r $(PREFIX)/lib/$(LIBSO) $(PREFIX)/include/sio.h $(PREFIX)/include/usio.h
	-@/bin/ls -l $(PREFIX)/lib/$(LIBSO) $(PREFIX)/include/sio.h $(PREFIX)/include/usio.h

ucase_c: ucase_c/ucase_c.c $(LIB)
	( cd ucase_c ; $(MAKE) "CFLAGS=$(CFLAGS)" "STRIP=$(STRIP)" "LIBS=$(LIBS)" )

ucase_s: ucase_s/ucase_s.c $(LIB)
	( cd ucase_s ; $(MAKE) "CFLAGS=$(CFLAGS)" "STRIP=$(STRIP)" "LIBS=$(LIBS)" )

srltest: srltest/srltest.c $(LIB)
	( cd srltest ; $(MAKE) "CFLAGS=$(CFLAGS)" "STRIP=$(STRIP)" "LIBS=$(LIBS)" )

time_c: time_c/time_c.c $(LIB)
	( cd time_c ; $(MAKE) "CFLAGS=$(CFLAGS)" "STRIP=$(STRIP)" "LIBS=$(LIBS)" )

time_s: time_s/time_s.c $(LIB)
	( cd time_s ; $(MAKE) "CFLAGS=$(CFLAGS)" "STRIP=$(STRIP)" "LIBS=$(LIBS)" )

samples: ucase_c ucase_s time_c time_s srltest

SHELL=/bin/sh
.SUFFIXES: .c .o .so

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

.c.so:
	$(CC) -fpic $(CFLAGS) $(CPPFLAGS) $(DEFS) $*.c -c -o $*.so

### Cleaning supplies ########################################################

clean:
	-/bin/rm -f $(OBJS) $(SOBJS) $(LIB) $(LIBSO) ucase_c/ucase_c ucase_s/ucase_s time_c/time_c time_s/time_s

distclean:	clean
	-/bin/rm -f config.h Makefile config.status config.cache config.log

### Archiving #################################################################

CFILES=\
PRead.c		  PWrite.c	    SAcceptA.c	      SAcceptS.c \
SBind.c		  SClose.c	    SConnect.c	      SConnectByName.c \
SNew.c		  SRead.c	    SReadline.c       SRecv.c \
SRecvfrom.c	  SRecvmsg.c	    SSelect.c	      SSend.c \
SSendto.c	  SSendtoByName.c   SWrite.c	      SocketUtil.c \
StrAddr.c	  UAcceptA.c	    UAcceptS.c	      UBind.c \
UConnect.c	  UConnectByName.c  UNew.c	      URecvfrom.c \
USendto.c	  USendtoByName.c   SWait.c           main.c	      

HFILES=sio.h usio.h

DOCFILES=sio.html
CFGFILES=config.h.in configure.in configure Makefile.in
CFGJUNK=config.h Makefile config.*
MOREJUNK=

# This is everything that is copied when you make a shar or tar.
PACKAGE=$(DOCFILES) $(HFILES) $(CFGFILES) $(MOREJUNK) $(CFILES)

TMPDIR=/tmp
TARDIR=sio-$(VER)
TARFILE=$(TARDIR).tar
TGZFILE=$(TARDIR).tar.gz

tarcp:
	-@mkdir -p $(TMPDIR)/TAR/$(TARDIR)
	-@chmod ga+r $(PACKAGE)
	-@chmod 755 $(TMPDIR)/TAR/$(TARDIR)
	cp -pr $(PACKAGE) $(TMPDIR)/TAR/$(TARDIR)

tar: $(PACKAGE)
	-@mkdir $(TMPDIR)/TAR
	-@mkdir $(TMPDIR)/TAR/$(TARDIR)
	-@chmod ga+r $(PACKAGE)
	find . -depth -type f -print | cut -c3- | grep -v '.o$$' | grep -v '.so$$' | grep -v 'core$$' | grep -v 'Makefile$$' | grep -v 'config.log$$' | grep -v 'config.h$$' | grep -v 'config.cache$$' | grep -v 'config.status$$' | grep -v '.a$$' | grep -v '.lib$$' | grep -v '.ncb$$' | grep -v '.opt$$' | grep -v '.zip$$' | grep -v '.gz$$' | grep -v '.swp$$' | grep -v '.tar$$' | cpio -pdm $(TMPDIR)/TAR/$(TARDIR)
	( cd $(TMPDIR)/TAR ; tar cf $(TARFILE) $(TARDIR) )
	cp $(TMPDIR)/TAR/$(TARFILE) .
	-@chmod 644 $(TARFILE)
	-@rm -rf $(TMPDIR)/TAR
	-@ls -l $(TARFILE)

gz: tar
	gzip -c $(TARFILE) > $(TGZFILE)
	-@rm $(TARFILE)
	-@chmod 644 $(TGZFILE)
	-@ls -l $(TGZFILE)

### Dependencies #############################################################

PRead.o: PRead.c sio.h
PWrite.o: PWrite.c sio.h
SAcceptA.o: SAcceptA.c sio.h
SAcceptS.o: SAcceptS.c sio.h
SBind.o: SBind.c sio.h
SClose.o: SClose.c sio.h
SConnect.o: SConnect.c sio.h
SConnectByName.o: SConnectByName.c sio.h
SNew.o: SNew.c sio.h
SRead.o: SRead.c sio.h
SReadline.o: SReadline.c sio.h
SRecv.o: SRecv.c sio.h
SRecvfrom.o: SRecvfrom.c sio.h
SRecvmsg.o: SRecvmsg.c sio.h
SSelect.o: SSelect.c sio.h
SSend.o: SSend.c sio.h
SSendto.o: SSendto.c sio.h
SSendtoByName.o: SSendtoByName.c sio.h
SWrite.o: SWrite.c sio.h
SWait.o: SWait.c sio.h
SocketUtil.o: SocketUtil.c sio.h
StrAddr.o: StrAddr.c sio.h
UAcceptA.o: UAcceptA.c sio.h usio.h
UAcceptS.o: UAcceptS.c sio.h usio.h
UBind.o: UBind.c sio.h usio.h
UConnect.o: UConnect.c sio.h usio.h
UConnectByName.o: UConnectByName.c sio.h usio.h
UNew.o: UNew.c sio.h usio.h
URecvfrom.o: URecvfrom.c sio.h usio.h
USendto.o: USendto.c sio.h usio.h
USendtoByName.o: USendtoByName.c sio.h usio.h
main.o: main.c sio.h
