include		Makefile.version

INCLUDE =	
PREFIX =	/usr/local
# .h files installed to $(PREFIX)/include/Sockets
# static lib .a files installed to $(PREFIX)/lib

CXX =		g++

CFLAGS =	-Wall -g $(INCLUDE) -MD -D_VERSION='"$(VERSION)"'

# turn off optimization if compiling with gcc 2.9.x:
#CFLAGS +=	-O0
CFLAGS +=	-O2


# uncomment depending on your operating system
#CFLAGS +=	-DLINUX
#CFLAGS +=	-DMACOSX 
# solaris > 8
#CFLAGS +=	-DSOLARIS
# solaris 8
#CFLAGS +=	-DSOLARIS8
# windows and/or cygwin
#CFLAGS +=	-D_WIN32
# cygwin
#CFLAGS +=	-D__CYGWIN__


# uncomment these lines if the library should be in its own namespace
#CFLAGS +=	-DSOCKETS_NAMESPACE=sockets
#CFLAGS +=	-DSOCKETS_NAMESPACE_STR='"sockets"'


# Enable insane amounts of debug output to stdout/stderr:
#CFLAGS +=	-D_DEBUG


CPPFLAGS =	$(CFLAGS) 

LIBS =		-lSockets -lpthread -lssl -lcrypto

PROGS =		Sockets-config

all:		libSockets.a $(PROGS)

Sockets-config:	Sockets-config.o
		$(CXX) -o $@ $^

libSockets.a:	$(OBJS)
		ar cru $@ $(OBJS)
		ranlib $@

clean:
		rm -f *.o *~ slask *.d $(PROGS) *.a */*~

-include	*.d

# everything which follows is www.alhem.net/Sockets website maintenance stuff, please ignore
HTDOCS =	/usr/local/apache/www.alhem.net/htdocs

diff:
		diff -C 3 $(HTDOCS)/Sockets/Sockets-$(DIFF_VERSION) . | \
			/usr/local/bin/d2html > \
			$(HTDOCS)/Sockets/latest_diff.html

install:	all 
		@mkdir -p $(PREFIX)/lib
		cp libSockets.a $(PREFIX)/lib
		@mkdir -p $(PREFIX)/include/Sockets
		cp -a *.h $(PREFIX)/include/Sockets
		@rm -f $(PREFIX)/include/Sockets/SSLSocket.*
		@rm -f $(PREFIX)/include/Sockets/HttpsGetSocket.*
		@rm -f $(PREFIX)/include/Sockets/HttpsSocket.*
		@rm -f $(PREFIX)/include/Sockets/EventSocket.*
		@rm -f $(PREFIX)/include/Sockets/PoolSocket.*
		@rm -f $(PREFIX)/include/Sockets/SocketThread.*
		@rm -f $(PREFIX)/include/Sockets/CircularBuffer.*
		@rm -f $(PREFIX)/include/Sockets/*Crypt.h
		@rm -f $(PREFIX)/include/Sockets/CTcpSocket.h
		@rm -f $(PREFIX)/include/Sockets/Min*Socket.h
		@rm -f $(PREFIX)/include/Sockets/Min*Handler.h
		@rm -f $(PREFIX)/include/Sockets/Uid.h
		@mkdir -p $(PREFIX)/bin
		install Sockets-config $(PREFIX)/bin

# no binary files, zip will translate lf to cr lf
FILES =		*.h *.cpp Makefile Makefile.* Project/*.ds* \
		README.macosx gpl.txt mkdot.sh \
		Project.net/Sockets/*.vcproj Project.net/Sockets/*.sln \
		Project.net/Test/*.vcproj \
		DevCpp/*.dev tests/Makefile tests/*.cpp

tar:		clean
		rm -f MinderSocket_T.h
		rm -f uuid.h
		rm -f Stdin.*
		rm -f sockets_test.cpp
		rm -f ListenSocketBase.*
		rm -f CircularBuffer.*
		rm -f ICrypt.* NullCrypt.* CTcpSocket.*
		rm -f Min*Socket.* Min*Handler.*
		rm -f Uid.*
		tar czf Sockets-$(VERSION).tar.gz $(FILES)
		/usr/local/bin/tarfix.sh Sockets-$(VERSION)
		cp Sockets-$(VERSION).tar.gz $(HTDOCS)/Sockets
		cp Sockets-$(VERSION).zip $(HTDOCS)/Sockets
		cp tests/sockets_test.cpp /usr/local/apache/www.alhem.net/htdocs/Sockets/

tmptar:		clean
		rm -f MinderSocket_T.h
		rm -f uuid.h
		rm -f Stdin.*
		rm -f sockets_test.cpp
		rm -f ListenSocketBase.*
		rm -f CircularBuffer.*
		rm -f ICrypt.* NullCrypt.* CTcpSocket.*
		rm -f Min*Socket.* Min*Handler.*
		rm -f Uid.*
		tar czf Sockets-$(VERSION).tar.gz $(FILES)
		/usr/local/bin/tarfix.sh Sockets-$(VERSION)
		cp Sockets-$(VERSION).tar.gz $(HTDOCS)/Sockets-tmp
		cp Sockets-$(VERSION).zip $(HTDOCS)/Sockets-tmp
		cp tests/sockets_test.cpp /usr/local/apache/www.alhem.net/htdocs/Sockets-tmp

docs:		clean
		doxygen dox2.cfg
		rm -f MinderSocket_T.h
		rm -f uuid.h
		rm -f Stdin.*
		rm -f sockets_test.cpp
		rm -f ListenSocketBase.*
		rm -f CircularBuffer.*
		rm -f ICrypt.* NullCrypt.* CTcpSocket.*
		rm -f Min*Socket.* Min*Handler.*
		rm -f Uid.*
		rm -f tests/*.cpp
		./mkdot.sh
		rm -rf /usr/local/apache/www.alhem.net/htdocs/Sockets/html
		doxygen doxygen.cfg
		./packdocs.sh Sockets-$(VERSION)-doxygendocs
		cvs up

tmpdocs:	clean
		rm -f MinderSocket_T.h
		rm -f uuid.h
		rm -f Stdin.*
		rm -f sockets_test.cpp
		rm -f ListenSocketBase.*
		rm -f CircularBuffer.*
		rm -f ICrypt.* NullCrypt.* CTcpSocket.*
		rm -f Min*Socket.* Min*Handler.*
		rm -f Uid.*
		rm -f tests/*.cpp
		./mkdot-tmp.sh
		rm -rf /usr/local/apache/www.alhem.net/htdocs/Sockets-tmp/html
		doxygen doxygen-tmp.cfg
		cvs up
