configs/psp: need to pass debug CFLAGS manually
[rofl0r-mmix-cross.git] / defs.sh
bloba732ea99eb52a6ee4742bf65e8bc22f86ce8fd84
1 # Definitions for build scripts
2 #
3 # Copyright (C) 2012-2014 Gregor Richards
4 #
5 # Permission to use, copy, modify, and/or distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
10 # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
11 # AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
12 # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
13 # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
14 # OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
15 # PERFORMANCE OF THIS SOFTWARE.
17 ORIGPWD="$PWD"
18 cd "$MUSL_CC_BASE"
19 MUSL_CC_BASE="$PWD"
20 export MUSL_CC_BASE
21 cd "$ORIGPWD"
22 unset ORIGPWD
24 if [ ! -e config.sh ]
25 then
26 echo 'Create a config.sh file.'
27 exit 1
30 # Versions of things (do this before config.sh so they can be config'd)
31 #BINUTILS_URL=http://ftp.gnu.org/gnu/binutils/binutils-2.25.1.tar.bz2
32 BINUTILS_URL=http://mirrors.kernel.org/sourceware/binutils/snapshots/binutils-2.24.90.tar.bz2
33 #last GPL2 release is 2.17, with backported -Bsymbolic support
34 #BINUTILS_URL=http://landley.net/aboriginal/mirror/binutils-2.17.tar.bz2
35 GCC_VERSION=4.2.4
36 GDB_VERSION=7.9.1
37 GMP_VERSION=6.1.0
38 MPC_VERSION=1.0.3
39 MPFR_VERSION=3.1.4
40 LIBELF_VERSION=master
41 # check available versions at ftp://sourceware.org/pub/newlib/index.html
42 NEWLIB_VERSION=1.19.0
44 # You can choose languages
45 LANG_CXX=no
46 LANG_OBJC=no
47 LANG_FORTRAN=no
49 . ./config.sh
51 # Auto-deteect an ARCH if not specified
52 test -z "$ARCH" && ARCH=mmix
53 test -z "$TRIPLE" && TRIPLE=mmix
55 # Choose our languages
56 LANGUAGES=c
57 [ "$LANG_CXX" = "yes" ] && LANGUAGES="$LANGUAGES,c++"
58 [ "$LANG_OBJC" = "yes" ] && LANGUAGES="$LANGUAGES,objc"
59 [ "$LANG_CXX" = "yes" -a "$LANG_OBJC" = "yes" ] && LANGUAGES="$LANGUAGES,obj-c++"
60 [ "$LANG_FORTRAN" = "yes" ] && LANGUAGES="$LANGUAGES,fortran"
62 # Use gmake if it exists
63 if [ -z "$MAKE" ]
64 then
65 MAKE=make
66 gmake --help > /dev/null 2>&1 && MAKE=gmake
69 # Generate CC_PREFIX from CC_BASE_PREFIX and TRIPLE if not specified
70 [ -n "$CC_BASE_PREFIX" -a -z "$CC_PREFIX" ] && CC_PREFIX="$CC_BASE_PREFIX/$TRIPLE"
71 [ -z "$CC_PREFIX" ] && die 'Failed to determine a CC_PREFIX.'
73 PATH="$CC_PREFIX/bin:$PATH"
74 export PATH
76 # Get the target-specific multilib option, if applicable
77 GCC_MULTILIB_CONFFLAGS="--disable-multilib --with-multilib-list="
78 if [ "$ARCH" = "x32" ]
79 then
80 GCC_MULTILIB_CONFFLAGS="--with-multilib-list=mx32"
83 die() {
84 echo "$@"
85 exit 1
88 fetch() {
89 if [ ! -e "$MUSL_CC_BASE/tarballs/$2" ]
90 then
91 wget -O "$MUSL_CC_BASE/tarballs/$2.part" -c "$1""$2"
92 mv "$MUSL_CC_BASE/tarballs/$2.part" "$MUSL_CC_BASE/tarballs/$2"
94 return 0
97 extract() {
98 if [ ! -e "$2/extracted.$3" ]
99 then
100 tar xf "$MUSL_CC_BASE/tarballs/$1" ||
101 tar Jxf "$MUSL_CC_BASE/tarballs/$1" ||
102 tar jxf "$MUSL_CC_BASE/tarballs/$1" ||
103 tar zxf "$MUSL_CC_BASE/tarballs/$1"
104 mkdir -p "$2"
105 touch "$2/extracted.$3"
109 stripfileext() {
110 case "$1" in
111 *.tar.*) printf "%s" "$1"| sed 's/\.tar\.[0-9a-z]*$//' ;;
112 *) basename "$1" | sed 's/\..*//' ;;
113 esac
116 fetchextract() {
117 name="$1"
118 shift
119 baseurl="$1"
120 [ -z "$2" ] && baseurl=$(printf "%s" "$1" | sed 's/\(.*\/\).*/\1/')
121 dir="$2"
122 [ -z "$dir" ] && dir=$(stripfileext $(basename "$1"))
123 fn="$2""$3"
124 [ -z "$fn" ] && fn=$(basename "$1")
126 fetch "$baseurl" "$fn"
127 extract "$fn" "$dir" "$name"
130 gitfetchextract() {
131 name="$1"
132 shift
133 if [ ! -e "$MUSL_CC_BASE/tarballs/$3".tar.gz ]
134 then
135 git archive --format=tar --remote="$1" "$2" | \
136 gzip -c > "$MUSL_CC_BASE/tarballs/$3".tar.gz || die "Failed to fetch $3-$2"
138 if [ ! -e "$3/extracted.$name" ]
139 then
140 mkdir -p "$3"
142 cd "$3" || die "Failed to cd $3"
143 extract "$3".tar.gz extracted
144 touch extracted.$name
149 newlibfetchextract() {
150 fetchextract newlib http://sourceware.org/pub/newlib/ newlib-${NEWLIB_VERSION} .tar.gz
153 gccprereqs() {
154 if [ ! -e gcc-$GCC_VERSION/gmp ]
155 then
156 fetchextract gmp http://ftp.gnu.org/pub/gnu/gmp/ gmp-$GMP_VERSION .tar.bz2
157 mv gmp-$GMP_VERSION gcc-$GCC_VERSION/gmp
160 if [ ! -e gcc-$GCC_VERSION/mpfr ]
161 then
162 fetchextract mpfr http://ftp.gnu.org/gnu/mpfr/ mpfr-$MPFR_VERSION .tar.bz2
163 mv mpfr-$MPFR_VERSION gcc-$GCC_VERSION/mpfr
166 if [ ! -e gcc-$GCC_VERSION/mpc ]
167 then
168 fetchextract mpc https://ftp.gnu.org/gnu/mpc/ mpc-$MPC_VERSION .tar.gz
169 mv mpc-$MPC_VERSION gcc-$GCC_VERSION/mpc
173 patch_source() {
174 BD="$1"
177 cd "$BD" || die "Failed to cd $BD"
179 if [ ! -e patched ]
180 then
181 for f in "$MUSL_CC_BASE/patches/$BD"-*.diff ; do
182 if [ -e "$f" ] ; then patch -p1 < "$f" || die "Failed to apply patch $f to $BD" ; fi
183 done
184 touch patched
189 build() {
190 BP="$1"
191 BD="$2"
192 CF="./configure"
193 BUILT="$PWD/$BD/built$BP"
194 shift; shift
196 if [ ! -e "$BUILT" ]
197 then
198 patch_source "$BD"
201 cd "$BD" || die "Failed to cd $BD"
203 if [ "$BP" ]
204 then
205 mkdir -p build"$BP"
206 cd build"$BP" || die "Failed to cd to build dir for $BD $BP"
207 CF="../configure"
209 ( $CF --prefix="$PREFIX" "$@" &&
210 $MAKE $MAKEFLAGS &&
211 touch "$BUILT" ) ||
212 die "Failed to build $BD"
218 buildmake() {
219 BD="$1"
220 BUILT="$PWD/$BD/built"
221 shift
223 if [ ! -e "$BUILT" ]
224 then
225 patch_source "$BD"
228 cd "$BD" || die "Failed to cd $BD"
230 ( $MAKE "$@" $MAKEFLAGS &&
231 touch "$BUILT" ) ||
232 die "Failed to build $BD"
238 doinstall() {
239 BP="$1"
240 BD="$2"
241 INSTALLED="$PWD/$BD/installed$BP"
242 shift; shift
244 if [ ! -e "$INSTALLED" ]
245 then
247 cd "$BD" || die "Failed to cd $BD"
249 if [ "$BP" ]
250 then
251 cd build"$BP" || die "Failed to cd build$BP"
254 ( $MAKE install "$@" $MAKEINSTALLFLAGS &&
255 touch "$INSTALLED" ) ||
256 die "Failed to install $BP"
262 buildinstall() {
263 build "$@"
264 doinstall "$1" "$2"