2010年2月27日土曜日

Google Goをスクリプトでインストールする。

本家サイト(Google Go Language)
参考ページ

$source install_go.sh
管理者権限を与えずにインストールを開始する。

install_go.sh
#!/bin/bash

#make working directory
mkdir -p ~/gcode/go


#set environment variable
GOROOT=$HOME/gcode/go
GOBIN=$GOROOT/local/bin

echo "export GOROOT=$GOROOT" >> ~/.bashrc
echo "export GOOS=linux" >> ~/.bashrc
echo "export GOARCH=386" >> ~/.bashrc
echo "export GOBIN=$GOBIN" >> ~/.bashrc
echo "export PATH=$PATH:$GOBIN" >> ~/.bashrc
source ~/.bashrc


#prepare to build and install Google go 
sudo apt-get install python-setuptools python-dev build-essential mercurial bison gcc libc6-dev ed gawk make


#Download Google Go Sourcecode
hg clone -r release https://go.googlecode.com/hg/ $GOROOT


#build and install go
mkdir -p $GOBIN
cd $GOROOT/src
./all.bash >> install_log.txt


#make "HelloWorld"
echo "package main" >> $GOROOT/hello.go
echo 'import "fmt"' >> $GOROOT/hello.go
echo "" >> $GOROOT/hello.go
echo "func main(){" >> $GOROOT/hello.go
echo '  fmt.Printf("Hello 世界\n")' >> $GOROOT/hello.go
echo "}" >> $GOROOT/hello.go


#Compile and Execute HelloWorld -> It's not works in bash
#8g $GOROOT/hello.go
#8l -o $GOROOT/hello $GOROOT/hello.8
#$GOROOT/hello

#!/bin/bash

#make working directory
mkdir -p ~/gcode/go


#set environment variable
echo "export GOROOT=$HOME/gcode/go" >> ~/.bashrc
echo "export GOOS=linux" >> ~/.bashrc
echo "export GOARCH=386" >> ~/.bashrc
echo "export GOBIN=$GOROOT/local/bin" >> ~/.bashrc
echo "export PATH=$PATH:$GOBIN" >> ~/.bashrc
source ~/.bashrc


#prepare to build and install Google go 
sudo apt-get install python-setuptools python-dev build-essential mercurial bison gcc libc6-dev ed gawk make


#Download Google Go Sourcecode
hg clone -r release https://go.googlecode.com/hg/ $GOROOT


#build and install go
mkdir -p $GOBIN
cd $GOROOT/src
./all.bash >> install_log.txt


#make "HelloWorld"
echo "package main" >> $GOROOT/hello.go
echo 'import "fmt"' >> $GOROOT/hello.go
echo "" >> $GOROOT/hello.go
echo "func main(){" >> $GOROOT/hello.go
echo '  fmt.Printf("Hello 世界\n")' >> $GOROOT/hello.go
echo "}" >> $GOROOT/hello.go


#Compile and Execute HelloWorld -> It's not works in bash
#8g $GOROOT/hello.go
#8l -o $GOROOT/hello $GOROOT/hello.8
#$GOROOT/hello
最初の作業ディレクトリのところと8行目の環境変数GOROOTの定義、環境変数GOBINの定義はお好みでやるとしてそれ以外はほっといてもインストールできる(はず、自分はできた)。

っていうかgccの開発者がそのうちgccにgoのコンパイラ統合するって話だから、こんなことしなくてもよかったのかもしれない。

追記:
アップデートしたい場合は
cd $GOROOT/src
hg pull
hg update release
./all.bash
とする。結構な頻度でソースコードは変更されてるみたい。

0 件のコメント:

コメントを投稿