#	Makefile for WorldWideWeb    Line Mode browser (www)
#
#	(c) COPYRIGHT MIT 1995.
#	Please first read the full copyright statement in the file COPYRIGH.
#
# This file should be invariant between systems.
#	DEPENDENCIES NOT COMPLETE @@
#
#	make		Compile and link the software (private version)
#	make install	Copy it into the system (implies make)
#	make update	Copy installed version into installed version
#	make uninstall	Unlink installed version from the system
#	make clean	Remove intermediate files
#	make cleanall	Remove intremediate files and products
#	
# Macros required to be defined already for make:
#
# CC		The C compiler
# CFLAGS	Flags for $(CC)
# LFLAGS	Flags for ld
# WWW		Root of WWW source tree
# USELIBDIR	Directory in which libwww.a should be found
#
# Macros needed for make install:
#
# BINDIR	Directory for installed binary
#______________________________________________________________________

#  If this env var is set to something else Some makes will use that instead
SHELL = /bin/sh

#	.h files are distributed but originally are made from the
#	self-documenting hypertext files.
.SUFFIXES: .h .html
.html.h:
	www -w90 -na -p -to text/x-c $*.html > $*.h

#	Directories
OBJ = $(WTMP)/LineMode/$(WWW_MACH)
LIB = $(WTMP)/Library/$(WWW_MACH)
CMN = $(WWW)/Library/Implementation/
LM  = $(WWW)/LineMode/Implementation/
DOC = $(WWW)/LineMode/Defaults
ICON= $(WWW)/Icons
VMS = $(LM)vms
WIN = $(LM)windows
BIN = $(WWW)/LineMode/$(WWW_MACH)
LIBWWW = $(LIB)/libwww.a
PROD= www
FTP = /afs/w3.org/devel/Dist/linemode

CFLAGS2 = $(CFLAGS) -I$(CMN) -I$(LM)
LFLAGS2 = $(LFLAGS) -L$(LIB) $(WAISLIB) $(MATHLIB) -lwww

#	memory leak checkers
PROOF = proof
PURIFY_CACHE = /home2/frystyk/purify-cache

#	MODULES
OBJS =	$(OBJ)/HTBrowse.o \
	$(OBJ)/GridText.o \
	$(OBJ)/DefaultStyles.o

OBJS-CYR = $(OBJ)/HTBrowse-cyr.o $(OBJ)/GridText-cyr.o $(OBJ)/DefaultStyles-cyr.o $(OBJ)/a_stdio.o 

CFILES =$(LM)HTBrowse.c \
	$(LM)GridText.c \
	$(LM)GridStyle.c \
	$(LM)DefaultStyles.c

HFILES=	$(LM)HTBrowse.h \
	$(LM)GridStyle.h \
	$(LM)GridText.h \
	$(LM)HTFont.h

SOURCES=$(CFILES) $(HFILES) \
	$(LM)Version.make \
	$(LM)CommonMakefile \
	$(LM)README \
	$(WWW)/Makefile \
	$(WWW)/BUILD \
	$(WWW)/BUILD.SH

ICONS = $(ICON)/WWW/Bug48x.gif \
	$(ICON)/WWW/LMB48x.gif \
	$(ICON)/WWW/w3c_48x48.gif \
	$(ICON)/WWW/doc48x.gif \
	$(ICON)/WWW/guide48x.gif \
	$(ICON)/WWW/internals48x.gif \
	$(ICON)/WWW/install48x.gif \
	$(ICON)/WWW/relnotes48x.gif \
	$(ICON)/WWW/startup48x.gif \
	$(ICON)/32x32/caution.gif

LEGAL =	$(WWW)/README \
	$(WWW)/COPYRIGH \
	$(WWW)/PATCHES \
	$(WWW)/CERN

DOCS =	$(LM)*.html \
	`find $(DOC) -follow \( -name \*.html -o -name \*.gif \) -print`

SPECIFIC = \
	$(WWW)/All/*/Makefile.include \
	$(WWW)/All/Implementation/Makefile \
	$(DOC)/Patch/*.fix \
	$(LM)DefaultStyles.c.classic \
	$(LM)DefaultStyles.c.modern \
	$(WIN)/*.rc \
	$(WIN)/*.ico \
	$(WIN)/*.mak \
	$(WIN)/*.def \
	$(WIN)/*.c \
	$(WIN)/*.h \
	$(VMS)/descrip.mms \
	$(VMS)/build_multinet.com \
	$(VMS)/setup.com \
 	$(LM)a_stdio.g \
	$(LM)a_stdio.h

TOTAL =	$(LEGAL) \
	$(SOURCES) \
	$(ICONS) \
	$(DOCS) \
	$(SPECIFIC)

all : inc $(BIN)/$(PROD)

$(BIN)/$(PROD) : $(OBJS) $(LIBWWW)
	$(CC) -o $(BIN)/$(PROD)_$(VL)  $(OBJS) $(LFLAGS2)
	-rm $(BIN)/$(PROD)
	ln -s $(PROD)_$(VL) $(BIN)/$(PROD)

purify : $(OBJS) $(LIBWWW)
	purify -cache-dir=$(PURIFY_CACHE) \
	$(CC) -o $(PROD)_$(VL) $(OBJS) $(LFLAGS2)
	-rm $(BIN)/$(PROD)
	ln -s $(PROD)_$(VL) $(BIN)/$(PROD)

proof : $(OBJS) $(LIBWWW)
	$(PROOF) $(CC) -o $(PROD)_$(VL) $(OBJS) $(LFLAGS2)
	-rm $(BIN)/$(PROD)
	ln -s $(PROD)_$(VL) $(BIN)/$(PROD)

cyrillic : $(OBJS-CYR) $(LIBWWW)
	$(CC) -o $(PROD)_$(VL) $(OBJS) $(OBJ)/a_stdio.o $(LFLAGS2)
	-rm $(BIN)/$(PROD)
	ln -s $(PROD)_$(VL) $(BIN)/$(PROD)

$(LIBWWW) :
	@echo You must get and make the WWWLibrary product first!
	(cd $(WWW)/Library/$(WWW_MACH) && make)

lib :
	(cd $(WWW)/Library/$(WWW_MACH) && make)

inc :	$(HFILES)
	@echo "Include files generated from member"

#	Make a copy of the binary and documentation on this machine
install :	$(PROD)
	cp $(PROD) $(BINDIR)/$(PROD)
	- mkdir /usr/local
	- mkdir /usr/local/lib
	- mkdir /usr/local/lib/WWW
	cp $(DEFAULTS)/*.html /usr/local/lib/WWW

#	Link system to the binary and documentation in this tree
link : Works/$(PROD)
	ln -s `pwd`/$(PROD) $(BINDIR)/$(PROD)
	- mkdir /usr/local
	- mkdir /usr/local/lib
	ln -s $(DEFAULTS) /usr/local/lib/WWW

uninstall :
	rm $(BINDIR)/$(PROD)
	rm -r /usr/local/lib/WWW

#	Clean up everything generatable except final products
#	Including obj directory UNLESS there is anything else in it
clean :
	rm $(OBJ)/.created $(OBJ)/*.o
	-rmdir $(OBJ)

#	Clean up everything generatable including final products
cleanall : clean
	rm $(PROD)

#		Distribution use only:
#		----------------------
distribute : inc $(LEGAL) $(SOURCES)
	(cd $(WWW)/.. && WWW=WWW ABS=`pwd`/ make $(MFLAGS) \
	-f WWW/LineMode/Implementation/Version.make \
	-f WWW/LineMode/Implementation/CommonMakefile \
	$(FTP)/$(PROD)_$(VL)_src.tar.Z)
	(cd $(WWW); cvs tag \
	    `sed -e 's/V. = /v/' LineMode/Implementation/Version.make | sed -e 's?\.?/?'` \
	    LineMode)
	@echo Distribution of Line Mode version $(VL) up to date.

#	Source Snapshot
snapshot : inc $(LEGAL) $(SOURCES)
	(cd $(WWW)/.. && WWW=WWW ABS=`pwd`/ make $(MFLAGS) \
	-f WWW/LineMode/Implementation/Version.make \
	-f WWW/LineMode/Implementation/CommonMakefile \
	$(FTP)/$(PROD)_$(VL)_src.tar.Z)
	@echo Snapshot of Line Mode version $(VL) up to date.

$(FTP)/$(PROD)_$(VL)_src.tar.Z : $(SOURCES)
	tar cvhf $(FTP)/$(PROD)_$(VL)_src.tar $(TOTAL)
	cp $(FTP)/$(PROD)_$(VL)_src.tar $(FTP)/temp.tar
	compress -f $(FTP)/$(PROD)_$(VL)_src.tar
	mv $(FTP)/temp.tar $(FTP)/$(PROD)_$(VL)_src.tar
	gzip -f $(FTP)/$(PROD)_$(VL)_src.tar

zip : $(LEGAL) $(SOURCES)
	(cd $(WWW)/..; WWW=WWW ABS=`pwd`/ make $(MFLAGS) \
	-f WWW/LineMode/Implementation/Version.make \
	-f WWW/LineMode/Implementation/CommonMakefile \
	$(FTP)/$(PROD)_$(VL)_src.zip)
	@echo Distribution of LineMode version $(VL) up to date.

$(FTP)/$(PROD)_$(VL)_src.zip : $(SOURCES)
	zip -v $(FTP)/$(PROD)_$(VL)_src.zip $(TOTAL)

#	Hypertext supplied in text format
#	---------------------------------

$(WWW)/README : /afs/w3.org/member/WWW/README.html
	www -p -na http://www.w3.org/member/WWW/README.html -o $(WWW)/README

$(WWW)/COPYRIGHT : /afs/w3.org/member/WWW/COPYRIGHT.html
	www -p -na http://www.w3.org/member/WWW/COPYRIGHT.html -o $(WWW)/COPYRIGH

$(WWW)/PATCHES : /afs/w3.org/member/WWW/PATCHES.html
	www -p -na http://www.w3.org/member/WWW/PATCHES.html -o $(WWW)/PATCHES

$(WWW)/CERN : /afs/w3.org/member/WWW/CERN.html
	www -p -na http://www.w3.org/member/WWW/CERN.html -o $(WWW)/CERN

#	OBJECT GENERATION
#	=================
#	Directory for object files - .created checks it exists
OE = $(OBJ)/.created
$(OE) :
	if [ ! -r $(WTMP) ] ; then mkdir $(WTMP); else echo OK ; fi
	if [ ! -r $(WTMP)/LineMode ] ; then mkdir $(WTMP)/LineMode; else echo OK ; fi
	if [ ! -r $(WTMP)/LineMode/$(WWW_MACH) ] ; \
		then mkdir $(WTMP)/LineMode/$(WWW_MACH); else echo OK ; fi
	touch $@

$(OBJ)/HTBrowse.o : $(OE) $(LM)HTBrowse.c $(LM)GridText.h $(LM)Version.make \
		$(CMN)HTUtils.h $(CMN)HTAccess.h
	$(CC) -c -o $@ $(CFLAGS2) -DVL=\"$(VL)\" $(LM)HTBrowse.c  

$(OBJ)/GridText.o : $(OE) $(LM)GridText.c $(LM)GridText.h $(LM)GridStyle.h\
	 $(CMN)HTAnchor.h $(CMN)HTStyle.h
	$(CC) -c -o $@ $(CFLAGS2) $(LM)GridText.c

$(OBJ)/DefaultStyles.o : $(OE) $(LM)DefaultStyles.c $(CMN)HTStyle.h
	$(CC) -c -o $@ $(CFLAGS2) $(LM)DefaultStyles.c  

# the cyrillic version 

$(OBJ)/HTBrowse-cyr.o : $(OE) $(LM)HTBrowse.c $(LM)GridText.h $(LM)Version.make \
		$(CMN)HTUtils.h $(CMN)HTAccess.h
	$(CC) -c -o $@ $(CFLAGS2) -DCYRILLIC -DVL=\"$(VL)\" $(LM)HTBrowse.c  

$(OBJ)/GridText-cyr.o : $(OE) $(LM)GridText.c $(LM)GridText.h $(LM)GridStyle.h\
	 $(CMN)HTAnchor.h $(CMN)HTStyle.h
	$(CC) -c -o $@ $(CFLAGS2) -DCYRILLIC $(LM)GridText.c

$(OBJ)/DefaultStyles-cyr.o : $(OE) $(LM)DefaultStyles.c $(CMN)HTStyle.h
	$(CC) -c -o $@ $(CFLAGS2) -DCYRILLIC $(LM)DefaultStyles.c  

$(OBJ)/a_stdio.o : $(OE) $(LM)a_stdio.g $(LM)a_stdio.h
	$(CC) -c -o $@ $(CFLAGS2) -xc $(LM)a_stdio.g
