###############################################################################
#
# Make-a-wish
# Makefile for Make-a-wish with standard or Extended Tcl
#
# Tom Poindexter 

###############################################################################
#
# set the following defines as needed: 
#

#------------------------------------------------------------------------------
# include Make-a-wish configure variables
#
# EXT_LIBS		# extension libraries
# TCL_EXEC		# tcl shell name
# WISH_EXEC		# wish shell name
# TCL_DIR  		# tcl base directory
# TK_DIR  		# tk base directory
# TCLX_DIR  		# tclX base directory
# TCL_LIBS 		# all tcl/tclx libs
# TK_LIBS 		# all tcl/tk/tclx libs
# TCL_MAIN 		# the tclsh/tcl  main file
# TK_MAIN 		# the wish/wishx main file
# TCL_INIT_OBJ 		# the tcl init object (tclAppInit.o or tclXAppInit.o)
# TK_INIT_OBJ 		# the tk  init object (tkAppInit.o  or tkXAppInit.o)

include mawtarget.mk


#------------------------------------------------------------------------------
# include compile and link flags gleaned from Tcl and Tk Makefiles
#
# from Tcl's Makefile:
# MATH_LIBS		# math libs needed to link tclsh
# AC_FLAGS		# compile time flags, for tcl.h, tclUnix.h
# PROTO_FLAGS		# use ansi function prototypes or not
# MEM_DEBUG_FLAGS	# use memory debug (ckalloc/ckfree)
# CFLAGS		# other cc flags, e.g. -O or -g
#
# and from Tk's Makefile
# X11_INCLUDES		# where X11 includes are, if not /usr/include
# X11_LIB_SWITCHES	# what X11 libs and associated network libs, if any
# LIBS			# all libs needed to link wish

# Tk's Makefile uses TCL_BIN_DIR to find libtcl.a, use our TCL_DIR
TCL_BIN_DIR=$(TCL_DIR)
TK_BIN_DIR=$(TK_DIR)

include tclflags.mk


#
# end of defines
#
###############################################################################


# define all the compile flags
TCL_CFLAGS=$(AC_FLAGS) $(GENERIC_FLAGS) $(PROTO_FLAGS) $(MEM_DEBUG_FLAGS) \
	   $(CFLAGS)

tclAppInit.c:
	sed -f mawtcl.sed <$(TCL_DIR)/tclAppInit.c >tclAppInit.c

tkAppInit.c:
	sed -f mawtk.sed  <$(TK_DIR)/tkAppInit.c >tkAppInit.c

tclAppInit.o:	tclAppInit.c
	cc -c -I$(TCL_DIR) $(TCL_CFLAGS) tclAppInit.c

tkAppInit.o:	tkAppInit.c
	cc -c -I$(TK_DIR) -I$(TCL_DIR) $(X11_INCLUDES) $(TCL_CFLAGS) tkAppInit.c

tclXAppInit.c:
	sed -f mawtcl.sed <$(TCLX_DIR)/src/tclXAppInit.c >tclXAppInit.c

tkXAppInit.c:
	sed -f mawtk.sed <$(TCLX_DIR)/tksrc/tkXAppInit.c >tkXAppInit.c

tclXAppInit.o:  tclXAppInit.c
	cc -O -c -I$(TCLX_DIR)/tclmaster/include -I$(TCL_DIR) $(TCL_CFLAGS) \
	     tclXAppInit.c

tkXAppInit.o:   tkXAppInit.c
	cc -O -c -I$(TCLX_DIR)/tclmaster/include \
	    -I$(TCLX_DIR)/tkmaster/include -I$(TK_DIR) -I$(TCL_DIR) \
	    $(X11_INCLUDES) $(TCL_CFLAGS) tkXAppInit.c

$(TCL_EXEC):	$(TCL_INIT_OBJ)
	cc $(TCL_MAIN) $(TCL_INIT_OBJ) $(EXT_LIBS) $(TCL_LIBS) $(MATH_LIBS) \
	   -o $(TCL_EXEC)

$(WISH_EXEC):	$(TK_INIT_OBJ)
	cc $(TK_MAIN)  $(TK_INIT_OBJ)  $(EXT_LIBS) $(TK_LIBS)  $(LIBS) \
	   -o $(WISH_EXEC)

configure:
	/bin/sh maw-configure

install:
	@echo "you'll have to install $(TCL_EXEC) $(WISH_EXEC) manually"

clean:
	rm -f $(TCL_EXEC) $(WISH_EXEC)  \
	      tcl*AppInit.c tk*AppInit.c tcl*AppInit.o tk*AppInit.o
	cp tclflags.mk.orig  tclflags.mk
	cp mawtarget.mk.orig mawtarget.mk

###############################################################################
# end of Makefile
###############################################################################

