scripts/build_mingw: also build against ffmpeg
authorPaul Brossier <piem@piem.org>
Fri, 17 Mar 2017 08:39:56 +0000 (09:39 +0100)
committerPaul Brossier <piem@piem.org>
Fri, 17 Mar 2017 08:39:56 +0000 (09:39 +0100)
This script now builds aubio for windows 4 times, for 32 and 64 bits,
with and without ffmpeg. Latest ffmpeg binaries are downloaded if not
found in the current directory.

Tarball containing aubio binaries are created once each build completed.

scripts/build_mingw

index 8c02894..ab4f7c7 100755 (executable)
 #! /bin/bash
 
-# This script cross compiles aubio for windows using mingw, both for 32 and 64
-# bits. Built binaries will be placed in ./dist-win32 and ./dist-win64.
-
+# This script cross compiles aubio for windows using mingw, four times:
+#
+#  - 32 and 64 bits with no external dependencies
+#  - 32 and 64 bits against ffmpeg
+#
 # On debian or ubuntu, you will want to 'apt-get install gcc-mingw-w64'
 
 set -e
 set -x
 
-WAFOPTS="-v --disable-avcodec --disable-samplerate --disable-jack --disable-sndfile"
+source VERSION
+VERSION="$AUBIO_MAJOR_VERSION.$AUBIO_MINOR_VERSION.$AUBIO_PATCH_VERSION"
+VERSION+="$AUBIO_VERSION_STATUS"
+
+FFMPEG_BUILDS_URL="https://ffmpeg.zeranoe.com/builds"
+FFMPEG_DEFAULT="20170315-6c4665d"
+
+# define some default CFLAGS
+DEF_CFLAGS="-Os -I/usr/share/mingw-w64"
+DEF_LDFLAGS=""
+
+WAFOPTS=""
+# disable external deps to make sure we don't try to use the host package
+WAFOPTS+=" --disable-samplerate --disable-jack --disable-sndfile"
+# enable ffmpeg build
+WAFOPTS+=" --disable-avcodec"
+# install without a prefix
+WAFOPTS+=" --prefix=/"
+# compile the tests, but fake running them
+# passing this option WAFOPTS fails (escaping?), added in actual waf call below
+#WAFOPTS+=" --testcmd='echo %s'"
+
+# debugging
+#WAFOPTS+=" -v"
+#WAFOPTS+=" -j1"
+#WAFOPTS+=" --notests"
+
+function fetch_ffpmeg() {
+  ## manually add ffmpeg (no pkg-config .pc files in bins)
+  [ -n "$FFMPEG_VERSION" ] || FFMPEG_VERSION=$FFMPEG_DEFAULT
+  FFMPEG_TARBALL="$PWD/ffmpeg-$FFMPEG_VERSION-$TARGET-dev.zip"
+  FFMPEG_BINARIES="${FFMPEG_TARBALL%%.zip}"
+  if [ ! -d "$FFMPEG_BINARIES" ]
+  then
+    if [ ! -f "$FFMPEG_TARBALL" ]
+    then
+      curl -O $FFMPEG_BUILDS_URL/$TARGET/dev/ffmpeg-$FFMPEG_VERSION-$TARGET-dev.zip
+    else
+      echo "using $FFMPEG_TARBALL"
+    fi
+    unzip -x $FFMPEG_TARBALL
+  else
+    echo "using $FFMPEG_BINARIES"
+  fi
+}
+
+function get_cflags() {
+  CFLAGS="$DEF_CFLAGS"
+  LDFLAGS="$DEF_LDFLAGS"
+  if [ -n "$WITH_FFMEG" ]
+  then
+    fetch_ffpmeg
+    CFLAGS+=" -DHAVE_LIBAV=1 -DHAVE_SWRESAMPLE=1"
+    CFLAGS+=" -I$FFMPEG_BINARIES/include"
+    LDFLAGS+=" -lavcodec -lavformat -lavutil -lswresample"
+    LDFLAGS+=" -L$FFMPEG_BINARIES/lib"
+  fi
+}
+
+function build_mingw() {
+  DESTDIR="$PWD/aubio-$VERSION-$TARGET"
+  [ -n "$WITH_FFMEG" ] && DESTDIR+="-ffmpeg"
+  [ -d $DESTDIR ] && rm -rf $DESTDIR $DESTDIR.zip
+  WAFOPTS_TGT="$WAFOPTS --destdir=$DESTDIR"
+  WAFOPTS_TGT+=" --with-target-platform=$TARGET"
+  get_cflags
+  CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \
+    ./waf distclean configure build install $WAFOPTS_TGT --testcmd='echo %s'
+  zip -r $DESTDIR.zip `basename $DESTDIR`
+  rm -rf $DESTDIR
+  sha256sum $DESTDIR.zip > $DESTDIR.zip.sha256
+}
+
+function build_mingw32() {
+  TARGET=win32
+  export CC=i686-w64-mingw32-gcc
+  build_mingw
+}
+
+function build_mingw64() {
+  TARGET=win64
+  export CC=x86_64-w64-mingw32-gcc
+  build_mingw
+}
 
-[ -d dist-win32 ] && rm -rf dist-win32
-[ -d dist-win64 ] && rm -rf dist-win64
+# fetch waf if needed
+[ -f "waf" ] || make getwaf
 
-CFLAGS="-Os" \
-  LDFLAGS="" \
-  CC=x86_64-w64-mingw32-gcc \
-  ./waf distclean configure build install --destdir=$PWD/dist-win64 \
-    --testcmd="echo %s" \
-    $WAFOPTS --with-target-platform=win64
+# first build without ffmpeg
+build_mingw32
+build_mingw64
 
-CFLAGS="-Os" \
-  LDFLAGS="" \
-  CC=i686-w64-mingw32-gcc \
-  ./waf distclean configure build install --destdir=$PWD/dist-win32 \
-    --testcmd="echo %s" \
-    $WAFOPTS --with-target-platform=win32
+# then build against ffmpeg
+WITH_FFMEG=1
+build_mingw32
+build_mingw64