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