##makefile for lynx

SHELL		= @CONFIG_SHELL@
CDPATH		= .

x		= @PROG_EXT@

.SUFFIXES:
@SET_MAKE@
prefix		= @prefix@
exec_prefix	= @exec_prefix@
top_srcdir	= @top_srcdir@
srcdir		= @srcdir@
VPATH		= $(srcdir)

CC		= @CC@
CFLAGS		= @CFLAGS@
DEFS		= @DEFS@
CPPFLAGS	= @CPPFLAGS@
LINT		= @LINT@

LIBS		= @LIBS@

INSTALL		= @INSTALL@
INSTALL_PROGRAM	= @INSTALL_PROGRAM@
INSTALL_DATA	= @INSTALL_DATA@
LN_S		= @LN_S@

## This is the version which we are developing (or, upon release, make this
## the same).  Use no dots in the name, since it must work on VMS and MS-DOS.
VERSION		= 2-8-3

##this is the name of the directory the lynx source code is in.
##(e.g., lynx2-8-3, not the full path)
lynxdir= lynx$(VERSION)
lynxname= lynx$(VERSION)

## The 'DESTDIR' variable allows you to install the program into a different
## location, e.g., for packaging, without affecting the compiled-in pathnames.
DESTDIR=

## Where you want lynx installed
bindir= @bindir@
BINDIR= $(DESTDIR)$(bindir)

## Where you want the lynx man file installed
mandir= @mandir@/man1
MANDIR= $(DESTDIR)$(mandir)

## Where you want the lynx.cfg file installed
libdir= @libdir@
LIBDIR= $(DESTDIR)$(libdir)

## Where you want the doc-files installed
docdir= @libdir@/lynx_doc
DOCDIR= $(DESTDIR)$(docdir)

## Where you want the help-files installed
helpdir= @libdir@/lynx_help
HELPDIR= $(DESTDIR)$(helpdir)

##set the relative location of the WWW library Implementation directory,
##from this directory
##do not set this to be an absolute path!!!
WWWINC= WWW/Library/Implementation

## Path to gzip that will compress the help files.
## It will be used when --enable-gzip-help is set by configure.
## Leave *both* empty if you don't want to gzip help files.
COMPRESS_PROG=@COMPRESS_PROG@
COMPRESS_EXT=@COMPRESS_EXT@

# !!!!!!!!!! SSL Support (HTTPS connections) !!!!!!!!!!!!!!!!!!!!!!!!!!!
# To build a Lynx binary which supports the Secure Sockets Layer (SSL), you
# must compile in the crypto and SSL libraries from the OpenSSL library,
# available at http://www.openssl.org/ .  Once you have installed OpenSSL
# change the location of the crypto and SSL libraries in SSL_LIBS and the
# location of ssl.h and crypto.h in SSL_DEFINES if necessary.  USE_SSL,
# defined below, enables Lynx to use the SSL and crypto libraries for
# handling "https" and "snews" URLs.
#
# This feature is added by a patch to Lynx (which has been applied,
# otherwise you wouldn't be seeing this message).  For more information
# about the SSL patch for Lynx, please see http://www.moxienet.com/lynx/.  
# This page also contains links which enable you to test your copy of Lynx'
# ability to make SSL connections.
SSL_DIR= /usr/local/ssl
SSL_LIBS= -L$(SSL_DIR)/lib -lssl -lcrypto
SSL_INCLUDES= -I$(SSL_DIR)/include -I$(SSL_DIR)/include/openssl
SSL_DEFINES= $(SSL_INCLUDES) -DUSE_SSL -DNO_IDEA

# !!!!!!!!!!! SUN resolv LIBRARY !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# To include resolv in the LIBS="" list for SUN 3, 4 or Solaris OS,
# point RESOLVLIB to that library.  You need this if you get the message
# "Alert!:  Unable to connect to remote host" whenever you try to
# access a host other than localhost and have made Lynx without it.
# See the PROBLEMS file for more information.
#RESOLVLIB= -lresolv

# !!!!!!!!!!!!!  DIRECT WAIS ACCESS !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# If you are adding direct wais access you must fill in the
# location of wais.a, client.a and the standard math library, libm.a.
# You can pick up the most current freeWAIS sources from
#	ftp://ftp.cnidr.org/pub/NIDR.tools/freewais
# If you are using freeWAIS-0.202 or older, include -DDECLARE_WAIS_LOGFILES
# in your SITE_DEFS.
# Please put an ABSOLUTE address here if you want it to work!
#WAISLIB= ../../freeWAIS-0.202/bin/client.a ../../freeWAIS-0.202/bin/wais.a /usr/lib/libm.a

# !!!!!!!!!!!!! SLANG Support (For color version of Lynx). !!!!!!!!!!!!!!!!
# The slang library is an alternative to curses, developed by John E. Davis
# (davis@space.mit.edu).  Version 0.99-27 or higher is available from
#	ftp://space.mit.edu/pub/davis
# It provides color support for Lynx.

# !!!!!!!!!!!!! NCURSES Support (For color version of Lynx). !!!!!!!!!!!!!!
# If you need ncurses, the latest version can always be found
# in ftp://ftp.clark.net/pub/dickey/ncurses/
# or ftp://ftp.gnu.org/pub/gnu/

# !!!!!!!!!!!!! Kerberos Support (For Kerberized SSL). !!!!!!!!!!!!!
# This is for use with the kssl patches to openssl, apache, and mod_ssl.
# These patches are not widely available yet.
KRB5_DIR= /usr/local/krb5
KRB5_DEFINES= -I$(KRB5_DIR)/include
KRB5_LIBS=-L $(KRB5_DIR)/lib -lgssapi_krb5 -lkrb5 -lcom_err $(KRB5_DIR)/lib/libcrypto.a  -lresolv

# Also be sure to check out the compilation symbols in userdefs.h
# before building Lynx!

# If you apply patches which require linking to site-specific libraries, set
# SITE_LIBS to those libraries.
SITE_LIBS= $(SSL_LIBS) $(KRB5_LIBS) # Your libraries here

# Set SITE_LYDEFS to one or more of the defines for the WWW Library:
SITE_LYDEFS = $(SSL_DEFINES) $(KRB5_DEFINES) # Your defines here

# Set SITE_DEFS to one or more of the defines for lynx below:
SITE_DEFS = $(SSL_DEFINES) $(KRB5_DEFINES) # Your defines here

# defines for which there are no configure options:
# -DHP_TERMINAL    For DIM workaround to REVERSE problems on HP terminals.
# -DIGNORE_CTRL_C  Define if Control-C shouldn't exit lynx.
# -DNO_CPU_LIMIT   Disables Max CPU timeout (includes CLOCKS_PER_SECOND)
# -DNO_RULES       Disables CERN-style access rules (see lynx.cfg).
# -DSHORTENED_RBIND  For a SOCKSified lynx with the short version of Rbind.
# -DSLANG_MBCS_HACK prevent cutoff lines when using UTF8 console (slang only)
# -DUSE_SCROLLBAR  supports scrollbar when built with ncurses
#
# if you are linking to freeWAIS-0.202 or older, you should define this
# in SITE_DEFS
#
# -DDECLARE_WAIS_LOGFILES
#
# if you have the reverse clear screen problem of some SUN4 systems you
# should define this in SITE_DEFS
#
# -DREVERSE_CLEAR_SCREEN_PROBLEM
#
# if you have an SVR4 system with the "type any key" problem, try defining
# this in LYFLAGS (SITE_LYDEFS) and SITE_DEFS
#
# -DSVR4_BSDSELECT
#
# Old Data General systems may need this in their SITE_LYDEFS
# for their inet_addr(host) calls.
#
# -DDGUX_OLD

# defines which have configure options   (see INSTALLATION, Section II-1c.):
# -DARCHIVE_ONLY
# -DDIRED_SUPPORT
# -DDISP_PARTIAL
# -DDONT_TRACK_INTERNAL_LINKS
# -DEXEC_LINKS
# -DEXEC_SCRIPTS
# -DEXP_CHARTRANS_AUTOSWITCH
# -DEXP_PERSISTENT_COOKIES
# -DLINKEDSTYLES
# -DLONG_LIST
# -DLYNXCGI_LINKS
# -DLY_FIND_LEAKS
# -DNCURSES
# -DNO_CHANGE_EXECUTE_PERMS
# -DNO_EXTENDED_HTMLDTD
# -DNO_PARENT_DIR_REFERENCE
# -DNSL_FORK
# -DOK_GZIP
# -DOK_OVERRIDE
# -DOK_PERMIT
# -DOK_TAR
# -DOK_UUDECODE
# -DOK_ZIP
# -DOPTIONS_FORMS
# -DOPTIONS_MENU
# -DSOCKS
# -DSYSLOG_REQUESTED_URLS
# -DUNDERLINE_LINKS
# -DUSE_COLOR_STYLE
# -DUSE_DEFAULT_COLORS
# -DUSE_EXTERNALS
# -DUSE_HASH
# -DUSE_SLANG
# -DUSE_SOCKS5
# -DUSE_ZLIB
#
# for installation of local execution links, please see the file userdefs.h

# TESTED: Linux FreeBSD SunOS Solaris IRIX CLIX HP-UX AIX SCO
all lynx$x: cfg_defs.h LYHelp.h
@MSG_DIR_MAKE@	$(SHELL) $(srcdir)/fixtext.sh $(srcdir)/LYMessages_en.h >LYMessages.c
@INTLDIR_MAKE@	cd intl && $(MAKE) CC="$(CC)"
@MSG_DIR_MAKE@	cd po && $(MAKE) CC="$(CC)"
	cd $(WWWINC) && $(MAKE) CC="$(CC)" \
		LY_CFLAGS="$(CFLAGS)" \
		CPPFLAGS="$(CPPFLAGS)" \
		LYFLAGS="$(SITE_LYDEFS)"
	cd src && $(MAKE) all CC="$(CC)" \
		CFLAGS="$(CFLAGS)" \
		CPPFLAGS="$(CPPFLAGS)" \
		LIBS="$(LIBS) $(RESOLVLIB) $(WAISLIB) $(SITE_LIBS)" \
		SITE_DEFS="$(SITE_DEFS)" \
		WWWINC=$(WWWINC) \
		WWWLIB="../$(WWWINC)/libwww.a"

lint:
	cd $(WWWINC) && $(MAKE) LINT="$(LINT)" CC="$(CC)" \
		LY_CFLAGS="$(CFLAGS)" \
		CPPFLAGS="$(CPPFLAGS)" \
		LYFLAGS="$(SITE_LYDEFS)" lint
	cd src && $(MAKE) all LINT="$(LINT)" CC="$(CC)" \
		CFLAGS="$(CFLAGS)" \
		CPPFLAGS="$(CPPFLAGS)" \
		LIBS="$(LIBS) $(RESOLVLIB) $(WAISLIB) $(SITE_LIBS)" \
		SITE_DEFS="$(SITE_DEFS)" \
		WWWINC=$(WWWINC) \
		WWWLIB="../$(WWWINC)/libwww.a" lint

help:
	@echo
	@echo "Please run make with one of the following arguments"
	@echo "all        -- to make the executable, put it in this directory"
	@echo "clean      -- removes all '.o' and 'core' files"
	@echo "depend     -- use makedepend to generate header-dependencies"
	@echo "tar        -- runs clean, removes executable, and tars the whole directory"
	@echo "compress   -- runs tar, then compresses the result"
	@echo "zip        -- runs clean, removes executable, and zips the whole directory"
	@echo

##Miscellaneous actions
clean:
	rm -f WWW/Library/*/*.[aoib]
	rm -f WWW/Library/*/.created
	cd src && $(MAKE) clean
@MSG_DIR_MAKE@	rm -f LYMessages.c
@INTLDIR_MAKE@	cd intl && $(MAKE) $@
@MSG_DIR_MAKE@	cd po && $(MAKE) $@
	rm -f *.b src/lynx$x *.leaks cfg_defs.h LYHelp.h lint.*
@LYNXCFG_MAKE@	-rm -f alphatoc.html body.html cattoc.html
	rm -f help_files.sed
	rm -f core *.core

depend: cfg_defs.h LYHelp.h
	cd $(WWWINC) && $(MAKE) $@
	cd src && $(MAKE) $@

distclean: clean
	-rm -f WWW/Library/*/*~
	-rm -f WWW/Library/*/*.bak
	-rm -rf src/obsolete
	-cd src && $(MAKE) $@
	-cd src/chrtrans && $(MAKE) $@
@INTLDIR_MAKE@	cd intl && $(MAKE) $@
@MSG_DIR_MAKE@	-rmdir intl
@MSG_DIR_MAKE@	cd po && $(MAKE) $@
@MSG_DIR_MAKE@	-rmdir po
	-rm -f *~ *.bak *.sav
	-rm -f $(WWWINC)/makefile src/makefile src/chrtrans/makefile
@SRCDIR_CLEAN@	-rmdir $(WWWINC) && rmdir WWW/Library && rmdir WWW
@SRCDIR_CLEAN@	-rmdir src/chrtrans && rmdir src
	-rm -f makefile lynx_cfg.h config.status config.log config.cache
	-rm -f lynx$x install-*

maintainer-clean: distclean
	-find . -type f -name '*.rej' -exec rm -f {} \;
	-find . -type f -name '*.orig' -exec rm -f {} \;
	-rm -rf WWW/Library/*/obsolete
	-rm -f Lynx.prj .*_aux

tar:  clean
	rm -f lynx$x
	$(MAKE) save

turnover:	clean
	$(MAKE) save

zipcompress: compress zip
	echo "done!"

zip:  clean
	rm -f src/lynx$x
	rm -f lynx$x
	rm -f src/a.out
	rm -f ../$(lynxname).zip
	cd ..; rm -f $(lynxname).zip; zip -r $(lynxname).zip $(lynxdir)

save:
	cd ..; rm -f $(lynxname).tar; tar -cf - $(lynxdir) > $(lynxname).tar

compress: tar
	cd ..; rm -f $(lynxname).tar.Z; compress -f -v $(lynxname).tar

# Directory containing reference source for patch generation,
#     either absolute or relative to $(top_srcdir)/..
REFDIR=orig/$(lynxdir)

lynx.patch: $(top_srcdir) $(top_srcdir)/CHANGES
	- cd $(top_srcdir)/.. && cd $(REFDIR) && { rm -f \
		config.log \
		config.status \
		lynx_cfg.h \
			; \
		for I in . src $(WWWINC); do ( set +e; \
			( set -x; cd $$I && rm -f *.orig *.rej makefile ); : ); \
		done; }
	( cd $(top_srcdir)/..; echo "%%% Created `date` by target $@. %%%"; \
	   if diff -bru /dev/null /dev/null;		     \
		   then diff -bru $(REFDIR) $(lynxdir);	     \
		   else diff -brc $(REFDIR) $(lynxdir); fi ) \
		| grep -v '^Common' \
		| grep -v '^Binary files ' \
		| grep -v '^Only ' | tee $@ | egrep '^\-\-\- .*$(lynxdir)'

install: install-bin install-man install-cfg @INSTALL_LSS@
	@echo
	@echo "Use $(MAKE) install-help to install the help-files"
	@echo "Use $(MAKE) install-doc to install extra documentation files"
	@echo

install-full: install install-help install-doc
	@echo Full installation complete.

install-bin: $(BINDIR) lynx$x
@MSG_DIR_MAKE@	cd po && $(MAKE) CC="$(CC)" install
	-mv -f $(BINDIR)/lynx$x $(BINDIR)/lynx.old
	$(INSTALL_PROGRAM) lynx$x $(BINDIR)/lynx$x

install-man : $(MANDIR)
	$(INSTALL_DATA) $(srcdir)/lynx.man $(MANDIR)/lynx.1

install-doc : $(DOCDIR) $(HELPDIR)
	@echo Copying sample files
	(cd $(srcdir) && tar cf - C[HO]* PROBLEMS README samples test ) | \
			       ( cd $(DOCDIR) && chmod -R u+w . && tar xf - )
	$(SHELL) -c 'for name in COPYING COPYHEADER; do \
		cd $(HELPDIR) && ( $(LN_S) $(DOCDIR)/$$name . || cp $(DOCDIR)/$$name . );\
		done'

# HPUX 'sed' does not seem to like '=' as pattern delimiter.
FIX_SED = tr '=' '%'
#FIX_SED = cat

help_files.sed : makefile $(srcdir)/lynx_help/help_files.txt
	@echo Constructing sed-script $@
	@-rm -f $@ help_files.tmp
	@cat $(srcdir)/lynx_help/help_files.txt > help_files.tmp
@LYNXCFG_MAKE@	@echo 's!http://www.hippo.ru/%7Ehvv/lynxcfg_toc.html#alphatoc!alphatoc.html!g' >> help_files.tmp
@LYNXCFG_MAKE@	@echo 's!http://www.hippo.ru/%7Ehvv/lynxcfg_toc.html!cattoc.html!g' >> help_files.tmp
@LYNXCFG_MAKE@	@echo 's!alphatoc\.html!alphatoc.html$(COMPRESS_EXT)!g' >> help_files.tmp
@LYNXCFG_MAKE@	@echo 's!cattoc\.html!cattoc.html$(COMPRESS_EXT)!g' >> help_files.tmp
@LYNXCFG_MAKE@	@echo 's!body\.html!body.html$(COMPRESS_EXT)!g' >> help_files.tmp
	@ECHO_CC@sed	-e '/^#/d' -e '/^$$/d' \
		-e 's%\(.*\)=\(.*\@.*\)$$%s=@\1@=\2=g%' \
		-e 's%\(.*\)=\(http:.*\)$$%s=@\1@=\2=g%' \
		-e 's%\(.*\)=\(ftp:.*\)$$%s=@\1@=\2=g%' \
		-e 's%\(.*\)=\(.*\.html\)$$%s=@\1@=\2$(COMPRESS_EXT)=g%' \
		help_files.tmp | $(FIX_SED) > $@
	@echo Appending interim-fix for existing html files to $@
	@ECHO_CC@sed	-e '/^#/d' -e '/[:@]/d' -e '/^$$/d' \
		-e 's%\(.*\)=\(.*\.html\)$$%s=\2=\2$(COMPRESS_EXT)=g%' \
		-e 's%\.html=%\\.html=%' \
		help_files.tmp | $(FIX_SED) >> $@
	@ECHO_CC@if test -n "$(COMPRESS_EXT)"; then echo 's%\$(COMPRESS_EXT)\$(COMPRESS_EXT)%$(COMPRESS_EXT)%g' >> $@; fi
	@-rm -f help_files.tmp

install-help : help_files.sed $(HELPDIR)
	(cd $(HELPDIR) && WD=`pwd` && HEAD=`echo $$WD|sed -e 's@/lynx_help$$@@'` && test $$WD != $$HEAD && rm -rf *)
@LYNXCFG_MAKE@	@echo 'Making htmlized lynx.cfg'
@LYNXCFG_MAKE@	@-rm -f alphatoc.html body.html cattoc.html
@LYNXCFG_MAKE@	perl $(srcdir)/scripts/cfg2html.pl $(srcdir)/lynx.cfg
	@echo Translating/copying html files
	@cat help_files.sed > $(HELPDIR)/help_files.sed
@LYNXCFG_MAKE@	@$(SHELL) -c 'for f in alphatoc.html body.html cattoc.html ; do \
@LYNXCFG_MAKE@		sed -f $(HELPDIR)/help_files.sed $$f > $(HELPDIR)/$$f ; \
@LYNXCFG_MAKE@		done'
	@ECHO_CC@$(SHELL) -c 'cd $(srcdir)/lynx_help && ( \
		dirs=keystrokes; \
		(cd $(HELPDIR) && mkdir $$dirs 2>/dev/null ) ; \
		files="*.html */*.html" ; \
		for f in $$files ; do \
			sed -f $(HELPDIR)/help_files.sed $$f > $(HELPDIR)/$$f ; \
		done ; \
		if test "$(COMPRESS_PROG)" != "" ; then \
			(cd $(HELPDIR) && $(COMPRESS_PROG) $$files ) \
		fi ; \
		)'
	@-rm -f $(HELPDIR)/help_files.sed
	@echo Updating $(libdir)/lynx.cfg
	$(SHELL) -c 'if test -f $(LIBDIR)/lynx.cfg ; then \
		mv $(LIBDIR)/lynx.cfg $(LIBDIR)/lynx.tmp ; \
	else \
		cp $(srcdir)/lynx.cfg $(LIBDIR)/lynx.tmp ; \
	fi'
	@echo Updating $(libdir)/lynx.cfg to point to installed help-files
	@ECHO_CC@sed	-e '/^HELPFILE:http/s@^@#@' \
		-e '/^#HELPFILE:file/s@#@@' \
		-e '/^HELPFILE:file/s@/PATH_TO/lynx_help@$(helpdir)@' \
		-e '/^[A-Z_]*:/s@/PATH_TO/lynx_doc@$(docdir)@' \
		-e '/^HELPFILE:file/s@$$@$(COMPRESS_EXT)@' \
		-e '/^HELPFILE:file/s@$(COMPRESS_EXT)$(COMPRESS_EXT)$$@$(COMPRESS_EXT)@' \
		$(LIBDIR)/lynx.tmp >$(LIBDIR)/lynx.cfg
	chmod 644 $(LIBDIR)/lynx.cfg
	-rm -f $(LIBDIR)/lynx.tmp

LYHelp.h : help_files.sed LYHelp.hin
	@echo Creating $@
	@sed -f help_files.sed $(srcdir)/LYHelp.hin > $@
	@echo '**********************************************'
	@echo
	@$(SHELL) -c 'if test "$(COMPRESS_PROG)" = "" ; then \
		echo "       Help files will NOT be gzipped."; \
	else \
		echo "       Help links point to compressed files"; \
		echo "       To access them properly you have to type"; \
		echo "                 make install-help"; \
	fi'
	@echo
	@echo '**********************************************'

cfg_defs.h : $(srcdir)/cfg_defs.sh $(srcdir)/cfg_edit.sh config.cache lynx_cfg.h
	@rm -f $@
	$(SHELL) -c '$(srcdir)/cfg_defs.sh $(srcdir)'

install-cfg : $(LIBDIR)
	-mv -f $(LIBDIR)/lynx.cfg $(LIBDIR)/lynx.oldcfg
	$(INSTALL_DATA) $(srcdir)/lynx.cfg $(LIBDIR)/lynx.cfg

install-lss : $(LIBDIR)
	-mv -f $(LIBDIR)/lynx.lss $(LIBDIR)/lynx.oldlss
	$(INSTALL_DATA) $(srcdir)/samples/lynx.lss $(LIBDIR)/lynx.lss

uninstall ::
@MSG_DIR_MAKE@	cd po && $(MAKE) CC="$(CC)" uninstall
	-rm -f $(BINDIR)/lynx$x
	-rm -f $(MANDIR)/lynx.1
	-rm -f $(LIBDIR)/lynx.cfg
	-rm -f $(LIBDIR)/lynx.lss

uninstall \
uninstall-help ::
	-test -d $(HELPDIR) && WD=`cd $(HELPDIR) && pwd` && HEAD=`echo $$WD|sed -e 's@/lynx_help$$@@'` && test $$WD != $$HEAD && rm -rf $(HELPDIR)

uninstall \
uninstall-doc ::
	-test -d $(DOCDIR) && WD=`cd $(DOCDIR) && pwd` && HEAD=`echo $$WD|sed -e 's@/lynx_doc$$@@'` && test $$WD != $$HEAD && rm -rf $(DOCDIR)

$(BINDIR) $(MANDIR) $(LIBDIR) $(HELPDIR) $(DOCDIR) :
	$(srcdir)/mkdirs.sh $@
