When generating Go code, make -cgo the default.
Add new -no-cgo option to disable the default.
Keep -cgo as a no-op for existing users.
diff --git a/Doc/Manual/Go.html b/Doc/Manual/Go.html
index b16c764..dbea7de 100644
--- a/Doc/Manual/Go.html
+++ b/Doc/Manual/Go.html
@@ -125,16 +125,15 @@
</p>
<p>
-When using the <tt>-cgo</tt> option, SWIG will generate files that can be used
-directly by <tt>go build</tt>. Starting with the Go 1.5 distribution the
-<tt>-cgo</tt> option has to be given. Put your SWIG interface file in a
-directory under GOPATH/src, and give it a name that does <b>not</b> end in the
-.swig or .swigcxx extension. Typically the SWIG interface file extension is .i
-in this case.
+By default SWIG will generate files that can be used directly
+by <tt>go build</tt>. This requires Go 1.2 or later. Put your SWIG
+interface file in a directory under GOPATH/src, and give it a name
+that does <b>not</b> end in the .swig or .swigcxx extension.
+Typically the SWIG interface file extension is .i in this case.
</p>
<div class="code"><pre>
-% swig -go -cgo example.i
+% swig -go example.i
% go install
</pre></div>
@@ -144,15 +143,16 @@
</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 Go compiler of
-the Go distribution would look like this:
+SWIG can be used without cgo, via the <tt>-no-cgo</tt> option, but
+more steps are required. 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 Go compiler of the Go
+distribution would look like this:
</p>
<div class="code"><pre>
-% swig -go example.i
+% swig -go -no-cgo example.i
% gcc -c code.c # The C library being wrapped.
% gcc -c example_wrap.c
% go tool 6g example.go
@@ -169,7 +169,7 @@
</p>
<div class="code"><pre>
-% swig -go -use-shlib example.i
+% swig -go -no-cgo -use-shlib example.i
% gcc -c -fpic example.c
% gcc -c -fpic example_wrap.c
% gcc -shared example.o example_wrap.o -o example.so
@@ -200,10 +200,15 @@
<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>
+<td>Generate files to be used as input for the Go cgo tool. This is
+ the default.</td>
+</tr>
+
+<tr>
+<td>-no-cgo</td>
+<td>Generate files that can be used directly, rather than via the Go
+ cgo tool. This option does not work with Go 1.5 or later. It is
+ required for versions of Go before 1.2.</td>
</tr>
<tr>
@@ -268,11 +273,11 @@
<p>There are two different approaches to generating wrapper 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>
+ controlled by SWIG's <tt>-no-cgo</tt> option. The <tt>-no-cgo</tt>
+ option only works with version of Go before 1.5. It is required
+ when using versions of Go before 1.2.</p>
-<p>With or without the <tt>-cgo</tt> option, SWIG will generate the
+<p>With or without the <tt>-no-cgo</tt> option, SWIG will generate the
following files when generating wrapper code:</p>
<ul>
@@ -296,8 +301,8 @@
</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>
+<p>When the <tt>-no-cgo</tt> option is used, and the <tt>-gccgo</tt>
+ option is not used, SWIG will also generate an additional file:</p>
<ul>
<li>
diff --git a/Examples/Makefile.in b/Examples/Makefile.in
index b2cbb65..d7b71af 100644
--- a/Examples/Makefile.in
+++ b/Examples/Makefile.in
@@ -1468,7 +1468,7 @@
# ----------------------------------------------------------------
go_nocgo: $(SRCDIR_SRCS)
- $(SWIG) -go $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
+ $(SWIG) -go -no-cgo $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
if $(GO12) || $(GO13) || $(GO15) || $(GOGCC); then \
$(CC) -g -c $(CPPFLAGS) $(CFLAGS) $(SRCDIR_SRCS) $(ISRCS) $(INCLUDES); \
else \
@@ -1504,7 +1504,7 @@
fi
go: $(SRCDIR_SRCS)
- $(SWIG) -go -cgo $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ISRCS) $(INTERFACEPATH)
+ $(SWIG) -go $(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
@@ -1548,7 +1548,7 @@
# ----------------------------------------------------------------
go_cpp_nocgo: $(SRCDIR_SRCS)
- $(SWIG) -go -c++ $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
+ $(SWIG) -go -c++ -no-cgo $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
if $(GO12) || $(GO13) || $(GO15) || $(GOGCC); then \
if test -n "$(SRCDIR_CXXSRCS)$(SRCDIR_SRCS)"; then \
$(CXX) -g -c $(CPPFLAGS) $(CXXFLAGS) $(SRCDIR_CXXSRCS) $(SRCDIR_SRCS) $(INCLUDES); \
@@ -1596,7 +1596,7 @@
fi
go_cpp: $(SRCDIR_SRCS)
- $(SWIG) -go -c++ -cgo $(GOOPT) $(GOSWIGARG) $(SWIGOPT) -o $(ICXXSRCS) $(INTERFACEPATH)
+ $(SWIG) -go -c++ $(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
diff --git a/Source/Modules/go.cxx b/Source/Modules/go.cxx
index 41e8f7d..9e8162b 100644
--- a/Source/Modules/go.cxx
+++ b/Source/Modules/go.cxx
@@ -199,7 +199,7 @@
public:
GO():package(NULL),
module(NULL),
- cgo_flag(false),
+ cgo_flag(true),
gccgo_flag(false),
go_prefix(NULL),
prefix_option(NULL),
@@ -269,6 +269,9 @@
} else if (strcmp(argv[i], "-cgo") == 0) {
Swig_mark_arg(i);
cgo_flag = true;
+ } else if (strcmp(argv[i], "-no-cgo") == 0) {
+ Swig_mark_arg(i);
+ cgo_flag = false;
} else if (strcmp(argv[i], "-gccgo") == 0) {
Swig_mark_arg(i);
gccgo_flag = true;
@@ -6979,6 +6982,7 @@
const char * const GO::usage = "\
Go Options (available with -go)\n\
-cgo - Generate cgo input files\n\
+ -no-cgo - Do not generate cgo input files\n\
-gccgo - Generate code for gccgo rather than 6g/8g\n\
-go-pkgpath <p> - Like gccgo -fgo-pkgpath option\n\
-go-prefix <p> - Like gccgo -fgo-prefix option\n\