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 src/cmd/fontsrv/x11.c >/dev/null 2>&1
132 if [ -f a.out ]; then
133 echo " fontsrv dependencies found."
134 echo "FONTSRV=fontsrv" >>$PLAN9/config
135 else
136 echo " fontsrv dependencies not found."
137 echo "FONTSRV=" >>$PLAN9/config
138 rm -f bin/fontsrv
139 fi
140 rm -f a.out
141 fi
143 if [ -f LOCAL.config ]; then
144 echo Using LOCAL.config options:
145 sed 's/^/ /' LOCAL.config
146 cat LOCAL.config >>config
147 fi
149 cd src
150 if $dobuild; then
151 if [ ! -x ../bin/mk ]; then
152 echo "* Building mk..."
153 ../dist/buildmk 2>&1 | sed 's/^[+] //'
154 fi
155 if [ ! -x ../bin/mk ]; then
156 echo "* Error: mk failed to build."
157 exit 1
158 fi
160 echo "* Building everything (be patient)..."
161 mk clean
162 mk libs-nuke
163 mk all || exit 1
164 if [ ! -x $PLAN9/src/cmd/o.cleanname -o ! -x $PLAN9/src/cmd/acme/o.acme ]; then
165 echo "* Warning: not all binaries built successfully."
166 fi
167 echo "* Installing everything in $PLAN9/bin..."
168 mk -k install || exit 1
169 if [ ! -x $PLAN9/bin/cleanname -o ! -x $PLAN9/bin/acme -o ! -x $PLAN9/bin/sam ]; then
170 echo " "
171 echo "* Warning: not all binaries built successfully."
172 fi
173 if [ -f $PLAN9/bin/quote1 ]; then
174 cp $PLAN9/bin/quote1 $PLAN9/bin/'"'
175 cp $PLAN9/bin/quote2 $PLAN9/bin/'""'
176 fi
177 echo "* Cleaning up..."
178 mk clean
179 fi
181 if $doinstall; then
182 if [ ! -x $PLAN9/bin/cleanname -o ! -x $PLAN9/bin/sam ]; then
183 # Cleanname and sam are needed for moveplan9.sh and the man updates.
184 if [ ! -x $PLAN9/bin/cleanname ]; then
185 echo " "
186 echo "* Installation failed: $PLAN9/bin/cleanname does not exist."
187 exit 1
188 fi
189 if [ ! -x $PLAN9/bin/sam ]; then
190 echo " "
191 echo "* Installation failed: $PLAN9/bin/sam does not exist."
192 exit 1
193 fi
194 echo "* NOT renaming hard-coded /usr/local/plan9 paths."
195 echo "* NOT building web manual."
196 else
197 echo "* Renaming hard-coded /usr/local/plan9 paths..."
198 cd $PLAN9
199 sh lib/moveplan9.sh
200 echo "* Building web manual..."
202 cd $PLAN9/dist
203 echo cd `pwd`';' mk man
204 mk man
206 fi
208 if [ -x LOCAL.INSTALL ]; then
209 echo "* Running local modifications..."
210 echo cd `pwd`';' ./LOCAL.INSTALL
211 ./LOCAL.INSTALL
212 fi
214 echo "* Done. "
215 echo " "
216 echo "* Add these to your profile environment."
217 echo " PLAN9=$PLAN9 export PLAN9"
218 echo ' PATH=$PATH:$PLAN9/bin export PATH'
219 fi
220 ) 2>&1 | tee install.log | $awk -f $PLAN9/dist/isum.awk -v 'copy='install.sum