summaryrefslogtreecommitdiff
path: root/hurd-toolchain.sh
blob: b95676cc0eaced8cc1ebd066e66b0a61e57aec86 (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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#!/bin/sh
#
# hurd-toolchain.sh - Script for setting up Hurd toolchain builds
#
# Copyright (C) 2007 Free Software Foundation, Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any later
# version.
# 
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
# for more details.
# 
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# Written by Shakthi Kannan <[email protected]>.

TOPDIR=`pwd`
DOWNLOADS=${TOPDIR}/downloads
ROOT=${TOPDIR}/root
PATCHES=${TOPDIR}/patches
SRC=${ROOT}/src
GLIBC_DIR=${SRC}/glibc
GCC_DIR=${SRC}/gcc
CROSS_GNU_URL=http://www.shakthimaan.com/downloads/hurd/toolchain
TARBALLS=${TOPDIR}/tarballs

all() {
    . ./patch.sh
    create_dir
    get_sources
    build_all
}

## Create directories
create_dir() {
	cd ${TOPDIR}
	mkdir -p ${DOWNLOADS}
	mkdir -p ${SRC}
}

get_sources() { 
    get_cross_gnu 
    get_binutils 
    get_gcc 
    get_gnumach 
    get_mig 
    get_hurd 
    get_glibc
}

get_cross_gnu() {
	echo "  ___ _ __ ___  ___ ___        __ _ _ __  _   _ "
	echo " / __| '__/ _ \/ __/ __|_____ / _\` | '_ \| | | |"
	echo "| (__| | | (_) \__ \__ \_____| (_| | | | | |_| |"
	echo " \___|_|  \___/|___/___/      \__, |_| |_|\__,_|"
	echo "                              |___/             "
	cd ${DOWNLOADS}
	if [ -f ${TARBALLS}/cross-gnu ] ; then
	    echo "Local copy of cross-gnu found..."
	    cp ${TARBALLS}/cross-gnu .
	else
		wget ${CROSS_GNU_URL}/cross-gnu -O cross-gnu
	fi
	echo "  ___ _ __ ___  ___ ___        __ _ _ __  _   _        ___ _ ____   __" 
	echo " / __| '__/ _ \/ __/ __|_____ / _\` | '_ \| | | |_____ / _ \ '_ \ \ / /"
	echo "| (__| | | (_) \__ \__ \_____| (_| | | | | |_| |_____|  __/ | | \ V / " 
	echo " \___|_|  \___/|___/___/      \__, |_| |_|\__,_|      \___|_| |_|\_/  " 
	echo "                              |___/                                   " 
	cd ${DOWNLOADS}
	if [ -f ${TARBALLS}/cross-gnu-env ] ; then
	    echo "Local copy of cross-gnu-env found..."
	    cp ${TARBALLS}/cross-gnu-env .
	else
	    wget ${CROSS_GNU_URL}/cross-gnu-env -O cross-gnu-env
	fi
	chmod +x cross-gnu
	chmod +x cross-gnu-env
}

get_binutils() {
	echo " _     _             _   _ _     "
	echo "| |__ (_)_ __  _   _| |_(_) |___ "
	echo "| '_ \| | '_ \| | | | __| | / __|"
	echo "| |_) | | | | | |_| | |_| | \__ \\"
	echo "|_.__/|_|_| |_|\__,_|\__|_|_|___/"
	cd ${SRC} 
	if test -d binutils; then
	    echo "Deleting existing sources for sanity. If you don't want this behaviour, "
	    echo "consider creating a tarball of the sources. Refer README for more"
	    echo "...."
	    rm -rf binutils
	fi
	if [ -f ${BINUTILS_TARBALL} ] ; then
	    echo "Local copy of BINUTILS tarball found. Extracting..."
	    tar xjvf ${BINUTILS_TARBALL}
	else
	    cvs -d:pserver:[email protected]:/cvs/src co -r ${BINUTILS} binutils
	    mv src binutils
	fi
}

get_gcc() {
	echo "  __ _  ___ ___ "
	echo " / _\` |/ __/ __|"
	echo "| (_| | (_| (__ "
	echo " \__, |\___\___|"
	echo " |___/          "
	cd ${SRC}
    	if test -d gcc; then
	    echo "Deleting existing sources for sanity. If you don't want this behaviour, "
	    echo "consider creating a tarball of the sources. Refer README for more"
	    echo "...."	   
	    rm -rf gcc
	fi
	if [ -f ${GCC_TARBALL} ] ; then
	    echo "Local copy of gcc tarball found. Extracting..."
	    tar xjvf ${GCC_TARBALL}
	else
	    svn co svn://gcc.gnu.org/svn/gcc/branches/${GCC}
	    mv ${GCC} gcc
	fi
	apply_gcc_patches
	cd gcc/ && contrib/gcc_update --touch
}

get_gnumach() {
	echo "                                        _     "
	echo "  __ _ _ __  _   _ _ __ ___   __ _  ___| |__  "
	echo " / _\` | '_ \| | | | '_ \` _ \ / _\` |/ __| '_ \ "
	echo "| (_| | | | | |_| | | | | | | (_| | (__| | | |"
	echo " \__, |_| |_|\__,_|_| |_| |_|\__,_|\___|_| |_|"
	echo " |___/                                        "
	cd ${SRC}
	if test -d gnumach; then
	    echo "Deleting existing sources for sanity. If you don't want this behaviour, "
	    echo "consider creating a tarball of the sources. Refer README for more"
	    echo "...."	   
	    rm -rf gnumach
	fi
	if [ -f ${GNUMACH_TARBALL} ] ; then
	    echo "Local copy of GNU MACH tarball found. Extracting..."
	    tar xjvf ${GNUMACH_TARBALL}
	else
	    cvs -d:pserver:[email protected]:/cvsroot/hurd co -r ${GNUMACH} gnumach
	fi
	cd gnumach/ && autoreconf -vfi
}

get_mig() {
	echo "           _       "
	echo " _ __ ___ (_) __ _ "
	echo "| '_ \` _ \| |/ _\` |"
	echo "| | | | | | | (_| |"
	echo "|_| |_| |_|_|\__, |"
	echo "             |___/ "
	cd ${SRC}
	if test -d mig; then
	    echo "Deleting existing sources for sanity. If you don't want this behaviour, "
	    echo "consider creating a tarball of the sources. Refer README for more"
	    echo "...."	   
	    rm -rf mig
	fi
	if [ -f ${MIG_TARBALL} ] ; then
	    echo "Local copy of MIG tarball found. Extracting..."
	    tar xjvf ${MIG_TARBALL}
	else
	    cvs -d:pserver:[email protected]:/cvsroot/hurd co ${MIG}
	fi
	cd mig/ && autoreconf -vfi
}

get_hurd() {
	echo " _                   _ "
	echo "| |__  _   _ _ __ __| |"
	echo "| '_ \| | | | '__/ _\` |"
	echo "| | | | |_| | | | (_| |"
	echo "|_| |_|\__,_|_|  \__,_|"
	cd ${SRC}
	if test -d hurd; then
	    echo "Deleting existing sources for sanity. If you don't want this behaviour, "
	    echo "consider creating a tarball of the sources. Refer README for more"
	    echo "...."	   
	    rm -rf hurd
	fi
	if [ -f ${HURD_TARBALL} ] ; then
	    echo "Local copy of HURD tarball found. Extracting..."
	    tar xjvf ${HURD_TARBALL}
	else
	    cvs -d:pserver:[email protected]:/cvsroot/hurd co ${HURD}
	fi
}

get_glibc() {
	echo "       _ _ _          "
	echo "  __ _| (_) |__   ___ "
	echo " / _\` | | | '_ \ / __|"
	echo "| (_| | | | |_) | (__ "
	echo " \__, |_|_|_.__/ \___|"
	echo " |___/                "
	cd ${SRC}
	if test -d glibc; then
	    echo "Deleting existing sources for sanity. If you don't want this behaviour, "
	    echo "consider creating a tarball of the sources. Refer README for more"
	    echo "...."	   
	    rm -rf glibc
	fi
	if [ -f ${GLIBC_TARBALL} ] ; then
	    echo "Local copy of glibc tarball found. Extracting..."
	    tar xjvf ${GLIBC_TARBALL}
	else
	    cvs -d:pserver:[email protected]:/cvs/glibc co -r ${GLIBC} glibc
	    mv libc glibc
	fi
	apply_glibc_patches
}

build_all() {
	ROOT=${TOPDIR}/root
	export PATH="$PATH:${DOWNLOADS}"
	. ${DOWNLOADS}/cross-gnu-env
	${DOWNLOADS}/cross-gnu
}

clean() {
	rm -rf downloads root *~
}

create_tarball() {
        echo "Creating tarball for $1"
        if ! [ -d ${TARBALLS} ]
	then
	    mkdir ${TARBALLS}
	fi
	cd root/src
	tar -cjvf ${TARBALLS}/$1.tar.bz2 $2
}	    

## Execute
. ./setenv
if [ "$1" = "clean" ]
then
    echo "Cleaning builds/sources"
    rm -rf root
elif [ "$1" = "archive" ]
    then
    echo "Archiving sources under tarballs/..."
    cd root/src
    create_tarball ${GCC} gcc
    create_tarball ${GLIBC} glibc
    create_tarball ${BINUTILS} binutils
    create_tarball ${HURD} hurd
    create_tarball ${GNUMACH} gnumach
    create_tarball ${MIG} mig
    echo "Done creating Tarballs"
elif [ "$1" = "help" ]
    then
    echo "hurd-toolchain, wrapper script for crossgnu to create a cross environment for GNU/Hurd"
    echo "Available options"
    echo "archive : Create an archive of the sources for later offline build"
    echo "clean   : Cleanup sources and objects"
else
    all
fi