#
#  Makefile for simple liburl
#
#  Darren Hardy, hardy@cs.colorado.edu, April 1994
#
#  Makefile.in,v 1.40 1995/11/01 22:59:43 duane Exp
#
prefix = @prefix@
INSTALL_BINDIR	= $(prefix)/bin
INSTALL_LIBDIR	= $(prefix)/lib
INSTALL_MANDIR 	= $(prefix)/man

CC		= @CC@
INSTALL		= @INSTALL@
INSTALL_BIN 	= @INSTALL_PROGRAM@
INSTALL_FILE 	= @INSTALL_DATA@
RANLIB		= @RANLIB@
XTRA_LIBS	= @XTRA_LIBS@

PERL		= @PERL@

#  By default, this should be "default"
#SOCKET_PH_TYPE  = @SOCKET_PH_TYPE@


DEBUG		= $(DEBUG_TOP) #-O #-g #-DDEBUG
DEBUG_LIBS	=

#
#  To compute MD5's then add objects here, and define USE_MD5 in config.h
#
MD5_LIB 	= -lmd5

#
#  To use the simple local disk caching, then define these
#
CACHE_FLAGS	= #-DUSE_LOCAL_CACHE
CACHE_OBJS	= cache.o
CACHE_LDFLAGS	= 
CACHE_LIBS	= -lgdbm

#
#  The FTP connection cache is still being tested; use at your own risk.
#  If you want to use the FTP connection cache, the define these
#
#CCACHE_FLAGS	= -DUSE_CCACHE
#CCACHE_OBJS	= ccache_error.o ccache_ftp.o ccache_hash.o ccache_list.o \
#		  ccache_queue.o ccache_util.o ccache_vtimer.o
#CCACHE_LDFLAGS	=
#CCACHE_LIBS	=

CFLAGS		= $(DEBUG) $(CACHE_FLAGS) -I../include
OBJS 		= rfc850.o rfc1738.o gopher.o ftp.o http.o url.o news.o \
		  url_relative.o $(CACHE_OBJS) $(CCACHE_OBJS)
PROGS		= gopherget.pl newsget.pl test-socket-ph.pl ftpget
GENPROGS	= ftpget.pl
UTILS		= urlget urlpurge
LIBDIR		= ../lib
LDFLAGS		= -L$(LIBDIR) $(CACHE_LDFLAGS) $(CCACHE_LDFLAGS)
LIBS		= -lurl -lutil \
		  $(MD5_LIB) $(CACHE_LIBS) $(CCACHE_LIBS) $(DEBUG_LIBS) \
		  $(XTRA_LIBS)
LIBFILE		= liburl.a
PERLS		= chat2.pl ftp.pl timelocal.pl
#SOCKET_PH	= socket.ph-$(SOCKET_PH_TYPE)
SOCKET_PH	= socket.ph

all:	$(LIBFILE) $(PERLS) $(PROGS) $(GENPROGS) $(UTILS) $(SOCKET_PH)

$(LIBFILE):	$(OBJS)
	ar r $@ $(OBJS)
	$(RANLIB) $@

urlget:	$(LIBFILE) $(LIBDIR)/$(LIBFILE) urlget.o
	$(CC) -o $@ $@.o $(LDFLAGS) $(LIBS)

urlpurge:	$(LIBFILE) $(LIBDIR)/$(LIBFILE) urlpurge.o
	$(CC) -o $@ $@.o $(LDFLAGS) $(LIBS)

ftpget:	$(LIBFILE) $(LIBDIR)/$(LIBFILE) ftpget.o
	$(CC) -o $@ $@.o $(LDFLAGS) $(LIBS)

ftpget.o: mime_table.h

mime_table.h: mime.table mk-mime-table-h.pl
	$(PERL) mk-mime-table-h.pl < mime.table > $@

ftpget.pl:	ftpget.pl.in mime.table
	-rm -f $@
	cat ftpget.pl.in mime.table > $@
	chmod 755 $@

socket.ph:	mk-socket-ph
	./mk-socket-ph > $@

mk-socket-ph: mk-socket-ph.o
	$(CC) -o $@ mk-socket-ph.o

clean:
	-rm -f core liburl.a *.o urlget urlpurge tags 
	-rm -f $(GENPROGS)

realclean:	clean
	-rm -f Makefile

install:	all
	@for f in $(PROGS) $(GENPROGS) $(UTILS); do \
		echo $(INSTALL_BIN) $$f $(INSTALL_LIBDIR); \
		$(INSTALL_BIN) $$f $(INSTALL_LIBDIR); \
	done
	@for f in $(PERLS); do \
		echo $(INSTALL_FILE) $$f $(INSTALL_LIBDIR); \
		$(INSTALL_FILE) $$f $(INSTALL_LIBDIR); \
	done
	@for f in $(SOCKET_PH); do \
		echo $(INSTALL_FILE) $$f $(INSTALL_LIBDIR)/socket.ph; \
		$(INSTALL_FILE) $$f $(INSTALL_LIBDIR)/socket.ph; \
	done
#	./h2ph - < /usr/include/sys/socket.h > $(INSTALL_LIBDIR)/socket.ph
#	chmod 644 $(INSTALL_LIBDIR)/socket.ph

install-lib:	$(LIBDIR)/$(LIBFILE)

$(LIBDIR)/$(LIBFILE):	$(LIBFILE)
	$(INSTALL_FILE) $(LIBFILE) $(LIBDIR)/$(LIBFILE)
	$(RANLIB) $(LIBDIR)/$(LIBFILE)
