-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbuild-devkit.sh
executable file
·382 lines (310 loc) · 11.4 KB
/
build-devkit.sh
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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#!/bin/bash
#---------------------------------------------------------------------------------
# devkitARM release 52-2
# devkitPPC release 35
# devkitA64 release 14
# devkitSH4 release 2
#---------------------------------------------------------------------------------
if [ 0 -eq 1 ] ; then
echo "Please use the latest release buildscripts unless advised otherwise by devkitPro staff."
echo "https://github.com/devkitPro/buildscripts/releases/latest"
echo
echo "The scripts in the git repository may be dependent on things which currently only exist"
echo "on developer machines. This is not a bug, use stable releases."
exit 1
fi
echo "Please note, these scripts are provided as a courtesy, toolchains built with them"
echo "are for personal use only and may not be distributed by entities other than devkitPro."
echo "See http://devkitpro.org/wiki/Trademarks"
echo
echo "Users should use devkitPro pacman to maintain toolchain installations where possible"
echo "See https://devkitpro.org/wiki/devkitPro_pacman"
echo
echo "Patches and improvements are of course welcome, please submit a PR"
echo "https://github.com/devkitPro/buildscripts/pulls"
echo
GENERAL_TOOLS_VER=1.0.2
LIBGBA_VER=0.5.2
GBATOOLS_VER=1.1.0
DKARM_RULES_VER=1.0.0
DKARM_CRTLS_VER=1.0.0
LIBNDS_VER=1.7.2
DEFAULT_ARM7_VER=0.7.4
DSWIFI_VER=0.4.2
MAXMOD_VER=1.0.11
FILESYSTEM_VER=0.9.14
LIBFAT_VER=1.1.3
DSTOOLS_VER=1.2.1
GRIT_VER=0.8.15
NDSTOOL_VER=2.1.1
MMUTIL_VER=1.8.7
DFU_UTIL_VER=0.9.1
STLINK_VER=1.2.3
GAMECUBE_TOOLS_VER=1.0.2
LIBOGC_VER=1.8.21
WIILOAD_VER=0.5.1
DKPPC_RULES_VER=1.0.0
LIBCTRU_VER=1.5.1
CITRO3D_VER=1.5.0
CITRO2D_VER=1.1.0
TOOLS3DS_VER=1.1.4
LINK3DS_VER=0.5.2
PICASSO_VER=2.7.0
TEX3DS_VER=1.0.0
GP32_TOOLS_VER=1.0.3
LIBMIRKO_VER=0.9.8
SWITCH_TOOLS_VER=1.4.1
LIBNX_VER=1.3.0
ELF2D01_VER=master
LIBDATAPLUS_VER=master
OSXMIN=${OSXMIN:-10.9}
#---------------------------------------------------------------------------------
function git_clone_project {
#---------------------------------------------------------------------------------
name=$(echo $1 | sed -e 's/.*\/\([^/]*\)\.git/\1/' )
if [ ! -f cloned-$name ]; then
echo "cloning $name"
git clone $1 -b $2 $name-$2 || { echo "Error cloning $name"; exit 1; }
touch cloned-$name
fi
}
#---------------------------------------------------------------------------------
function extract_and_patch {
#---------------------------------------------------------------------------------
if [ ! -f extracted-$1-$2 ]; then
echo "extracting $1-$2"
tar -xf "$SRCDIR/$1-$2.tar.$3" || { echo "Error extracting "$1; exit 1; }
touch extracted-$1-$2
fi
if [[ ! -f patched-$1-$2 && -f $patchdir/$1-$2.patch ]]; then
echo "patching $1-$2"
patch -p1 -d $1-$2 -i $patchdir/$1-$2.patch || { echo "Error patching $1"; exit 1; }
touch patched-$1-$2
fi
}
if [ ! -z "$CROSSBUILD" ] ; then
if [ ! -x $(which $CROSSBUILD-gcc) ]; then
echo "error $CROSSBUILD-gcc not in PATH"
exit 1
fi
fi
#---------------------------------------------------------------------------------
# Sane defaults for building toolchain
#---------------------------------------------------------------------------------
export CFLAGS="-O2 -pipe"
export CXXFLAGS="$CFLAGS"
unset LDFLAGS
#---------------------------------------------------------------------------------
# Look for automated configuration file to bypass prompts
#---------------------------------------------------------------------------------
echo -n "Looking for configuration file... "
if [ -f ./config.sh ]; then
echo "Found."
. ./config.sh
else
echo "Not found"
fi
. ./select_toolchain.sh
#---------------------------------------------------------------------------------
# Get preferred installation directory and set paths to the sources
#---------------------------------------------------------------------------------
if [ ! -z "$BUILD_DKPRO_INSTALLDIR" ] ; then
INSTALLDIR="$BUILD_DKPRO_INSTALLDIR"
else
echo
echo "Please enter the directory where you would like '$package' to be installed:"
echo "for mingw/msys you must use <drive>:/<install path> or you will have include path problems"
echo "this is the top level directory for devkitpro, i.e. e:/devkitPro"
read -e INSTALLDIR
echo
fi
[ ! -z "$INSTALLDIR" ] && mkdir -p $INSTALLDIR && touch $INSTALLDIR/nonexistantfile && rm $INSTALLDIR/nonexistantfile || exit 1;
if test "`curl -V`"; then
FETCH="curl -f -L -O"
elif test "`wget -V`"; then
FETCH=wget
else
echo "ERROR: Please make sure you have wget or curl installed."
exit 1
fi
#---------------------------------------------------------------------------------
# find proper make
#---------------------------------------------------------------------------------
if [ -z "$MAKE" -a -x "$(which gnumake)" ]; then MAKE=$(which gnumake); fi
if [ -z "$MAKE" -a -x "$(which gmake)" ]; then MAKE=$(which gmake); fi
if [ -z "$MAKE" -a -x "$(which make)" ]; then MAKE=$(which make); fi
if [ -z "$MAKE" ]; then
echo no make found
exit 1
fi
echo use $MAKE as make
export MAKE
#---------------------------------------------------------------------------------
# Add installed devkit to the path, adjusting path on minsys
#---------------------------------------------------------------------------------
TOOLPATH=$(echo $INSTALLDIR | sed -e 's/^\([a-zA-Z]\):/\/\1/')
export PATH=$PATH:$TOOLPATH/$package/bin
CROSS_PARAMS="--build=`./config.guess`"
if [ ! -z $CROSSBUILD ]; then
toolsprefix=$INSTALLDIR/$CROSSBUILD/tools
prefix=$INSTALLDIR/$CROSSBUILD/$package
toolsprefix=$INSTALLDIR/$CROSSBUILD/tools
CROSS_PARAMS="$CROSS_PARAMS --host=$CROSSBUILD"
CROSS_GCC_PARAMS="--with-gmp=$CROSSPATH --with-mpfr=$CROSSPATH --with-mpc=$CROSSPATH"
else
toolsprefix=$INSTALLDIR/tools
prefix=$INSTALLDIR/$package
fi
if [ "$BUILD_DKPRO_AUTOMATED" != "1" ] ; then
echo
echo 'Ready to install '$package' in '$prefix
echo
echo 'press return to continue'
read dummy
fi
PLATFORM=`uname -s`
case $PLATFORM in
Darwin )
cppflags="-mmacosx-version-min=${OSXMIN} -I/usr/local/include"
ldflags="-mmacosx-version-min=${OSXMIN} -L/usr/local/lib"
if [ "x${OSXSDKPATH}x" != "xx" ]; then
cppflags="$cppflags -isysroot ${OSXSDKPATH}"
ldflags="$ldflags -Wl,-syslibroot,${OSXSDKPATH}"
fi
TESTCC=`cc -v 2>&1 | grep clang`
if [ "x${TESTCC}x" != "xx" ]; then
cppflags="$cppflags -fbracket-depth=512"
fi
;;
MINGW32* )
cppflags="-D__USE_MINGW_ACCESS"
;;
esac
if [ ! -z $CROSSBUILD ] && grep -q "mingw" <<<"$CROSSBUILD" ; then
cppflags="-D__USE_MINGW_ACCESS -D__USE_MINGW_ANSI_STDIO=1"
fi
BUILDSCRIPTDIR=$(pwd)
BUILDDIR=$(pwd)/.$package
if [ ! -z $CROSSBUILD ]; then
BUILDDIR=$BUILDDIR-$CROSSBUILD
fi
DEVKITPRO_URL="https://downloads.devkitpro.org/"
DATAPLUS_URL="https://github.com/downloads/brijohn/"
patchdir=$(pwd)/$basedir/patches
scriptdir=$(pwd)/$basedir/scripts
archives="binutils-${BINUTILS_VER}.tar.xz gcc-${GCC_VER}.tar.xz newlib-${NEWLIB_VER}.tar.gz gdb-${GDB_VER}.tar.xz"
if [ $VERSION -eq 1 ]; then
targetarchives="libnds-src-${LIBNDS_VER}.tar.bz2 libgba-src-${LIBGBA_VER}.tar.bz2
libmirko-src-${LIBMIRKO_VER}.tar.bz2 dswifi-src-${DSWIFI_VER}.tar.bz2 maxmod-src-${MAXMOD_VER}.tar.bz2
default-arm7-src-${DEFAULT_ARM7_VER}.tar.bz2 libfilesystem-src-${FILESYSTEM_VER}.tar.bz2
libfat-src-${LIBFAT_VER}.tar.bz2 libctru-src-${LIBCTRU_VER}.tar.bz2 citro3d-src-${CITRO3D_VER}.tar.bz2
citro2d-src-${CITRO2D_VER}.tar.bz2"
hostarchives="gba-tools-$GBATOOLS_VER.tar.bz2 gp32-tools-$GP32_TOOLS_VER.tar.bz2
dstools-$DSTOOLS_VER.tar.bz2 grit-$GRIT_VER.tar.bz2 ndstool-$NDSTOOL_VER.tar.bz2
general-tools-$GENERAL_TOOLS_VER.tar.bz2 mmutil-$MMUTIL_VER.tar.bz2
dfu-util-$DFU_UTIL_VER.tar.bz2 stlink-$STLINK_VER.tar.bz2 3dstools-$TOOLS3DS_VER.tar.bz2
picasso-$PICASSO_VER.tar.bz2 tex3ds-$TEX3DS_VER.tar.bz2 3dslink-$LINK3DS_VER.tar.bz2"
archives="devkitarm-rules-$DKARM_RULES_VER.tar.xz devkitarm-crtls-$DKARM_CRTLS_VER.tar.xz $archives"
fi
if [ $VERSION -eq 2 ]; then
targetarchives="libogc-src-${LIBOGC_VER}.tar.bz2 libfat-src-${LIBFAT_VER}.tar.bz2"
hostarchives="gamecube-tools-$GAMECUBE_TOOLS_VER.tar.bz2 wiiload-$WIILOAD_VER.tar.bz2 general-tools-$GENERAL_TOOLS_VER.tar.bz2"
archives="binutils-${MN_BINUTILS_VER}.tar.bz2 devkitppc-rules-$DKPPC_RULES_VER.tar.xz $archives"
fi
if [ $VERSION -eq 3 ]; then
targetarchives=" libnx-src-${LIBNX_VER}.tar.bz2"
hostarchives="general-tools-$GENERAL_TOOLS_VER.tar.bz2 switch-tools-$SWITCH_TOOLS_VER.tar.bz2"
fi
if [ $VERSION -eq 4 ]; then
gitrepos="git://github.com/brijohn/libdataplus.git:$LIBDATAPLUS_VER git://github.com/brijohn/elf2d01.git:$ELF2D01_VER"
hostarchives="general-tools-$GENERAL_TOOLS_VER.tar.bz2"
fi
if [ ! -z "$BUILD_DKPRO_SRCDIR" ] ; then
SRCDIR="$BUILD_DKPRO_SRCDIR"
else
SRCDIR=`pwd`
fi
cd "$SRCDIR"
for archive in $archives $targetarchives $hostarchives
do
echo $archive
if [ ! -f $archive ]; then
$FETCH https://downloads.devkitpro.org/$archive || { echo "Error: Failed to download $archive"; exit 1; }
fi
done
cd $BUILDSCRIPTDIR
mkdir -p $BUILDDIR
cd $BUILDDIR
for repo in $gitrepos
do
url=$(echo $repo | sed -e 's/\(.*\/[^/]*\.git\).*/\1/' )
branch=$(echo $repo | sed -e 's/.*\/[^/]*\.git:\(.*\)/\1/' )
git_clone_project $url $branch
done
extract_and_patch binutils $BINUTILS_VER xz
extract_and_patch gcc $GCC_VER xz
extract_and_patch newlib $NEWLIB_VER gz
extract_and_patch gdb $GDB_VER xz
if [ $VERSION -eq 2 ]; then
extract_and_patch binutils $MN_BINUTILS_VER bz2
fi
for archive in $targetarchives
do
archive=`basename $archive`
destdir=$(echo $archive | sed -e 's/\(.*\)-src-\(.*\)\.tar\.bz2/\1-\2/' )
echo $destdir
if [ ! -d $destdir ]; then
mkdir -p $destdir
bzip2 -cd "$SRCDIR/$archive" | tar -xf - -C $destdir || { echo "Error extracting "$archive; exit 1; }
fi
done
for archive in $hostarchives
do
archive=`basename $archive`
destdir=$(echo $archive | sed -e 's/\(.*\)-src-\(.*\)\.tar\.bz2/\1-\2/' )
if [ ! -d $destdir ]; then
tar -xjf "$SRCDIR/$archive"
fi
done
#---------------------------------------------------------------------------------
# Build and install devkit components
#---------------------------------------------------------------------------------
if [ -f $scriptdir/build-gcc.sh ]; then . $scriptdir/build-gcc.sh || { echo "Error building toolchain"; exit 1; }; cd $BUILDSCRIPTDIR; fi
if [ "$BUILD_DKPRO_SKIP_TOOLS" != "1" ] && [ -f $scriptdir/build-tools.sh ]; then
. $scriptdir/build-tools.sh || { echo "Error building tools"; exit 1; }; cd $BUILDSCRIPTDIR;
fi
if [ "$BUILD_DKPRO_SKIP_LIBRARIES" != "1" ] && [ -f $scriptdir/build-libs.sh ]; then
. $scriptdir/build-libs.sh || { echo "Error building libraries"; exit 1; }; cd $BUILDSCRIPTDIR;
fi
cd $BUILDSCRIPTDIR
if [ ! -z $CROSSBUILD ] && grep -q "mingw" <<<"$CROSSBUILD" ; then
cp -v $CROSSBINPATH//libwinpthread-1.dll $prefix/bin
fi
echo "stripping installed binaries"
. ./strip_bins.sh
#---------------------------------------------------------------------------------
# Clean up temporary files and source directories
#---------------------------------------------------------------------------------
cd $BUILDSCRIPTDIR
if [ "$BUILD_DKPRO_AUTOMATED" != "1" ] ; then
echo
echo "Would you like to delete the build folders and patched sources? [Y/n]"
read answer
else
answer=y
fi
if [ "$answer" != "n" -a "$answer" != "N" ]; then
echo "Removing patched sources and build directories"
rm -fr $BUILDDIR
fi
echo
echo "note: Add the following to your environment;"
echo
echo " DEVKITPRO=$TOOLPATH"
if [ "$toolchain" != "DEVKITA64" ]; then
echo " $toolchain=$TOOLPATH/$package"
fi
echo
echo "add $TOOLPATH/tools/bin to your PATH"
echo
echo