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 # Installing first will create the header files we want. 27 28 GOPATH=$(pwd) go install -buildmode=c-archive libgo 29 $(go env CC) $(go env GOGCCFLAGS) $ccargs -o testp main.c pkg/$(go env GOOS)_$(go env GOARCH)/libgo.a 30 $bin arg1 arg2 31 rm -f libgo.a libgo.h testp 32 33 # Test building libgo other than installing it. 34 # Header files are now present. 35 36 GOPATH=$(pwd) go build -buildmode=c-archive src/libgo/libgo.go 37 $(go env CC) $(go env GOGCCFLAGS) $ccargs -o testp main.c libgo.a 38 $bin arg1 arg2 39 rm -f libgo.a libgo.h testp 40 41 GOPATH=$(pwd) go build -buildmode=c-archive -o libgo.a libgo 42 $(go env CC) $(go env GOGCCFLAGS) $ccargs -o testp main.c libgo.a 43 $bin arg1 arg2 44 rm -rf libgo.a libgo.h testp pkg 45