# 
#  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.96p8

XCOMM  # uncomment the following line if you have no write permission in the 
XCOMM  # default BINDIR (usually /usr/bin/X11)
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  # The following variables define the Wafe configuration:
XCOMM  # -> If MOTIF11 or MOTIF12 is specifies, an OSF/Motif version of 
XCOMM  #    Wafe (mofe) is being build (using Motif 1.1 or Motif 1.2).
XCOMM  # -> If no MOTIF variable is defined, a verions of Wafe using
XCOMM  #    the Athena widget set is built.
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  # currently unsupported packages
#undef XEDW
#undef XC

XCOMM  # If Perl installed on a different place on your systems change
XCOMM  # the path here. genc is only needed when a .spec file, a .inc
XCOMM  # file, 'types; or 'genc' is changed. 
GENC = /usr/local/bin/perl ./genc

XCOMM  # This is the standard place where wafe looks for library scripts etc
WAFELIB = /usr/lib/X11/wafe

# CDEBUGFLAGS = -Wall
# CC=cc

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  # $(WAFESHELL).c is the source of the program containing main()
# WAFESHELL = w
WAFESHELL = wafe
# WAFEHOME = `pwd`

TCL_INCLUDES    = ../tcl7.3
TCL_LDFLAGS     = -L../tcl7.3
TCL_LIBRARY_    = -ltcl

#ifdef DEBUG
DBUG_LDFLAGS    = -L../dbug
DBUG_LIBRARY    = -ldbug
#else
DBUG_DEFINES    = -DDBUG_OFF
#endif
DBUG_INCLUDES   = -I../dbug

#undef MALLOC_DEBUG

#ifdef MALLOC_DEBUG
DBMALLOC_DEFINES  = -DDEBUG_MALLOC
DBMALLOC_INCLUDES = 
DBMALLOC_LDFLAGS  = -L../malloc
DBMALLOC_LIBRARY  = -lmalloc_d
#endif


XCOMM  ################# security fence
#ifdef MOTIF
WAFE              = mofe
#undef ATHENA
#undef XAW3D
#endif

#ifdef ATHENA
WAFE              = wafe
ATHENA_DEFINES    = -DATHENA
#undef XMGRAPH
XMLIB             =
#else
XAWLIB            =
XAW3D_DEFINES     = 
XAW3D_INCLUDES    = 
#endif

XCOMM  ################# configuration for various packages

#ifdef XPM
XPM_INCLUDES      = -I../xpm-3.2g/lib
XPM_LDFLAGS       = -L../xpm-3.2g/lib
XPM_LIBRARY       = -lXpm
XPM_DEFINES       = -DXPM
#endif

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

#ifdef HTML
HTML_SRC          = ../libhtmlw
HTML_LIB          = htmlw
HTML_INCLUDES     = -I$(HTML_SRC)
HTML_LDFLAGS      = -L$(HTML_SRC)
HTML_LIBRARY      = -l$(HTML_LIB)
HTML_DEFINES      = -DHTML
#endif

#ifdef XAW3D
XAWLIB            = -lXaw3d
XAW3D_DEFINES     = -DXAW3D
#endif

XCOMM  we use the Layout widget from the XAW3D distribution
#ifdef LAYOUT
LAYOUT_INCLUDES   = -I../lib/Xaw3d
LAYOUT_LDFLAGS    = -L../lib/Xaw3d
LAYOUT_LIBRARY    = 
LAYOUT_DEFINES    = -DLAYOUT
#endif

#ifdef XMGRAPH
XMGRAPH_DEFINES   = -DXMGRAPH
XMGRAPH_INCLUDES  = -I../XmGraph
XMGRAPH_LDFLAGS   = -L../XmGraph
XMGRAPH_LIBRARY   = -lgraph
#endif


#ifdef XC
XC_INCLUDES       = -I..
XC_LDFLAGS        = -L../X11/Xc
XC_LIBRARY        = -lXc
XC_DEFINES        = -DXC
XC_SRCS           = XcGen.c
XC_OBJS           = XcGen.o
#endif

#ifdef PLOTTER
PLOTTER_INCLUDES  = -I../plotter/At
PLOTTER_LDFLAGS   = -L../plotter/At
PLOTTER_LIBRARY   = -lAt
PLOTTER_DEFINES   = -DPLOTTER
#endif

#ifdef XEDW
XEDW_DEFINES      = -DXEDW
XEDW_OBJS         = XedwList.o edwlist.o
XEDW_SRCS         = Xedw/XedwList.c edwlist.c
#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_LDFLAGS     = # -L${MOTIF_HOME}
MCLIENTINCLUDES   = -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      = -lXpm-R4
#  #endif
#  #ifdef PLOTTER
#  PLOTTER_LIBRARY  = -lAt-R4
#  #endif
#ifdef LAYOUT
LAYOUT_LDFLAGS    = -L../lib/Xaw3d
LAYOUT_LIBRARY    = -lXaw3d
#  LAYOUT_LIBRARY     = -llayout
#endif
#ifdef HTML
HTML_LIB          = m-htmlw
HTML_LIBRARY      = -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_DOTA = $(HTML_SRC)/lib$(HTML_LIB).a
#endif

INCLUDES = -I. \
	${MCLIENTINCLUDES} ${XMGRAPH_INCLUDES} \
	${XPM_INCLUDES} ${DBUG_INCLUDES} \
	${XC_INCLUDES} ${PLOTTER_INCLUDES} ${RDD_INCLUDES} \
	${LAYOUT_INCLUDES} ${HTML_INCLUDES} ${DBMALLOC_INCLUDES}

NON_X_LIBRARIES = \
	${TCL_LIBRARY_} ${DBUG_LIBRARY} -lm ${DBMALLOC_LIBRARY}

LOCAL_LDFLAGS =  -L. \
	${XPM_LDFLAGS} ${TCL_LDFLAGS} ${DBUG_LDFLAGS} \
	${XC_LDFLAGS}  ${PLOTTER_LDFLAGS} ${LAYOUT_LDFLAGS} ${HTML_LDFLAGS} \
	${MOTIF_LDFLAGS} ${XMGRAPH_LDFLAGS}  ${DBMALLOC_LDFLAGS}

LOCAL_LIBRARIES = -l$(WAFE) \
	${XPM_LIBRARY}  ${XC_LIBRARY} ${PLOTTER_LIBRARY} \
	${LAYOUT_LIBRARY} ${XMGRAPH_LIBRARY} ${HTML_LIBRARY} \
	${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} ${XEDW_DEFINES} ${XC_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 $(XEDW_SRCS) $(XC_SRCS) \
	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 $(XEDW_OBJS) $(XC_OBJS) \
	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 = lib$(WAFE).a $(HTML_DOTA)

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

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

tcllib/tclIndex: $(WAFE)
	(cd tcllib;../${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_INCLUDES)/tcl.h
	$(RM) tcl.h
	ln -s $(TCL_INCLUDES)/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 types
	$(GENC) XawR5Gen.spec

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


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

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

clean_version:
	rm -f ${VOBJECTS}
	(cd $(HTML_SRC); $(MAKE) clean)

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

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

#objs: 
#	for f in $(OBJS) ;\
#	do \
#	echo $(WAFEHOME)/$$f; \
#	done
