Cómo compilar el entorno de desarrollo completo para GP2X en Mac OS X
De Wiki GP32Spain, la enciclopedia libre.
Estos son los pasos a seguir para compilar, prácticamente desde cero, un entorno de desarrollo completo para Mac OS X. De esta manera se garantiza que el compilador aprovecha efectivamente el tipo de procesador que tenga el Mac. Para poder seguirlos adecuadamente, se debe tener un conocimiento del trabajo con línea de comandos en entornos UNIX/Linux, ya que casi todos los pasos deben realizarse desde la aplicación Terminal de Mac OS X u otra aplicación de similar (xterm, etc). El script está pensado para trabajar con la shell BASH.
Este procedimiento se ha utilizado con éxito para preparar entornos de compilación en ordenadores Apple Macintosh con procesador:
- PowerPC G4
- Intel CoreDuo
- Intel Xeon
Y con el sistema operativo Mac OS X 10.4.x (Tiger) o superior con XCode 2.x o XCode 3.0. Se indica en donde sea apropiado pasos específicos según la versión de XCode utilizada.
Instrucciones para compilar el entorno de desarrollo básico
- Instalar las herramientas gratuitas de desarrollo de Apple, que vienen incluidas con los discos de instalación del sistema operativo, o se pueden descargar desde http://developer.apple.com/tools/xcode/
- Usando DarwinPorts (http://darwinports.opendarwin.org/) o Fink (http://fink.sourceforge.net/), instalar gawk, wget y subversion
- Obtener el script oficial del SDK para Linux (http://dev.gp2x.com/sdk/gp2xsdk_linux.tar.gz) y descomprimirlo en un lugar con espacio suficiente.
- Editar buildgp2xtools.sh, con el fin de que soporten Darwin/OS X, cambiando
case $UNAME in CYGWIN*) export USE_CYGWIN="yes" export HOST="i686-pc-cygwin" ;; Linux*) export USE_CYGWIN="no" export HOST="i386-linux" ;; *)
por
case $UNAME in CYGWIN*) export USE_CYGWIN="yes" export HOST="i686-pc-cygwin" ;; Linux*) export USE_CYGWIN="no" export HOST="i386-linux" ;; Darwin*) export USE_CYGWIN="no" export HOST=`uname -p`"-apple" ;; *)
En el caso de que se utilice XCode 3.0 o superior, se deben añadir además cambios para poder añadir varios parches necesarios, cambiando
# download source
por
# Leopard patches
# check binutils patch
if test ! -f "$PATCHES/Leopard_$BINUTILS.patch" ; then
if test ! -f "Leopard_$BINUTILS.patch" ; then
echo "Error : Not found Leopard binutils.patch";
exit;
else
cp "Leopard_$BINUTILS.patch" "$PATCHES";
fi
fi
# check glibc patches
if test $OLDGLIBC = "yes"; then
echo "No Leopard Patch for $GLIBC"
else
if test ! -f "$PATCHES/Leopard_$GLIBC.patch" ; then
if test ! -f "Leopard_$GLIBC.patch" ; then
echo "Error : Not found Leopard glibc.patch";
exit;
else
cp "Leopard_$GLIBC.patch" "$PATCHES";
fi
fi
fi
# download sources
Con el fin de que se copien los parches específicos para XCode 3. Se debe cambiar también
# extract sources mkdir -p "$SOURCE" if test ! -d "$SOURCE/$BINUTILS" ; then tar -jxvf "$FILES/$BINUTILS.tar.bz2" -C "$SOURCE" fi
por
# extract sources mkdir -p "$SOURCE" if test ! -d "$SOURCE/$BINUTILS" ; then tar -jxvf "$FILES/$BINUTILS.tar.bz2" -C "$SOURCE" #Leopard Patch cd "$SOURCE/$BINUTILS" patch -p1 < "$PATCHES/Leopard_$BINUTILS.patch" fi
Y además
else
patch -p1 < "$PATCHES/$GCC-$GLIBC.patch"
fi
fi
por
else
patch -p1 < "$PATCHES/$GCC-$GLIBC.patch"
fi
#Leopard Patch
if test $OLDGLIBC = "yes"; then
echo "No Leopard Patch for $GLIBC"
else
patch -p1 < "$PATCHES/Leopard_$GLIBC.patch"
fi
fi
Con el fin de que se apliquen dichos parches. Por último, se tiene que cambiar
$SOURCE/$BINUTILS/configure $CROSSBIN --disable-nls make && make install if test ! -f "$PREFIX/bin/$TARGET-ld" && test ! "`$TARGET-ld -v`" ; then
por
$SOURCE/$BINUTILS/configure $CROSSBIN --disable-nls
make && make install
#Leopard Fixes
cd "$PREFIX/bin"
for n in *.dSYM; do nn=${n}; mv $n ${nn/.dSYM/}; done
cd "$PREFIX/$TARGET/bin"
for n in *.dSYM; do nn=${n}; mv $n ${nn/.dSYM/}; done
cd "$BUILD/binutils"
if test ! -f "$PREFIX/bin/$TARGET-ld" && test ! "`$TARGET-ld -v`" ; then
Para corregir un efecto nuevo de XCode 3, que hace que se generen archivos con la extensión dSYM cuando no deberían tener ninguna.
- Crear una imagen de disco, al menos de 1,5 GBytes de espacio y con soporte para mayusculas y minúsculas (necesario para que compilen bien cosas de Linux)
hdiutil create -size 1.5G -fs HFSX -type "SPARSE" -volname gp2xSDKbuild -partitionType Apple_HFS gp2xSDKbuild
(ajustar el parámetro size al tamaño deseado, en este ejemplo es de 1,5 GBytes). Montar la imagen haciendo doble clic sobre ella una vez se haya generado.
- Crear enlaces "falsos" para que compile bien todo
mkdir /Volumes/gp2xSDKbuild/bin ln -s /usr/bin/install /Volumes/gp2xSDKbuild/bin/ginstall ln -s /usr/bin/make /Volumes/gp2xSDKbuild/bin/gmake ln -s /usr/bin/sed /Volumes/gp2xSDKbuild/bin/gsed
(en el caso de que la imagen se llamara con un nombre distinto de "gp2xSDKBuild", ajustar los enlaces anteriores de forma adecuada)
- Ajustar el PATH con estos enlaces
export PATH=/Volumes/gp2xSDKbuild/bin:$PATH
(en el caso de que la imagen se llamara con un nombre distinto de "gp2xSDKBuild", ajustar el PATH de forma adecuada)
- Editar buildgp2xtools.sh para apuntar al disco que hemos creado, modificando el valor PREFIX
export PREFIX="/Volumes/gp2xSDKbuild"
(en el caso de que la imagen se llamara con un nombre distinto de "gp2xSDKBuild", ajustar PREFIX de forma adecuada.
- Obtener los parches adecuados para varias de las librerías (que se pueden descargar desde http://80.35.206.140/gp2xdevPatches.zip o desde http://www.gp32spain.com/foros/attachment.php?attachmentid=15637&d=1195407131), y dejarlos todos en el mismo directorio donde se encuentra el script modificado buildgp2xtools.sh .
- Desde la ventana de terminal con el PATH actualizado, situarse en directorio donde esté el script modificado y lanzarlo, usando la opción static si se desea gcc 4.0 o sin opciones si se desea gcc 2.95 (esta segunda posibilidad no suele funcionar con XCode 2.x y parece no funcionar nunca con XCode 3. Se recomienda usar siempre la opción static).
./buildgp2xtools.sh static
- Esperar un rato, que puede variar entre varios minutos y varias horas, según la potencia del ordenador que se utilice.
Normalmente no se produce ningún error, y ahora, para poder compilar, basta con:
- Montar la imagen de disco
- Ajustar PATH para que incluya /Volumes/gp2xSDKbuild/bin (o la ruta equivalente si el disco se monta en otra ruta distinta)
- Preparar Makefile para que use arm-gp2x-linux como arquitectura, /Volumes/gp2xSDKbuild/arm-gp2x-linux/include para incluir cabeceras y /Volumes/gp2xSDKbuild/arm-gp2x-linux/lib para enlazar librerías.
Instrucciones para preparar algunas librerías de desarrollo (incluyendo SDL)
A continuación se indica el código fuente completo de un script que permite instalar las siguientes librerías:
- zlib-1.2.3
- jpeg-6b
- libpng-1.2.24
- freetype-2.1.10
- mikmod-3.1.11
- tremor-1.0.0
- SDL-1.2.9 (paeryn)
- SDL_image-1.2.4
- SDL_ttf-2.0.7
- smpeg-0.4.4
- SDL_mixer-1.2.6
- SDL_gfx-2.0.13
- libxml2-2.6.24
- expat-2.0.1
El script necesita tener en su mismo directorio, descomprida, una carpeta llamada "patches" con los parches adecuados para varias de las librerías (que se pueden descargar desde http://80.35.206.140/MacGP2XLibsPatches.zip o desde http://www.gp32spain.com/foros/attachment.php?attachmentid=13105&d=1163931773), así como presupone que se ha instalado un entorno de desarrollo estático como el indicado en el punto anterior, en una imagen de disco montada en la ruta /Volumes/gp2xSDKbuild, finalmente, debe estar ajustada la variable PATH como se ha visto más arriba. Por lo tanto, debería editarse adecuadamente si se desea utilizar con otra configuración distinta.
#!/bin/sh
UNAMEM=`uname -p`-apple
HOST=arm-gp2xstatic-linux
BUILDENV=$HOST-
TARGETGCC="$BUILDENV"gcc
TARGETAR="$BUILDENV"ar
TARGETRANLIB="$BUILDENV"ranlib
BASEDIR=/Volumes/gp2xSDKBuild/
FILESDIR="$BASEDIR"files/
SRCDIR="$BASEDIR"src/
PATCHDIR="$SRCDIR"patches
GP2XDEV="$BASEDIR"arm-gp2xstatic-linux/
cp -r ./patches $PATCHDIR
#"zlib-1.2.3"
cd $FILESDIR
if test ! -f "$FILESDIR"zlib-1.2.3.tar.gz ; then
curl -O http://www.gzip.org/zlib/zlib-1.2.3.tar.gz
fi
cd $SRCDIR
rm -Rf zlib-1.2.3
tar xfvz "$FILESDIR"zlib-1.2.3.tar.gz
export CC="$TARGETGCC"
export RANLIB="$TARGETRANLIB"
export AR="$TARGETAR"
export AR="${AR} rc"
cd zlib-1.2.3
./configure --prefix=$GP2XDEV
make
make install prefix=$GP2XDEV
make clean
export CC=
export RANLIB=
export AR=
if test ! -f "$GP2XDEV"lib/libz.a ; then
echo "Error : Fallo creando libz.a"
exit
fi
#"jpeg-6b"
cd $FILESDIR
if test ! -f "$FILESDIR"jpegsrc.v6b.tar.gz ; then
curl -O http://www.ijg.org/files/jpegsrc.v6b.tar.gz
fi
cd $SRCDIR
rm -Rf jpeg-6b
tar xfvz "$FILESDIR"jpegsrc.v6b.tar.gz
cd jpeg-6b
cat $PATCHDIR/libjpeg-0.6b-GP2X.patch | patch -p1
export CC=$TARGETGCC
export RANLIB=$TARGETRANLIB
./configure --prefix=$GP2XDEV --build=$UNAMEM --host=$HOST --disable-shared --enable-static
make
make install-lib
make install-headers
make clean
export CC=
export RANLIB=
if test ! -f "$GP2XDEV"lib/libjpeg.a ; then
echo "Error : Fallo creando libjpeg.a"
exit
fi
#"libpng-1.2.24"
cd $FILESDIR
if test ! -f "$FILESDIR"libpng-1.2.24.tar.bz2 ; then
curl -O ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.2.24.tar.bz2
fi
cd $SRCDIR
rm -Rf libpng-1.2.24
tar xfvj "$FILESDIR"libpng-1.2.24.tar.bz2
cd libpng-1.2.24
./configure --prefix=$GP2XDEV --build=$UNAMEM --host=$HOST --disable-shared --enable-static
make
make install
make clean
if test ! -f "$GP2XDEV"lib/libpng.a ; then
echo "Error : Fallo creando libpng.a"
exit
fi
#"freetype-2.1.10"
cd $FILESDIR
if test ! -f "$FILESDIR"freetype-2.1.10.tar.bz2 ; then
curl -O http://download.savannah.gnu.org/releases/freetype/freetype-2.1.10.tar.bz2
fi
cd $SRCDIR
rm -Rf freetype-2.1.10
tar xfvj "$FILESDIR"freetype-2.1.10.tar.bz2
cd freetype-2.1.10
export CC="$TARGETGCC"
export CXX="$BUILDENV"g++
export RANLIB="$TARGETRANLIB"
export AR="$TARGETAR"
./configure --prefix=$GP2XDEV --build=$UNAMEM --host=$HOST --disable-shared --enable-static
make
make install
make clean
export CC=
export CXX=
export RANLIB=
export AR=
if test ! -f "$GP2XDEV"lib/libfreetype.a ; then
echo "Error : Fallo creando libfreetype.a"
exit
fi
#"mikmod-3.1.11"
cd $FILESDIR
if test ! -f "$FILESDIR"libmikmod-3.1.11.tar.gz ; then
curl -O http://mikmod.raphnet.net/files/libmikmod-3.1.11.tar.gz
fi
cd $SRCDIR
rm -Rf libmikmod-3.1.11
tar xfvz "$FILESDIR"libmikmod-3.1.11.tar.gz
cd libmikmod-3.1.11
export CC=arm-gp2xstatic-linux-gcc
export CXX=arm-gp2xstatic-linux-g++
./configure --prefix=$GP2XDEV --build=$UNAMEM --host=$HOST --disable-esd --disable-shared --enable-static
make
make install
make clean
export CC=
export CCX=
if test ! -f "$GP2XDEV"lib/libmikmod.a ; then
echo "Error : Fallo creando libmikmod.a"
exit
fi
#"tremor-1.0.0"
cd $SRCDIR
rm -Rf Tremor
svn checkout http://svn.xiph.org/trunk/Tremor
cd Tremor
./autogen.sh
./configure --prefix=$GP2XDEV --build=$UNAMEM --host=$HOST --disable-shared --enable-static --enable-low-accuracy
make
make install
make clean
if test ! -f "$GP2XDEV"lib/libvorbisidec.a ; then
echo "Error : Fallo creando libvorbisidec.a"
exit
fi
#"SDL-1.2.9 (paeryn)"
cd $FILESDIR
if test ! -f "$FILESDIR"SDL-1.2.9-GP2X-paeryn.zip ; then
curl -O http://archive.gp2x.de/cfiles/uploads/Home/gp2x%20-%20Development/Sourcecodes/SDL-1.2.9-GP2X-paeryn.zip
fi
cd $SRCDIR
rm -Rf SDL-1.2.9-GP2X
unzip "$FILESDIR"SDL-1.2.9-GP2X-paeryn.zip
mv "$SRCDIR"SDL-1.2.9-GP2X-paeryn "$SRCDIR"SDL-1.2.9-GP2X
cd SDL-1.2.9-GP2X
chmod -R u+x *
./configure --prefix=$GP2XDEV --build=$UNAMEM --host=$HOST --enable-pthreads --enable-pthreads-sem --disable-shared --enable-static --enable-threads
make
make install
make clean
if test ! -f "$GP2XDEV"lib/libSDL.a ; then
echo "Error : Fallo creando libSDL.a"
exit
fi
#"SDL_image-1.2.4"
cd $FILESDIR
if test ! -f "$FILESDIR"SDL_image-1.2.4.tar.gz ; then
curl -O http://www.libsdl.org/projects/SDL_image/release/SDL_image-1.2.4.tar.gz
fi
cd $SRCDIR
rm -Rf SDL_image-1.2.4
tar xfvz "$FILESDIR"SDL_image-1.2.4.tar.gz
cd SDL_image-1.2.4
export CFLAGS=-I$GP2XDEV/include
./configure --prefix=$GP2XDEV --build=$UNAMEM --host=$HOST --disable-shared --enable-static --with-sdl-prefix=$GP2XDEV
make
make install
make clean
export CFLAGS=
if test ! -f "$GP2XDEV"lib/libSDL_image.a ; then
echo "Error : Fallo creando libSDL_image.a"
exit
fi
#"SDL_ttf-2.0.7"
cd $FILESDIR
if test ! -f "$FILESDIR"SDL_ttf-2.0.7.tar.gz ; then
curl -O http://www.libsdl.org/projects/SDL_ttf/release/SDL_ttf-2.0.7.tar.gz
fi
cd $SRCDIR
rm -Rf SDL_ttf-2.0.7
tar xfvz "$FILESDIR"SDL_ttf-2.0.7.tar.gz
cd SDL_ttf-2.0.7
export CC="$TARGETGCC"
export CXX="$BUILDENV"g++
export RANLIB="$TARGETRANLIB"
export AR="$TARGETAR"
./configure --prefix=$GP2XDEV --build=$UNAMEM --host=$HOST --disable-shared --enable-static --with-freetype-prefix=$GP2XDEV --with-sdl-prefix=$GP2XDEV --without-x
make
make install
make clean
export CC=
export CXX=
export RANLIB=
export AR=
if test ! -f "$GP2XDEV"lib/libSDL_ttf.a ; then
echo "Error : Fallo creando libSDL_ttf.a"
exit
fi
#"smpeg-0.4.4"
cd $FILESDIR
if test ! -f "$FILESDIR"smpeg-0.4.4.tar.gz ; then
#curl -O http://freshmeat.net/redir/smpeg/9713/url_tgz/smpeg-0.4.4.tar.gz
#curl -O ftp://sunsite.dk/pub/os/linux/loki/open-source/smpeg/smpeg-0.4.4.tar.gz
curl -O http://mirrors.dotsrc.org/lokigames/open-source/smpeg/smpeg-0.4.4.tar.gz
fi
cd $SRCDIR
rm -Rf smpeg-0.4.4
tar xfvz "$FILESDIR"smpeg-0.4.4.tar.gz
cd smpeg-0.4.4
export CC="$TARGETGCC"
export CXX="$BUILDENV"g++
export RANLIB="$TARGETRANLIB"
export AR="$TARGETAR"
INCLUDEFLAG="$GP2XDEV"include
LDFLAG="$GP2XDEV"lib
export CFLAGS="-I$INCLUDEFLAG"
export LDFLAGS="-L$LDFLAG -lstdc++"
./configure --prefix=$GP2XDEV --build=$UNAMEM --host=$HOST --disable-gtk-player --disable-opengl-player --disable-shared --enable-static --with-sdl-prefix=$GP2XDEV
make
make install
make clean
rm "$GP2XDEV"lib/libsmpeg.la
export CC=
export CCX=
export RANLIB=
export AR=
export CFLAGS=
export LDFLAGS=
if test ! -f "$GP2XDEV"lib/libsmpeg.a ; then
echo "Error : Fallo creando libsmpeg.a"
exit
fi
#"SDL_mixer-1.2.6"
cd $FILESDIR
if test ! -f "$FILESDIR"SDL_mixer-1.2.6.tar.gz ; then
curl -O http://www.libsdl.org/projects/SDL_mixer/release/SDL_mixer-1.2.6.tar.gz
fi
cd $SRCDIR
rm -Rf SDL_mixer-1.2.6
tar xfvz "$FILESDIR"SDL_mixer-1.2.6.tar.gz
cd SDL_mixer-1.2.6
./configure --prefix=$GP2XDEV --build=$UNAMEM --host=$HOST --disable-shared --enable-static --with-sdl-prefix=$GP2XDEV
make
make install
make clean
if test ! -f "$GP2XDEV"lib/libSDL_mixer.a ; then
echo "Error : Fallo creando libSDL_mixer.a"
exit
fi
#"SDL_gfx-2.0.13"
cd $FILESDIR
if test ! -f "$FILESDIR"SDL_gfx-2.0.13.tar.gz ; then
curl -O http://www.ferzkopp.net/Software/SDL_gfx-2.0/SDL_gfx-2.0.13.tar.gz
fi
cd $SRCDIR
rm -Rf SDL_gfx-2.0.13
tar xfvz "$FILESDIR"SDL_gfx-2.0.13.tar.gz
cd SDL_gfx-2.0.13
export AR=$TARGETAR
./configure --prefix=$GP2XDEV --build=$UNAMEM --host=$HOST --disable-mmx --disable-shared --enable-static --with-sdl-prefix=$GP2XDEV
make
make install
make clean
export AR=
if test ! -f "$GP2XDEV"lib/libSDL_gfx.a ; then
echo "Error : Fallo creando libSDL_gfx.a"
exit
fi
#"libxml2-2.6.24"
cd $FILESDIR
if test ! -f "$FILESDIR"libxml2-2.6.24.tar.gz ; then
curl -O ftp://ftp.gnome.org/pub/GNOME/sources/libxml2/2.6/libxml2-2.6.24.tar.gz
fi
cd $SRCDIR
rm -Rf libxml2-2.6.24
tar xfvz "$FILESDIR"libxml2-2.6.24.tar.gz
cd libxml2-2.6.24
cat "$PATCHDIR"/libxml2-2.6.24-GP2X.patch | patch -p1
./configure --prefix=$GP2XDEV --build=$UNAMEM --host=$HOST --disable-shared --enable-static
make
make install
make clean
if test ! -f "$GP2XDEV"lib/libxml2.a ; then
echo "Error : Fallo creando libxml2.a"
exit
fi
#"SDL_svg-1.1.9"
#cd $FILESDIR
#if test ! -f "$FILESDIR"SDL_svg-1.1.9.tar.gz ; then
# curl -O http://www.linuxmotors.com/SDL_svg/download/SDL_svg-1.1.9.tar.gz
#fi
#cd $SRCDIR
#rm -Rf SDL_svg-1.1.9
#tar xfvz "$FILESDIR"SDL_svg-1.1.9.tar.gz
#cd SDL_svg-1.1.9
#cat "$PATCHDIR"/SDL_svg-1.1.9-GP2X.patch | patch -p1
#INCLUDEFLAG="$GP2XDEV"include
#LDFLAG="$GP2XDEV"lib
#export CFLAGS="-I$INCLUDEFLAG -I$INCLUDEFLAG/libxml2"
#export LDFLAGS="-L$LDFLAG"
#./configure --prefix=$GP2XDEV --build=$UNAMEM --host=$HOST --disable-shared --enable-static --with-sdl-prefix=$GP2XDEV --without-x
#make
#make install
#make clean
#export CFLAGS=
#export LDFLAGS=
#if test ! -f "$GP2XDEV"lib/libSDL_svg.a ; then
# echo "Error : Fallo creando libSDL_svg.a"
# exit
#fi
#"expat-2.0.1"
cd $FILESDIR
if test ! -f "$FILESDIR"expat-2.0.1.tar.gz ; then
curl -O http://switch.dl.sourceforge.net/sourceforge/expat/expat-2.0.1.tar.gz
fi
cd $SRCDIR
rm -Rf expat-2.0.1
tar xfvz "$FILESDIR"expat-2.0.1.tar.gz
cd expat-2.0.1
./configure --prefix=$GP2XDEV --build=$UNAMEM --host=$HOST --disable-shared --enable-static
make
make install
make clean
if test ! -f "$GP2XDEV"lib/libexpat.a ; then
echo "Error : Fallo creando libexpat.a"
exit
fi
echo "Finalizado"
exit 0
