##
#
# Makefile of XOTcl adapted for the cygwin B20 compiler (Win32)
# read README.WINDOWS for details
#
##

PREFIX = 	c:\progra~1\Tcl
EXEC_PREFIX=	c:\progra~1\Tcl

CYGHOME= 		/cygnus/cygwin-b20
CYGINSTALL= 	$(CYGHOME)/H-i586-cygwin32/bin

INST_XOLIBPKG = \"$(PREFIX)/lib/xotcl\"
XOTCLVERSION = \"0.82\"

# Generated automatically from Makefile.in by configure.

#
# try ./configure first to fill in all the definitions corresponding
# to your system, but you always can edit the sections below manually.
#

CC=		gcc
CFLAGS=		 -O -D__NO_STRING_INLINES -D__NO_MATH_INLINES -Wall -DXOLIBPKG=\"$(INST_XOLIBPKG)\" -DXOTCLVERSION=\"$(XOTCLVERSION)\"  
RANLIB= 	ranlib
INSTALL=	/usr/bin/install -c


#
# where to find tcl/tk source (for includes) and binaries (for libraries)
#

TCLINC=		-I$(CYGHOME)/src/tcl/generic
TCLLIB=		-L$(CYGHOME)/src/tcl/win -l$(TCL)
TKDIR= 		$(CYGHOME)/src/tk/win
TKINC=		-I$(TKDIR) -I$(CYGHOME)/src/tk/generic 
TKLIB=		-L$(TKDIR) -l$(TK)

#
# X11 and other libraries from tcl/tk make as needed to link tclsh and wish
#

XINC=		
XLIB=	
OTHER_TCL_LIBS=	
OTHER_TK_LIBS=	

#
# how to compile, link, and name shared libraries
#

#SHLIB_LD=	ld -shared
#SHLIB_CFLAGS=	-fPIC
#SHLIB_SUFFIX=	.so
#SHLD_FLAGS=	
#DL_LIBS=	-ldl
					  
#
# where to install shells, libraries, and includes
#						   

INST_XOTCLSH=	/
INST_XOWISH=	/usr/lbin
INST_OLIB=	/usr/local/lib
INST_OLIBSH=	/usr/local/lib
INST_OINC=	/usr/local/include

TCL=  tcl80
TK=   tk80
#XOTCL= @XOTCL@
XOTCL= xotcl
XOTCLVERSION= 0.821
MAKE_XOWISH= yes


#
# ------------ you shouldn't need to configure below here -----------------
#
INCLUDES= -I. $(TCLINC) $(TKINC) $(XINC) 
XOTCLLIB= -L. -l$(XOTCL)

SRCS = xotclError.c xotclTrace.c xotclProfile.c xotclReference.c xotcl.c
OBJS = o/xotclError.o o/xotclTrace.o o/xotclProfile.o o/xotclReference.o o/xotcl.o
SOBJS = so/xotclError.o so/xotclTrace.o so/xotclProfile.o so/xotclReference.o so/xotcl.o

xotcllibs: lib$(XOTCL).a #lib$(XOTCL)$(SHLIB_SUFFIX)



all: xotclsh xowish

o/%.o: %.c 
	@if test ! -d o; then mkdir o; fi
	$(CC) -c -o $@ $(CFLAGS) $(INCLUDES) $<
so/%.o: %.c
	@if test ! -d so; then mkdir so; fi
	$(CC) -c -o $@ $(CFLAGS) $(SHLIB_CFLAGS) $(INCLUDES) $<
%.o: %.c
	$(CC) -c -o $@ $(CFLAGS) $(INCLUDES) $<

# create a predefined .h file from an .xotcl file.
# for development only, .h file included in distrbution
predefined.h: mk_predefined.xotcl predefined.xotcl
	./xotclsh mk_predefined.xotcl > predefined.h

#
# compile an appinit with tcl and xotcl and link against
# libxotcl.a plus required tcl libs to give a standalone binary
xotclsh: xotclAppInit.o lib$(XOTCL).a
	$(CC) -o xotclsh xotclAppInit.o lib$(XOTCL).a $(SHLD_FLAGS) $(CFLAGS) \
		$(INCLUDES) $(TCLLIB) $(DL_LIBS) \
		$(OTHER_TCL_LIBS) 

baselibs   = -lkernel32 $(optlibs) -ladvapi32
winlibs    = $(baselibs) -luser32 -lgdi32 -lcomdlg32 -lwinspool
conlflags = $(lflags) -Wl,--subsystem,console -mwindows
guilflags = $(lflags) -mwindows
dlllflags = $(lflags)
guilibsdll = $(libcdll) $(winlibs)

WISHRES = $(TKDIR)/wishres.o

# compile an appinit with tcl/tk and xotcl and link against
# libxotcl.a plus required tcl/tk libs to give a standalone binary
xowish: xotkAppInit.o lib$(XOTCL)$(SHLIB_SUFFIX)
	@if test "$(MAKE_XOWISH)" = "yes" ; then \
	  $(CC) -o xowish $(guilflags) xotclWinMain.o $(TKDIR)/tkConsole.o $(WISHRES) $(CFLAGS)  \
	  $(XOTCLLIB) $(TKLIB) $(TCLLIB) \
	  $(OTHER_TK_LIBS) $(OTHER_TCL_LIBS) \
	  $(guilibsdll)
	fi

#
# compile xotcl.c and link it into a library archive
# INCLUDES give a path to tclInt.h (plus tk and X11)
lib$(XOTCL).a: $(OBJS)
	ar cr $@ $(OBJS)
	$(RANLIB) $@


#
# compile xotcl.c and link it into a shared object
# INCLUDES give a path to tclInt.h (plus tk and X11)
lib$(XOTCL)$(SHLIB_SUFFIX): $(SOBJS)
	$(SHLIB_LD) -o $@ $(SOBJS)


lib/pkgIndex.tcl: 
	(cd lib; ../xotclsh ../../packages/make.xotcl -all)


test: xotclsh
	./xotclsh lib/speedtest.xotcl
	./xotclsh lib/testx.xotcl
	./xotclsh lib/testo.xotcl

libs: lib/pkgIndex.tcl lib$(XOTCL)$(SHLIB_SUFFIX) lib$(XOTCL).a

install: install_xotclsh install_xowish

install_xotclsh: xotclsh lib$(XOTCL).a lib$(XOTCL)$(SHLIB_SUFFIX) $(INST_XOTCLSH) $(INST_XOLIB) $(INST_XOINC)
	if test ! -d $(INST_XOLIBSH); then mkdir $(INST_XOLIBSH); fi;
	if test ! -d $$(INST_XOLIBPKG)/lib; then mkdir $(INST_XOLIBPKG)/lib; fi;
	$(INSTALL) -s xotclsh $(INST_XOTCLSH) 
	$(INSTALL) lib$(XOTCL).a $(INST_XOLIB) 
	$(INSTALL) lib$(XOTCL)$(SHLIB_SUFFIX) $(INST_XOLIBSH)
	$(INSTALL) xotcl.h xotclInt.h $(INST_XOINC)
	cp *.add $(INST_XOLIBPKG)
	cp lib/*tcl lib/*.add $(INST_XOLIBPKG)/lib
	./xotclsh ../packages/make.xotcl -install.index  
	@#./xotclsh ./appendPkgIndex.xotcl $(INST_XOLIBPKG)

install_xowish: xowish lib$(XOTCL).a lib$(XOTCL)$(SHLIB_SUFFIX) $(INST_XOWISH) $(INST_XOLIB) $(INST_XOLIBSH) $(INST_XOINC)
	@if test "$(MAKE_XOWISH)" = "yes" ; then \
		if test ! -d $(INST_XOWISH); then mkdir $(INST_XOWISH); fi; \
		$(INSTALL) -s xowish $(INST_XOWISH); \
		$(INSTALL) lib$(XOTCL).a $(INST_XOLIB);\
		$(INSTALL) lib$(XOTCL)$(SHLIB_SUFFIX) $(INST_XOLIBSH); \
		$(INSTALL) xotcl.h xotclInt.h $(INST_XOINC); \
	fi

$(INST_XOTCLSH):
	if test ! -d $@; then mkdir $@; fi

$(INST_XOLIB):
	if test ! -d $@; then mkdir $@; fi

$(INST_XOINC):
	if test ! -d $@; then mkdir $@; fi

$(INST_XOLIBPKG)/lib:
	if test ! -d $(INST_XOLIBPKG); then mkdir $(INST_XOLIBPKG); fi
	if test ! -d $@; then mkdir $@; fi


xref:
	cxref -xref-all -html32 -I $(INCLUDES) xotcl.c xotcl.h xotclInt.h xotcl*Init.c


clean:
	rm -rf xowish xotclsh lib$(XOTCL).a lib$(XOTCL)$(SHLIB_SUFFIX) \
		*.o o so config.status config.log config.cache \
		*.html xref.* \
		core so_locations gmon.out *~ \#*

binclean:
	rm -rf *.o o so config.status config.log config.cache \
		core so_locations

tar:
	(cd ../..; tar zcvf xotcl-src-$(XOTCLVERSION).tar.gz \
		$(XOTCL)/src/Makefile.in \
		$(XOTCL)/src/Makefile.vc \
		$(XOTCL)/src/Makefile.vc.in \
		$(XOTCL)/src/Makefile.win \
		$(XOTCL)/src/appendPkgIndex.xotcl \
		$(XOTCL)/src/dllEntryPoint.c \
		$(XOTCL)/src/lib/Makefile \
		$(XOTCL)/src/lib/Script.xotcl \
		$(XOTCL)/src/lib/makeDoc.xotcl \
		$(XOTCL)/src/lib/mixinStrategy.xotcl \
		$(XOTCL)/src/lib/package.xotcl \
		$(XOTCL)/src/lib/pkgIndex-package.add \
		$(XOTCL)/src/lib/pkgIndex.tcl \
		$(XOTCL)/src/lib/speedtest.xotcl \
		$(XOTCL)/src/lib/testo.xotcl \
		$(XOTCL)/src/lib/testx.xotcl \
		$(XOTCL)/src/lib/trace.xotcl \
		$(XOTCL)/src/lib/wafecompat.tcl \
		$(XOTCL)/src/lib/xodoc.xotcl \
		$(XOTCL)/src/lib/metadataAnalyzer.xotcl \
		$(XOTCL)/src/lib/staticMetadata.xotcl \
		$(XOTCL)/src/mk_predefined.xotcl \
		$(XOTCL)/src/pkgIndex-xotcl.add \
		$(XOTCL)/src/pkgIndex-xotcl.add.in \
		$(XOTCL)/src/predefined.h \
		$(XOTCL)/src/predefined.xotcl \
		$(XOTCL)/src/scripts/adapter.xotcl \
		$(XOTCL)/src/scripts/adapterExample.xotcl \
		$(XOTCL)/src/scripts/composite.xotcl \
		$(XOTCL)/src/scripts/compositeExample.xotcl \
		$(XOTCL)/src/scripts/observer.xotcl \
		$(XOTCL)/src/scripts/pinger.xotcl \
		$(XOTCL)/src/scripts/simpleFilters.xotcl \
		$(XOTCL)/src/winMain.c \
		$(XOTCL)/src/winDumpExts.c \
		$(XOTCL)/src/xotcl.c  \
		$(XOTCL)/src/xotcl.h \
		$(XOTCL)/src/xotclAppInit.c \
		$(XOTCL)/src/xotclError.c \
		$(XOTCL)/src/xotclInt.h \
		$(XOTCL)/src/xotclProfile.c \
		$(XOTCL)/src/xotclReference.c \
		$(XOTCL)/src/xotclTrace.c \
		$(XOTCL)/src/xotclWinMain.c \
		$(XOTCL)/src/xotkAppInit.c \
	)


o/xotcl.o: xotcl.h xotclInt.h predefined.h
so/xotcl.o: xotcl.h xotclInt.h predefined.h
xotclAppInit.o: xotcl.h xotclInt.h
xotkAppInit.o: xotcl.h xotclInt.h
