diff options
author | Steve Bennett <steveb@workware.net.au> | 2011-05-30 12:01:12 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2011-06-10 14:00:34 +1000 |
commit | dbe7729d6b03470bf91de94a998b1c2e56b4ee3b (patch) | |
tree | bbb4d36fb9d7e43cdcb5a2d1d298963ea0970dd9 | |
parent | 2d1f4f8041c487fcdef221d0c9c75b9c00d7225e (diff) | |
download | jimtcl-dbe7729d6b03470bf91de94a998b1c2e56b4ee3b.zip jimtcl-dbe7729d6b03470bf91de94a998b1c2e56b4ee3b.tar.gz jimtcl-dbe7729d6b03470bf91de94a998b1c2e56b4ee3b.tar.bz2 |
Switch to a Tcl version of make-c-ext
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | Makefile.in | 2 | ||||
-rw-r--r-- | make-c-ext.sh | 25 | ||||
-rw-r--r-- | make-c-ext.tcl | 42 |
3 files changed, 43 insertions, 26 deletions
diff --git a/Makefile.in b/Makefile.in index 9943b02..4978864 100644 --- a/Makefile.in +++ b/Makefile.in @@ -46,7 +46,7 @@ EXTENSION_TCL := $(patsubst %,%.tcl,@JIM_TCL_EXTENSIONS@) # Create C extensions from pure Tcl extensions jim-%.c: %.tcl - sh @srcdir@/make-c-ext.sh $< >$@ + @tclsh@ @srcdir@/make-c-ext.tcl $< >$@ OBJS += jim-load-static-exts.o diff --git a/make-c-ext.sh b/make-c-ext.sh deleted file mode 100644 index c4415fa..0000000 --- a/make-c-ext.sh +++ /dev/null @@ -1,25 +0,0 @@ -source="$1" - -case "$source" in -*.tcl) ;; -*) echo 1>&2 "Source $source is not a .tcl file"; exit 1;; -esac - -basename=`basename $source .tcl` - -cat <<EOF -#include <jim.h> -int Jim_${basename}Init(Jim_Interp *interp) -{ - if (Jim_PackageProvide(interp, "$basename", "1.0", JIM_ERRMSG)) - return JIM_ERR; - - return Jim_Eval_Named(interp, -EOF - -# Note: Keep newlines so that line numbers match in error messages -sed -e 's/^[ ]*#.*//' -e 's@\\@\\\\@g' -e 's@"@\\"@g' -e 's@^\(.*\)$@"\1\\n"@' $source -#sed -e 's@^\(.*\)$@"\1\\n"@' $source - -echo ",\"$source\", 1);" -echo "}" diff --git a/make-c-ext.tcl b/make-c-ext.tcl new file mode 100644 index 0000000..29f1107 --- /dev/null +++ b/make-c-ext.tcl @@ -0,0 +1,42 @@ +#!/usr/bin/env tclsh + +# Usage: make-c-ext.tcl source.tcl >jim-source.c + +# Converts a Tcl source file into C source suitable +# for loading as a static extension. + +lassign $argv source + +if {![string match *.tcl $source]} { + error "Source $source is not a .tcl file" +} + +# Read the Tcl source and convert to C +# Note that no lines are removed in order to preserve line numbering +set sourcelines {} +set f [open $source] +while {[gets $f buf] >= 0} { + # Remove comment lines + regsub {^[ \t]*#.*$} $buf "" buf + # Escape quotes and backlashes + set buf [string map [list \\ \\\\ \" \\"] $buf] + lappend sourcelines \"$buf\\n\" +} +close $f + +lappend lines {/* autogenerated - do not edit */} +lappend lines {#include <jim.h>} +lappend lines "static const char basename\[\] = \"[file tail $source]\";" +lappend lines "static const char pkgname\[\] = \"[file rootname [file tail $source]]\";" + +lappend lines {static const char source[] = } +lappend lines {*}$sourcelines \; + +lappend lines "int Jim_[file rootname [file tail $source]]Init(Jim_Interp *interp)" +lappend lines \ +{{ + if (Jim_PackageProvide(interp, pkgname, "1.0", JIM_ERRMSG)) return JIM_ERR; + return Jim_Eval_Named(interp, source, basename, 1); +}} + +puts [join $lines \n] |