diff --git a/bin/Makefile.am b/bin/Makefile.am index 74b231bd..25bc36cb 100644 --- a/bin/Makefile.am +++ b/bin/Makefile.am @@ -37,3 +37,56 @@ hawk_LDFLAGS = $(LDFLAGS_COMMON) ## of different behavior depending on the libtool tag. ## hawk_LDADD = $(LIBADD_COMMON) $(LIBM) + + + +if ENABLE_HAWKGO + +## the attempt to compose a proper procedure using a regular compiler failed. +## e.g ./configure GOC=opt/go/pkg/tool/linux_amd64/ +## while go.m4 is included in autoconf 2.71, the support for the go language +## is very limited and the go language itself is pursuing the module based builder. +## +## the following is to trick autoconf/automake as if it's building go files with +## a real compiler whereas the actual building is done thru `go build` + +bin_PROGRAMS += hawkgo +hawkgo_SOURCES = \ + ../go.mod \ + ../hawk.go \ + ../hawk-inst.go \ + hawkgo.go +##hawkgo_DEPENDENCIES = + +## let the linker to move hawkgo.bin to the actual target +##hawkgo_LINK = mv -f hawkgo.bin hawkgo$(EXEEXT) || echo "FAILED TO LINK" +hawkgo_LINK = + +if ENABLE_STATIC +CGO_CFLAGS_ADD="-static" +CGO_LDFLAGS_ADD="-static" +else +CGO_CFLAGS_ADD="" +CGO_LDFLAGS_ADD="" +endif + +hawkgo$(EXEEXT): ../lib/libhawk.la $(hawkgo_OBJECTS) + cp -pf $(top_srcdir)/go.mod $(builddir)/go.mod >/dev/null 2>&1 || true + chmod u+w $(builddir)/go.mod ## with `make distcheck`, the echo's redirection to the file fails without this permission change + [ -f $(srcdir)/go.sum ] && cp -pf $(srcdir)/go.sum $(builddir)/go.sum >/dev/null 2>&1 || true + ## --------------------------------------------------------------- + CC=$(CC) \ + CGO_CFLAGS="-I$(abs_top_srcdir)/lib -I$(abs_top_builddir)/lib $(CFLAGS) $(CGO_CFLAGS_EXTRA) $(CGO_CFLAGS_ADD)" \ + CGO_LDFLAGS="-L$(abs_top_builddir)/lib -L$(abs_top_builddir)/lib/.libs -lhawk -ldl $(LIBM) $(CGO_LDFLAGS_EXTRA) $(CGO_LDFLAGS_ADD)" \ + go build -C $(srcdir) -ldflags "-X 'main.BINDIR=$(bindir)' -X 'main.SBINDIR=$(sbindir)' -X 'main.LIBDIR=$(libdir)' -X 'main.SYSCONFDIR=$(sysconfdir)'" -x -o $(abs_builddir)/$@ -modfile $(abs_builddir)/go.mod $(abs_srcdir)/hawkgo.go + ## --------------------------------------------------------------- + go clean -C $(srcdir) -x -modfile $(abs_builddir)/go.mod + +## the go to o recipe is fake to deceive make +.go.o: + echo $< > $@ + +.mod.o: + echo $< > $@ + +endif diff --git a/bin/Makefile.in b/bin/Makefile.in index b0f2c8a1..91eba7d2 100644 --- a/bin/Makefile.in +++ b/bin/Makefile.in @@ -90,7 +90,8 @@ PRE_UNINSTALL = : POST_UNINSTALL = : build_triplet = @build@ host_triplet = @host@ -bin_PROGRAMS = hawk$(EXEEXT) +bin_PROGRAMS = hawk$(EXEEXT) $(am__EXEEXT_1) +@ENABLE_HAWKGO_TRUE@am__append_1 = hawkgo subdir = bin ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 am__aclocal_m4_deps = $(top_srcdir)/m4/ax_check_sign.m4 \ @@ -109,6 +110,7 @@ mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/lib/hawk-cfg.h CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = +@ENABLE_HAWKGO_TRUE@am__EXEEXT_1 = hawkgo$(EXEEXT) am__installdirs = "$(DESTDIR)$(bindir)" PROGRAMS = $(bin_PROGRAMS) am_hawk_OBJECTS = hawk-cut.$(OBJEXT) hawk-hawk.$(OBJEXT) \ @@ -123,6 +125,14 @@ am__v_lt_1 = hawk_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ $(LIBTOOLFLAGS) --mode=link $(CCLD) $(hawk_CFLAGS) $(CFLAGS) \ $(hawk_LDFLAGS) $(LDFLAGS) -o $@ +am__hawkgo_SOURCES_DIST = ../go.mod ../hawk.go ../hawk-inst.go \ + hawkgo.go +am__dirstamp = $(am__leading_dot)dirstamp +@ENABLE_HAWKGO_TRUE@am_hawkgo_OBJECTS = ../go.$(OBJEXT) \ +@ENABLE_HAWKGO_TRUE@ ../hawk.$(OBJEXT) ../hawk-inst.$(OBJEXT) \ +@ENABLE_HAWKGO_TRUE@ hawkgo.$(OBJEXT) +hawkgo_OBJECTS = $(am_hawkgo_OBJECTS) +hawkgo_LDADD = $(LDADD) AM_V_P = $(am__v_P_@AM_V@) am__v_P_ = $(am__v_P_@AM_DEFAULT_V@) am__v_P_0 = false @@ -159,8 +169,8 @@ AM_V_CCLD = $(am__v_CCLD_@AM_V@) am__v_CCLD_ = $(am__v_CCLD_@AM_DEFAULT_V@) am__v_CCLD_0 = @echo " CCLD " $@; am__v_CCLD_1 = -SOURCES = $(hawk_SOURCES) -DIST_SOURCES = $(hawk_SOURCES) +SOURCES = $(hawk_SOURCES) $(hawkgo_SOURCES) +DIST_SOURCES = $(hawk_SOURCES) $(am__hawkgo_SOURCES_DIST) am__can_run_installinfo = \ case $$AM_UPDATE_INFO_DIR in \ n|no|NO) false;; \ @@ -361,10 +371,21 @@ hawk_CPPFLAGS = $(CPPFLAGS_COMMON) hawk_CFLAGS = $(CFLAGS_COMMON) hawk_LDFLAGS = $(LDFLAGS_COMMON) hawk_LDADD = $(LIBADD_COMMON) $(LIBM) +@ENABLE_HAWKGO_TRUE@hawkgo_SOURCES = \ +@ENABLE_HAWKGO_TRUE@ ../go.mod \ +@ENABLE_HAWKGO_TRUE@ ../hawk.go \ +@ENABLE_HAWKGO_TRUE@ ../hawk-inst.go \ +@ENABLE_HAWKGO_TRUE@ hawkgo.go + +@ENABLE_HAWKGO_TRUE@hawkgo_LINK = +@ENABLE_HAWKGO_TRUE@@ENABLE_STATIC_FALSE@CGO_CFLAGS_ADD = "" +@ENABLE_HAWKGO_TRUE@@ENABLE_STATIC_TRUE@CGO_CFLAGS_ADD = "-static" +@ENABLE_HAWKGO_TRUE@@ENABLE_STATIC_FALSE@CGO_LDFLAGS_ADD = "" +@ENABLE_HAWKGO_TRUE@@ENABLE_STATIC_TRUE@CGO_LDFLAGS_ADD = "-static" all: all-am .SUFFIXES: -.SUFFIXES: .c .lo .o .obj +.SUFFIXES: .c .go .lo .mod .o .obj $(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) @for dep in $?; do \ case '$(am__configure_deps)' in \ @@ -442,9 +463,24 @@ clean-binPROGRAMS: hawk$(EXEEXT): $(hawk_OBJECTS) $(hawk_DEPENDENCIES) $(EXTRA_hawk_DEPENDENCIES) @rm -f hawk$(EXEEXT) $(AM_V_CCLD)$(hawk_LINK) $(hawk_OBJECTS) $(hawk_LDADD) $(LIBS) +../$(am__dirstamp): + @$(MKDIR_P) .. + @: >>../$(am__dirstamp) +../$(DEPDIR)/$(am__dirstamp): + @$(MKDIR_P) ../$(DEPDIR) + @: >>../$(DEPDIR)/$(am__dirstamp) +../go.$(OBJEXT): ../$(am__dirstamp) ../$(DEPDIR)/$(am__dirstamp) +../hawk.$(OBJEXT): ../$(am__dirstamp) ../$(DEPDIR)/$(am__dirstamp) +../hawk-inst.$(OBJEXT): ../$(am__dirstamp) \ + ../$(DEPDIR)/$(am__dirstamp) + +@ENABLE_HAWKGO_FALSE@hawkgo$(EXEEXT): $(hawkgo_OBJECTS) $(hawkgo_DEPENDENCIES) $(EXTRA_hawkgo_DEPENDENCIES) +@ENABLE_HAWKGO_FALSE@ @rm -f hawkgo$(EXEEXT) +@ENABLE_HAWKGO_FALSE@ $(AM_V_GEN)$(hawkgo_LINK) $(hawkgo_OBJECTS) $(hawkgo_LDADD) $(LIBS) mostlyclean-compile: -rm -f *.$(OBJEXT) + -rm -f ../*.$(OBJEXT) distclean-compile: -rm -f *.tab.c @@ -664,6 +700,8 @@ clean-generic: distclean-generic: -$(am__rm_f) $(CONFIG_CLEAN_FILES) -test . = "$(srcdir)" || $(am__rm_f) $(CONFIG_CLEAN_VPATH_FILES) + -$(am__rm_f) ../$(DEPDIR)/$(am__dirstamp) + -$(am__rm_f) ../$(am__dirstamp) maintainer-clean-generic: @echo "This command is intended for maintainers to use" @@ -763,6 +801,22 @@ uninstall-am: uninstall-binPROGRAMS .PRECIOUS: Makefile +@ENABLE_HAWKGO_TRUE@hawkgo$(EXEEXT): ../lib/libhawk.la $(hawkgo_OBJECTS) +@ENABLE_HAWKGO_TRUE@ cp -pf $(top_srcdir)/go.mod $(builddir)/go.mod >/dev/null 2>&1 || true +@ENABLE_HAWKGO_TRUE@ chmod u+w $(builddir)/go.mod ## with `make distcheck`, the echo's redirection to the file fails without this permission change +@ENABLE_HAWKGO_TRUE@ [ -f $(srcdir)/go.sum ] && cp -pf $(srcdir)/go.sum $(builddir)/go.sum >/dev/null 2>&1 || true +@ENABLE_HAWKGO_TRUE@ CC=$(CC) \ +@ENABLE_HAWKGO_TRUE@ CGO_CFLAGS="-I$(abs_top_srcdir)/lib -I$(abs_top_builddir)/lib $(CFLAGS) $(CGO_CFLAGS_EXTRA) $(CGO_CFLAGS_ADD)" \ +@ENABLE_HAWKGO_TRUE@ CGO_LDFLAGS="-L$(abs_top_builddir)/lib -L$(abs_top_builddir)/lib/.libs -lhawk -ldl $(LIBM) $(CGO_LDFLAGS_EXTRA) $(CGO_LDFLAGS_ADD)" \ +@ENABLE_HAWKGO_TRUE@ go build -C $(srcdir) -ldflags "-X 'main.BINDIR=$(bindir)' -X 'main.SBINDIR=$(sbindir)' -X 'main.LIBDIR=$(libdir)' -X 'main.SYSCONFDIR=$(sysconfdir)'" -x -o $(abs_builddir)/$@ -modfile $(abs_builddir)/go.mod $(abs_srcdir)/hawkgo.go +@ENABLE_HAWKGO_TRUE@ go clean -C $(srcdir) -x -modfile $(abs_builddir)/go.mod + +@ENABLE_HAWKGO_TRUE@.go.o: +@ENABLE_HAWKGO_TRUE@ echo $< > $@ + +@ENABLE_HAWKGO_TRUE@.mod.o: +@ENABLE_HAWKGO_TRUE@ echo $< > $@ + # Tell versions [3.59,3.63) of GNU make to not export all variables. # Otherwise a system limit (for SysV at least) may be exceeded. .NOEXPORT: diff --git a/bin/hawkgo.go b/bin/hawkgo.go new file mode 100644 index 00000000..d3a97eac --- /dev/null +++ b/bin/hawkgo.go @@ -0,0 +1,72 @@ +package main + +import "hawk" +import "fmt" +import "os" +import "runtime" +import "runtime/debug" +//import "sync" +import "time" + +func exit_with_error(msg string, err error) { + fmt.Printf("ERROR: %s - %s\n", msg, err.Error()) + os.Exit(1) +} + +func make_hawk(script string) (*hawk.Hawk, error) { + var h *hawk.Hawk + var err error + + h, err = hawk.New() + if err != nil { return nil, err } + + err = h.ParseText(script) + if err != nil { + h.Close() + return nil, err + } + + return h, nil +} + +func main() { + var h *hawk.Hawk + var rtx *hawk.Rtx + var err error + + debug.SetGCPercent(100) // enable normal GC + + fmt.Printf ("BEGINNING OF TEST3\n") + + h, err = make_hawk(`function main(s) { +print enbase64(s, "hello", 1.289); +print debase64(s); +return x +}`) + if err != nil { + fmt.Printf("ERROR: failed to make hawk - %s\n", err.Error()) + return + } + + rtx, err = h.NewRtx("test3") + if err != nil { + // + } else { + var v *hawk.Val + + v, err = rtx.Call("main", hawk.Must(rtx.NewValFromStr("this is a test3 string"))) + if err != nil { + // + } else { + fmt.Printf("V=>[%v]\n", v.String()) + } + } + + h.Close() + fmt.Printf ("END OF TEST3\n") + + runtime.GC() + runtime.Gosched() + time.Sleep(1000 * time.Millisecond) // give finalizer time to print +} +