diff options
-rw-r--r-- | Makefile.in | 4 | ||||
-rw-r--r-- | make-c-ext.sh | 30 | ||||
-rw-r--r-- | make-c-ext.tcl | 40 |
3 files changed, 32 insertions, 42 deletions
diff --git a/Makefile.in b/Makefile.in index dac7c1a..f4f626a 100644 --- a/Makefile.in +++ b/Makefile.in @@ -31,7 +31,7 @@ EXTENSIONS_OBJS := $(patsubst %,jim-%.o,$(EXTENSIONS)) # Create C extensions from pure Tcl extensions jim-%.c: %.tcl echo $@ >>.clean - tclsh make-c-ext.tcl $@ $*.tcl + sh @SRCDIR@/make-c-ext.sh $@ $< ifdef jim_nofork CFLAGS += -DNO_FORK @@ -39,7 +39,7 @@ endif OBJS += load_extensions.o -TARGETS += jimsh $(LIBJIM) +TARGETS += $(LIBJIM) jimsh all: $(TARGETS) $(MAKE) -C doc all diff --git a/make-c-ext.sh b/make-c-ext.sh new file mode 100644 index 0000000..cd9173a --- /dev/null +++ b/make-c-ext.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env tclsh + +target="$1" +source="$2" + +case "$target" in +*.c) ;; +*) echo 1>&2 "Target $target is not a .c file"; exit 1;; +esac +case "$source" in +*.tcl) ;; +*) echo 1>&2 "Source $source is not a .tcl file"; exit 1;; +esac + +basename=`basename $source .tcl` + +exec >$target + +cat <<EOF +#include <jim.h> +int Jim_${basename}Init(Jim_Interp *interp) +{ + return Jim_EvalGlobal(interp, +EOF + +sed -e '/^#/d' -e 's@\\@\\\\@g' -e 's@"@\\"@g' -e 's@^\(.*\)$@"\1\\n"@' $source +#sed -e 's@^\(.*\)$@"\1\\n"@' $source + +echo ");" +echo "}" diff --git a/make-c-ext.tcl b/make-c-ext.tcl deleted file mode 100644 index 96f6355..0000000 --- a/make-c-ext.tcl +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env tclsh - -proc tcl_to_string {str} { - set result {} - foreach buf [split $str \n] { - set trimmed [string trim $buf] - if {[string match "#*" $trimmed] || $trimmed == ""} { - continue - } - regsub -all {\\} $buf {\\\\} buf - regsub -all \" $buf "\\\"" buf - append result {"} $buf {\n"} \n - } - return $result -} - -set outfile [lindex $argv 0] -set argv [lrange $argv 1 end] - -foreach file $argv { - if {![string match *.tcl $file]} { - error "Not a tcl file: $file" - } - set tmp [file tail $file] - set rootname [file rootname $tmp] - if {0} { - set outfile jim-$rootname.c - } - set f [open $file] - set str [read $f] - close $f - set f [open $outfile w] - puts $f {#include <jim.h>} - puts $f "int Jim_${rootname}Init(Jim_Interp *interp)" - puts $f "{" - puts $f "\treturn Jim_EvalGlobal(interp, " - puts -nonewline $f [tcl_to_string $str] - puts $f ");\t}" - close $f -} |