xref: /unit/auto/modules/go (revision 216:07257705cd64)
1
2# Copyright (C) Max Romanov
3# Copyright (C) NGINX, Inc.
4
5
6shift
7
8NXT_GO=go
9
10for nxt_option; do
11
12    case "$nxt_option" in
13        -*=*) value=`$echo "$nxt_option" | sed -e 's/[-_a-zA-Z0-9]*=//'`     ;;
14           *) value="" ;;
15    esac
16
17    case "$nxt_option" in
18        --go=*)       NXT_GO="$value"                                        ;;
19        --go-path=*)  NXT_GO_PATH="$value"                                   ;;
20
21        --help)
22            cat << END
23
24    --go=NAME        set go executable
25    --go-path=PATH   set GOPATH variable to install package
26
27END
28            exit 0
29        ;;
30
31        *)
32            $echo
33            $echo $0: error: invalid Go option \"$nxt_option\"
34            $echo
35            exit 1
36        ;;
37
38    esac
39
40done
41
42
43$echo "configuring Go package"
44$echo "configuring Go package ..." >> $NXT_AUTOCONF_ERR
45
46$echo -n "checking for Go ..."
47$echo "checking for Go ..." >> $NXT_AUTOCONF_ERR
48
49nxt_go_test="GOPATH=`pwd` CGO_CPPFLAGS=-DNXT_CONFIGURE \
50    \"${NXT_GO}\" build -o build/nxt_go_gen.a --buildmode=c-archive nginext"
51
52
53if /bin/sh -c "$nxt_go_test" >> $NXT_AUTOCONF_ERR 2>&1; then
54    $echo " found"
55
56    NXT_GO_VERSION="`${NXT_GO} version`"
57    $echo " + ${NXT_GO_VERSION}"
58
59else
60    $echo "----------"    >> $NXT_AUTOCONF_ERR
61    $echo $nxt_go_test    >> $NXT_AUTOCONF_ERR
62    $echo "----------"    >> $NXT_AUTOCONF_ERR
63    $echo
64    $echo
65    $echo $0: error: no Go found.
66    $echo
67    exit 1;
68fi
69
70
71
72NXT_GO_PATH=${NXT_GO_PATH=`go env GOPATH`}
73NXT_GO_PATH=${NXT_GO_PATH:-`pwd`/${NXT_GO}}
74
75$echo " + Go package path: \"${NXT_GO_PATH}\""
76
77if grep ^$NXT_GO: $NXT_MAKEFILE 2>&1 > /dev/null; then
78    $echo
79    $echo $0: error: duplicate \"$NXT_GO\" package configured.
80    $echo
81    exit 1;
82fi
83
84cat << END >> $NXT_MAKEFILE
85
86.PHONY:		${NXT_GO}
87
88NXT_ROOT =	`pwd`
89
90GOPATH =	$NXT_GO_PATH
91GOOS =		`go env GOOS`
92GOARCH =	`go env GOARCH`
93
94${NXT_GO}:
95	install -d \$(GOPATH)/src/nginext
96	install -p ./src/nginext/*.c ./src/nginext/*.h \\
97		./src/nginext/*.go \$(GOPATH)/src/nginext/
98	CGO_CFLAGS="-I\$(NXT_ROOT)/build -I\$(NXT_ROOT)/src" \\
99		CGO_LDFLAGS="-L\$(NXT_ROOT)/build" \\
100		GOPATH=$NXT_GO_PATH \\
101		go install -v nginext
102
103${NXT_GO}-uninstall:
104	rm -rf \$(GOPATH)/src/nginext
105	rm -f \$(GOPATH)/pkg/\$(GOOS)_\$(GOARCH)/nginext.a
106
107END
108
109sed -i.bak -e "s/\(all:.*\)/\1 ${NXT_GO}/" $NXT_MAKEFILE
110