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 # On Darwin, uname -m -p cannot be trusted.
108 echo "* Running on Darwin: checking architecture..."
109 rm -f ./a.out
110 if ! gcc lib/darwin-main.c >/dev/null 2>&1; then
111 echo "Cannot find gcc. You may need to install the command-line tools using Xcode." >&2
112 echo "See http://swtch.com/go/xcodegcc for details." >&2
113 exit 1
114 fi
115 case "$(file ./a.out 2>/dev/null)" in
116 *x86_64*)
117 echo " x86-64 found."
118 echo "OBJTYPE=x86_64" >>$PLAN9/config
119 echo "CC9='xcrun --sdk macosx clang'" >>$PLAN9/config
120 ;;
121 *i386*)
122 echo " i386 found."
123 echo "OBJTYPE=386" >>$PLAN9/config
124 ;;
125 *ppc*)
126 echo " power found."
127 echo "OBJTYPE=power" >>$PLAN9/config
128 ;;
129 esac
130 rm -f ./a.out
131 fi
133 if [ `uname` != Darwin ]; then
134 # Determine whether fontsrv X11 files are available.
135 rm -f a.out
136 gcc -o a.out -c -Iinclude -I/usr/include -I/usr/local/include -I/usr/include/freetype2 -I/usr/local/include/freetype2 \
137 -I/usr/X11R6/include -I/usr/X11R6/include/freetype2 src/cmd/fontsrv/x11.c >/dev/null 2>&1
138 if [ -f a.out ]; then
139 echo " fontsrv dependencies found."
140 echo "FONTSRV=fontsrv" >>$PLAN9/config
141 else
142 echo " fontsrv dependencies not found."
143 echo "FONTSRV=" >>$PLAN9/config
144 rm -f bin/fontsrv
145 fi
146 rm -f a.out
147 fi
149 if [ -f LOCAL.config ]; then
150 echo Using LOCAL.config options:
151 sed 's/^/ /' LOCAL.config
152 cat LOCAL.config >>config
153 fi
155 echo "* Compiler version:"
156 9c -v 2>&1 | grep -v 'Configured with:' | grep -i version | sed 's/^/ /'
158 cd src
159 if $dobuild; then
160 if [ ! -x ../bin/mk ]; then
161 echo "* Building mk..."
162 ../dist/buildmk 2>&1 | sed 's/^[+] //'
163 fi
164 if [ ! -x ../bin/mk ]; then
165 echo "* Error: mk failed to build."
166 exit 1
167 fi
169 echo "* Building everything (be patient)..."
170 mk clean
171 mk libs-nuke
172 mk all || exit 1
173 if [ ! -x $PLAN9/src/cmd/o.cleanname -o ! -x $PLAN9/src/cmd/acme/o.acme ]; then
174 echo "* Warning: not all binaries built successfully."
175 fi
176 echo "* Installing everything in $PLAN9/bin..."
177 mk -k install || exit 1
178 if [ ! -x $PLAN9/bin/cleanname -o ! -x $PLAN9/bin/acme -o ! -x $PLAN9/bin/sam ]; then
179 echo " "
180 echo "* Warning: not all binaries built successfully."
181 fi
182 if [ -f $PLAN9/bin/quote1 ]; then
183 cp $PLAN9/bin/quote1 $PLAN9/bin/'"'
184 cp $PLAN9/bin/quote2 $PLAN9/bin/'""'
185 fi
186 echo "* Cleaning up..."
187 mk clean
188 fi
190 if $doinstall; then
191 if [ ! -x $PLAN9/bin/cleanname -o ! -x $PLAN9/bin/sam ]; then
192 # Cleanname and sam are needed for moveplan9.sh and the man updates.
193 if [ ! -x $PLAN9/bin/cleanname ]; then
194 echo " "
195 echo "* Installation failed: $PLAN9/bin/cleanname does not exist."
196 exit 1
197 fi
198 if [ ! -x $PLAN9/bin/sam ]; then
199 echo " "
200 echo "* Installation failed: $PLAN9/bin/sam does not exist."
201 exit 1
202 fi
203 echo "* NOT renaming hard-coded /usr/local/plan9 paths."
204 echo "* NOT building web manual."
205 else
206 echo "* Renaming hard-coded /usr/local/plan9 paths..."
207 cd $PLAN9
208 sh lib/moveplan9.sh
209 echo "* Building web manual..."
211 cd $PLAN9/dist
212 echo cd `pwd`';' mk man
213 mk man
215 fi
217 if [ -x LOCAL.INSTALL ]; then
218 echo "* Running local modifications..."
219 echo cd `pwd`';' ./LOCAL.INSTALL
220 ./LOCAL.INSTALL
221 fi
223 echo "* Done. "
224 echo " "
225 echo "* Add these to your profile environment."
226 echo " PLAN9=$PLAN9 export PLAN9"
227 echo ' PATH=$PATH:$PLAN9/bin export PATH'
228 fi
229 ) 2>&1 | tee install.log | $awk -f $PLAN9/dist/isum.awk -v 'copy='install.sum