Blob


1 #!/bin/sh
3 dobuild=true
4 doinstall=true
6 case "x$1" in
7 x)
8 ;;
9 x-b)
10 dobuild=true
11 doinstall=false
12 ;;
13 x-c)
14 dobuild=false
15 doinstall=true
16 ;;
17 x-r)
18 shift
19 PLAN9_TARGET=$1 export PLAN9_TARGET
20 ;;
21 *)
22 echo 'usage: INSTALL [-b | -c] [-r path]' 1>&2
23 exit 1
24 esac
26 PLAN9=`pwd` export PLAN9
27 PATH=/bin:/usr/bin:$PLAN9/bin:$PATH export PATH
28 case `uname` in
29 SunOS)
30 awk=nawk
31 ;;
32 *)
33 awk=awk
34 ;;
35 esac
37 echo "+ Mailing list: http://groups.google.com/group/plan9port-dev"
38 echo "+ Issue tracker: http://code.swtch.com/plan9port/issues/"
39 echo "+ Submitting changes: http://swtch.com/go/codereview"
40 echo " "
41 echo "* Resetting $PLAN9/config"
42 rm -f config
44 (
45 echo "* Compiler version:"
46 9c -v 2>&1 | grep -v 'Configured with:' | grep -i version | sed 's/^/ /'
48 if [ `uname` = FreeBSD ]; then
49 echo "* Running on FreeBSD, adjusting linker flags"
50 echo "LDFLAGS='-L/usr/local/lib'" >> $PLAN9/config
51 fi
53 if [ `uname` = DragonFly ]; then
54 echo "* Running on DragonFly BSD, adjusting linker flags"
55 echo "LDFLAGS='-L/usr/local/lib -pthread'" >> $PLAN9/config
56 echo "CFLAGS='-pthread'" >> $PLAN9/config
57 fi
59 if [ `uname` = OpenBSD ]; then
60 echo "* Running on OpenBSD, adjusting linker flags"
61 echo "LDFLAGS='-L/usr/X11R6/lib -pthread'" >> $PLAN9/config
62 fi
64 if [ `uname` = Linux ]; then
65 # On Linux, we use the kernel version to decide whether
66 # to use pthreads or not. On 2.6 versions that aren't
67 # linking with NPTL by default, pretend to be an older kernel.
68 echo "* Running on Linux: checking for NPTL..."
69 gcc lib/linux-isnptl.c -lpthread
70 if ./a.out >/dev/null
71 then
72 echo " NPTL found."
73 echo "SYSVERSION=2.6.x" >>$PLAN9/config
74 else
75 echo " NPTL not found."
76 echo "SYSVERSION=2.4.x" >>$PLAN9/config
77 fi
78 rm -f ./a.out
79 fi
81 if [ `uname` = SunOS ]; then
82 # On Solaris x86, uname -p cannot be trusted.
83 echo "* Running on Solaris: checking architecture..."
84 case "$(isainfo -n)" in
85 *amd64*)
86 echo " x86-64 found."
87 echo "OBJTYPE=x86_64" >>$PLAN9/config
88 echo "CC9=gcc" >>$PLAN9/config # defaults to gcc on Solaris/amd64
89 ;;
90 *i386*)
91 echo " i386 found."
92 echo "OBJTYPE=386" >>$PLAN9/config
93 echo "CC9=gcc" >>$PLAN9/config # defaults to gcc on Solaris/i386
94 ;;
95 *sparc*)
96 echo " Sparc found."
97 echo "OBJTYPE=sparc" >>$PLAN9/config
98 ;;
99 esac
100 fi
102 if [ `uname` = Darwin ]; then
103 # On Darwin, uname -m -p cannot be trusted.
104 echo "* Running on Darwin: checking architecture..."
105 rm -f ./a.out
106 if ! gcc lib/darwin-main.c >/dev/null 2>&1; then
107 echo "Cannot find gcc. You may need to install the command-line tools using Xcode." >&2
108 echo "See http://swtch.com/go/xcodegcc for details." >&2
109 exit 1
110 fi
111 case "$(file ./a.out 2>/dev/null)" in
112 *x86_64*)
113 echo " x86-64 found."
114 echo "OBJTYPE=x86_64" >>$PLAN9/config
115 ;;
116 *i386*)
117 echo " i386 found."
118 echo "OBJTYPE=386" >>$PLAN9/config
119 ;;
120 *ppc*)
121 echo " power found."
122 echo "OBJTYPE=power" >>$PLAN9/config
123 ;;
124 esac
125 rm -f ./a.out
126 fi
128 if [ `uname` != Darwin ]; then
129 # Determine whether fontsrv X11 files are available.
130 rm -f a.out
131 gcc -o a.out -c -Iinclude -I/usr/include -I/usr/local/include -I/usr/include/freetype2 -I/usr/local/include/freetype2 \
132 -I/usr/X11R6/include -I/usr/X11R6/include/freetype2 src/cmd/fontsrv/x11.c >/dev/null 2>&1
133 if [ -f a.out ]; then
134 echo " fontsrv dependencies found."
135 echo "FONTSRV=fontsrv" >>$PLAN9/config
136 else
137 echo " fontsrv dependencies not found."
138 echo "FONTSRV=" >>$PLAN9/config
139 rm -f bin/fontsrv
140 fi
141 rm -f a.out
142 fi
144 if [ -f LOCAL.config ]; then
145 echo Using LOCAL.config options:
146 sed 's/^/ /' LOCAL.config
147 cat LOCAL.config >>config
148 fi
150 cd src
151 if $dobuild; then
152 if [ ! -x ../bin/mk ]; then
153 echo "* Building mk..."
154 ../dist/buildmk 2>&1 | sed 's/^[+] //'
155 fi
156 if [ ! -x ../bin/mk ]; then
157 echo "* Error: mk failed to build."
158 exit 1
159 fi
161 echo "* Building everything (be patient)..."
162 mk clean
163 mk libs-nuke
164 mk all || exit 1
165 if [ ! -x $PLAN9/src/cmd/o.cleanname -o ! -x $PLAN9/src/cmd/acme/o.acme ]; then
166 echo "* Warning: not all binaries built successfully."
167 fi
168 echo "* Installing everything in $PLAN9/bin..."
169 mk -k install || exit 1
170 if [ ! -x $PLAN9/bin/cleanname -o ! -x $PLAN9/bin/acme -o ! -x $PLAN9/bin/sam ]; then
171 echo " "
172 echo "* Warning: not all binaries built successfully."
173 fi
174 if [ -f $PLAN9/bin/quote1 ]; then
175 cp $PLAN9/bin/quote1 $PLAN9/bin/'"'
176 cp $PLAN9/bin/quote2 $PLAN9/bin/'""'
177 fi
178 echo "* Cleaning up..."
179 mk clean
180 fi
182 if $doinstall; then
183 if [ ! -x $PLAN9/bin/cleanname -o ! -x $PLAN9/bin/sam ]; then
184 # Cleanname and sam are needed for moveplan9.sh and the man updates.
185 if [ ! -x $PLAN9/bin/cleanname ]; then
186 echo " "
187 echo "* Installation failed: $PLAN9/bin/cleanname does not exist."
188 exit 1
189 fi
190 if [ ! -x $PLAN9/bin/sam ]; then
191 echo " "
192 echo "* Installation failed: $PLAN9/bin/sam does not exist."
193 exit 1
194 fi
195 echo "* NOT renaming hard-coded /usr/local/plan9 paths."
196 echo "* NOT building web manual."
197 else
198 echo "* Renaming hard-coded /usr/local/plan9 paths..."
199 cd $PLAN9
200 sh lib/moveplan9.sh
201 echo "* Building web manual..."
203 cd $PLAN9/dist
204 echo cd `pwd`';' mk man
205 mk man
207 fi
209 if [ -x LOCAL.INSTALL ]; then
210 echo "* Running local modifications..."
211 echo cd `pwd`';' ./LOCAL.INSTALL
212 ./LOCAL.INSTALL
213 fi
215 echo "* Done. "
216 echo " "
217 echo "* Add these to your profile environment."
218 echo " PLAN9=$PLAN9 export PLAN9"
219 echo ' PATH=$PATH:$PLAN9/bin export PATH'
220 fi
221 ) 2>&1 | tee install.log | $awk -f $PLAN9/dist/isum.awk -v 'copy='install.sum