aboutsummaryrefslogtreecommitdiff
path: root/INSTALL
blob: 8f123b8542f2e18bf71c40f3e4709aecf61d7b03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/bin/sh

dobuild=true
doinstall=true

case "x$1" in
x)
	;;
x-b)
	dobuild=true
	doinstall=false
	;;
x-c)
	dobuild=false
	doinstall=true
	;;
x-r)
    shift
    PLAN9_TARGET=$1 export PLAN9_TARGET
    ;;
*)
	echo 'usage: INSTALL [-b | -c] [-r path]' 1>&2
	exit 1
esac

PLAN9=`pwd` export PLAN9
PATH=/bin:/usr/bin:$PLAN9/bin:$PATH export PATH
case `uname` in
SunOS)
	awk=nawk
	;;
*)
	awk=awk
	;;
esac

echo "+ Mailing list: http://groups.google.com/group/plan9port-dev"
echo "+ Issue tracker: http://code.swtch.com/plan9port/issues/"
echo "+ Submitting changes: http://swtch.com/go/codereview"
echo " "
echo "* Resetting $PLAN9/config"
rm -f config

(
echo "* Compiler version:"
9c -v 2>&1 | grep -v 'Configured with:' | grep -i version | sed 's/^/	/'

if [ `uname` = FreeBSD ]; then
       echo "* Running on FreeBSD, adjusting linker flags"
       echo "LDFLAGS='-L/usr/local/lib'" >> $PLAN9/config
fi

if [ `uname` = DragonFly ]; then
       echo "* Running on DragonFly BSD, adjusting linker flags"
       echo "LDFLAGS='-L/usr/local/lib -pthread'" >> $PLAN9/config
       echo "CFLAGS='-pthread'" >> $PLAN9/config
fi

if [ `uname` = OpenBSD ]; then
       echo "* Running on OpenBSD, adjusting linker flags"
       echo "LDFLAGS='-L/usr/X11R6/lib -pthread'" >> $PLAN9/config
fi

if [ `uname` = Linux ]; then
	# On Linux, we use the kernel version to decide whether
	# to use pthreads or not.  On 2.6 versions that aren't
	# linking with NPTL by default, pretend to be an older kernel.
	echo "* Running on Linux: checking for NPTL..."
	gcc lib/linux-isnptl.c -lpthread
	if ./a.out >/dev/null
	then	
		echo "	NPTL found."
		echo "SYSVERSION=2.6.x" >>$PLAN9/config
	else
		echo "	NPTL not found."
		echo "SYSVERSION=2.4.x" >>$PLAN9/config
	fi
	rm -f ./a.out
fi

if [ `uname` = SunOS ]; then
	# On Solaris x86, uname -p cannot be trusted.
  echo "* Running on Solaris: checking architecture..."
  case "$(isainfo -n)" in
	*amd64*)
		echo "	x86-64 found."
		echo "OBJTYPE=x86_64" >>$PLAN9/config
		echo "CC9=gcc" >>$PLAN9/config # defaults to gcc on Solaris/amd64
		;;
	*i386*)
		echo "	i386 found."
		echo "OBJTYPE=386" >>$PLAN9/config
		echo "CC9=gcc" >>$PLAN9/config # defaults to gcc on Solaris/i386
		;;
  *sparc*)
		echo "	Sparc found."
		echo "OBJTYPE=sparc" >>$PLAN9/config
		;;
	esac
fi

if [ `uname` = Darwin ]; then
	# On Darwin, uname -m -p cannot be trusted.
	echo "* Running on Darwin: checking architecture..."
	rm -f ./a.out
	if ! gcc lib/darwin-main.c >/dev/null 2>&1; then
		echo "Cannot find gcc. You may need to install the command-line tools using Xcode." >&2
		echo "See http://swtch.com/go/xcodegcc for details." >&2
		exit 1
	fi
	case "$(file ./a.out 2>/dev/null)" in
	*x86_64*)
		echo "	x86-64 found."
		echo "OBJTYPE=x86_64" >>$PLAN9/config
		;;
	*i386*)
		echo "	i386 found."
		echo "OBJTYPE=386" >>$PLAN9/config
		;;
	*ppc*)
		echo "  power found."
		echo "OBJTYPE=power" >>$PLAN9/config
		;;
	esac
	rm -f ./a.out
fi

if [ `uname` != Darwin ]; then
	# Determine whether fontsrv X11 files are available.
	rm -f a.out
	gcc -o a.out -c -Iinclude -I/usr/include -I/usr/local/include -I/usr/include/freetype2 -I/usr/local/include/freetype2 \
	    -I/usr/X11R6/include -I/usr/X11R6/include/freetype2 src/cmd/fontsrv/x11.c >/dev/null 2>&1
	if [ -f a.out ]; then
		echo "	fontsrv dependencies found."
		echo "FONTSRV=fontsrv" >>$PLAN9/config
	else
		echo "	fontsrv dependencies not found."
		echo "FONTSRV=" >>$PLAN9/config
		rm -f bin/fontsrv
	fi
	rm -f a.out
fi

if [ -f LOCAL.config ]; then
	echo Using LOCAL.config options:
	sed 's/^/	/' LOCAL.config
	cat LOCAL.config >>config
fi

cd src
if $dobuild; then
	if [ ! -x ../bin/mk ]; then
		echo "* Building mk..."
		../dist/buildmk 2>&1 | sed 's/^[+] //'
	fi
	if [ ! -x ../bin/mk ]; then
		echo "* Error: mk failed to build."
		exit 1
	fi
	
	echo "* Building everything (be patient)..."
	mk clean
	mk libs-nuke
	mk all || exit 1
	if [ ! -x $PLAN9/src/cmd/o.cleanname -o ! -x $PLAN9/src/cmd/acme/o.acme ]; then
		echo "* Warning: not all binaries built successfully."
	fi
	echo "* Installing everything in $PLAN9/bin..."
	mk -k install || exit 1
	if [ ! -x $PLAN9/bin/cleanname -o ! -x $PLAN9/bin/acme -o ! -x $PLAN9/bin/sam ]; then
		echo " "
		echo "* Warning: not all binaries built successfully."
	fi
	if [ -f $PLAN9/bin/quote1 ]; then
		cp $PLAN9/bin/quote1 $PLAN9/bin/'"'
		cp $PLAN9/bin/quote2 $PLAN9/bin/'""'
	fi
	echo "* Cleaning up..."
	mk clean
fi

if $doinstall; then
	if [ ! -x $PLAN9/bin/cleanname -o ! -x $PLAN9/bin/sam ]; then
		# Cleanname and sam are needed for moveplan9.sh and the man updates.
		if [ ! -x $PLAN9/bin/cleanname ]; then
			echo " "
			echo "* Installation failed: $PLAN9/bin/cleanname does not exist."
			exit 1
		fi
		if [ ! -x $PLAN9/bin/sam ]; then
			echo " "
			echo "* Installation failed: $PLAN9/bin/sam does not exist."
			exit 1
		fi
		echo "* NOT renaming hard-coded /usr/local/plan9 paths."
		echo "* NOT building web manual."
	else
		echo "* Renaming hard-coded /usr/local/plan9 paths..."
		cd $PLAN9
		sh lib/moveplan9.sh
		echo "* Building web manual..."
		(
			cd $PLAN9/dist
			echo cd `pwd`';' mk man
			mk man
		)
	fi
	
	if [ -x LOCAL.INSTALL ]; then
		echo "* Running local modifications..."
		echo cd `pwd`';' ./LOCAL.INSTALL
		./LOCAL.INSTALL
	fi
	
	echo "* Done. "
	echo "	"
	echo "* Add these to your profile environment."
	echo "	PLAN9=$PLAN9 export PLAN9"
	echo '	PATH=$PATH:$PLAN9/bin export PATH'
fi
) 2>&1 | tee install.log | $awk -f $PLAN9/dist/isum.awk -v 'copy='install.sum