fix various problems with the tcl bindings -- Peter Breitenlohner
authoroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sat, 11 Jun 2005 05:26:13 +0000 (05:26 +0000)
committeroetiker <oetiker@a5681a0c-68f1-0310-ab6d-d61299d08faa>
Sat, 11 Jun 2005 05:26:13 +0000 (05:26 +0000)
git-svn-id: svn://svn.oetiker.ch/rrdtool/branches/1.2/program@623 a5681a0c-68f1-0310-ab6d-d61299d08faa

bindings/tcl/Makefile.am
bindings/tcl/ifOctets.tcl [deleted file]
bindings/tcl/ifOctets.tcl.in [new file with mode: 0644]
bindings/tcl/tclrrd.c
configure.ac

index 9606d6d..e31daa8 100644 (file)
@@ -1,43 +1,56 @@
 
-EXTRA_DIST = README ifOctets.tcl tclrrd.c
-CLEANFILES = tclrrd.o tclrrd.so
+EXTRA_DIST = README tclrrd.c
 
 VERSION = @VERSION@
 
-CFLAGS = @CFLAGS@
+AM_CFLAGS = @CFLAGS@
+
 TCL_PREFIX = @TCL_PREFIX@
 TCL_SHLIB_LD = @TCL_SHLIB_LD@
 TCL_SHLIB_CFLAGS = @TCL_SHLIB_CFLAGS@
 TCL_SHLIB_SUFFIX = @TCL_SHLIB_SUFFIX@
-TCL_PACKAGE_PATH = $(DESTDIR)@TCL_PACKAGE_PATH@
+TCL_PACKAGE_PATH = @TCL_PACKAGE_PATH@
 TCL_LD_SEARCH_FLAGS = @TCL_LD_SEARCH_FLAGS@
-GD_LIB_DIR       = $(top_srcdir)/@GD_LIB_DIR@
+
+CLEANFILES = tclrrd.o tclrrd.so
 
 SRC_DIR            = $(top_srcdir)/src
-AM_CPPFLAGS        = -I$(TCL_PREFIX)/include -I$(SRC_DIR)  -I$(GD_LIB_DIR)
-LIBDIRS            = -L$(libdir) -L$(SRC_DIR)  -L../../src/.libs
+AM_CPPFLAGS        = -I$(TCL_PREFIX)/include -I$(SRC_DIR)
+LIBDIRS            = -L$(top_builddir)/src/.libs -L$(top_builddir)/src -L$(libdir)
 LIB_RUNTIME_DIR    = $(libdir)
 
+pkglibdir = @TCL_PACKAGE_DIR@
+
 if BUILD_TCL
 
-tclrrd$(TCL_SHLIB_SUFFIX): tclrrd.o
-       $(TCL_SHLIB_LD) $(LIBDIRS) $< -o $@ -lrrd
+# Automake doen't like `tclrrd$(VERSION)$(TCL_SHLIB_SUFFIX)' as
+# library name. So we build and install this library `by hand'.
+#
+# We do, however, specify a lib_LIBRARIES target such that
+# automake creates the directory (if neecessary).
+#
+TCL_RRD_LIB = tclrrd$(VERSION)$(TCL_SHLIB_SUFFIX)
 
-tclrrd.o: tclrrd.c
-       $(CC) $(AM_CPPFLAGS) $(CPPFLAGS) $(CFLAGS) $(TCL_SHLIB_CFLAGS) $(INCLUDES) -c $< -DVERSION=\"$(VERSION)\"
+lib_LIBRARIES =
+
+all-local: $(TCL_RRD_LIB)
+
+pkglib_DATA = pkgIndex.tcl
 
-all-local: tclrrd$(TCL_SHLIB_SUFFIX)
+pkglib_SCRIPTS = ifOctets.tcl
 
-tcl-install: tclrrd$(TCL_SHLIB_SUFFIX)
-       cp tclrrd$(TCL_SHLIB_SUFFIX) $(TCL_PACKAGE_PATH)/tclrrd$(VERSION)$(TCL_SHLIB_SUFFIX)
-       if [ ! -d $(TCL_PACKAGE_PATH)/tclrrd$(VERSION) ] ; then \
-               mkdir $(TCL_PACKAGE_PATH)/tclrrd$(VERSION) ; \
-       fi
-       echo "package ifneeded Rrd $(VERSION) [list load [file join \$$dir .. tclrrd$(VERSION)$(TCL_SHLIB_SUFFIX)]]" > $(TCL_PACKAGE_PATH)/tclrrd$(VERSION)/pkgIndex.tcl
+$(TCL_RRD_LIB): tclrrd.o
+       $(TCL_SHLIB_LD) $(TCL_LD_SEARCH_FLAGS) $(LIBDIRS) $< -o $@ -lrrd -lm
+
+tclrrd.o: tclrrd.c
+       $(CC) $(AM_CFLAGS) $(CFLAGS) $(TCL_SHLIB_CFLAGS) $(AM_CPPFLAGS) -c $< -DVERSION=\"$(VERSION)\"
 
-else
+pkgIndex.tcl:
+       echo "package ifneeded Rrd $(VERSION) \"load $(libdir)/tclrrd$(VERSION)[info sharedlibextension]\"" > $@
 
-all-local:
+install-exec-local: $(TCL_RRD_LIB)
+       @$(NORMAL_INSTALL)
+       $(INSTALL_PROGRAM) $(TCL_RRD_LIB) $(DESTDIR)$(libdir)/$(TCL_RRD_LIB)
 
 endif
 
diff --git a/bindings/tcl/ifOctets.tcl b/bindings/tcl/ifOctets.tcl
deleted file mode 100644 (file)
index 34185b2..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/bin/sh
-# the next line restarts using tclsh -*- tcl -*- \
-exec tclsh8.2 "$0" "$@"
-
-#package require Tnm 3.0
-package require Rrd 1.0.13
-
-set rrdfile "[lindex $argv 0]-[lindex $argv 1].rrd"
-
-# create rrdfile if not yet existent
-if {[file exists $rrdfile] == 0} {
-    Rrd::create $rrdfile --step 5 \
-           DS:inOctets:COUNTER:10:U:U DS:outOctets:COUNTER:10:U:U \
-           RRA:AVERAGE:0.5:1:12
-}
-
-# get an snmp session context
-set session [Tnm::snmp generator -address [lindex $argv 0]]
-
-# walk through the ifDescr column to find the right interface
-$session walk descr IF-MIB!ifDescr {
-
-    # is this the right interface?
-    if {"[Tnm::snmp value $descr 0]" == "[lindex $argv 1]"} {
-
-       # get the instance part of this table row
-       set inst [lindex [Tnm::mib split [Tnm::snmp oid $descr 0]] 1]
-
-       # get the two interface's octet counter values
-       set in [lindex [lindex [$session get IF-MIB!ifInOctets.$inst] 0] 2]
-       set out [lindex [lindex [$session get IF-MIB!ifOutOctets.$inst] 0] 2]
-
-       # write the values to the rrd
-       puts "$in $out"
-       Rrd::update $rrdfile --template inOctets:outOctets N:$in:$out
-
-       Rrd::graph gaga.png --title "gaga" \
-               DEF:in=$rrdfile:inOctets:AVERAGE \
-               DEF:out=$rrdfile:outOctets:AVERAGE \
-               AREA:in#0000FF:inOctets \
-               LINE2:out#00C000:outOctets
-
-       #puts [Rrd::fetch $rrdfile AVERAGE]
-    }
-}
diff --git a/bindings/tcl/ifOctets.tcl.in b/bindings/tcl/ifOctets.tcl.in
new file mode 100644 (file)
index 0000000..7a36397
--- /dev/null
@@ -0,0 +1,45 @@
+#!/bin/sh
+# the next line restarts using tclsh -*- tcl -*- \
+exec tclsh@TCL_VERSION@ "$0" "$@"
+
+#package require Tnm 3.0
+package require Rrd @VERSION@
+
+set rrdfile "[lindex $argv 0]-[lindex $argv 1].rrd"
+
+# create rrdfile if not yet existent
+if {[file exists $rrdfile] == 0} {
+    Rrd::create $rrdfile --step 5 \
+           DS:inOctets:COUNTER:10:U:U DS:outOctets:COUNTER:10:U:U \
+           RRA:AVERAGE:0.5:1:12
+}
+
+# get an snmp session context
+set session [Tnm::snmp generator -address [lindex $argv 0]]
+
+# walk through the ifDescr column to find the right interface
+$session walk descr IF-MIB!ifDescr {
+
+    # is this the right interface?
+    if {"[Tnm::snmp value $descr 0]" == "[lindex $argv 1]"} {
+
+       # get the instance part of this table row
+       set inst [lindex [Tnm::mib split [Tnm::snmp oid $descr 0]] 1]
+
+       # get the two interface's octet counter values
+       set in [lindex [lindex [$session get IF-MIB!ifInOctets.$inst] 0] 2]
+       set out [lindex [lindex [$session get IF-MIB!ifOutOctets.$inst] 0] 2]
+
+       # write the values to the rrd
+       puts "$in $out"
+       Rrd::update $rrdfile --template inOctets:outOctets N:$in:$out
+
+       Rrd::graph gaga.png --title "gaga" \
+               DEF:in=$rrdfile:inOctets:AVERAGE \
+               DEF:out=$rrdfile:outOctets:AVERAGE \
+               AREA:in#0000FF:inOctets \
+               LINE2:out#00C000:outOctets
+
+       #puts [Rrd::fetch $rrdfile AVERAGE]
+    }
+}
index 92616de..ad8a8a3 100644 (file)
@@ -16,7 +16,7 @@
 #include <rrd_tool.h>
 #include <rrd_format.h>
 
-
+extern int Tclrrd_Init(Tcl_Interp *interp, int safe);
 
 extern int __getopt_initialized;
 
@@ -167,7 +167,7 @@ Rrd_Fetch(clientData, interp, argc, argv)
     int argc;
     char *argv[];
 {
-    time_t start, end;
+    time_t start, end, j;
     unsigned long step, ds_cnt, i, ii;
     rrd_value_t *data, *datai;
     char **ds_namv;
@@ -180,7 +180,7 @@ Rrd_Fetch(clientData, interp, argc, argv)
                  &ds_cnt, &ds_namv, &data) != -1) {
         datai = data;
         listPtr = Tcl_GetObjResult(interp);
-        for (i = start; i <= end; i += step) {
+        for (j = start; j <= end; j += step) {
             for (ii = 0; ii < ds_cnt; ii++) {
                sprintf(s, "%.2f", *(datai++));
                 Tcl_ListObjAppendElement(interp, listPtr,
index 0dae62f..bf2ae7e 100644 (file)
@@ -371,20 +371,23 @@ if test  "$enable_tcl" = "yes"; then
   withval=""
   AC_ARG_WITH(tcllib,[  --with-tcllib=DIR       location of the tclConfig.sh])
   enable_tcl=no
-  AC_MSG_CHECKING(for tclConfig.sh in $withval)
-  if test -f "$withval/tclConfig.sh" ; then
-       tcl_config=$withval/tclConfig.sh
+  for dir in $withval /usr/lib /usr/local/lib; do
+    AC_MSG_CHECKING(for tclConfig.sh in $dir)
+    if test -f "$dir/tclConfig.sh" ; then
+       tcl_config=$dir/tclConfig.sh
         enable_tcl=yes
         AC_MSG_RESULT(yes)
         break
-  else
+    else
         AC_MSG_RESULT(no)
-  fi
+    fi
+  done
 
   if test "$enable_tcl" = "no"; then
         AC_MSG_WARN([tclConfig.sh not found - Tcl interface won't be built])
   else
        . $tcl_config
+       TCL_PACKAGE_DIR="$TCL_PACKAGE_PATH/tclrrd$VERSION"
   fi
 fi
 
@@ -396,6 +399,8 @@ AC_SUBST(TCL_SHLIB_LD)
 AC_SUBST(TCL_SHLIB_SUFFIX)
 AC_SUBST(TCL_PACKAGE_PATH)
 AC_SUBST(TCL_LD_SEARCH_FLAGS)
+AC_SUBST(TCL_VERSION)
+AC_SUBST(TCL_PACKAGE_DIR)
 
 AC_ARG_ENABLE(python,[  --disable-python        do not build the python modules],
 [],[enable_python=yes])
@@ -452,6 +457,7 @@ AC_CONFIG_FILES([examples/shared-demo.pl                    \
           src/Makefile                                 \
           bindings/Makefile                             \
           bindings/tcl/Makefile                                \
+          bindings/tcl/ifOctets.tcl                    \
           bindings/python/Makefile                     \
           Makefile])
 AC_CONFIG_COMMANDS([default],[[\