1#!/bin/sh
2
3# Builds a GCC package from the sources.
4#
5# Usage: build-gcc2-package-Haiku.sh <version date> <release>
6#   <version date> must be version date string formatted YYMMDD.
7#   <release> must be a number between 1 and 99.
8
9# get version date and release parameters
10if [ $# -ne 2 ]; then
11	echo "Usage: $0 <version date YYMMDD> <release>" >&2
12	exit 1
13fi
14
15export GCCDATE=$1
16release=$2
17
18# get current dir and buildtools dir
19currentDir="$(pwd)/build-gcc-package"
20rm -rf "$currentDir"
21mkdir "$currentDir"
22cd "$(dirname $0)"
23buildtoolsDir="$(pwd)/legacy"
24cd "$currentDir"
25
26# prepare an install dir with a .PackageInfo
27installDir="$currentDir/install"
28rm -rf "$installDir"
29mkdir "$installDir"
30
31version=2.95.3_${GCCDATE}
32
33packageInfoFile="package-info"
34
35cat > "$packageInfoFile" << ENDOFHERE
36	name			gcc
37	version			$version-$release
38	architecture	x86_gcc2
39	summary			"c/c++ compiler"
40	description		"standard compiler for x86_gcc2 platform, ABI-compatible with BeOS R5"
41	packager		"Oliver Tappe <zooey@hirschkaefer.de>"
42	vendor			"Haiku Project"
43	copyrights		"1988-2000 Free Software Foundation, Inc."
44	licenses {
45		"GNU GPL v2"
46		"GNU LGPL v2"
47	}
48	provides {
49		gcc = $version compat >= 2.95.3
50		binutils = 2.17_$GCCDATE compat >= 2.17
51	}
52	requires {
53		haiku >= r1-alpha3
54		haiku-devel >= r1-alpha3
55	}
56ENDOFHERE
57
58# create a build package
59versionedPackageName=gcc-$version-$release
60packageFileName="$versionedPackageName-x86_gcc2.hpkg"
61packageFile="$currentDir/$packageFileName"
62
63echo "Creating build package..."
64package create -b -I "$installDir" -i "$packageInfoFile" $packageFile ||
65	exit 1
66
67# activate the package
68rm -f /boot/common/packages/$packageFileName
69ln -s "$packageFile" /boot/common/packages
70
71finalInstallDir="/packages/$versionedPackageName/.self"
72
73sleep 1
74
75if [ ! -e "$finalInstallDir" ]; then
76	echo "Activating the build package failed!"
77	exit 1
78fi
79
80gccInstallDir="$finalInstallDir/develop/tools/gcc-2.95.3-${GCCDATE}"
81mkdir -p "$gccInstallDir"
82
83# build binutils
84mkdir binutils-obj
85cd binutils-obj
86CFLAGS="-O2" CXXFLAGS="-O2" "$buildtoolsDir/binutils/configure" \
87	--prefix=$gccInstallDir \
88	--disable-nls --enable-shared=yes || exit 1
89make || exit 1
90make install || exit 1
91cd ..
92
93# build gcc
94mkdir gcc-obj
95cd gcc-obj
96CFLAGS="-O2" CXXFLAGS="-O2" "$buildtoolsDir/gcc/configure" \
97	--prefix=$gccInstallDir \
98	--disable-nls --enable-shared=yes --enable-languages=c,c++ || exit 1
99make bootstrap
100	# the above will fail when compiling builtinbuf.cc, but we can ignore that
101	# since it's trying to build libstdc++.so, which haiku provides anyway
102make install || exit 1
103cd ..
104
105
106base=$gccInstallDir
107
108### HTML documentation ####################################
109
110html_base=$base/html-docs
111if [ ! -d "$html_base" ]; then
112	echo "Building HTML documentation..."
113	mkdir $html_base
114	cd $html_base
115
116	makeinfo --html "$buildtoolsDir/gcc/gcc/cpp.texi"
117	makeinfo --html "$buildtoolsDir/gcc/gcc/gcc.texi"
118	makeinfo --html "$buildtoolsDir/binutils/libiberty/libiberty.texi"
119	makeinfo --force --html "$buildtoolsDir/gcc/libio/iostream.texi"
120
121	ln -sf cpp/index.html $html_base/cpp.html
122	ln -sf gcc/index.html $html_base/gcc.html
123	ln -sf libiberty/index.html $html_base/libiberty.html
124	ln -sf iostream/index.html $html_base/iostream.html
125fi
126if [ -d "$base/share/doc" ]; then
127	echo "Adding binutils HTML documentation..."
128
129	mv $base/share/doc/as.html $html_base/as
130	mv $base/share/doc/binutils.html $html_base/binutils
131	mv $base/share/doc/gprof.html $html_base/gprof
132	mv $base/share/doc/ld.html $html_base/ld
133	#mv $base/share/doc/configure.html $html_base/
134
135	ln -sf as/index.html $html_base/as.html
136	ln -sf binutils/index.html $html_base/binutils.html
137	ln -sf gprof/index.html $html_base/gprof.html
138	ln -sf ld/index.html $html_base/ld.html
139fi
140if [ ! -e "$html_base/as.html" ]; then
141	echo "binutils HTML documentation missing, see" \
142		"INSTALL-gcc2-from-source-Haiku."
143fi
144
145### Cleanup ###############################################
146
147echo "Cleanup"
148
149cd $base/bin
150for binary in ../i586-pc-haiku/bin/*; do
151	ln -sfn $binary .
152done
153
154if [ -d $base/man -o -d $base/info -o -d $base/share ]; then
155	rm -rf $base/man
156	rm -rf $base/info
157	rm -rf $base/share
158fi
159
160rm -f $base/lib/gcc-lib/i586-pc-haiku/2.95.3-haiku-$GCCDATE/include/math.h
161
162### C++ includes ######################################
163
164echo "Install C++ includes & library"
165
166rm -rf $base/include/g++
167ln -snf /boot/system/develop/headers/c++/2.95.3 $base/include/g++
168
169ln -snf /boot/system/lib/libstdc++.r4.so $base/lib/
170ln -snf /boot/system/lib/libstdc++.so $base/lib/
171
172### package ###########################################
173
174echo "Building package ..."
175
176cd "$currentDir"
177mimeset -F "$installDir"
178package create -C "$installDir" -i "$packageInfoFile" $packageFile || exit 1
179
180echo "Built package $packageInfoFile successfully."
181