# 
#  Copyright (C) 1992 by Gustaf Neumann, Stefan Nusser
# 
#       Wirtschaftsuniversitaet Wien,
#       Abteilung fuer Wirtschaftsinformatik
#       Augasse 2-6,
#       A-1090 Vienna, Austria
#       neumann@wu-wien.ac.at, nusser@wu-wien.ac.at
# 
#  Permission to use, copy, modify, and distribute this software and its
#  documentation for any purpose and without fee is hereby granted, provided
#  that the above copyright notice appears in all copies and that both that
#  copyright notice and this permission notice appear in all supporting
#  documentation.  This software is provided "as is" without expressed or
#  implied warranty.
# 
#  Date: Mon, Apr 13 1992
#  Author: Gustaf Neumann
#  Version: 0.97

XCOMM  # ----------------- Wafe configuration -------------------------
XCOMM  # uncomment the following line if you have no write 
XCOMM  # permission in the default X11 BINDIR (usually /usr/bin/X11)
XCOMM  # BINDIR is the place where executables will be installed.
XCOMM  # BINDIR=${HOME}/bin

XCOMM  # if you have no socketpair on your system, you might try 
XCOMM  # -DPIPES or -DSTREAMS. 
XCOMM  # in this case uncomment one of the following lines
XCOMM  # COMPAT_DEFINES = -DSTREAMS
XCOMM  # COMPAT_DEFINES = -DPIPES
XCOMM  # COMPAT_DEFINES = -DWIDGETLISTTRACE

XCOMM  # CDEBUGFLAGS = -Wall -g
XCOMM  # CC=cc

XCOMM  # If Perl installed on a different place on your systems change
XCOMM  # the path here. Perl might be called during make to execute genc
XCOMM  # (the C code generator), when a  .spec file, a .inc file, 'types',
XCOMM  # or 'genc' is changed. 
GENC = /usr/local/bin/perl ./genc

XCOMM  # This is the standard place where wafe/mofe will look for 
XCOMM  # library scripts etc.
WAFELIB = /usr/lib/X11/wafe


XCOMM  # ----------------- Wafe configuration -------------------------

XCOMM  # The following variables define the Wafe configuration:
XCOMM  # -> If MOTIF11 or MOTIF12 is specified, an OSF/Motif version of 
XCOMM  #    Wafe (mofe) is being build (using Motif 1.1 or Motif 1.2).
XCOMM  #    otherwise
XCOMM  #    a version of Wafe using the Athena widget set is built (wafe).
XCOMM  #
XCOMM  # -> If during the compilation Layout.h is not found, either
XCOMM  #    get XAW3D (+patches) or #undef LAYOUT

#undef MOTIF12
#define ATHENA
#define DEBUG
#define XPM
#define XAW3D
#define  LAYOUT
#define PLOTTER
#define XMGRAPH
#define RDD
#define HTML


XCOMM  # ----------------- which libraries should be built -------------

XCOMM  # The following packages might be already installed on your
XCOMM  # system; if they are not and if you want to build them uncomment
XCOMM  # the necessary lines. Be aware, that building shared libraries is
XCOMM  # a moving target on some operating systems. It might be easier to
XCOMM  # obtain a binary distribution in some cases (eg. Linux)

#define BUILD_TCL
#define BUILD_PLOTTER
#define BUILD_XPM
XCOMM #define BUILD_XAW3D

XCOMM  # ----------------- implied variables --------------------

XCOMM  # MOTIF11 implies MOTIF
#ifdef MOTIF11
#define MOTIF
#endif

XCOMM  # MOTIF12 implies MOTIF
#ifdef MOTIF12
#define MOTIF
#endif

XCOMM  # backward compatibility: MOTIF defined, but not MOTIF11
#ifdef MOTIF
#ifndef MOTIF11
#define MOTIF11
#endif
#endif

XCOMM  # if MOTIF is defined, ATHENA or XAW3d cannot be defined
XCOMM  # the wafe executable will be called mofe
#ifdef MOTIF
WAFE                  =   mofe
#undef ATHENA 
#undef XAW3D
#endif

XCOMM  # if ATHENA is defined, the ATHENA_DEFINES flag is added automatically,
XCOMM  # XMGRAPH is not allowed.
XCOMM  # The wafe executable will be called wafe
#ifdef ATHENA
WAFE                  = wafe
ATHENA_DEFINES        = -DATHENA
#undef XMGRAPH
XMLIB                 =
#else
XAWLIB                =
XAW3D_DEFINES         = 
XAW3D_INCLUDE_FLAG    = 
#endif


XCOMM  # $(WAFESHELL).c is the source of the program containing main()
XCOMM  # WAFESHELL=wafe is the standard setup for wafe and mofe.
XCOMM  # If libwafe/libmofe should be linked to a different program
XCOMM  # it could be specified here
WAFESHELL = wafe



XCOMM  # ----------------- configuration of packages --------------------

XCOMM  # Dictionary of Variable names:
XCOMM  #  *HOME         ... home directroy of the sources of this package
XCOMM  #  *LD_PATH      ... linker option to locate library
XCOMM  #  *LIBRARY_FLAG ... linker option to use library
XCOMM  #  *INCLUDE_FLAG ... compiler option to locate include files
XCOMM  #  *DEFINES      ... compiler option to pass preprocessor variables
XCOMM  #  *DEP_LIB      ... name of the library used in dependencies


TCL_HOME              = ../lib/tcl7.3
TCL_H                 = $(TCL_HOME)/tcl.h 
#ifdef BUILD_TCL
TCL_LD_PATH           = -L$(TCL_HOME) 
TCL_DEP_LIB           = $(TCL_HOME)/libtcl.a
TCL_ENV_VAR           =	TCL_HOME=$(TCL_HOME);export TCL_HOME;
#else
#endif
TCL_LIBRARY_FLAG      = -ltcl


DBUG_HOME             = ../lib/dbug
DBUG_INCLUDE_FLAG     = -I$(DBUG_HOME)
#ifdef DEBUG
DBUG_DEP_LIB          = $(DBUG_HOME)/libdbug.a
DBUG_LIBRARY_FLAG     = -ldbug
DBUG_LD_PATH          = -L$(DBUG_HOME)
#else
DBUG_DEFINES          = -DDBUG_OFF
#endif


#ifdef XPM
XPM_HOME              = ../lib/xpm-3.2g
XPM_INCLUDE_FLAG      = -I$(XPM_HOME)/lib
#ifdef BUILD_XPM
XPM_DEP_LIB           = $(XPM_HOME)/libXpm.a
XPM_LD_PATH           = -L$(XPM_HOME)/lib
#endif
XPM_LIBRARY_FLAG      = -lXpm
XPM_DEFINES           = -DXPM
#else
#undef BUILD_XPM
#endif

#ifdef RDD
RDD_DEFINES           = -DRDD
RDD_SRCS              = rdd.c
RDD_OBJS              = rdd.o
RDD_INCLUDE_FLAG      =
#endif

#ifdef HTML
HTML_HOME             = ../lib/libhtmlw
HTML_LIB              = htmlw
HTML_INCLUDE_FLAG     = -I$(HTML_HOME)
HTML_LD_PATH          = -L$(HTML_HOME)
HTML_LIBRARY_FLAG     = -l$(HTML_LIB)
HTML_DEFINES          = -DHTML
HTML_CLEAN            = (cd $(HTML_HOME); $(MAKE) clean)
#endif

#ifdef XAW3D
XAWLIB                = -lXaw3d
XAW3D_DEFINES         = -DXAW3D
#ifdef BUILD_XAW3D
XAW3D_HOME            = ../lib/Xaw3d
XAW3D_INCLUDE_FLAG    = -I$(XAW3D_HOME) 
XAW3D_LD_PATH         = -L$(XAW3D_HOME)
XAW3D_DEP_LIB         = $(XAW3D_HOME)/libXaw3d.a
#endif
#else
#undef BUILD_XAW3D
#endif

XCOMM  # we use the Layout widget from the XAW3D distribution
#ifdef LAYOUT
LAYOUT_HOME           = ../lib/Xaw3d
LAYOUT_INCLUDE_FLAG   = -I$(LAYOUT_HOME) 
LAYOUT_LD_PATH        = -L$(LAYOUT_HOME)
LAYOUT_LIBRARY_FLAG   = 
LAYOUT_DEFINES        = -DLAYOUT
#endif

#ifdef XMGRAPH
XMGRAPH_HOME          = ../lib/XmGraph
XMGRAPH_DEFINES       = -DXMGRAPH
XMGRAPH_INCLUDE_FLAG  = -I$(XMGRAPH_HOME)
XMGRAPH_LD_PATH       = -L$(XMGRAPH_HOME)
XMGRAPH_LIBRARY_FLAG  = -lgraph
XMGRAPH_DEP_LIB       = $(XMGRAPH_HOME)/libgraph.a
#endif

#ifdef PLOTTER
PLOTTER_DEFINES       = -DPLOTTER
#ifdef BUILD_PLOTTER
PLOTTER_HOME          = ../lib/plotter/At
PLOTTER_INCLUDE_FLAG  = -I$(PLOTTER_HOME) 
PLOTTER_LD_PATH       = -L$(PLOTTER_HOME)
PLOTTER_LIBRARY_FLAG  = -lAt
PLOTTER_DEP_LIB       = $(PLOTTER_HOME)/libAt.a
#endif
#else
#undef BUILD_PLOTTER
#endif



#ifdef MOTIF
MOTIF_EDITRES         = -DMOTIF_EDITRES
#ifdef MOTIF12
MOTIF_DEFINES         = -DMOTIF11 -DMOTIF12 ${MOTIF_EDITRES}
#else
MOTIF_DEFINES         = -DMOTIF11 ${MOTIF_EDITRES}
#endif
MOTIF_HOME            = /usr
MOTIF_LD_PATH         = # -L${MOTIF_HOME}
MCLIENTINCLUDE_FLAG   = -I${MOTIF_HOME}/include/X11  -I${MOTIF_HOME}/include
XMLIB                 = -lXm 
#XMLIB                = /usr/lib/libXm.a 
#  EXTENSIONLIB       = -lXext-R4
#  XTOOLLIB           = -lXt-R4
#  XLIB               = ${EXTENSIONLIB} -lX11-R4
#  XMULIB             = -lXmu-R4
#  PROTO_DEFINES      = -DNPROTO
#  #define ProjectX 4
#  /**/# On our system we have to compile MOTIF with the R4 versions of all
#  /**/# Libraries. We have separate R4 based libraries on the motif path
#  #ifdef XPM
#  XPM_LIBRARY_FLAG      = -lXpm-R4
#  #endif
#  #ifdef PLOTTER
#  PLOTTER_LIBRARY_FLAG  = -lAt-R4
#  #endif
#ifdef LAYOUT
LAYOUT_LD_PATH        = -L../lib/Xaw3d
LAYOUT_LIBRARY_FLAG   = -lXaw3d
#  LAYOUT_LIBRARY_FLAG= -llayout
#endif
#ifdef HTML
HTML_LIB              = m-htmlw
HTML_LIBRARY_FLAG     = -l$(HTML_LIB)
#ifdef MOTIF12
HTML_MDEFINES         = -DMOTIF -DMOTIF1_2
#else
HTML_MDEFINES         = -DMOTIF 
#endif
HTML_MV               = ; mv libhtmlw.a lib$(HTML_LIB).a
#endif
#endif  /*MOTIF */

#ifdef HTML
HTML_DEP_LIB = $(HTML_HOME)/lib$(HTML_LIB).a
#endif


XCOMM  # DBMALLOC is a debugging malloc package available from
XCOMM  # ftp.cs.toronto.edu; this is for development purposes only
#undef MALLOC_DEBUG
#ifdef MALLOC_DEBUG
DBMALLOC_HOME         = ../lib/malloc
DBMALLOC_DEFINES      = -DDEBUG_MALLOC
DBMALLOC_INCLUDE_FLAG = 
DBMALLOC_LD_PATH      = -L$(DBMALLOC_HOME) 
DBMALLOC_LIBRARY_FLAG = -lmalloc_d
#endif


INCLUDES = -I. \
	${MCLIENTINCLUDE_FLAG} ${XMGRAPH_INCLUDE_FLAG} \
	${XPM_INCLUDE_FLAG} ${DBUG_INCLUDE_FLAG} \
	${PLOTTER_INCLUDE_FLAG} ${RDD_INCLUDE_FLAG} \
	${LAYOUT_INCLUDE_FLAG} ${HTML_INCLUDE_FLAG} ${DBMALLOC_INCLUDE_FLAG}

NON_X_LIBRARIES = \
	${TCL_LIBRARY_FLAG} ${DBUG_LIBRARY_FLAG} -lm ${DBMALLOC_LIBRARY_FLAG}

LOCAL_LDFLAGS =  -L. \
	${XPM_LD_PATH} ${TCL_LD_PATH} ${DBUG_LD_PATH} \
	${PLOTTER_LD_PATH} ${LAYOUT_LD_PATH} ${HTML_LD_PATH} \
	${MOTIF_LD_PATH} ${XMGRAPH_LD_PATH}  ${DBMALLOC_LD_PATH}

LOCAL_LIBRARIES = -l$(WAFE) \
	${XPM_LIBRARY_FLAG}  ${PLOTTER_LIBRARY_FLAG} \
	${LAYOUT_LIBRARY_FLAG} ${XMGRAPH_LIBRARY_FLAG} ${HTML_LIBRARY_FLAG} \
	${XMLIB} XawClientLibs ${NON_X_LIBRARIES}


#if (ProjectX < 5)
STD_DEFINES     = LibraryDefines
# CDEBUGFLAGS     = LibraryCDebugFlags
LDOPTIONS       = ${LOCAL_LDFLAGS}
VERSIONDEFINES  = -DPRER5
#else
#ifdef ATHENA
VERSIONDEFINES  = -DATHENAR5
STD_INCLUDES    = -I/usr/local/X11R5/include
#endif
#endif

DEFINES = ${VERSIONDEFINES} -DWAFELIB=\"${WAFELIB}\" \
	${XPM_DEFINES} ${DBUG_DEFINES} ${COMPAT_DEFINES} \
	${ATHENA_DEFINES} ${XAW3D_DEFINES}  \
	${PLOTTER_DEFINES} ${MOTIF_DEFINES} ${XMGRAPH_DEFINES} ${RDD_DEFINES} \
	${LAYOUT_DEFINES} ${DBMALLOC_DEFINES} ${HTML_DEFINES}

SRCS =  $(WAFESHELL).c createW.c converters.c selection.c actionsCB.c mm.c \
	resources.c handlers.c \
	XtGen.c MiscGen.c XawGen.c XawR5Gen.c XmGen.c Xm12Gen.c AtGen.c \
	XmGraphGen.c  htmlwGen.c rddGen.c  \
	callback.c $(RDD_SRCS)

OBJS = $(WAFESHELL).o
LIBOBJS =  \
	createW.o converters.o selection.o actionsCB.o mm.o \
	resources.o handlers.o \
	XtGen.o MiscGen.o XawGen.o XawR5Gen.o XmGen.o Xm12Gen.o AtGen.o \
	XmGraphGen.o rddGen.o  htmlwGen.o \
	callback.o $(RDD_OBJS)

VOBJECTS = XawGen.o XawR5Gen.o XmGen.o Xm12Gen.o XmGraphGen.o AtGen.o XtGen.o \
	htmlwGen.o rddGen.o rdd.o converters.o resources.o mm.o \
	wafe.o createW.o callback.o actionsCB.o handlers.o

DEPLIBS = $(TCL_DEP_LIB) $(DBUG_DEP_LIB) $(XPM_DEP_LIB) $(PLOTTER_DEP_LIB) \
		$(XAW3D_DEP_LIB)  $(HTML_DEP_LIB) $(XMGRAPH_DEP_LIB) \
		lib$(WAFE).a

ComplexProgramTarget($(WAFE))
AllTarget(tcllib/tclIndex)

NormalLibraryObjectRule()
NormalLibraryTarget($(WAFE),$(LIBOBJS))
InstallLibrary($(WAFE),$(USRLIBDIR))

tcllib/tclIndex: $(WAFE)
	(cd tcllib; $(TCL_ENV_VAR) ../$(WAFE) --f buildIndex)


wafe.o: tcl.h version.h wafe.h
mm.o: wafe.h
converters.o: wafe.h
handlers.o: wafe.h

tcl.h: $(TCL_H)
	$(RM) tcl.h
	ln -s $(TCL_H) .

XtGen.c: genc XtGen.spec Xt.inc xpm.inc types
	$(GENC) XtGen.spec

XawGen.c: genc XawGen.spec athena.inc types
	$(GENC)  XawGen.spec

XawR5Gen.c: genc XawR5Gen.spec athenaR5.inc types
	$(GENC) XawR5Gen.spec

htmlwGen.c: genc htmlwGen.spec types gifread.inc htmlw.inc
	$(GENC) htmlwGen.spec


XmGen.c: genc XmGen.spec motif.inc types
	$(GENC) XmGen.spec

Xm12Gen.c: genc Xm12Gen.spec motif12.inc types
	$(GENC) Xm12Gen.spec

XmGraphGen.c: genc XmGraphGen.spec types
	$(GENC) XmGraphGen.spec

AtGen.c: genc AtGen.spec AtHandCraft.inc types
	$(GENC) AtGen.spec

MiscGen.c: genc MiscGen.spec misc.inc types
	$(GENC) MiscGen.spec

rddGen.c: genc rddGen.spec rdd.inc types
	$(GENC) rddGen.spec


#ifdef BUILD_TCL
$(TCL_DEP_LIB):
	(cd $(TCL_HOME); ./configure; make)
#	(cd $(TCL_HOME); ./configure; make; make install-libraries)
#endif

#	(cd $(HTML_HOME);  $(MAKE) clean;
#ifdef HTML
$(HTML_DEP_LIB):
	(cd $(HTML_HOME); \
	$(MAKE) CC="$(CC)" CFLAGS="$(HTML_MDEFINES) $(CFLAGS)"\
	 RANLIB="$(RANLIB)" $(HTML_MV))
#endif

#ifdef DEBUG
$(DBUG_DEP_LIB):
	(cd $(DBUG_HOME); make lib)
#endif

#ifdef BUILD_XPM
$(XPM_DEP_LIB):
	(cd $(XPM_HOME); xmkmf; make Makefiles; cd lib; make)
#endif

#ifdef BUILD_PLOTTER
$(PLOTTER_DEP_LIB):
	(cd $(PLOTTER_HOME); xmkmf; make)
#endif

#ifdef BUILD_XAW3D
$(XAW3D_DEP_LIB):
	(cd $(XAW3D_HOME); xmkmf; make includes; make)
#endif

#ifdef XMGRAPH
$(XMGRAPH_DEP_LIB):
	(cd $(XMGRAPH_HOME); make libgraph.a)
#endif

clean_version:
	rm -f ${VOBJECTS}
	$(HTML_CLEAN) 

doc:
	latex wafedoc.tex
	makeindex wafedoc.idx
	latex wafedoc.tex
	dvips -o ../hardcopy/wafedoc-a4.ps -t a4 wafedoc.dvi
	dvips -o ../hardcopy/wafedoc.ps -t a4 wafedoc.dvi

install::
	-@mkdir ${WAFELIB}
	-@mkdir ${WAFELIB}/tcllib
	cp -r ./tcllib ${WAFELIB}

runtimedist:
	find wafe mofe libwafe.a libmofe.a tcl tcllib \
		-regex ".*[a-z]$$" -type f -print | sort > distfiles

