1#!/bin/sh
2#
3# This script will automates the steps used to producing a win32 package
4# of SoX.
5#
6# It is used on a Fedora box with mingw32 cross compiler and wine to
7# test.
8#
9# It will optionally package up VC++ version of wget if found in
10# ../wget-1.11.4.
11#
12# Various notes:
13#
14# The following command lines were used to generate the external libraries
15# SoX ships with.
16#
17# Needed for libltdl support.
18# FIXME: Install
19# cd libtool-2.4.2
20# mingw32-configure --disable-shared --enable-static;mingw32-make;sudo mingw32-make install
21#
22# yum install ming32-libpng mingw32-libpng-static
23#  or
24# cd libpng-1.6.15
25# mingw32-configure --disable-shared --enable-static;mingw32-make;sudo mingw32-make install
26#
27# yum install mingw32-wavpack
28#  or
29# cd ../wavpack-4.70.0
30# mingw32-configure --disable-shared --enable-static;mingw32-make;sudo mingw32-make install
31#
32# yum install mingw32-flac
33#  or
34# Need to disable optional ogg support to prevent duplicate symbols during
35# link.
36# Edited Makefile and removed "examples" from SUBDIRS.
37# cd ../flac-1.3.1
38# mingw32-configure --disable-ogg --disable-shared --enable-static;mingw32-make;sudo mingw32-make install
39#
40# yum install mingw32-libogg
41#  or
42# cd ../libogg-1.3.2
43# mingw32-configure --disable-shared --enable-static;mingw32-make;sudo mingw32-make install
44#
45# yum install mingw32-libvorbis
46#  or
47# cd ../libvorbis-1.3.4
48# mingw32-configure --disable-shared --enable-static;mingw-32-make;sudo mingw32-make install
49#
50# FIXME: Install libsndfile
51# Compile libsndfile after FLAC and ogg vorbis so that it will include
52# support for that.
53# MINGW work around: Can either add -lwsock32 to end of *_LDADD for any
54# failed program links or modify top leve Makefile and remove
55# "programs", "examples", "regtests", and "tests" from SUBDIRS.
56# cd ../libsndfile-1.0.25
57# mingw32-configure --disable-shared --enable-static;mingw32-make;sudo mingw32-make install
58#
59# yum install mingw32-libid3tag
60#  or
61# libid3tag does not like to be compiled shared on mingw32 cross compiler.
62# cd ../libid3tag-0.15.1b
63# mingw32-configure --disable-shared --enable-static;mingw32-make;sudo mingw32-make install
64#
65# To get MP3 header files used to enable MP3 support (no libraries used):
66#
67# yum install mingw32-libmad
68#  or
69# MINGW work around: Edit Makefile and remove -fforce-mem from CFLAGS
70# cd ../libmad-0.15.1b
71# mingw32-configure --enable-shared --disable-static;mingw32-make;sudo mingw32-make install
72
73[ ! -x configure ] && autoreconf -i
74
75SYS_ROOT="/usr/i686-w64-mingw32/sys-root"
76CONFIGURE=mingw32-configure
77DOC_TARGETS="pdf"
78DOCS="sox.pdf soxformat.pdf soxi.pdf"
79TMP_SNDFILE_LIBS="-lsndfile -lFLAC -lvorbisenc -lvorbisfile -lvorbis -logg"
80STRIP=i686-pc-mingw32-strip
81
82# Some versions of autoconf (2.63?) seem to get easily confused about
83# CPP variable. If you see warning messages about header files
84# rejected by preprocessor then its most likely from that.
85# Force the value of CPP=cpp works around that bug.
86# static versions of libsndfile do not advertise when they have
87# FLAC or ogg vorbis support.  Need to force the link ourselves.
88if [ $# -ne 0 -o ! -r Makefile ]; then
89  $CONFIGURE \
90    --with-libltdl \
91    --enable-dl-lame --enable-dl-mad --enable-dl-amrnb --enable-dl-amrwb \
92    LDFLAGS="-L/usr/local/lib" CPPFLAGS=-I/usr/local/include \
93    SNDFILE_LIBS="${TMP_SNDFILE_LIBS}" \
94    $*
95fi
96
97# Reduce total size of sox.exe by over half.
98make -s all txt $DOC_TARGETS || exit 1
99
100${STRIP} src/.libs/sox.exe
101
102dir=sox-`grep Version: sox.pc | cut -d ' ' -f 2`
103rm -rf $dir $dir-win32.zip
104mkdir -p $dir
105
106for f in ChangeLog LICENSE.GPL README README.win32; do
107  cp -p $f $dir/$f.txt
108  unix2dos $dir/$f.txt
109done
110
111binaries=src/.libs/sox.exe
112
113dlls=`/usr/i686-w64-mingw32/bin/objdump -p src/.libs/libsox-3.dll | grep "DLL Name:" | sed "s|DLL Name: |${SYS_ROOT}/mingw/bin/|" | grep -v KERNEL32.dll | grep -v msvcrt.dll | grep -v USER32.dll | grep -v WINMM.DLL`
114dlls="$dlls src/.libs/libsox-3.dll"
115dlls="$dlls ${SYS_ROOT}/mingw/bin/libwinpthread-1.dll"
116
117cp -p \
118  $binaries \
119  $dlls \
120  $DOCS \
121  scripts/batch-example.bat \
122  $dir
123
124# Special case fixup for nsiswrapper. Rename libFLAC-8.dll to libflac-8.dll.
125mv $dir/libFLAC-8.dll $dir/libflac-8.dll
126
127unix2dos $dir/batch-example.bat
128
129if test -r "../wget-1.11.4/wget.exe"; then
130  cp ../wget-1.11.4/wget.exe $dir
131  cp ../wget-1.11.4/wget.ini $dir
132fi
133
134zip -r $dir-win32.zip $dir
135
136# Optionally, create windows installer if nsiswrapper exists.
137if test -r "/usr/bin/nsiswrapper"; then
138  cd ${dir}
139  export PATH=$PATH:.
140  nsiswrapper --run --name $dir --outfile ../${dir}-win32.exe *.exe *.dll *.ini *.txt *.pdf *.bat
141  cd ..
142fi
143
144rm -rf $dir
145