[Go] Add -cgo option, required for Go version 1.5 and later.

This commit is contained in:
Ian Lance Taylor 2015-03-02 14:03:33 -08:00
parent df36d84f1b
commit 9ad497c08e
11 changed files with 1697 additions and 300 deletions

View File

@ -5,6 +5,10 @@ See the RELEASENOTES file for a summary of changes in each release.
Version 3.0.6 (in progress)
===========================
2015-03-02: ianlancetaylor
[Go] Add -cgo option, required for Go versions 1.5 and
later.
2015-02-26: olly
Fix segmentation fault when top==NULL, introduced by nested class
handling (reported in issue#346 by Paweł Tomulik).

View File

@ -111,6 +111,14 @@ swig -go -help
<th>Go specific options</th>
</tr>
<tr>
<td>-cgo</td>
<td>Generate files to be used as input for the Go cgo tool. This
option is required for Go 1.5 and later, and works for Go 1.2 and
later. In the future this option will likely become the
default.</td>
</tr>
<tr>
<td>-intgosize &lt;s&gt;</td>
<td>Set the size for the Go type <tt>int</tt>. This controls the size
@ -171,8 +179,13 @@ swig -go -help
<H3><a name="Go_outputs"></a>23.3.2 Go Output Files</H3>
<p> When generating Go code, SWIG will generate the following
files:</p>
<p>There are two different approaches to generating output files,
controlled by SWIG's <tt>-cgo</tt> option. The <tt>-cgo</tt> option
works with Go version 1.2 or later. It is required when using Go
version 1.5 or later.</p>
<p>With or without the <tt>-cgo</tt> option, SWIG will generate the
following files when generating Go code:</p>
<ul>
<li>
@ -180,21 +193,30 @@ MODULE.go will contain the Go functions that your Go code will call.
These functions will be wrappers for the C++ functions defined by your
module. This file should, of course, be compiled with the Go
compiler.
</li>
<li>
MODULE_wrap.c or MODULE_wrap.cxx will contain C/C++ functions will be
invoked by the Go wrapper code. This file should be compiled with the
usual C or C++ compiler and linked into a shared library.
usual C or C++ compiler.
</li>
<li>
MODULE_wrap.h will be generated if you use the directors feature. It
provides a definition of the generated C++ director classes. It is
generally not necessary to use this file, but in some special cases it
may be helpful to include it in your code, compiled with the usual C
or C++ compiler.
</li>
</ul>
<p>When neither the <tt>-cgo</tt> nor the <tt>-gccgo</tt> option is
used, SWIG will also generate an additional file:</p>
<ul>
<li>
If using the gc compiler, MODULE_gc.c will contain C code which should
be compiled with the C compiler distributed as part of the gc
compiler. It should then be combined with the compiled MODULE.go
using gopack. This file will not be generated when using gccgo.
MODULE_gc.c will contain C code which should be compiled with the C
compiler distributed as part of the gc compiler. It should then be
combined with the compiled MODULE.go using go tool pack.
</li>
</ul>
<p>
@ -203,14 +225,33 @@ support for SWIG. To use it, put your SWIG interface into a file with
the extension .swig, or, if you are wrapping C++ code, .swigcxx. Put
that file in a GOPATH/src directory as usual for Go sources. Put
other interface code in the same directory with extensions of .c and
.cxx. The go build command and go install commands will automatically
run SWIG for you and will build the interface code.
.cxx. The <tt>go build</tt> and <tt>go install</tt> commands will
automatically run SWIG for you and will build the interface code.
</p>
<p>
You can also use SWIG directly yourself. When using the gc compiler
version 1.2 or later, or when using gccgo, the code generated by SWIG
can be linked directly into the Go program. A typical command
You can also use SWIG directly yourself. When using
the <tt>-cgo</tt> option, SWIG will generate files that can be used
directly by <tt>go build</tt>. Put your SWIG input file in a
directory under GOPATH/src, and give it a name that does not end in
.swig or .swigcxx.
</p>
<div class="code"><pre>
% swig -go -cgo example.i
% go install
</pre></div>
<p>
You will now have a Go package that you can import from other Go
packages as usual.
</p>
<p>
To use SWIG without the <tt>-cgo</tt> option, more steps are required.
Recall that this only works with Go versions before 1.5. When using
Go version 1.2 or later, or when using gccgo, the code generated by
SWIG can be linked directly into the Go program. A typical command
sequence when using the gc compiler would look like this:
</p>
@ -227,9 +268,8 @@ sequence when using the gc compiler would look like this:
<p>
You can also put the wrapped code into a shared library, and when
using the gc compiler before version 1.2 this is the only supported
option. A typical command sequence for this approach would look like
this:
using the Go versions before 1.2 this is the only supported option. A
typical command sequence for this approach would look like this:
</p>
<div class="code"><pre>

View File

@ -1752,15 +1752,18 @@ scilab_clean:
GO = @GO@
GOGCC = @GOGCC@
GCCGO = @GCCGO@
GO1 = @GO1@
GO12 = @GO12@
GO13 = @GO13@
GO15 = @GO15@
GOC = @GOC@
GOOPT = @GOOPT@
GCCGOOPT = @GCCGOOPT@
GOVERSIONOPTION = @GOVERSIONOPTION@
GOSWIGARG = `if $(GOGCC) ; then echo -gccgo; fi`
GOCOMPILEARG = `if $(GOGCC) ; then echo -c -g; elif $(GO1) ; then echo tool $(GOC:c=g) ; fi` `if $(GO13) && ! $(GOGCC); then echo -pack ; fi`
GOCOMPILEARG = `if $(GO1) ; then echo tool $(GOC:c=g) ; fi` `if $(GO13) || $(GO15); then echo -pack ; fi`
GOSRCS = $(INTERFACE:.i=.go)
GOCSRCS = $(INTERFACE:.i=_gc.c)
@ -1769,7 +1772,9 @@ GOLD = $(GOC:c=l)
GOTOOL = `if $(GO1) ; then echo go tool; fi`
GOPACK = `if $(GO1) ; then echo go tool pack; else echo gopack; fi`
GOPACKAGE = $(INTERFACE:.i=.a)
GOPACKAGE = $(notdir $(INTERFACE:.i=.a))
GOPATHDIR = gopath/src/$(INTERFACE:.i=)
GOOBJEXT = $(GOC:c=)
GOGCOBJS = $(GOSRCS:.go=.$(GOOBJEXT))
@ -1779,19 +1784,21 @@ GOGCCOBJS = $(GOSRCS:.go=.@OBJEXT@)
# Build a Go module (C)
# ----------------------------------------------------------------
go: $(SRCDIR_SRCS)
go_nocgo: $(SRCDIR_SRCS)
$(SWIG) -go $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
if $(GO12) || $(GO13) || $(GOGCC); then \
if $(GO12) || $(GO13) || $(GO15) || $(GOGCC); then \
$(CC) -g -c $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES); \
else \
$(CC) -g -c $(CCSHARED) $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES); \
$(LDSHARED) $(CFLAGS) $(LDFLAGS) $(OBJS) $(IOBJS) $(LIBS) -o $(LIBPREFIX)$(TARGET)$(SO); \
fi
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS)
if ! $(GOGCC) ; then \
if $(GOGCC) ; then \
$(COMPILETOOL) $(GCCGO) -g -c -I . $(GOSRCS); \
else \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(GOSRCS); \
$(COMPILETOOL) $(GOTOOL) $(GOC) -I $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`} $(GOCSRCS); \
rm -f $(GOPACKAGE); \
if $(GO13); then \
if $(GO13) || $(GO15); then \
cp $(GOGCOBJS) $(GOPACKAGE); \
$(COMPILETOOL) $(GOPACK) r $(GOPACKAGE) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \
elif $(GO12); then \
@ -1801,12 +1808,54 @@ go: $(SRCDIR_SRCS)
fi; \
fi
if test -f $(SRCDIR)$(RUNME).go; then \
$(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
if $(GOGCC) ; then \
$(COMPILETOOL) $(GO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS); \
elif $(GO12) || $(GO13); then \
$(COMPILETOOL) $(GCCGO) -g -c $(SRCDIR)$(RUNME).go; \
$(COMPILETOOL) $(GCCGO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS); \
elif $(GO12) || $(GO13) || $(GO15); then \
$(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld "$(CC)" -extldflags "$(CFLAGS) $(LDFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \
else \
$(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \
fi; \
fi
go: $(SRCDIR_SRCS)
$(SWIG) -go -cgo $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
@mkdir gopath 2>/dev/null || true
@mkdir gopath/src 2>/dev/null || true
@mkdir gopath/src/$(INTERFACE:.i=) 2>/dev/null || true
rm -f $(GOPATHDIR)/*
cp $(ISRCS) $(GOPATHDIR)/
if test -f $(IWRAP:.i=.h); then \
cp $(IWRAP:.i=.h) $(GOPATHDIR)/; \
fi
if test -n "$(SRCDIR_SRCS)"; then \
cp $(SRCDIR_SRCS) $(GOPATHDIR)/; \
fi
cp $(GOSRCS) $(GOPATHDIR)/
GOPATH=`pwd`/gopath; \
export GOPATH; \
CGO_CPPFLAGS="$(CPPFLAGS) $(INCLUDES) -I `pwd`"; \
export CGO_CPPFLAGS; \
CGO_CFLAGS="$(CFLAGS)"; \
export CGO_CFLAGS; \
CGO_LDFLAGS="$(LDFLAGS) -lm"; \
export CGO_LDFLAGS; \
(cd $(GOPATHDIR)/ && $(COMPILETOOL) $(GO) build `if $(GOGCC); then echo -compiler=gccgo; fi` -o $(GOPACKAGE))
cp $(GOPATHDIR)/$(GOPACKAGE) $(dir $(INTERFACE))/$(GOPACKAGE)
if $(GOGCC); then \
cp $(dir $(INTERFACE))/$(GOPACKAGE) $(dir $(INTERFACE))/$(GOPACKAGE:.a=.gox); \
fi
if test -f $(SRCDIR)$(RUNME).go; then \
if $(GOGCC) ; then \
$(COMPILETOOL) $(GCCGO) -c -g $(SRCDIR)$(RUNME).go; \
$(COMPILETOOL) $(GCCGO) -o $(RUNME) $(RUNME).@OBJEXT@ $(dir $(INTERFACE))/$(GOPACKAGE); \
elif $(GO12) || $(GO13) || $(GO15); then \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld "$(CC)" -extldflags "$(CFLAGS) $(LDFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \
else \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \
fi; \
fi
@ -1815,9 +1864,9 @@ go: $(SRCDIR_SRCS)
# Build a Go module (C++)
# ----------------------------------------------------------------
go_cpp: $(SRCDIR_SRCS)
go_cpp_nocgo: $(SRCDIR_SRCS)
$(SWIG) -go -c++ $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
if $(GO12) || $(GO13) || $(GOGCC); then \
if $(GO12) || $(GO13) || $(GO15) || $(GOGCC); then \
if test -n "$(SRCDIR_CXXSRCS)$(SRCDIR_SRCS)"; then \
$(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_CXXSRCS) $(SRCDIR_SRCS) $(INCLUDES); \
fi; \
@ -1837,7 +1886,7 @@ go_cpp: $(SRCDIR_SRCS)
-o $(addsuffix .$(GOOBJEXT),$(basename $f)) $f; \
) \
rm -f $(GOPACKAGE); \
if $(GO13); then \
if $(GO13) || $(GO15); then \
cp $(GOGCOBJS) $(GOPACKAGE); \
$(COMPILETOOL) $(GOPACK) r $(GOPACKAGE) $(GOCSRCS:.c=.$(GOOBJEXT)) $(OBJS) $(IOBJS); \
elif $(GO12); then \
@ -1847,16 +1896,63 @@ go_cpp: $(SRCDIR_SRCS)
fi; \
else \
$(foreach f,$(GOSRCS), \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . -o $(addsuffix .@OBJEXT@,$(basename $f)) $f \
$(COMPILETOOL) $(GCCGO) -g -c -I . -o $(addsuffix .@OBJEXT@,$(basename $f)) $f \
); \
fi
if test -f $(SRCDIR)$(RUNME).go; then \
$(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
if $(GOGCC) ; then \
$(COMPILETOOL) $(GO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS) -lstdc++; \
elif $(GO12) || $(GO13); then \
$(COMPILETOOL) $(GCCGO) -g -c $(SRCDIR)$(RUNME).go; \
$(COMPILETOOL) $(GCCGO) -o $(RUNME) $(RUNME).@OBJEXT@ $(GOGCCOBJS) $(OBJS) $(IOBJS) -lstdc++; \
elif $(GO12) || $(GO13) || $(GO15); then \
$(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld "$(CXX)" -extldflags "$(CXXFLAGS) $(LDFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \
else \
$(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \
fi; \
fi
go_cpp: $(SRCDIR_SRCS)
$(SWIG) -go -c++ -cgo $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
@mkdir gopath 2>/dev/null || true
@mkdir gopath/src 2>/dev/null || true
@mkdir gopath/src/$(INTERFACE:.i=) 2>/dev/null || true
rm -f $(GOPATHDIR)/*
cp $(ICXXSRCS) $(GOPATHDIR)/
if test -f $(IWRAP:.i=.h); then \
cp $(IWRAP:.i=.h) $(GOPATHDIR)/; \
fi
if test -n "$(SRCDIR_CXXSRCS)"; then \
cp $(SRCDIR_CXXSRCS) $(GOPATHDIR)/; \
fi
if test -n "$(SRCDIR_SRCS)"; then \
cp $(SRCDIR_SRCS) $(GOPATHDIR)/; \
fi
cp $(GOSRCS) $(GOPATHDIR)/
GOPATH=`pwd`/gopath; \
export GOPATH; \
CGO_CPPFLAGS="$(CPPFLAGS) $(INCLUDES) -I `pwd`"; \
export CGO_CPPFLAGS; \
CGO_CFLAGS="$(CFLAGS)"; \
export CGO_CFLAGS; \
CGO_CXXFLAGS="$(CXXFLAGS)"; \
export CGO_CXXFLAGS; \
CGO_LDFLAGS="$(LDFLAGS) -lm"; \
export CGO_LDFLAGS; \
(cd $(GOPATHDIR) && $(COMPILETOOL) $(GO) build `if $(GOGCC); then echo -compiler=gccgo; fi` -o $(GOPACKAGE))
cp $(GOPATHDIR)/$(GOPACKAGE) $(dir $(INTERFACE))/$(GOPACKAGE)
if $(GOGCC); then \
cp $(dir $(INTERFACE))/$(GOPACKAGE) $(dir $(INTERFACE))/$(GOPACKAGE:.a=.gox); \
fi
if test -f $(SRCDIR)$(RUNME).go; then \
if $(GOGCC) ; then \
$(COMPILETOOL) $(GCCGO) -g -c $(SRCDIR)$(RUNME).go; \
$(COMPILETOOL) $(GCCGO) -o $(RUNME) $(RUNME).@OBJEXT@ $(dir $(INTERFACE))/$(GOPACKAGE) -lstdc++; \
elif $(GO12) || $(GO13) || $(GO15); then \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld "$(CXX)" -extldflags "$(CXXFLAGS) $(LDFLAGS)" -o $(RUNME) $(RUNME).$(GOOBJEXT); \
else \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) $(SRCDIR)$(RUNME).go; \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $(RUNME) $(RUNME).$(GOOBJEXT); \
fi; \
fi
@ -1880,7 +1976,8 @@ go_version:
# -----------------------------------------------------------------
go_clean:
rm -f *_wrap* *_gc* .~* $(RUNME) $(GOSRCS)
rm -f *_wrap* *_gc* *.gox .~* $(RUNME) $(GOSRCS)
rm -rf gopath
rm -f core @EXTRA_CLEAN@
rm -f *.@OBJEXT@ *.[568] *.a *@SO@

View File

@ -5,13 +5,15 @@
LANGUAGE = go
GO = @GO@
GOGCC = @GOGCC@
GCCGO = @GCCGO@
GO1 = @GO1@
GO12 = @GO12@
GO13 = @GO13@
GO15 = @GO15@
GOC = @GOC@
SCRIPTSUFFIX = _runme.go
GOCOMPILEARG = `if $(GOGCC) ; then echo -c -g; elif $(GO1) ; then echo tool $(GOC:c=g) ; fi`
GOCOMPILEARG = `if $(GO1) ; then echo tool $(GOC:c=g) ; fi`
GOLD = $(GOC:c=l)
GOTOOL = `if $(GO1) ; then echo go tool; fi`
GOPACK = `if $(GO1) ; then echo go tool pack; else echo gopack; fi`
@ -20,9 +22,10 @@ GOOBJEXT = $(GOC:c=)
SO = @SO@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
srcdir = @srcdir@
top_srcdir = @top_srcdir@
top_builddir = @top_builddir@
abs_top_srcdir = @abs_top_srcdir@
CPP_TEST_CASES = \
go_inout \
@ -33,6 +36,8 @@ MULTI_CPP_TEST_CASES = \
include $(srcdir)/../common.mk
INCLUDES = -I$(abs_top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)
.SUFFIXES: .cpptest .ctest .multicpptest
# Rules for the different types of tests
@ -40,17 +45,37 @@ include $(srcdir)/../common.mk
$(setup)
+$(swig_and_compile_cpp)
$(run_testcase_cpp)
if ! $(GO15); then \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" CXXSRCS="$(CXXSRCS)" \
SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \
INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \
TARGET="$(TARGETPREFIX)$*$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$*.i" \
$(LANGUAGE)$(VARIANT)_cpp_nocgo; \
$(run_testcase_cpp); \
fi
%.ctest:
$(setup)
+$(swig_and_compile_c)
$(run_testcase)
if ! $(GO15); then \
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" CSRCS="$(CSRCS)" \
SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" \
INCLUDES="$(INCLUDES)" SWIGOPT="$(SWIGOPT)" NOLINK=true \
TARGET="$(TARGETPREFIX)$*$(TARGETSUFFIX)" INTERFACEDIR="$(INTERFACEDIR)" INTERFACE="$*.i" \
$(LANGUAGE)$(VARIANT)_nocgo; \
$(run_testcase); \
fi
%.multicpptest:
$(setup)
+$(swig_and_compile_multi_cpp)
$(run_multi_testcase)
li_windows.cpptest:
# Does not work because go build won't build li_windows.go,
# because file names with "windows" are only built on Windows.
multi_import.multicpptest:
$(setup)
for f in multi_import_b multi_import_a; do \
@ -65,6 +90,7 @@ multi_import.multicpptest:
go_subdir_import.multicpptest:
$(setup)
mkdir -p testdir/go_subdir_import/
mkdir -p gopath/src/testdir/go_subdir_import/
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" CXXSRCS="$(CXXSRCS)" \
SWIG_LIB="$(SWIG_LIB)" SWIG="$(SWIG)" LIBS='$(LIBS)' \
INTERFACEPATH="$(SRCDIR)$(INTERFACEDIR)go_subdir_import_b.i" \
@ -80,19 +106,24 @@ go_subdir_import.multicpptest:
$(LANGUAGE)$(VARIANT)_cpp; \
done
if $(GOGCC); then \
cp testdir/go_subdir_import/*.@OBJEXT@ .; \
cp gopath/src/testdir/go_subdir_import/go_subdir_import_b/go_subdir_import_b.a gopath/src/testdir/go_subdir_import/go_subdir_import_b.gox; \
cp gopath/src/testdir/go_subdir_import/go_subdir_import_b/go_subdir_import_b.a .; \
cp gopath/src/testdir/go_subdir_import/go_subdir_import_c/go_subdir_import_c.a gopath/src/testdir/go_subdir_import/go_subdir_import_c.gox; \
cp gopath/src/testdir/go_subdir_import/go_subdir_import_c/go_subdir_import_c.a testdir/go_subdir_import/; \
fi
$(run_multi_testcase)
# Runs the testcase.
run_testcase = \
if test -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
if $(GOGCC) ; then \
$(COMPILETOOL) $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.@OBJEXT@ $*_wrap.@OBJEXT@; \
elif $(GO12) || $(GO13); then \
$(COMPILETOOL) $(GCCGO) -c -g -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GCCGO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.a; \
elif $(GO12) || $(GO13) || $(GO15); then \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CC) -extldflags "$(CFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
else \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
fi && \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \
@ -100,12 +131,14 @@ run_testcase = \
run_testcase_cpp = \
if test -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
if $(GOGCC) ; then \
$(COMPILETOOL) $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.@OBJEXT@ $*_wrap.@OBJEXT@ -lstdc++; \
elif $(GO12) || $(GO13); then \
$(COMPILETOOL) $(GCCGO) -c -g -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GCCGO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ $*.a -lstdc++; \
elif $(GO12) || $(GO13) || $(GO15); then \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
else \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
fi && \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \
@ -113,29 +146,38 @@ run_testcase_cpp = \
run_multi_testcase = \
if test -f $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX); then \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
if $(GOGCC) ; then \
$(COMPILETOOL) $(GCCGO) -c -g -I . -I gopath/src $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
files=`cat $(top_srcdir)/$(EXAMPLES)/$(TEST_SUITE)/$*.list`; \
$(COMPILETOOL) $(GO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ `for f in $$files; do echo $$f.@OBJEXT@ $${f}_wrap.@OBJEXT@; done` -lstdc++; \
elif $(GO12) || $(GO13); then \
$(COMPILETOOL) $(GCCGO) -o $*_runme $(SCRIPTPREFIX)$*_runme.@OBJEXT@ `for f in $$files; do echo $$f.a; done` -lstdc++; \
elif $(GO12) || $(GO13) || $(GO15); then \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -linkmode external -extld $(CXX) -extldflags "$(CXXFLAGS)" -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
else \
$(COMPILETOOL) $(GO) $(GOCOMPILEARG) -I . $(SCRIPTDIR)/$(SCRIPTPREFIX)$*$(SCRIPTSUFFIX) && \
$(COMPILETOOL) $(GOTOOL) $(GOLD) -L . -r $${GOROOT:-`go env GOROOT`}/pkg/$${GOOS:-`go env GOOS`}_$${GOARCH:-`go env GOARCH`}:. -o $*_runme $(SCRIPTPREFIX)$*_runme.$(GOOBJEXT); \
fi && \
env LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH $(RUNTOOL) ./$*_runme; \
fi
%.clean:
@rm -f $*.go $*_gc.c $*_wrap.* $*_runme
@rm -rf $*.go $*_gc.c $*_wrap.* $*_runme $*.gox $*.a
clean:
$(MAKE) -f $(top_builddir)/$(EXAMPLES)/Makefile SRCDIR="$(SRCDIR)" go_clean
rm -f mod_a.go mod_b.go imports_a.go imports_b.go
rm -f clientdata_prop_a.go clientdata_prop_b.go
rm -f multi_import_a.go multi_import_b.go
rm -rf go_subdir_import_a.go testdir
rm -f packageoption_a.go packageoption_b.go packageoption_c.go
rm -f import_stl_a.go import_stl_b.go
rm -f mod_a.go mod_a.gox mod_b.go mod_b.gox
rm -f imports_a.go imports_a.gox imports_b.go imports_b.gox
rm -f clientdata_prop_a.go clientdata_prop_a.gox
rm -f clientdata_prop_b.go clientdata_prop_b.gox
rm -f multi_import_a.go multi_import_a.gox
rm -f multi_import_b.go multi_import_b.gox
rm -rf go_subdir_import_a.go go_subdir_import_a.gox testdir
rm -f packageoption_a.go packageoption_a.gox
rm -f packageoption_b.go packageoption_b.gox
rm -f packageoption_c.go packageoption_c.gox
rm -f import_stl_a.go import_stl_a.gox
rm -f import_stl_b.go import_stl_b.gox
rm -rf gopath
cvsignore:
@echo '*_gc.c *_wrap.* *.so *.dll *.exp *.lib'

View File

@ -20,12 +20,12 @@
%{
class ObjC {
public:
int getInt() const;
virtual int getInt() const;
};
class ObjB {
public:
int getInt() const;
virtual int getInt() const;
};
%}

View File

@ -4,7 +4,7 @@
%inline %{
class ObjB {
public:
int getInt() const {
virtual int getInt() const {
return 27;
}
};

View File

@ -4,7 +4,7 @@
%inline %{
class ObjC {
public:
int getInt() const {
virtual int getInt() const {
return 18;
}
};

View File

@ -533,7 +533,7 @@
%typemap(directorin) enum SWIGTYPE & (intgo e)
%{
e = (intgo)$1;
$input = &e;
$input = ($1_ltype)&e;
%}
%typemap(godirectorin) enum SWIGTYPE & ""

View File

@ -19,21 +19,45 @@ static void Swig_free(void* p) {
%}
#if SWIGGO_CGO
%insert(cgo_comment_typedefs) %{
#include <stdint.h>
%}
#endif
#if SWIGGO_INTGO_SIZE == 32
%insert(runtime) %{
typedef int intgo;
typedef unsigned int uintgo;
%}
#if SWIGGO_CGO
%insert(cgo_comment_typedefs) %{
typedef int intgo;
typedef unsigned int uintgo;
%}
#endif
#elif SWIGGO_INTGO_SIZE == 64
%insert(runtime) %{
typedef long long intgo;
typedef unsigned long long uintgo;
%}
#if SWIGGO_CGO
%insert(cgo_comment_typedefs) %{
typedef long long intgo;
typedef unsigned long long uintgo;
%}
#endif
#else
%insert(runtime) %{
typedef ptrdiff_t intgo;
typedef size_t uintgo;
%}
#if SWIGGO_CGO
%insert(cgo_comment_typedefs) %{
typedef ptrdiff_t intgo;
typedef size_t uintgo;
%}
#endif
#endif
%insert(runtime) %{
@ -43,6 +67,17 @@ typedef struct { void* array; intgo len; intgo cap; } _goslice_;
%}
#ifdef SWIGGO_CGO
%insert(cgo_comment_typedefs) %{
typedef struct { char *p; intgo n; } _gostring_;
typedef struct { void* array; intgo len; intgo cap; } _goslice_;
%}
#endif
#ifndef SWIGGO_GCCGO
/* Boilerplate for C/C++ code when using 6g/8g. This code is compiled
with gcc. */
@ -98,6 +133,8 @@ static void _swig_gopanic(const char *p) {
%}
#if !SWIGGO_CGO
/* Boilerplate for C code when using 6g/8g. This code is compiled
with 6c/8c. */
%insert(gc_header) %{
@ -111,6 +148,8 @@ void *·_cgo_runtime_cgocall = &cgocall;
%}
#endif
#else
/* Boilerplate for C/C++ code when using gccgo. */
@ -122,6 +161,17 @@ extern "C" {
#endif
extern void *_cgo_allocate(size_t);
extern void _cgo_panic(const char *);
#ifdef __cplusplus
}
#endif
#define _swig_goallocate _cgo_allocate
#define _swig_gopanic _cgo_panic
%}
#if !SWIGGO_CGO
%insert(runtime) %{
/* Implementations of SwigCgocall and friends for different versions
of gccgo. The Go code will call these functions using C names with
@ -130,6 +180,10 @@ extern void _cgo_panic(const char *);
version. We assume that the version of gcc used to compile this
file is the same as the version of gccgo. */
#ifdef __cplusplus
extern "C" {
#endif
#define SWIG_GCC_VERSION \
(__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__)
@ -184,13 +238,12 @@ void SwigCgocallBackDone() {
}
#endif
#define _swig_goallocate _cgo_allocate
#define _swig_gopanic _cgo_panic
%}
#endif
#endif
%insert(runtime) %{
static _gostring_ _swig_makegostring(const char *p, size_t l) {
@ -209,9 +262,11 @@ static _gostring_ _swig_makegostring(const char *p, size_t l) {
%go_import("unsafe", _ "runtime/cgo")
#if !SWIGGO_CGO
%insert(go_header) %{
var _cgo_runtime_cgocall func(unsafe.Pointer, uintptr)
%}
#endif
#else
@ -231,6 +286,8 @@ type _ unsafe.Pointer
%}
#if !SWIGGO_CGO
/* Swig_always_false is used to conditionally assign parameters to
Swig_escape_val so that the compiler thinks that they escape. We
only assign them if Swig_always_false is true, which it never is.
@ -241,6 +298,8 @@ var Swig_escape_always_false bool
var Swig_escape_val interface{}
%}
#endif
/* Function pointers are translated by the code in go.cxx into
_swig_fnptr. Member pointers are translated to _swig_memberptr. */

File diff suppressed because it is too large Load Diff

View File

@ -2319,109 +2319,102 @@ if test x"${GOBIN}" = xno -o x"${with_alllang}" = xno ; then
GO1=false
GO12=false
GO13=false
GO15=false
GOGCC=false
GCCGO=
GOOPT=
GCCGOOPT=
GOVERSIONOPTION=
else
if test "x$GOBIN" = xyes; then
AC_CHECK_PROGS(GO, go 6g 8g gccgo)
AC_CHECK_PROGS(GO, go)
else
GO="$GOBIN"
fi
AC_CHECK_PROGS(GCCGO, gccgo)
GOGCC=false
GCCGO=
GO1=false
GO12=false
GO13=false
GO15=false
GOOPT=
GCCGOOPT=
GOVERSIONOPTION=
if test -n "$GO" ; then
if $GO --help 2>/dev/null | grep gccgo >/dev/null 2>&1 ; then
GOGCC=true
GOVERSIONOPTION=--version
AC_MSG_CHECKING([whether gccgo version is too old])
go_version=[`$GO $GOVERSIONOPTION | sed -n '1p' | sed -e 's/^.* \([0-9.]*\) *$/\1/' -e 's/[.]//g'`]
if test "x$go_version" = x; then
AC_MSG_RESULT([could not determine gccgo version - disabling Go])
GO=
elif test "$go_version" -lt 470; then
AC_MSG_RESULT([yes - minimum version is 4.7.0])
GO=
else
AC_MSG_RESULT([no])
if test "$go_version" -lt 480; then
GOOPT="-intgosize 32"
else
AC_CHECK_SIZEOF([void *], [4])
if test "$ac_cv_sizeof_void_p" = "8"; then
GOOPT="-intgosize 64"
else
GOOPT="-intgosize 32"
fi
fi
fi
elif test "`echo $GO | sed -e 's|.*/||'`" = "go"; then
GO1=true
GOVERSIONOPTION=version
GOC=$(sh -c "$(go env) && echo \$GOCHAR")c
go_version=$($GO $GOVERSIONOPTION | sed -e 's/go version //')
AC_MSG_CHECKING([whether go version is too old])
case $go_version in
go1.0* | go1 )
AC_MSG_RESULT([yes - minimum version is 1.1])
GO=
GOOPT="-intgosize 32"
;;
*)
AC_MSG_RESULT([no])
if test "$GOC" = "6c"; then
GOOPT="-intgosize 64"
else
GOOPT="-intgosize 32"
fi
;;
esac
case $go_version in
go1.0* | go1 | go1.1*)
GOOPT="$GOOPT -use-shlib"
;;
go1.2*)
GO12=true
;;
*)
GO13=true
;;
esac
GO1=true
GOVERSIONOPTION=version
GOC=$(sh -c "$(go env) && echo \$GOCHAR")c
go_version=$($GO $GOVERSIONOPTION | sed -e 's/go version //')
AC_MSG_CHECKING([whether go version is too old])
case $go_version in
go1.0* | go1 )
AC_MSG_RESULT([yes - minimum version is 1.1])
GO=
GOOPT="-intgosize 32"
;;
*)
AC_MSG_RESULT([no])
if test "$GOC" = "6c"; then
GOOPT="-intgosize 64"
else
GOC=`echo $GO | sed -e 's/g/c/'`
GOVERSIONOPTION=-V
AC_MSG_CHECKING([whether Go ($GO) version is too old])
AC_MSG_RESULT([yes - minimum version is 1.1])
GO=
dnl Old code retained for now in case we implement an option for it.
dnl go_version=`$GO $GOVERSIONOPTION 2>/dev/null | sed -e 's/.*version.* \([[0-9]]*\).*/\1/'`
dnl go_min_version=7077
dnl if test "$go_version" != "" -a "$go_version" -lt $go_min_version; then
dnl AC_MSG_RESULT([yes - minimum version is $go_min_version])
dnl GO=
dnl else
dnl AC_MSG_RESULT([no])
dnl fi
GOOPT="-intgosize 32"
GO12=false
GO13=false
fi
;;
esac
case $go_version in
go1.0* | go1 | go1.1*)
GOOPT="$GOOPT -use-shlib"
;;
go1.2*)
GO12=true
;;
go1.3* | go1.4*)
GO13=true
;;
*)
GO15=true
;;
esac
if $GCCGO --help 2>/dev/null | grep gccgo >/dev/null 2>&1 ; then
AC_MSG_CHECKING([whether gccgo version is too old])
go_version=[`$GO $GOVERSIONOPTION | sed -n '1p' | sed -e 's/^.* \([0-9.]*\) *$/\1/' -e 's/[.]//g'`]
if test "x$go_version" = x; then
AC_MSG_RESULT([could not determine gccgo version])
GCCGO=
elif test "$go_version" -lt 470; then
AC_MSG_RESULT([yes - minimum version is 4.7.0])
GCCGO=
else
AC_MSG_RESULT([no])
if test "$go_version" -lt 480; then
GCCGOOPT="-intgosize 32"
else
AC_CHECK_SIZEOF([void *], [4])
if test "$ac_cv_sizeof_void_p" = "8"; then
GCCGOOPT="-intgosize 64"
else
GCCGOOPT="-intgosize 32"
fi
fi
fi
fi
fi
AC_SUBST(GOGCC)
AC_SUBST(GCCGO)
AC_SUBST(GO)
AC_SUBST(GOC)
AC_SUBST(GO1)
AC_SUBST(GO12)
AC_SUBST(GO13)
AC_SUBST(GO15)
AC_SUBST(GOOPT)
AC_SUBST(GCCGOOPT)
AC_SUBST(GOVERSIONOPTION)
#----------------------------------------------------------------