1
- #! /bin/sh -e
1
+ #! /usr/bin/env bash
2
+
3
+ set -e
2
4
3
5
llgodir=$( dirname " $0 " )
4
6
llgodir=$( cd " $llgodir " && pwd)
@@ -7,73 +9,136 @@ workdir=$llgodir/workdir
7
9
gofrontenddir=$workdir /gofrontend
8
10
gofrontend_builddir=$workdir /gofrontend_build
9
11
10
- bootstrap_type=" $1 "
11
- shift
12
-
13
- case " $bootstrap_type " in
14
- quick | full)
12
+ case " $1 " in
13
+ libgodeps | quick | full)
14
+ bootstrap_type=" $1 "
15
+ shift
15
16
;;
16
17
17
18
* )
18
- echo " Bootstrap type must be 'quick' or 'full'"
19
- exit 1
20
19
;;
21
20
esac
22
21
23
- configure_flags=" --disable-multilib --without-libatomic"
22
+ llgo_cc=" ${LIBGO_CC:- $workdir / clang_build/ bin/ clang} $LIBGO_CFLAGS "
23
+ llgo_cxx=" ${LIBGO_CXX:- $workdir / clang_build/ bin/ clang++} $LIBGO_CFLAGS "
24
+
25
+ build_libgodeps () {
26
+ local cflags=" $1 "
27
+ local destdir=" $2 "
28
+ local variantname=" $3 "
29
+ local makeflags=" $4 "
30
+
31
+ for d in libbacktrace libffi ; do
32
+ rm -rf $destdir /$d
33
+ mkdir -p $destdir /$d
34
+ case $d in
35
+ libbacktrace)
36
+ config_flags=" --enable-host-shared"
37
+ ;;
38
+ * )
39
+ config_flags=" "
40
+ ;;
41
+ esac
42
+
43
+ echo " # Configuring $variantname $d ."
44
+ (cd $destdir /$d && CC=" $llgo_cc $cflags " $gofrontenddir /$d /configure --disable-multilib $config_flags > $workdir /${d} -config.log 2>&1 || (echo " # Configure failed, see $workdir /${d} -config.log" && exit 1))
45
+ echo " # Building $variantname $d ."
46
+ make -C $destdir /$d $makeflags > $workdir /${d} -make.log 2>&1 || (echo " # Build failed, see $workdir /${d} -make.log" && exit 1)
47
+ done
48
+ }
49
+
50
+ build_libgo_stage () {
51
+ local goc=" $1 "
52
+ local cflags=" $2 "
53
+ local gocflags=" $3 "
54
+ local destdir=" $4 "
55
+ local variantname=" $5 "
56
+ local makeflags=" $6 "
57
+
58
+ # Wrap Clang in a program that understands -fgo-dump-spec and -fplan9-extensions.
59
+ libgo_cc=" $llgo_cc $cflags "
60
+ libgo_wrapped_cc=" env REAL_CC=$( echo $libgo_cc | sed -e ' s/ /@SPACE@/g' ) $workdir /cc-wrapper"
61
+
62
+ mkdir -p $destdir
63
+ echo " # Configuring $variantname libgo."
64
+ (cd $destdir && $gofrontenddir /libgo/configure --disable-multilib --without-libatomic CC=" $libgo_wrapped_cc " GOC=" $goc -no-prefix $GOCFLAGS $gocflags " > $workdir /${variantname} -config.log 2>&1 || (echo " # Configure failed, see $workdir /${variantname} -config.log" && exit 1))
65
+ echo " # Building $variantname libgo."
66
+ make -C $destdir $makeflags 2>&1 | tee $workdir /${variantname} -make.log | $workdir /makefilter
67
+ test " ${PIPESTATUS[0]} " = " 0" || (echo " # Build failed, see $workdir /${variantname} -make.log" && exit 1)
68
+ echo
69
+ }
70
+
71
+ build_libgo_variant () {
72
+ local goc=" $1 "
73
+ local cflags=" $2 "
74
+ local gocflags=" $3 "
75
+ local variantname=" $4 "
76
+ local makeflags=" $5 "
77
+
78
+ local destdir=" $workdir /gofrontend_build_$variantname "
79
+ rm -rf $destdir
80
+ build_libgodeps " $cflags " " $destdir " " $variantname " " $makeflags "
81
+ build_libgo_stage " $goc " " $cflags " " $gocflags " " $destdir /libgo" " $variantname " " $makeflags "
82
+ }
83
+
84
+ if [ " $bootstrap_type " = " libgodeps" ]; then
85
+ build_libgodeps " $LIBGO_CFLAGS " " $gofrontend_builddir " " normal" " $* "
86
+ touch $workdir /.build-libgodeps-stamp
87
+ exit 0
88
+ fi
24
89
25
- # Wrap Clang in a program that understands -fgo-dump-spec and -fplan9-extensions.
26
- (cd $llgodir /cmd/cc-wrapper && go build -o $workdir /cc-wrapper)
27
- libgo_wrapped_cc=" $( echo " ${LIBGO_CC:- $workdir / clang_build/ bin/ clang} " | sed -e ' s/ /@SPACE@/g' ) "
28
- libgo_cc=" env REAL_CC=${libgo_wrapped_cc} $workdir /cc-wrapper"
90
+ if [ " $bootstrap_type " != " " ]; then
91
+ # Clean up any previous libgo stages.
92
+ rm -rf $gofrontend_builddir /libgo* $workdir /gofrontend_build_*
29
93
30
- # Clean up any previous libgo stages.
31
- rm -rf $gofrontend_builddir /libgo*
94
+ echo " # Building helper programs."
95
+ (cd $llgodir /cmd/cc-wrapper && go build -o $workdir /cc-wrapper)
96
+ (cd $llgodir /cmd/makefilter && go build -o $workdir /makefilter)
32
97
33
- # Build a stage1 compiler with gc.
34
- (cd $llgodir /cmd/gllgo && go build -o $workdir /gllgo-stage1)
98
+ # Build a stage1 compiler with gc.
99
+ echo " # Building stage1 compiler."
100
+ (cd $llgodir /cmd/gllgo && go build -o $workdir /gllgo-stage1)
35
101
36
- # Build libgo with the stage1 compiler.
37
- mkdir -p $gofrontend_builddir /libgo-stage1
38
- (cd $gofrontend_builddir /libgo-stage1 && $gofrontenddir /libgo/configure $configure_flags CC=" $libgo_cc " GOC=" $workdir /gllgo-stage1 -no-prefix" )
39
- make -C $gofrontend_builddir /libgo-stage1 " $@ "
102
+ # Build libgo with the stage1 compiler.
103
+ build_libgo_stage $workdir /gllgo-stage1 " " " " $gofrontend_builddir /libgo-stage1 stage1 " $* "
40
104
41
- # Set up a directory which when added to $PATH causes "gccgo" to resolve
42
- # to our stage1 compiler. This is necessary because the logic in "go build"
43
- # for locating the compiler is fixed.
44
- mkdir -p $gofrontend_builddir /stage1-path
45
- ln -sf $workdir /gllgo-stage1 $gofrontend_builddir /stage1-path/gccgo
105
+ # Set up a directory which when added to $PATH causes "gccgo" to resolve
106
+ # to our stage1 compiler. This is necessary because the logic in "go build"
107
+ # for locating the compiler is fixed.
108
+ mkdir -p $gofrontend_builddir /stage1-path
109
+ ln -sf $workdir /gllgo-stage1 $gofrontend_builddir /stage1-path/gccgo
46
110
47
- # Build a stage2 compiler using the stage1 compiler and libgo.
48
- gllgoflags=" -no-prefix -L$gofrontend_builddir /libgo-stage1 -L$gofrontend_builddir /libgo-stage1/.libs -static-libgo"
49
- (cd $llgodir /cmd/gllgo && PATH=$gofrontend_builddir /stage1-path:$PATH go build -compiler gccgo -gccgoflags " $gllgoflags " -o $workdir /gllgo-stage2)
111
+ # Build a stage2 compiler using the stage1 compiler and libgo.
112
+ echo " # Building stage2 compiler."
113
+ gllgoflags=" -no-prefix -L$gofrontend_builddir /libgo-stage1 -L$gofrontend_builddir /libgo-stage1/.libs -static-libgo $GOCFLAGS "
114
+ (cd $llgodir /cmd/gllgo && PATH=$gofrontend_builddir /stage1-path:$PATH CC=" $llgo_cc " CXX=" $llgo_cxx " go build -compiler gccgo -gccgoflags " $gllgoflags " -o $workdir /gllgo-stage2)
50
115
51
- # If this is a quick bootstrap, do not rebuild libgo with the stage2 compiler.
52
- # Instead, use the stage1 libgo.
116
+ # If this is a quick bootstrap, do not rebuild libgo with the stage2 compiler.
117
+ # Instead, use the stage1 libgo.
53
118
54
- if [ " $bootstrap_type " == " full" ] ; then
55
- # Build libgo with the stage2 compiler.
56
- mkdir -p $gofrontend_builddir /libgo-stage2
57
- (cd $gofrontend_builddir /libgo-stage2 && $gofrontenddir /libgo/configure $configure_flags CC=" $libgo_cc " GOC=" $workdir /gllgo-stage2 -no-prefix" )
58
- make -C $gofrontend_builddir /libgo-stage2 " $@ "
119
+ if [ " $bootstrap_type " == " full" ] ; then
120
+ # Build libgo with the stage2 compiler.
121
+ build_libgo_stage $workdir /gllgo-stage2 " " " " $gofrontent_builddir /libgo-stage2 stage2 " $* "
59
122
60
- # Set up $gllgoflags to use the stage2 libgo.
61
- gllgoflags=" -no-prefix -L$gofrontend_builddir /libgo-stage2 -L$gofrontend_builddir /libgo-stage2/.libs -static-libgo"
62
- fi
123
+ # Set up $gllgoflags to use the stage2 libgo.
124
+ gllgoflags=" -no-prefix -L$gofrontend_builddir /libgo-stage2 -L$gofrontend_builddir /libgo-stage2/.libs -static-libgo $GOCFLAGS "
125
+ fi
63
126
64
- # Set up a directory which when added to $PATH causes "gccgo" to resolve
65
- # to our stage2 compiler.
66
- mkdir -p $gofrontend_builddir /stage2-path
67
- ln -sf $workdir /gllgo-stage2 $gofrontend_builddir /stage2-path/gccgo
127
+ # Set up a directory which when added to $PATH causes "gccgo" to resolve
128
+ # to our stage2 compiler.
129
+ mkdir -p $gofrontend_builddir /stage2-path
130
+ ln -sf $workdir /gllgo-stage2 $gofrontend_builddir /stage2-path/gccgo
68
131
69
- # Build the stage3 compiler.
70
- (cd $llgodir /cmd/gllgo && PATH=$gofrontend_builddir /stage2-path:$PATH go build -compiler gccgo -gccgoflags " $gllgoflags " -o $workdir /gllgo-stage3)
132
+ # Build the stage3 compiler.
133
+ echo " # Building stage3 compiler."
134
+ (cd $llgodir /cmd/gllgo && PATH=$gofrontend_builddir /stage2-path:$PATH CC=" $llgo_cc " CXX=" $llgo_cxx " go build -compiler gccgo -gccgoflags " $gllgoflags " -o $workdir /gllgo-stage3)
71
135
72
- # Strip the compiler binaries. The binaries are currently only
73
- # expected to compare equal modulo debug info.
74
- strip -R .note.gnu.build-id -o $workdir /gllgo-stage2.stripped $workdir /gllgo-stage2
75
- strip -R .note.gnu.build-id -o $workdir /gllgo-stage3.stripped $workdir /gllgo-stage3
136
+ # Strip the compiler binaries. The binaries are currently only
137
+ # expected to compare equal modulo debug info.
138
+ strip -R .note.gnu.build-id -o $workdir /gllgo-stage2.stripped $workdir /gllgo-stage2
139
+ strip -R .note.gnu.build-id -o $workdir /gllgo-stage3.stripped $workdir /gllgo-stage3
76
140
77
- cmp $workdir /gllgo-stage2.stripped $workdir /gllgo-stage3.stripped && \
78
- echo " Bootstrap completed successfully" && touch $workdir /.bootstrap-stamp && exit 0 || \
79
- echo " Bootstrap failed, binaries differ" && exit 1
141
+ cmp $workdir /gllgo-stage2.stripped $workdir /gllgo-stage3.stripped && \
142
+ echo " # Bootstrap completed successfully." && touch $workdir /.bootstrap-stamp || \
143
+ (echo " # Bootstrap failed, binaries differ." && exit 1)
144
+ fi
0 commit comments