srcdir   = @srcdir@
VPATH    = @srcdir@

CC           	= @CC@
MAKED    	= @MAKED@
BINRM    	= @BINRM@
INSTALL  	= @INSTALL@
RANLIB	 	= @RANLIB@
AR       	= ar rv
LDFLAGS  	= @LDFLAGS@
LIBS     	= @LIBS@
SHLIB_CFLAGS 	= @SHLIB_CFLAGS@
SHLIB_OFLAGS 	= @SHLIB_OFLAGS@
SHLIB_LFLAGS 	= @SHLIB_LFLAGS@
SHLIB_LIBS   	= @SHLIB_LIBS@
PLUGIN_LIBS     = @PLUGIN_LIBS@
SHLIB_LIB    	= @SHLIB_LIB@
SHLIB_DIR    	= @SHLIB_DIR@
SHLIB_LD     	= @SHLIB_LD@
DLLIBS       	= @DLLIBS@
CDEBUG_FLAGS 	= @CDEBUG_FLAGS@
EXTRA_CFLAGS 	= 
CLIENT_PLUGIN_OBJS = @CLIENT_PLUGIN_OBJS@

SOCKS5_CFLAGS   = -I../include -I$(srcdir)/../lib -I$(srcdir)/../include @CFLAGS@ $(CDEBUG_FLAGS) @DEFS@ $(EXTRA_CFLAGS) $(SHLIB_CFLAGS)
CFLAGS          = $(SOCKS5_CFLAGS) -DFOR_SHARED_LIBRARY -DIN_LIBRARY
#PIN_CFLAGS avoids RLD prepended to function calls when the object is to be a plugin
PIN_CFLAGS      = $(SOCKS5_CFLAGS) @SHARED_LIBSOCKS5_CFLAGS@

prefix 		= @prefix@
exec_prefix 	= @exec_prefix@
libdir 		= $(prefix)/lib

OBJS = msg.o protocol.o log.o hostname.o confutil.o buffer.o cache.o wrap.o wrap_tcp.o wrap_udp.o    \
	conf.o libproto.o select.o rld.o null.o addr.o shim.o dpin.o dpinutil.o $(CLIENT_PLUGIN_OBJS) 
AUTH_U_OBJS     = upwd.o
AUTH_K_OBJS     = gss.o
AUTH_C_OBJS     = cram.o
FILTER_P_OBJS   = packet.o

SRCS = $(srcdir)/../lib/msg.c $(srcdir)/../lib/protocol.c $(srcdir)/../lib/log.c \
	$(srcdir)/../lib/hostname.c $(srcdir)/../lib/confutil.c $(srcdir)/../lib/buffer.c \
	$(srcdir)/../lib/cache.c $(srcdir)/../lib/wrap.c $(srcdir)/../lib/wrap_tcp.c $(srcdir)/../lib/wrap_udp.c  \
	$(srcdir)/../lib/conf.c $(srcdir)/../lib/libproto.c $(srcdir)/../lib/select.c $(srcdir)/../lib/rld.c       \
	$(srcdir)/../lib/null.c $(srcdir)/../lib/addr.c $(srcdir)/../lib/shim.c \
	$(srcdir)/../lib/dpin.c $(srcdir)/../lib/dpinutil.c \
	$(srcdir)/../lib/upwd.c $(srcdir)/../lib/gss.c $(srcdir)/../lib/cram.c $(srcidr)/../server/packet.c
HDRS = $(srcdir)/../lib/msg.h $(srcdir)/../lib/protocol.h $(srcdir)/../lib/log.h \
	$(srcdir)/../lib/hostname.h $(srcdir)/../lib/confutil.h $(srcdir)/../lib/buffer.h \
	$(srcdir)/../lib/cache.h $(srcdir)/../lib/wrap.h $(srcdir)/../lib/wrap_tcp.h $(srcdir)/../lib/wrap_udp.h  \
	$(srcdir)/../lib/conf.h $(srcdir)/../lib/libproto.h \
	$(srcdir)/../lib/null.h $(srcdir)/../lib/addr.h $(srcdir)/../lib/shim.h \
	$(srcdir)/../lib/dpin.h $(srcdir)/../lib/dpinutil.h \
	$(srcdir)/../lib/upwd.h $(srcdir)/../lib/gss.h $(srcdir)/../lib/cram.h $(srcidr)/../server/packet.h

all:: Makefile runsocks $(SHLIB_LIB) $(PLUGIN_LIBS)
	@(if [ ! -x runsocks ]     ; then (chmod +x runsocks);   fi)

Makefile: $(srcdir)/Makefile.in ../config.status
	(cd ..; CONFIG_FILES=shlib/Makefile CONFIG_HEADERS= ./config.status)

runsocks: $(srcdir)/runsocks.in ../config.status
	(cd ..; CONFIG_FILES=shlib/runsocks CONFIG_HEADERS= ./config.status)

libsocks5_sh.so: $(OBJS)
	$(SHLIB_LD) -o $@ $(SHLIB_LFLAGS) $(OBJS) $(LDFLAGS) $(SHLIB_LIBS) $(DLLIBS)

libs5auth_u.so: $(AUTH_U_OBJS)
	$(SHLIB_LD) -o $@ $(SHLIB_LFLAGS) $(AUTH_U_OBJS) $(LDFLAGS) $(SHLIB_LIBS) $(DLLIBS)

libs5auth_k.so: $(AUTH_K_OBJS)
	$(SHLIB_LD) -o $@ $(SHLIB_LFLAGS) $(AUTH_K_OBJS) $(LDFLAGS) $(SHLIB_LIBS) $(DLLIBS)

libs5auth_c.so: $(AUTH_C_OBJS)
	$(SHLIB_LD) -o $@ $(SHLIB_LFLAGS) $(AUTH_C_OBJS) $(LDFLAGS) $(SHLIB_LIBS) $(DLLIBS)

libs5filter_p.so: $(FILTER_P_OBJS)
	$(SHLIB_LD) -o $@ $(SHLIB_LFLAGS) $(FILTER_P_OBJS) $(LDFLAGS) $(SHLIB_LIBS) $(DLLIBS)

install: Makefile $(SHLIB_LIB) runsocks
	if [ -n "$(SHLIB_LIB)" -a -f "$(SHLIB_LIB)" ] ; then $(INSTALL) $(SHLIB_LIB) $(prefix)/lib ; $(INSTALL) runsocks $(exec_prefix)/bin; fi

clean:
	-$(BINRM) *.o $(SHLIB_LIB) $(PLUGIN_LIBS) so_locations

distclean: clean
	-$(BINRM) Makefile runsocks *~ #*# *.bak

depend:
	$(MAKED) -I/usr/local/include -- $(CFLAGS) -- $(SRCS)
	mv Makefile Makefile.tmp; cat Makefile.tmp | sed s,\^$(srcdir)/\.\./lib/,,g > Makefile; rm Makefile.tmp


msg.o: $(srcdir)/../lib/msg.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/msg.c

protocol.o: $(srcdir)/../lib/protocol.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/protocol.c

log.o: $(srcdir)/../lib/log.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/log.c

hostname.o: $(srcdir)/../lib/hostname.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/hostname.c

confutil.o: $(srcdir)/../lib/confutil.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/confutil.c

buffer.o: $(srcdir)/../lib/buffer.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/buffer.c

cache.o: $(srcdir)/../lib/cache.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/cache.c

wrap.o: $(srcdir)/../lib/wrap.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/wrap.c

wrap_tcp.o: $(srcdir)/../lib/wrap_tcp.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/wrap_tcp.c

wrap_udp.o: $(srcdir)/../lib/wrap_udp.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/wrap_udp.c

conf.o: $(srcdir)/../lib/conf.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/conf.c

libproto.o: $(srcdir)/../lib/libproto.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/libproto.c

select.o: $(srcdir)/../lib/select.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/select.c

rld.o: $(srcdir)/../lib/rld.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/rld.c

null.o: $(srcdir)/../lib/null.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/null.c

addr.o: $(srcdir)/../lib/addr.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/addr.c

shim.o: $(srcdir)/../lib/shim.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/shim.c

dpin.o: $(srcdir)/../lib/dpin.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/dpin.c

dpinutil.o: $(srcdir)/../lib/dpinutil.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c $(srcdir)/../lib/dpinutil.c

upwd.o: $(srcdir)/../lib/upwd.c
	$(CC) $(CPPFLAGS) $(PIN_CFLAGS) -c $(srcdir)/../lib/upwd.c

gss.o: $(srcdir)/../lib/gss.c
	$(CC) $(CPPFLAGS) $(PIN_CFLAGS) -c $(srcdir)/../lib/gss.c

cram.o: $(srcdir)/../lib/cram.c
	$(CC) $(CPPFLAGS) $(PIN_CFLAGS) -c $(srcdir)/../lib/cram.c

packet.o: $(srcdir)/../server/packet.c
	$(CC) $(CPPFLAGS) $(PIN_CFLAGS) -c $(srcdir)/../server/packet.c
