github.com/sean-/go@v0.0.0-20151219100004-97f854cd7bb6/misc/cgo/testcarchive/test.bash (about) 1 #!/usr/bin/env bash 2 # Copyright 2015 The Go Authors. All rights reserved. 3 # Use of this source code is governed by a BSD-style 4 # license that can be found in the LICENSE file. 5 6 set -e 7 8 ccargs= 9 if [ "$(go env GOOS)" == "darwin" ]; then 10 ccargs="-Wl,-no_pie" 11 # For darwin/arm. 12 # TODO(crawshaw): Can we do better? 13 ccargs="$ccargs -framework CoreFoundation -framework Foundation" 14 fi 15 ccargs="$ccargs -I pkg/$(go env GOOS)_$(go env GOARCH)" 16 17 # TODO(crawshaw): Consider a go env for exec script name. 18 bin=./testp 19 exec_script=go_$(go env GOOS)_$(go env GOARCH)_exec 20 if [ "$(which $exec_script)" != "" ]; then 21 bin="$exec_script ./testp" 22 fi 23 24 rm -rf libgo.a libgo.h testp pkg 25 26 status=0 27 28 # Installing first will create the header files we want. 29 30 GOPATH=$(pwd) go install -buildmode=c-archive libgo 31 $(go env CC) $(go env GOGCCFLAGS) $ccargs -o testp main.c pkg/$(go env GOOS)_$(go env GOARCH)/libgo.a 32 if ! $bin arg1 arg2; then 33 echo "FAIL test1" 34 status=1 35 fi 36 rm -f libgo.a libgo.h testp 37 38 # Test building libgo other than installing it. 39 # Header files are now present. 40 41 GOPATH=$(pwd) go build -buildmode=c-archive src/libgo/libgo.go 42 $(go env CC) $(go env GOGCCFLAGS) $ccargs -o testp main.c libgo.a 43 if ! $bin arg1 arg2; then 44 echo "FAIL test2" 45 status=1 46 fi 47 rm -f libgo.a libgo.h testp 48 49 GOPATH=$(pwd) go build -buildmode=c-archive -o libgo.a libgo 50 $(go env CC) $(go env GOGCCFLAGS) $ccargs -o testp main.c libgo.a 51 if ! $bin arg1 arg2; then 52 echo "FAIL test3" 53 status=1 54 fi 55 rm -rf libgo.a libgo.h testp pkg 56 57 GOPATH=$(pwd) go build -buildmode=c-archive -o libgo2.a libgo2 58 $(go env CC) $(go env GOGCCFLAGS) $ccargs -o testp main2.c libgo2.a 59 if ! $bin; then 60 echo "FAIL test4" 61 status=1 62 fi 63 rm -rf libgo2.a libgo2.h testp pkg 64 65 exit $status