source: scripts/build_mingw @ bb07c7e

feature/autosinkfeature/cnnfeature/cnn_orgfeature/constantqfeature/crepefeature/crepe_orgfeature/pitchshiftfeature/pydocstringsfeature/timestretchfix/ffmpeg5
Last change on this file since bb07c7e was 8122581d, checked in by Paul Brossier <piem@piem.org>, 8 years ago

scripts/build_mingw: generate .def file (closes #97)

  • Property mode set to 100755
File size: 3.2 KB
Line 
1#! /bin/bash
2
3# This script cross compiles aubio for windows using mingw, four times:
4#
5#  - 32 and 64 bits with no external dependencies
6#  - 32 and 64 bits against ffmpeg
7#
8# On debian or ubuntu, you will want to 'apt-get install gcc-mingw-w64'
9
10set -e
11set -x
12
13python this_version.py -v
14VERSION=`python $PWD/this_version.py -v`
15
16FFMPEG_BUILDS_URL="https://ffmpeg.zeranoe.com/builds"
17FFMPEG_DEFAULT="20170404-1229007"
18
19# define some default CFLAGS
20DEF_CFLAGS="-Os -I/usr/share/mingw-w64"
21DEF_LDFLAGS=""
22
23WAFOPTS=""
24# disable external deps to make sure we don't try to use the host package
25WAFOPTS+=" --disable-samplerate --disable-jack --disable-sndfile"
26# enable ffmpeg build
27WAFOPTS+=" --disable-avcodec"
28# install without a prefix
29WAFOPTS+=" --prefix=/"
30# compile the tests, but fake running them
31# passing this option WAFOPTS fails (escaping?), added in actual waf call below
32#WAFOPTS+=" --testcmd='echo %s'"
33
34# debugging
35#WAFOPTS+=" -v"
36#WAFOPTS+=" -j1"
37#WAFOPTS+=" --notests"
38
39function fetch_ffpmeg() {
40  ## manually add ffmpeg (no pkg-config .pc files in bins)
41  [ -n "$FFMPEG_VERSION" ] || FFMPEG_VERSION=$FFMPEG_DEFAULT
42  FFMPEG_TARBALL="$PWD/ffmpeg-$FFMPEG_VERSION-$TARGET-dev.zip"
43  FFMPEG_BINARIES="${FFMPEG_TARBALL%%.zip}"
44  if [ ! -d "$FFMPEG_BINARIES" ]
45  then
46    if [ ! -f "$FFMPEG_TARBALL" ]
47    then
48      curl -O $FFMPEG_BUILDS_URL/$TARGET/dev/ffmpeg-$FFMPEG_VERSION-$TARGET-dev.zip
49    else
50      echo "using $FFMPEG_TARBALL"
51    fi
52    unzip -x $FFMPEG_TARBALL
53  else
54    echo "using $FFMPEG_BINARIES"
55  fi
56}
57
58function get_cflags() {
59  CFLAGS="$DEF_CFLAGS"
60  LDFLAGS="$DEF_LDFLAGS"
61  if [ -n "$WITH_FFMEG" ]
62  then
63    fetch_ffpmeg
64    CFLAGS+=" -DHAVE_LIBAV=1 -DHAVE_SWRESAMPLE=1"
65    CFLAGS+=" -I$FFMPEG_BINARIES/include"
66    LDFLAGS+=" -lavcodec -lavformat -lavutil -lswresample"
67    LDFLAGS+=" -L$FFMPEG_BINARIES/lib"
68  fi
69}
70
71function build_mingw() {
72  DESTDIR="$PWD/aubio-$VERSION-$TARGET"
73  [ -n "$WITH_FFMEG" ] && DESTDIR+="-ffmpeg"
74  [ -f $DESTDIR.zip ] && echo "Remove existing $DESTDIR.zip first" && exit 1
75  [ -d $DESTDIR ] && rm -rf $DESTDIR
76  WAFOPTS_TGT="$WAFOPTS --destdir=$DESTDIR"
77  WAFOPTS_TGT+=" --with-target-platform=$TARGET"
78  get_cflags
79  CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \
80    ./waf distclean configure build install $WAFOPTS_TGT --testcmd='echo %s'
81  # fix dll location (see https://github.com/waf-project/waf/issues/1860)
82  mv $DESTDIR/lib/libaubio-5.dll $DESTDIR/bin
83  # generate def file (see https://github.com/aubio/aubio/issues/97)
84  ( echo -e "EXPORTS"; $NM $DESTDIR/bin/libaubio-5.dll | grep T\  | \
85    egrep "(aubio|fvec|cvec|lvec|fmat)" | sed 's/^.* T _\?//' ) \
86    > $DESTDIR/bin/libaubio-5.def
87  zip -r $DESTDIR.zip `basename $DESTDIR`
88  rm -rf $DESTDIR
89  sha256sum $DESTDIR.zip > $DESTDIR.zip.sha256
90}
91
92function build_mingw32() {
93  TARGET=win32
94  export CC=i686-w64-mingw32-gcc
95  export NM=i686-w64-mingw32-nm
96  build_mingw
97}
98
99function build_mingw64() {
100  TARGET=win64
101  export CC=x86_64-w64-mingw32-gcc
102  export NM=x86_64-w64-mingw32-nm
103  build_mingw
104}
105
106# fetch waf if needed
107[ -f "waf" ] || make getwaf
108
109# first build without ffmpeg
110build_mingw32
111build_mingw64
112
113# then build against ffmpeg
114WITH_FFMEG=1
115build_mingw32
116build_mingw64
117
118set +x
119echo ""
120echo "All done! The following files were generated:"
121echo ""
122ls -lart aubio*.zip*
Note: See TracBrowser for help on using the repository browser.