xref: /unit/auto/modules/go (revision 1131:ec7d924d8dfb)
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
43if [ ! -f $NXT_AUTOCONF_DATA ]; then
44   echo
45   echo Please run common $0 before configuring module \"$nxt_module\".
46   echo
47   exit 1
48fi
49
50. $NXT_AUTOCONF_DATA
51
52
53$echo "configuring Go package"
54$echo "configuring Go package ..." >> $NXT_AUTOCONF_ERR
55
56$echo -n "checking for Go ..."
57$echo "checking for Go ..." >> $NXT_AUTOCONF_ERR
58
59
60if /bin/sh -c "${NXT_GO} version" >> $NXT_AUTOCONF_ERR 2>&1; then
61    $echo " found"
62
63    NXT_GO_VERSION="`${NXT_GO} version`"
64    $echo " + ${NXT_GO_VERSION}"
65
66else
67    $echo
68    $echo $0: error: no Go found.
69    $echo
70    exit 1;
71fi
72
73
74NXT_GO_PATH=${NXT_GO_PATH=`${NXT_GO} env GOPATH`}
75NXT_GO_PATH=${NXT_GO_PATH:-`pwd`/${NXT_GO}}
76
77$echo " + Go package path: \"${NXT_GO_PATH}\""
78
79if grep ^$NXT_GO: $NXT_MAKEFILE 2>&1 > /dev/null; then
80    $echo
81    $echo $0: error: duplicate \"$NXT_GO\" package configured.
82    $echo
83    exit 1;
84fi
85
86cat << END >> $NXT_MAKEFILE
87
88.PHONY: ${NXT_GO}
89.PHONY: ${NXT_GO}-install
90.PHONY: ${NXT_GO}-install-src
91.PHONY: ${NXT_GO}-install-build
92.PHONY: ${NXT_GO}-uninstall
93
94GOPATH =	$NXT_GO_PATH
95GOOS =		`${NXT_GO} env GOOS`
96GOARCH =	`${NXT_GO} env GOARCH`
97
98NXT_GO_DST =	${NXT_GO_PATH%%:*}
99
100install: ${NXT_GO}-install
101
102${NXT_GO}:
103
104${NXT_GO}-install: ${NXT_GO}-install-build
105
106${NXT_GO}-install-src: ${NXT_VERSION_H}
107	install -d \$(DESTDIR)\$(NXT_GO_DST)/src/nginx/unit
108	install -p -m644 ./src/*.h ./build/*.h ./src/go/unit/* \
109    ./src/nxt_unit.c ./src/nxt_lvlhsh.c ./src/nxt_murmur_hash.c \
110    ./src/nxt_websocket.c \
111    \$(DESTDIR)\$(NXT_GO_DST)/src/nginx/unit/
112
113${NXT_GO}-install-build: ${NXT_GO}-install-src
114	GOPATH=\$(DESTDIR)\$(GOPATH) ${NXT_GO} build nginx/unit
115
116
117uninstall: ${NXT_GO}-uninstall
118
119${NXT_GO}-uninstall:
120	rm -rf \$(DESTDIR)\$(NXT_GO_DST)/src/nginx/unit
121	rm -rf \$(DESTDIR)\$(NXT_GO_DST)/pkg/\$(GOOS)_\$(GOARCH)/nginx/unit
122
123END
124