#
# Makefile for Xmtscm.
# Copyright 1995 Thomas Kwong (tomkwong@wilshire.com)
#
# Primary platform: Solaris 2.4/2.5 for x86.
#
# $Id$
#

# =====> Compiler options.
#CC		= cc
#OPTIMIZE	= -g -xF -xpentium 
CC=gcc
OPTIMIZE=-g -O2

# =====> How to compile Xmt applications?
#   Note: I put my Xmt library under the /usr/local directory.
#	  For Solaris, /usr/dt contains Motif, /usr/openwin contains X.
INCLUDES	= -I/usr/local/include -I/usr/openwin/include \
		  -I/usr/dt/include

LIBPATH		= -L/usr/local/lib -R/usr/local/lib \
		  -L/usr/dt/lib -R/usr/dt/lib \
		  -L/usr/openwin/lib -R/usr/openwin/lib 

# =====> Put libraries needed to be linked here.
SYSLIBES	= -lnsl -lsocket -lm
X_LIBES		= -lXext -lXmu -lX11
XM_LIBES	= $(CDELIB) -lXm -lXt
XMT_LIBES	= -lXmt

# =====> Define the followings if you want to have
#	 Common Desktop Environment widgets support.
#CDEDEF		= -DCDE
#CDEINCLUDE	= -I/usr/dt/include
#CDEOBJ		= dt-xm.o
#CDEOBJ2		= dt-xmt.o
#CDELIB		= -lDtWidget

#  =====> Define the followings if you want to use the HTML widget
#	  from Mosaic source.  Make sure you have compiled inside
#	  the libhtmlw directory.
#HTMLDEF		= -DHTML_WIDGET
#HTMLPATH	= /home/tomkwong/src/Mosaic-src/libhtmlw
#HTMLOBJ		= html.o
#HTMLINCLUDE	= -I$(HTMLPATH)
#HTMLLIB		= $(HTMLPATH)/libhtmlw.a

# =====> Installation programs.
MV		= mv
INSTALL		= cp
CHMOD		= chmod 755

#  =====> Installation paths for binaries(xscm,xmscm,xmtscm).
#BINDIR		= /usr/local/bin
BINDIR		= /home/jaffer/bin

#  =====> Where to find SCM source codes?
SCMSRCDIR 	= /home/jaffer/scm

#  =====> SCM initialization file.
SCMINITFILE	= /usr/local/lib/scm/Init.scm

# =====> SCM objects.
#        Make sure you compile all these objects in the scheme source
#	 directory before you make xmtscm.  The extensions ioext, posix,
#	 ramap and not required by Xmtscm.
SCMOBJS 	= $(SCMSRCDIR)/time.o \
		  $(SCMSRCDIR)/repl.o \
		  $(SCMSRCDIR)/fscl.o \
		  $(SCMSRCDIR)/sys.o \
		  $(SCMSRCDIR)/feval.o \
		  $(SCMSRCDIR)/subr.o \
		  $(SCMSRCDIR)/funif.o \
		  $(SCMSRCDIR)/rope.o \
		  $(SCMSRCDIR)/continue.o \
		  $(SCMSRCDIR)/ioext.o \
		  $(SCMSRCDIR)/posix.o \
		  $(SCMSRCDIR)/ramap.o 

# SCM flags for scm.c.
# Depending your machine and operating system type, you may have
# to use a different setting below.
SCMDEF		= -DFLOAT -DSIG

# SCM compiled extensions.  
# Remember to add the right object file in SCMOBJS if you want to have any
# compiled extensions.
SCMEXT		= -DCOMPILED_INITS="init_ioext();init_posix()"

#  =====> ccxmtscm.
#	  Define the followings if you want to compile ccxmtscm.
#	  This extension is very old as one of my first SCM extension project.
#	  Use it at your own risk. :-)
#CCLIBPATH	= /home/tomkwong/src/imap/c-client
#CCLIBFILE	= $(CCLIBPATH)/c-client.a
#CCXMT_LIBES	= $(CCLIBFILE) $(XMT_LIBES)
#CCINCLUDES	= -I$(CCLIBPATH)


###########################################################################
#
#  Don't modify anything below... if you are not an expert in makefiles :-)
#
###########################################################################

TMP="\"$(SCMINITFILE)\""

CFLAGS 		= $(XDEFS) -DUSE_APPCONTEXT -DXLIB_ILLEGAL_ACCESS -DSUPER_X\
		  -DUSE_RESOURCE_MANAGER $(OPTIMIZE) -I$(SCMSRCDIR) \
		  -DIMPLINIT=$(TMP) $(SCMEXT) $(XCFLAGS) \
		  $(CDEDEF) $(HTMLDEF) $(CDEINCLUDE) $(HTMLINCLUDE) \
		  $(INCLUDES) $(CCINCLUDES) $(XCFLAGS)
LDOPTIONS	= $(XLDFLAGS) $(LIBPATH)

# Objects

XOBJS		= xscm.o x.o
XMOBJS 		= xmscm.o x.o xt-xm.o xm-xm.o $(CDEOBJ) $(HTMLOBJ)
XMTOBJS 	= xmtscm.o x.o xt-xmt.o xm-xmt.o xmt.o $(CDEOBJ2) $(HTMLOBJ)
CCXMTOBJS 	= ccxmtscm.o x.o xt-xmt.o xm-xmt.o xmt-cc.o password.o \
		  $(CDEOBJ) $(HTMLOBJ) cc.o unix.o

# Targets

all: xmtscm xmscm xscm

xscm: $(XOBJS)
	$(CC) -o $@ $(XOBJS) $(LDOPTIONS) $(SCMOBJS) $(X_LIBES) $(SYSLIBES)

xmscm: $(XMOBJS)
	$(CC) -o $@ $(XMOBJS) $(LDOPTIONS) $(SCMOBJS) $(HTMLLIB) $(XM_LIBES) $(X_LIBES) $(SYSLIBES)

xmtscm: $(XMTOBJS)
	$(CC) -o $@ $(XMTOBJS) $(LDOPTIONS) $(SCMOBJS) $(HTMLLIB) $(XMT_LIBES) $(XM_LIBES) $(X_LIBES) $(SYSLIBES)

ccxmtscm: $(CCXMTOBJS)
	$(CC) -o $@ $(CCXMTOBJS) $(LDOPTIONS) $(SCMOBJS) $(CCXMT_LIBES) $(XMT_LIBES) $(XM_LIBES) $(X_LIBES) $(SYSLIBES)

real-clean: latex-clean
	$(RM) *.o *.log *.toc *.ind *.aux *~ 
	$(RM) xscm xmscm xmtscm ccxmtscm core
	$(RM) -rf xmt-html

backup-clean:
	$(RM) *~

latex-clean:
	$(RM) *.aux *.toc *.idx *.ilg *.ind *.log 

xscm-clean:
	$(RM) $(XOBJS)

xmscm-clean:
	$(RM) $(XMOBJS)

xmtscm-clean:
	$(RM) $(XMTOBJS)

ccxmtscm-clean:
	$(RM) $(CCXMTOBJS)

REMINDER="Remember to change require.scm in your scm library path."

install-xscm: xscm
	$(INSTALL) $< $(BINDIR)/$< && $(CHMOD) $(BINDIR)/$< 
	@echo $(REMINDER)

install-xmscm: xmscm
	$(INSTALL) $< $(BINDIR)/$< && $(CHMOD) $(BINDIR)/$< 
	@echo $(REMINDER)

install-xmtscm: xmtscm
	$(INSTALL) $< $(BINDIR)/$< && $(CHMOD) $(BINDIR)/$< 
	@echo $(REMINDER)

install-ccxmtscm: ccxmtscm
	$(INSTALL) $< $(BINDIR)/$< && $(CHMOD) $(BINDIR)/$< 
	@echo $(REMINDER)

install: xscm xmscm xmtscm
	$(INSTALL) $? $(BINDIR) && \
	( $(CHMOD) $(BINDIR)/xscm ; \
	  $(CHMOD) $(BINDIR)/xmscm ; \
	  $(CHMOD) $(BINDIR)/xmtscm )
	@echo $(REMINDER)


# Dependencies

xscm.o:	$(SCMSRCDIR)/scm.c $(SCMSRCDIR)/scm.h $(SCMSRCDIR)/scmfig.h $(SCMSRCDIR)/patchlvl.h
	$(CC) $(CFLAGS) -c -DINITS=init_x\(\) $(SCMSRCDIR)/scm.c -o $@

xmscm.o: $(SCMSRCDIR)/scm.c $(SCMSRCDIR)/scm.h $(SCMSRCDIR)/scmfig.h $(SCMSRCDIR)/patchlvl.h
	$(CC) $(CFLAGS) -c -DINITS=init_x\(\)\;init_xt\(\)\;init_xm\(\)\; $(SCMSRCDIR)/scm.c -o $@

xmtscm.o: $(SCMSRCDIR)/scm.c $(SCMSRCDIR)/scm.h $(SCMSRCDIR)/scmfig.h $(SCMSRCDIR)/patchlvl.h
	$(CC) $(CFLAGS) -c -DINITS=init_x\(\)\;init_xt\(\)\;init_xm\(\)\;init_xmt\(\) $(SCMSRCDIR)/scm.c -o $@

ccxmtscm.o: $(SCMSRCDIR)/scm.c $(SCMSRCDIR)/scm.h $(SCMSRCDIR)/scmfig.h $(SCMSRCDIR)/patchlvl.h
	$(CC) $(CFLAGS) -c -DINITS=init_x\(\)\;init_xt\(\)\;init_xm\(\)\;init_xmt\(\)\;init_cc\(\) $(SCMSRCDIR)/scm.c -o $@

ol.o:	ol.c x.h xt.h
	$(CC) $(CFLAGS) -c ol.c

x.o:	x.c xevent.h x.h version.h

xevent.h xevent.scm: xgen.scm
	scm xgen

xm-xm.o: xm.c x.h xt.h
	$(CC) $(CFLAGS) -DMOTIF -DSUPER_MOTIF -c xm.c -o xm-xm.o

xm-xmt.o: xm.c x.h xt.h
	$(CC) $(CFLAGS) -DMOTIF -DSUPER_MOTIF -DXMT -c xm.c -o xm-xmt.o

xmt.o: xmt.c x.h xt.h
	$(CC) $(CFLAGS) -DXMT -DMOTIF -c xmt.c

dt-xm.o: dt.c x.h xt.h
	$(CC) $(CFLAGS) -DMOTIF -c dt.c -o $@

dt-xmt.o: dt.c x.h xt.h
	$(CC) $(CFLAGS) -DMOTIF -DXMT -c dt.c -o $@

xmt-cc.o: xmt.c x.h xt.h
	$(CC) $(CFLAGS) -DXMT -DPASSWORD_TEXT -c xmt.c -o $@

xt-xm.o: xt.c x.h xt.h
	$(CC) $(CFLAGS) -DMOTIF -c xt.c -o $@

xt-xmt.o: xt.c x.h xt.h
	$(CC) $(CFLAGS) -DMOTIF -DXMT -c xt.c -o $@

README: README.template
	./versionify <README.template >README

html: xmt.tex
	/bin/rm -rf xmt-html
	cp xmt.tex xmt-html.tex
	latex2html -t "Xmtscm Manual" -address "tomkwong@wilshire.com" -no_navigation -no_reuse xmt-html.tex

xmt.dvi: xmt.tex
	latex xmt && makeindex xmt && latex xmt

xmt.ps: xmt.dvi
	dvips -o xmt.ps xmt.dvi

EXTMOTIF=extmotif.pl

xmtconst.scm:
	echo ";;; This file is generated automatically by $(EXTMOTIF)" > xmtconst.scm
	for i in /usr/local/include/Xmt/*; do \
		$(EXTMOTIF) $$i Xmt xmt >> xmtconst.scm; \
	done

xmconst.scm:
	echo ";;; This file is generated automatically by $(EXTMOTIF)" > xmconst.scm
	$(EXTMOTIF)  /usr/dt/include/Xm/XmStrDefs.h Xm xm >> xmconst.scm

dtconst.scm:
	echo ";;; This file is generated automatically by $(EXTMOTIF)" > dtconst.scm
	for i in /usr/dt/include/Dt/*.h; do \
		$(EXTMOTIF) $$i Dt dt >> dtconst.scm; \
	done

DIST=xmtscm-0.9
archive: xmt.ps real-clean
	cd ..; gtar --create --file - --exclude $(DIST)/RCS $(DIST) | gzip -c > $(DIST).tar.gz

test: xmtscm
	for i in bingo combo newcombo rheostat spin multitop; do xmtscm $$i; done

