go.sh (1499B)
1# 2# This helper is for templates for Go packages. 3# 4 5do_configure() { 6 # $go_import_path must be set, or we can't link $PWD into $GOSRCPATH 7 # nor build from modules 8 if [ -z "$go_import_path" ]; then 9 msg_error "\"\$go_import_path\" not set on $pkgname template.\n" 10 fi 11 12 # This isn't really configuration, but its needed by packages 13 # that do unusual things with the build where the expect to be 14 # able to cd into the $GOSRCPATH 15 if [ "${go_mod_mode}" != "off" ] && [ -f go.mod ]; then 16 # Skip GOPATH symlink for Go modules 17 msg_normal "Building $pkgname using Go modules.\n" 18 else 19 mkdir -p ${GOSRCPATH%/*}/ 20 ln -fs "$PWD" "${GOSRCPATH}" 21 fi 22} 23 24do_build() { 25 go_package=${go_package:-$go_import_path} 26 # Build using Go modules if there's a go.mod file 27 if [ "${go_mod_mode}" != "off" ] && [ -f go.mod ]; then 28 if [ -z "${go_mod_mode}" ] && [ -d vendor ]; then 29 msg_normal "Using vendor dir for $pkgname Go dependencies.\n" 30 go_mod_mode=vendor 31 elif [ "${go_mod_mode}" = "default" ]; then 32 # Allow templates to explicitly opt into the go tool's 33 # default behavior. 34 go_mod_mode= 35 fi 36 go install -p "$XBPS_MAKEJOBS" -mod="${go_mod_mode}" -x -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package} 37 else 38 # Otherwise, build using GOPATH 39 go get -p "$XBPS_MAKEJOBS" -x -tags "${go_build_tags}" -ldflags "${go_ldflags}" ${go_package} 40 fi 41} 42 43do_install() { 44 for f in ${GOPATH}/bin/* ${GOPATH}/bin/**/*; do 45 if [ -f "$f" ] && [ -x "$f" ]; then 46 vbin "$f" 47 fi 48 done 49}