# 
#  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

#ifndef XCOMM
# define XCOMM #
#endif

XCOMM  # ----------------- Wafe configuration -------------------------
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  # xmkmf
XMKMF = $(BINDIR)/xmkmf

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

XCOMM  # BINDIR is the place where executables will be installed.
XCOMM  # Uncomment the following lines (or set it to different values)
XCOMM  # if you have no write permission in the default X11 BINDIR
XCOMM  # (usually /usr/bin/X11).  Since also some standard X11
XCOMM  # utilities are addressed relative to BINDIR, we have to
XCOMM  # redefine these here as well. Make sure that the standard X11
XCOMM  # BINDIR is on your path.
XCOMM  # BINDIR    = ${HOME}/bin
XCOMM  # MKDIRHIER = mkdirhier
XCOMM  # XMKMF     = xmkmf

XCOMM  # USRLIBDIR is the place where the wafe libraries libwafe.a and
XCOMM  # libmofe.a will be installed.  Uncomment the line below if
XCOMM  # you have no write permission in the default X11 USRLIBDIR
XCOMM  # (usually /usr/lib/X11).
XCOMM  # USRLIBDIR = ${HOME}/lib

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

XCOMM  # The following variables define the Wafe configuration:
XCOMM  # -> If MOTIF 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

#ifndef CONFIGURATION_VIA_CMDLINE
# undef  MOTIF
# define ATHENA
# define DEBUG
# define XPM
# define XAW3D
# define LAYOUT
# define PLOTTER
# define XMGRAPH
# define RDD
# define HTML

# undef ITCL
#endif

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
XCOMM #define BUILD_XPM
XCOMM #define BUILD_XAW3D

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

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
 XMLIB                 =
#undef XMGRAPH
#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;
#endif
TCL_LIBRARY_FLAG      = -ltcl

#ifdef ITCL
 ITCL_HOME            = ../lib/itcl-1.5/src
 ITCL_INCLUDE_FLAG    = -I$(ITCL_HOME)
 ITCL_LD_PATH         = -L$(ITCL_HOME)
 ITCL_LIBRARY_FLAG    = -litcl
 ITCL_DEFINES         = -DITCL
#endif

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.4a
 XPM_INCLUDE_FLAG     = -I$(XPM_HOME)/lib
# ifdef BUILD_XPM
  XPM_DEP_LIB         = $(XPM_HOME)/lib/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); rm -f *.o)
#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
 MOTIF_DEFINES         = -DMOTIF ${MOTIF_EDITRES}
 MOTIF_HOME            = /usr
 MOTIF_LD_PATH         = # -L${MOTIF_HOME}
 MCLIENTINCLUDE_FLAG   = # -I${MOTIF_HOME}/include/X11 -I${MOTIF_HOME}/include
 XMLIB                 = -lXm 
XCOMM  XMLIB              = /usr/lib/libXm.a 
XCOMM  EXTENSIONLIB       = -lXext-R4
XCOMM  XTOOLLIB           = -lXt-R4
XCOMM  XLIB               = ${EXTENSIONLIB} -lX11-R4
XCOMM  XMULIB             = -lXmu-R4
XCOMM  PROTO_DEFINES      = -DNPROTO
XCOMM  #define ProjectX 4
XCOMM  /**/# On our system we have to compile MOTIF with the R4 versions of all
XCOMM  /**/# Libraries. We have separate R4 based libraries on the motif path
XCOMM  #ifdef XPM
XCOMM  XPM_LIBRARY_FLAG      = -lXpm-R4
XCOMM  #endif
XCOMM  #ifdef PLOTTER
XCOMM  PLOTTER_LIBRARY_FLAG  = -lAt-R4
XCOMM  #endif
# ifdef LAYOUT
  LAYOUT_LD_PATH      = -L../lib/Xaw3d
  LAYOUT_LIBRARY_FLAG = -lXaw3d
XCOMM  LAYOUT_LIBRARY_FLAG= -llayout
# endif
# ifdef HTML
  HTML_LIB            = m-htmlw
  HTML_LIBRARY_FLAG   = -l$(HTML_LIB)
  HTML_MDEFINES       = -DMOTIF
  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) $(ITCL_INCLUDE_FLAG) 

NON_X_LIBRARIES = \
	$(ITCL_LIBRARY_FLAG) $(TCL_LIBRARY_FLAG) \
	$(DBUG_LIBRARY_FLAG) -lm $(DBMALLOC_LIBRARY_FLAG)

LOCAL_LDFLAGS =  -L. \
	$(XPM_LD_PATH) $(TCL_LD_PATH) $(ITCL_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)
XCOMM CDEBUGFLAGS = LibraryCDebugFlags
 STD_DEFINES     = LibraryDefines

 LDOPTIONS       = $(LOCAL_LDFLAGS)
 VERSIONDEFINES  = -DPRER5 -DPRER6
#else
# ifdef ATHENA
  ATHENAVERSION = -DATHENAR5
# endif
# if (ProjectX < 6)
  VERSIONDEFINES  = $(ATHENAVERSION)  -DPRER6
# else
  VERSIONDEFINES  = $(ATHENAVERSION)
# endif
XCOMM STD_INCLUDES    = -I/usr/local/X11R5/include
#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) \
	$(ITCL_DEFINES) 

GENSRCS = \
	XtGen.c MiscGen.c XawGen.c Xaw5Gen.c XmGen.c Xm12Gen.c AtGen.c \
	XmGrGen.c  htmlGen.c rddGen.c \
	callback.c

SRCS =  $(WAFESHELL).c createW.c converters.c selection.c actionsCB.c mm.c \
	resources.c handlers.c $(RDD_SRCS) $(GENSRCS) 

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

VOBJECTS = XawGen.o Xaw5Gen.o XmGen.o Xm12Gen.o XmGrGen.o AtGen.o XtGen.o \
	htmlGen.o rddGen.o rdd.o converters.o resources.o \
	createW.o callback.o actionsCB.o handlers.o wafe.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()
NormalDepLibraryTarget($(WAFE),$(WAFE)_built $(LIBOBJS),$(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) $(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

Xaw5Gen.c: genc Xaw5Gen.spec athena5.inc types
	$(GENC) Xaw5Gen.spec

htmlGen.c: genc htmlGen.spec types gifread.inc html.inc xpmread.inc
	$(GENC) htmlGen.spec

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

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

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

AtGen.c: genc AtGen.spec At.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

#ifdef HTML
$(HTML_DEP_LIB):
	(cd $(HTML_HOME); $(XMKMF); \
	$(MAKE) CC="$(CC)" CFLAGS="$(HTML_MDEFINES) $(CFLAGS)" \
	 cleano lib$(HTML_LIB).a)
#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

c_code: $(GENSRCS) 

real_clean_version:
	rm -f $(VOBJECTS) $(WAFESHELL) 
	$(HTML_CLEAN) 

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

wafe_built:
	$(MAKE) clean_version
	rm -f mofe_built
	touch $@

mofe_built:
	$(MAKE) clean_version
	rm -f wafe_built
	touch $@


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 \
	    	/usr/lib/X11/wafe/tcllib /usr/lib/tcl \
		-regex ".*[a-z]$$" -type f -print | sort > distfiles

