2009-08-12 14:18:46 -06:00
|
|
|
# Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style
|
|
|
|
# license that can be found in the LICENSE file.
|
|
|
|
|
2009-08-13 15:41:10 -06:00
|
|
|
all: package
|
2009-08-12 14:18:46 -06:00
|
|
|
package: _obj/$(TARG).a
|
|
|
|
testpackage: _test/$(TARG).a
|
|
|
|
|
2010-03-19 16:14:46 -06:00
|
|
|
include $(QUOTED_GOROOT)/src/Make.common
|
2009-12-11 16:14:09 -07:00
|
|
|
|
2010-08-26 18:21:34 -06:00
|
|
|
# The quietgcc wrapper is for our own source code
|
|
|
|
# while building the libraries, not arbitrary source code
|
|
|
|
# as encountered by cgo.
|
|
|
|
ifeq ($(HOST_CC),quietgcc)
|
|
|
|
HOST_CC:=gcc
|
|
|
|
endif
|
|
|
|
ifeq ($(HOST_LD),quietgcc)
|
|
|
|
HOST_LD:=gcc
|
|
|
|
endif
|
|
|
|
|
2009-11-11 13:00:50 -07:00
|
|
|
# GNU Make 3.80 has a bug in lastword
|
|
|
|
# elem=$(lastword $(subst /, ,$(TARG)))
|
|
|
|
TARG_words=$(subst /, ,$(TARG))
|
|
|
|
elem=$(word $(words $(TARG_words)),$(TARG_words))
|
|
|
|
|
2009-12-21 09:31:02 -07:00
|
|
|
ifeq ($(elem),$(TARG))
|
|
|
|
dir=
|
|
|
|
else
|
|
|
|
dir=$(patsubst %/$(elem),%,$(TARG))
|
|
|
|
endif
|
2009-11-23 18:32:51 -07:00
|
|
|
|
|
|
|
pkgdir=$(QUOTED_GOROOT)/pkg/$(GOOS)_$(GOARCH)
|
2009-08-12 14:18:46 -06:00
|
|
|
|
2011-04-26 19:00:34 -06:00
|
|
|
ifeq ($(TARGDIR),)
|
|
|
|
TARGDIR:=$(pkgdir)
|
|
|
|
endif
|
|
|
|
|
|
|
|
INSTALLFILES+=$(TARGDIR)/$(TARG).a
|
2009-09-30 12:51:08 -06:00
|
|
|
|
|
|
|
# The rest of the cgo rules are below, but these variable updates
|
|
|
|
# must be done here so they apply to the main rules.
|
2009-12-17 14:20:56 -07:00
|
|
|
ifdef CGOFILES
|
2011-03-02 12:22:33 -07:00
|
|
|
GOFILES+=$(patsubst %.go,_obj/%.cgo1.go,$(CGOFILES)) _obj/_cgo_gotypes.go
|
2010-12-17 10:51:55 -07:00
|
|
|
CGO_OFILES+=$(patsubst %.go,%.cgo2.o,$(CGOFILES)) _cgo_export.o
|
|
|
|
OFILES+=_cgo_defun.$O _cgo_import.$O $(CGO_OFILES)
|
2009-12-17 14:20:56 -07:00
|
|
|
endif
|
2009-09-30 12:51:08 -06:00
|
|
|
|
2011-03-22 14:05:51 -06:00
|
|
|
ifdef SWIGFILES
|
|
|
|
GOFILES+=$(patsubst %.swig,_obj/%.go,$(patsubst %.swigcxx,%.swig,$(SWIGFILES)))
|
|
|
|
OFILES+=$(patsubst %.swig,_obj/%_gc.$O,$(patsubst %.swigcxx,%.swig,$(SWIGFILES)))
|
|
|
|
SWIG_PREFIX=$(subst /,-,$(TARG))
|
|
|
|
SWIG_SOS+=$(patsubst %.swig,_obj/$(SWIG_PREFIX)-%.so,$(patsubst %.swigcxx,%.swig,$(SWIGFILES)))
|
2011-04-26 19:00:34 -06:00
|
|
|
INSTALLFILES+=$(patsubst %.swig,$(TARGDIR)/swig/$(SWIG_PREFIX)-%.so,$(patsubst %.swigcxx,%.swig,$(SWIGFILES)))
|
2011-03-22 14:05:51 -06:00
|
|
|
endif
|
|
|
|
|
2010-03-19 16:14:46 -06:00
|
|
|
PREREQ+=$(patsubst %,%.make,$(DEPS))
|
|
|
|
|
2009-08-12 14:18:46 -06:00
|
|
|
coverage:
|
2010-08-24 18:00:33 -06:00
|
|
|
gotest
|
|
|
|
6cov -g $(shell pwd) $O.out | grep -v '_test\.go:'
|
2009-08-12 14:18:46 -06:00
|
|
|
|
2011-04-06 13:06:28 -06:00
|
|
|
CLEANFILES+=*.so _obj _test _testmain.go *.exe _cgo* *.cgo[12].* test.out build.out
|
2009-08-12 14:18:46 -06:00
|
|
|
|
|
|
|
test:
|
2010-08-24 18:00:33 -06:00
|
|
|
gotest
|
2009-08-12 14:18:46 -06:00
|
|
|
|
2011-03-25 15:50:44 -06:00
|
|
|
testshort:
|
2011-04-02 23:23:34 -06:00
|
|
|
gotest -test.short -test.timeout=120
|
2011-03-25 15:50:44 -06:00
|
|
|
|
2010-01-12 16:43:20 -07:00
|
|
|
bench:
|
2011-02-22 21:23:21 -07:00
|
|
|
gotest -test.bench=. -test.run="Do not run tests"
|
2010-01-12 16:43:20 -07:00
|
|
|
|
2009-08-12 14:18:46 -06:00
|
|
|
nuke: clean
|
2011-04-26 19:00:34 -06:00
|
|
|
rm -f $(TARGDIR)/$(TARG).a
|
2009-08-12 14:18:46 -06:00
|
|
|
|
|
|
|
testpackage-clean:
|
2011-03-02 12:22:33 -07:00
|
|
|
rm -f _test/$(TARG).a
|
2009-08-12 14:18:46 -06:00
|
|
|
|
2009-09-30 12:51:08 -06:00
|
|
|
install: $(INSTALLFILES)
|
2009-08-12 15:40:29 -06:00
|
|
|
|
2011-04-26 19:00:34 -06:00
|
|
|
$(TARGDIR)/$(TARG).a: _obj/$(TARG).a
|
2011-05-29 20:35:55 -06:00
|
|
|
@mkdir -p $(TARGDIR)/$(dir)
|
2009-11-23 18:32:51 -07:00
|
|
|
cp _obj/$(TARG).a "$@"
|
2009-08-12 14:18:46 -06:00
|
|
|
|
2009-11-01 06:43:26 -07:00
|
|
|
_go_.$O: $(GOFILES) $(PREREQ)
|
2011-04-26 19:00:34 -06:00
|
|
|
$(GC) $(GCIMPORTS) -o $@ $(GOFILES)
|
2009-08-12 14:18:46 -06:00
|
|
|
|
2009-11-01 06:43:26 -07:00
|
|
|
_gotest_.$O: $(GOFILES) $(GOTESTFILES) $(PREREQ)
|
2011-04-26 19:00:34 -06:00
|
|
|
$(GC) $(GCIMPORTS) -o $@ $(GOFILES) $(GOTESTFILES)
|
2009-08-12 14:18:46 -06:00
|
|
|
|
|
|
|
_obj/$(TARG).a: _go_.$O $(OFILES)
|
2009-09-30 12:51:08 -06:00
|
|
|
@mkdir -p _obj/$(dir)
|
2009-08-12 14:18:46 -06:00
|
|
|
rm -f _obj/$(TARG).a
|
2010-08-24 18:00:33 -06:00
|
|
|
gopack grc $@ _go_.$O $(OFILES)
|
2009-08-12 14:18:46 -06:00
|
|
|
|
|
|
|
_test/$(TARG).a: _gotest_.$O $(OFILES)
|
2009-09-30 12:51:08 -06:00
|
|
|
@mkdir -p _test/$(dir)
|
2009-08-12 14:18:46 -06:00
|
|
|
rm -f _test/$(TARG).a
|
2010-08-24 18:00:33 -06:00
|
|
|
gopack grc $@ _gotest_.$O $(OFILES)
|
2009-08-12 14:18:46 -06:00
|
|
|
|
|
|
|
importpath:
|
|
|
|
@echo $(TARG)
|
|
|
|
|
2009-08-13 15:41:10 -06:00
|
|
|
dir:
|
|
|
|
@echo $(dir)
|
|
|
|
|
2009-09-30 12:51:08 -06:00
|
|
|
# To use cgo in a Go package, add a line
|
|
|
|
#
|
2009-12-17 14:20:56 -07:00
|
|
|
# CGOFILES=x.go y.go
|
2009-09-30 12:51:08 -06:00
|
|
|
#
|
2009-12-17 14:20:56 -07:00
|
|
|
# to the main Makefile. This signals that cgo should process x.go
|
|
|
|
# and y.go when building the package.
|
2010-04-09 14:31:05 -06:00
|
|
|
# There are three optional variables to set, CGO_CFLAGS, CGO_LDFLAGS,
|
|
|
|
# and CGO_DEPS, which specify compiler flags, linker flags, and linker
|
|
|
|
# dependencies to use when compiling (using gcc) the C support for
|
|
|
|
# x.go and y.go.
|
2009-09-30 12:51:08 -06:00
|
|
|
|
2009-12-17 14:20:56 -07:00
|
|
|
# Cgo translates each x.go file listed in $(CGOFILES) into a basic
|
2011-03-02 12:22:33 -07:00
|
|
|
# translation of x.go, called _obj/x.cgo1.go. Additionally, three other
|
2009-12-17 14:20:56 -07:00
|
|
|
# files are created:
|
2009-09-30 12:51:08 -06:00
|
|
|
#
|
2011-03-02 12:22:33 -07:00
|
|
|
# _obj/_cgo_gotypes.go - declarations needed for all .go files in the package; imports "unsafe"
|
|
|
|
# _obj/_cgo_defun.c - C trampoline code to be compiled with 6c and linked into the package
|
|
|
|
# _obj/x.cgo2.c - C implementations compiled with gcc to create a dynamic library
|
2009-09-30 12:51:08 -06:00
|
|
|
#
|
|
|
|
|
2010-12-17 10:51:55 -07:00
|
|
|
ifdef CGOFILES
|
2011-03-02 12:22:33 -07:00
|
|
|
_obj/_cgo_run: $(CGOFILES)
|
2011-03-03 09:51:16 -07:00
|
|
|
@mkdir -p _obj
|
2010-08-24 18:00:33 -06:00
|
|
|
CGOPKGPATH=$(dir) cgo -- $(CGO_CFLAGS) $(CGOFILES)
|
2011-03-02 12:22:33 -07:00
|
|
|
touch _obj/_cgo_run
|
2009-12-17 14:20:56 -07:00
|
|
|
|
2011-02-01 06:44:18 -07:00
|
|
|
# _CGO_CFLAGS and _CGO_LDFLAGS are defined via the evaluation of _cgo_flags.
|
|
|
|
# The include happens before the commands in the recipe run,
|
|
|
|
# so it cannot be done in the same recipe that runs cgo.
|
2011-03-02 12:22:33 -07:00
|
|
|
_obj/_load_cgo_flags: _obj/_cgo_run
|
|
|
|
$(eval include _obj/_cgo_flags)
|
2011-02-01 06:44:18 -07:00
|
|
|
|
|
|
|
# Include any previous flags in case cgo files are up to date.
|
2011-03-02 12:22:33 -07:00
|
|
|
-include _obj/_cgo_flags
|
2011-02-01 06:44:18 -07:00
|
|
|
|
2010-12-17 12:37:11 -07:00
|
|
|
# Ugly but necessary - cgo writes these files too.
|
2011-03-02 12:22:33 -07:00
|
|
|
_obj/_cgo_gotypes.go _obj/_cgo_export.c _obj/_cgo_export.h _obj/_cgo_main.c _obj/_cgo_defun.c: _obj/_load_cgo_flags
|
2010-09-07 13:14:14 -06:00
|
|
|
@true
|
|
|
|
|
2011-03-02 12:22:33 -07:00
|
|
|
_obj/%.cgo1.go _obj/%.cgo2.c: _obj/_cgo_defun.c
|
2009-12-17 14:20:56 -07:00
|
|
|
@true
|
2010-12-17 14:22:20 -07:00
|
|
|
endif
|
2009-12-17 14:20:56 -07:00
|
|
|
|
2010-12-08 11:56:51 -07:00
|
|
|
# Compile rules for gcc source files.
|
2010-12-17 10:51:55 -07:00
|
|
|
%.o: %.c
|
2011-02-01 06:44:18 -07:00
|
|
|
$(HOST_CC) $(_CGO_CFLAGS_$(GOARCH)) -g -fPIC -O2 -o $@ -c $(CGO_CFLAGS) $(_CGO_CFLAGS) $*.c
|
2010-12-08 11:56:51 -07:00
|
|
|
|
2011-03-02 12:22:33 -07:00
|
|
|
%.o: _obj/%.c
|
|
|
|
$(HOST_CC) $(_CGO_CFLAGS_$(GOARCH)) -I . -g -fPIC -O2 -o $@ -c $(CGO_CFLAGS) $(_CGO_CFLAGS) $^
|
|
|
|
|
2010-12-08 11:56:51 -07:00
|
|
|
# To find out which symbols are needed from external libraries
|
|
|
|
# and which libraries are needed, we build a simple a.out that
|
|
|
|
# links all the objects we just created and then use cgo -dynimport
|
|
|
|
# to inspect it. That is, we make gcc tell us which dynamic symbols
|
|
|
|
# and libraries are involved, instead of duplicating gcc's logic ourselves.
|
2010-12-17 10:51:55 -07:00
|
|
|
# After main we have to define all the symbols that will be provided
|
|
|
|
# by Go code. That's crosscall2 and any exported symbols.
|
2010-12-08 11:56:51 -07:00
|
|
|
|
2010-12-17 10:51:55 -07:00
|
|
|
_cgo1_.o: _cgo_main.o $(CGO_OFILES)
|
2011-02-01 06:44:18 -07:00
|
|
|
$(HOST_CC) $(_CGO_CFLAGS_$(GOARCH)) -g -fPIC -O2 -o $@ $^ $(CGO_LDFLAGS) $(_CGO_LDFLAGS)
|
2010-12-08 11:56:51 -07:00
|
|
|
|
2011-03-02 12:22:33 -07:00
|
|
|
_obj/_cgo_import.c: _cgo1_.o
|
2011-03-02 12:52:35 -07:00
|
|
|
@mkdir -p _obj
|
2011-03-02 12:22:33 -07:00
|
|
|
cgo -dynimport _cgo1_.o >$@_ && mv -f $@_ $@
|
2010-04-09 14:31:05 -06:00
|
|
|
|
2009-12-17 14:20:56 -07:00
|
|
|
# The rules above added x.cgo1.go and _cgo_gotypes.go to $(GOFILES),
|
|
|
|
# added _cgo_defun.$O to $OFILES, and added the installed copy of
|
|
|
|
# package_x.so (built from x.cgo2.c) to $(INSTALLFILES).
|
2009-09-30 12:51:08 -06:00
|
|
|
|
2011-03-22 14:30:16 -06:00
|
|
|
# Have to run gcc with the right size argument on hybrid 32/64 machines.
|
|
|
|
_CGO_CFLAGS_386=-m32
|
|
|
|
_CGO_CFLAGS_amd64=-m64
|
|
|
|
_CGO_LDFLAGS_freebsd=-shared -lpthread -lm
|
|
|
|
_CGO_LDFLAGS_linux=-shared -lpthread -lm
|
|
|
|
_CGO_LDFLAGS_darwin=-dynamiclib -Wl,-undefined,dynamic_lookup
|
|
|
|
_CGO_LDFLAGS_windows=-shared -lm -mthreads
|
|
|
|
|
2010-12-08 11:56:51 -07:00
|
|
|
# Have to compile the runtime header.
|
2011-02-02 22:42:03 -07:00
|
|
|
RUNTIME_CFLAGS=-I$(pkgdir)
|
2009-09-30 12:51:08 -06:00
|
|
|
|
2009-12-17 14:20:56 -07:00
|
|
|
# Compile _cgo_defun.c with 6c; needs access to the runtime headers.
|
2011-03-02 12:22:33 -07:00
|
|
|
_cgo_defun.$O: _obj/_cgo_defun.c
|
|
|
|
$(CC) $(CFLAGS) $(RUNTIME_CFLAGS) -I . -o "$@" _obj/_cgo_defun.c
|
2009-12-17 14:20:56 -07:00
|
|
|
|
2011-03-22 14:05:51 -06:00
|
|
|
# To use swig in a Go package, add a line
|
|
|
|
#
|
|
|
|
# SWIGFILES=x.swig
|
|
|
|
#
|
|
|
|
# to the main Makefile. This signals that SWIG should process the
|
|
|
|
#.swig file when building the package.
|
|
|
|
#
|
|
|
|
# To wrap C code, use an extension of .swig. To wrap C++ code, use an
|
|
|
|
# extension of .swigcxx.
|
|
|
|
#
|
|
|
|
# SWIGFILES=myclib.swig mycxxlib.swigcxx
|
|
|
|
|
|
|
|
ifdef SWIGFILES
|
|
|
|
_obj/%._swig_run _obj/%.go _obj/%_gc.c _obj/%_wrap.c: %.swig
|
|
|
|
@mkdir -p _obj
|
|
|
|
swig -go -module $* -soname $(SWIG_PREFIX)-$*.so -o _obj/$*_wrap.c -outdir _obj $<
|
|
|
|
|
|
|
|
_obj/%._swig_run _obj/%.go _obj/%_gc.c _obj/%_wrap.cxx: %.swigcxx
|
|
|
|
@mkdir -p _obj
|
|
|
|
swig -go -c++ -module $* -soname $(SWIG_PREFIX)-$*.so -o _obj/$*_wrap.cxx -outdir _obj $<
|
|
|
|
|
|
|
|
_obj/%_gc.$O: _obj/%_gc.c
|
|
|
|
$(CC) $(CFLAGS) -I . -I$(pkgdir) -o "$@" _obj/$*_gc.c
|
|
|
|
|
|
|
|
_obj/%_wrap.o: _obj/%_wrap.c
|
|
|
|
$(HOST_CC) $(_CGO_CFLAGS_$(GOARCH)) -I . -g -fPIC -O2 -o $@ -c $^ $(SWIG_CFLAGS)
|
|
|
|
|
|
|
|
HOST_CXX=g++
|
|
|
|
|
|
|
|
_obj/%_wrapcxx.o: _obj/%_wrap.cxx
|
|
|
|
$(HOST_CXX) $(_CGO_CFLAGS_$(GOARCH)) -I . -g -fPIC -O2 -o $@ -c $^ $(SWIG_CXXFLAGS)
|
|
|
|
|
|
|
|
_obj/$(SWIG_PREFIX)-%.so: _obj/%_wrap.o
|
|
|
|
$(HOST_CC) $(_CGO_CFLAGS_$(GOARCH)) -o $@ $^ $(SWIG_LDFLAGS) $(_CGO_LDFLAGS_$(GOOS)) $(_SWIG_LDFLAGS_$(GOOS))
|
|
|
|
|
|
|
|
_obj/$(SWIG_PREFIX)-%.so: _obj/%_wrapcxx.o
|
|
|
|
$(HOST_CXX) $(_CGO_CFLAGS_$(GOARCH)) -o $@ $^ $(SWIG_LDFLAGS) $(_CGO_LDFLAGS_$(GOOS)) $(_SWIG_LDFLAGS_$(GOOS))
|
|
|
|
|
2011-04-26 19:00:34 -06:00
|
|
|
$(TARGDIR)/swig/$(SWIG_PREFIX)-%.so: _obj/$(SWIG_PREFIX)-%.so
|
2011-05-29 20:35:55 -06:00
|
|
|
@mkdir -p $(TARGDIR)/swig
|
2011-03-22 14:05:51 -06:00
|
|
|
cp $< "$@"
|
|
|
|
|
|
|
|
all: $(SWIG_SOS)
|
|
|
|
|
2011-04-26 19:00:34 -06:00
|
|
|
SWIG_RPATH=-r $(TARGDIR)/swig
|
2011-03-22 14:05:51 -06:00
|
|
|
|
|
|
|
endif
|
|
|
|
|
2009-09-30 12:51:08 -06:00
|
|
|
# Generic build rules.
|
|
|
|
# These come last so that the rules above can override them
|
|
|
|
# for more specific file names.
|
runtime: fix signal stack bug
In CL 4188061 I changed malg to allocate the requested
number of bytes n, not n+StackGuard, so that the
allocations would use rounder numbers.
The allocation of the signal stack asks for 32k and
then used g->stackguard as the base, but g->stackguard
is StackGuard bytes above the base. Previously, asking
for 32k meant getting 32k+StackGuard bytes, so using
g->stackguard as the base was safe. Now, the actual base
must be computed, so that the signal handler does not
run StackGuard bytes past the top of the stack.
Was causing flakiness mainly in programs that use the
network, because they sometimes write to closed network
connections, causing SIGPIPEs. Was also causing problems
in the doc/progs test.
Also fix Makefile so that changes to stack.h trigger rebuild.
R=bradfitzgo, r, r2
CC=golang-dev
https://golang.org/cl/4230044
2011-02-24 14:46:44 -07:00
|
|
|
%.$O: %.c $(HFILES)
|
2011-03-02 12:22:33 -07:00
|
|
|
$(CC) $(CFLAGS) -o "$@" $*.c
|
|
|
|
|
|
|
|
%.$O: _obj/%.c $(HFILES)
|
|
|
|
$(CC) $(CFLAGS) -I . -o "$@" _obj/$*.c
|
2009-09-30 12:51:08 -06:00
|
|
|
|
|
|
|
%.$O: %.s
|
2010-08-24 18:00:33 -06:00
|
|
|
$(AS) $*.s
|