From a059cf86434aa2dab930008c5f549e05e256561d Mon Sep 17 00:00:00 2001 From: nishi Date: Tue, 6 Feb 2024 09:04:55 +0000 Subject: [PATCH] tclw3 git-svn-id: file:///raid/svn-main/nishi-libw3/trunk@177 d27a3e52-49c5-7645-884c-6793ebffc270 --- Example/Makefile | 9 +++++++++ Example/tclw3/Makefile | 18 ++++++++++++++++++ Example/tclw3/tclw3.c | 36 +++++++++++++++++++++++++++++++++++ Makefile | 43 +++++++++++++++++++++++++++++++----------- 4 files changed, 95 insertions(+), 11 deletions(-) create mode 100644 Example/tclw3/Makefile create mode 100644 Example/tclw3/tclw3.c diff --git a/Example/Makefile b/Example/Makefile index 6c58b35..b92f3a1 100644 --- a/Example/Makefile +++ b/Example/Makefile @@ -10,12 +10,18 @@ examples: $(MAKE) -C ./interactive CC=$(CC) SUFFIX=$(SUFFIX) $(MAKE) -C ./pop3-list CC=$(CC) SUFFIX=$(SUFFIX) $(MAKE) -C ./w3b CC=$(CC) SUFFIX=$(SUFFIX) +ifeq ($(TCL),YES) + $(MAKE) -C ./tclw3 CC=$(CC) TCL_LIBS="$(TCL_LIBS)" TCL_CFLAGS="$(TCL_CFLAGS)" SUFFIX=$(SUFFIX) +endif install: $(MAKE) -C ./fetch CC=$(CC) PREFIX=$(PREFIX) SUFFIX=$(SUFFIX) install $(MAKE) -C ./interactive CC=$(CC) PREFIX=$(PREFIX) SUFFIX=$(SUFFIX) install $(MAKE) -C ./pop3-list CC=$(CC) PREFIX=$(PREFIX) SUFFIX=$(SUFFIX) install $(MAKE) -C ./w3b CC=$(CC) PREFIX=$(PREFIX) SUFFIX=$(SUFFIX) install +ifeq ($(TCL),YES) + $(MAKE) -C ./tclw3 CC=$(CC) PREFIX=$(PREFIX) SUFFIX=$(SUFFIX) install +endif clean: rm -f *.o *.so *.core *~ *.exe *.res @@ -23,3 +29,6 @@ clean: $(MAKE) -C ./interactive SUFFIX=$(SUFFIX) clean $(MAKE) -C ./pop3-list SUFFIX=$(SUFFIX) clean $(MAKE) -C ./w3b SUFFIX=$(SUFFIX) clean +ifeq ($(TCL),YES) + $(MAKE) -C ./tclw3 CC=$(CC) SUFFIX=$(SUFFIX) clean +endif diff --git a/Example/tclw3/Makefile b/Example/tclw3/Makefile new file mode 100644 index 0000000..68f8a0b --- /dev/null +++ b/Example/tclw3/Makefile @@ -0,0 +1,18 @@ +# $Id$ +.PHONY: clean install + +./tclw3$(SUFFIX): ./tclw3.o $(RESFILE) + $(CC) -g -o $@ -L ../../Library $^ -lw3 $(TCL_LIBS) + +./%.o: ./%.c + $(CC) $(TCL_CFLAGS) -g -c -o $@ -I ../../Library $< + +../libw3.res: + $(MAKE) -C .. ./libw3.res WINDRES=$(WINDRES) + +clean: + rm -f tclw3 *.o *.so *.core *~ *.exe *.res + +install: ./tclw3 + mkdir -p $(PREFIX)/bin + cp ./tclw3 $(PREFIX)/bin/tclw3 diff --git a/Example/tclw3/tclw3.c b/Example/tclw3/tclw3.c new file mode 100644 index 0000000..798bb0b --- /dev/null +++ b/Example/tclw3/tclw3.c @@ -0,0 +1,36 @@ +/* + * $Id$ + * + * Tcl/W3 + */ + +#include + +#include + +#include + +int main(int argc, char** argv){ + if(argc < 2){ + fprintf(stderr, "Usage: %s filename\n", argv[0]); + return 1; + } + Tcl_Interp* interp = Tcl_CreateInterp(); + Tcl_FindExecutable(argv[0]); + if(Tcl_Init(interp) == TCL_ERROR){ + const char* errmsg = Tcl_GetStringResult(interp); + fprintf(stderr, "Tcl error: %s\n", errmsg); + return -1; + } + if(W3_Init(interp) == TCL_ERROR){ + const char* errmsg = Tcl_GetStringResult(interp); + fprintf(stderr, "LibW3 error: %s\n", errmsg); + return -1; + } + if(Tcl_EvalFile(interp, argv[1]) == TCL_ERROR){ + const char* errmsg = Tcl_GetStringResult(interp); + fprintf(stderr, "Tcl error: %s\n", errmsg); + return -1; + } + Tcl_DeleteInterp(interp); +} diff --git a/Makefile b/Makefile index 91c9b3f..285e16d 100644 --- a/Makefile +++ b/Makefile @@ -7,10 +7,21 @@ else GREP = grep endif +PKGCONF := pkg-config + +ifeq ($(TCL),YES) +ifneq ($(TCL_PKGCONF),NO) +TCL_CFLAGS += $(shell $(PKGCONF) --cflags tcl) -DTCL_BINDING +TCL_LIBS += $(shell $(PKGCONF) --libs tcl) +else +TCL_LIBS += -ltcl +endif +endif + CC := cc -CFLAGS := -g -std=c99 -fPIC -D_XOPEN_SOURCE=600 +CFLAGS := -g -std=c99 -fPIC -D_XOPEN_SOURCE=600 $(TCL_CFLAGS) LDFLAGS := -LIBS := +LIBS := $(TCL_LIBS) PREFIX := /usr/local VERSION = $(shell cat Library/W3Version.h | $(GREP) -m 1 LIBW3_VERSION | sed -E "s/.+\"([^\"]+)\".+/\1/g")$(shell cat Library/W3Version.h | grep -A 1 -E "LIBW3_VERSION" | sed "s/LIBW3_VERSION//g" | tail -n1 | grep -Eo "W") @@ -24,6 +35,7 @@ CC := i686-w64-mingw32-gcc WINDRES := i686-w64-mingw32-windres WINDOWS := YES WINARCH := x86 +MINGW := i686-w64-mingw32 endif ifeq ($(WIN64),YES) @@ -31,13 +43,7 @@ CC := x86_64-w64-mingw32-gcc WINDRES := x86_64-w64-mingw32-windres WINDOWS := YES WINARCH := x64 -endif - -PKGCONF := pkg-config - -ifeq ($(TCL),YES) -CFLAGS += $(shell $(PKGCONF) --cflags tcl) -DTCL_BINDING -LIBS += $(shell $(PKGCONF) --libs tcl) +MINGW := x86_64-w64-mingw32 endif ifeq ($(WINDOWS),YES) @@ -68,7 +74,7 @@ all: ./Library/W3Version.h ./w3.pc $(ALL) $(MAKE) -C ./Library CC=$(CC) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)" WINDOWS=YES WINARCH=$(WINARCH) TCL=$(TCL) ./Example: ./Library/w3.dll - $(MAKE) -C ./Example CC=$(CC) examples SUFFIX=.exe + $(MAKE) -C ./Example CC=$(CC) TCL=$(TCL) TCL_LIBS="$(TCL_LIBS)" TCL_CFLAGS="$(TCL_CFLAGS)" examples SUFFIX=.exe ./Library/W3Version.h: m4 -DSUFFIX=\"W\" ./W3Version.h.p > $@ @@ -88,7 +94,7 @@ all: ./Library/W3Version.h ./w3.pc $(ALL) $(MAKE) -C ./Library CC=$(CC) CFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" LIBS="$(LIBS)" TCL=$(TCL) ./libw3.a ./Example: ./Library/libw3.so - $(MAKE) -C ./Example CC=$(CC) examples + $(MAKE) -C ./Example CC=$(CC) TCL_LIBS="$(TCL_LIBS)" TCL_CFLAGS="$(TCL_CFLAGS)" TCL=$(TCL) examples ./Library/W3Version.h: m4 -DSUFFIX=\"\" ./W3Version.h.p > $@ @@ -121,6 +127,10 @@ install: ./w3.pc archive: all mkdir -p w3-$(VERSION)/Library mkdir -p w3-$(VERSION)/Example/w3b +ifeq ($(TCL),YES) + mkdir -p w3-$(VERSION)/Example/tclw3/bin + mkdir -p w3-$(VERSION)/Example/tclw3/lib +endif mkdir -p w3-$(VERSION)/Example/pop3-list mkdir -p w3-$(VERSION)/Example/interactive mkdir -p w3-$(VERSION)/Example/fetch @@ -132,12 +142,23 @@ ifeq ($(WINDOWS),YES) cp ./Example/interactive/interactive.exe w3-$(VERSION)/Example/interactive/ cp ./Example/pop3-list/pop3-list.exe w3-$(VERSION)/Example/pop3-list/ cp ./Example/w3b/w3b.exe w3-$(VERSION)/Example/w3b/ +ifeq ($(TCL),YES) + cp ./Example/tclw3/tclw3.exe w3-$(VERSION)/Example/tclw3/bin/ + cp /usr/$(MINGW)/sys-root/mingw/bin/tcl86.dll w3-$(VERSION)/Example/tclw3/bin/ + cp /usr/$(MINGW)/sys-root/mingw/bin/tk86.dll w3-$(VERSION)/Example/tclw3/bin/ + cp /usr/$(MINGW)/sys-root/mingw/bin/libssp-0.dll w3-$(VERSION)/Example/tclw3/bin/ + cp /usr/$(MINGW)/sys-root/mingw/bin/zlib1.dll w3-$(VERSION)/Example/tclw3/bin/ + cp -rf /usr/$(MINGW)/sys-root/mingw/share/tcl8.6 w3-$(VERSION)/Example/tclw3/tcl8.6 +endif else cp ./Library/*.so w3-$(VERSION)/Library/ cp ./Example/fetch/fetch w3-$(VERSION)/Example/fetch/ cp ./Example/interactive/interactive w3-$(VERSION)/Example/interactive/ cp ./Example/pop3-list/pop3-list w3-$(VERSION)/Example/pop3-list/ cp ./Example/w3b/w3b w3-$(VERSION)/Example/w3b/ +ifeq ($(TCL),YES) + cp ./Example/tclw3/tclw3 w3-$(VERSION)/Example/tclw3/bin/ +endif endif -mv w3-$(VERSION)/*.h w3-$(VERSION)/Library/ -mv w3-$(VERSION)/*.so w3-$(VERSION)/Library/ -- 2.43.0