summaryrefslogtreecommitdiffstats
path: root/x-osx-buildstack.sh
blob: 7aa3a53fe74ccb5d2229ccd0e2f2c41d2db57545 (plain)
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
#!/bin/sh

# we keep a copy of the sources here:
: ${SRCDIR=$HOME/src/stack}
# actual build location
: ${BUILDD=$HOME/src/hv_build}
# target install dir:
: ${PREFIX=$HOME/src/hv_stack}
# concurrency
: ${MAKEFLAGS="-j2"}

case `sw_vers -productVersion | cut -d'.' -f1,2` in
	"10.4")
		echo "Tiger"
		HVARCH="-arch i386 -arch ppc"
		OSXCOMPAT=""
		;;
	"10.5")
		echo "Leopard"
		HVARCH="-arch i386 -arch ppc"
		OSXCOMPAT=""
		;;
	"10.6")
		echo "Snow Leopard"
		HVARCH="-arch i386 -arch ppc -arch x86_64"
		OSXCOMPAT="-isysroot /Developer/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5"
		;;
	*)
		echo "**UNTESTED OSX VERSION**"
		echo "if it works, please report back :)"
		HVARCH="-arch i386 -arch x86_64"
		OSXCOMPAT="-mmacosx-version-min=10.5"
		;;
	esac

################################################################################
set -e

# start with a clean slate:
if test -z "$NOCLEAN"; then
	rm -rf ${BUILDD}
	rm -rf ${PREFIX}
fi

mkdir -p ${SRCDIR}
mkdir -p ${PREFIX}
mkdir -p ${BUILDD}

unset PKG_CONFIG_PATH
export PKG_CONFIG_PATH=${PREFIX}/lib/pkgconfig
export PREFIX
export SRCDIR

OSXCOMPAT="$OSXCOMPAT -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64"

export PATH=${PREFIX}/bin:${HOME}/bin:/usr/local/git/bin/:/usr/bin:/bin:/usr/sbin:/sbin

function autoconfbuild {
echo "======= $(pwd) ======="
CFLAGS="${HVARCH}${OSXCOMPAT:+ $OSXCOMPAT}" \
CXXFLAGS="${HVARCH}${OSXCOMPAT:+ $OSXCOMPAT}" \
LDFLAGS="${HVARCH}${OSXCOMPAT:+ $OSXCOMPAT} -headerpad_max_install_names" \
./configure --disable-dependency-tracking --prefix=$PREFIX --enable-shared $@
make $MAKEFLAGS && make install
}

function download {
echo "--- Downloading.. $2"
test -f ${SRCDIR}/$1 || curl -L -o ${SRCDIR}/$1 $2
}

function src {
download ${1}.${2} $3
cd ${BUILDD}
rm -rf $1
tar xf ${SRCDIR}/${1}.${2}
cd $1
}

################################################################################
src pkg-config-0.28 tar.gz http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz
./configure --prefix=$PREFIX --with-internal-glib
make $MAKEFLAGS
make install

################################################################################
src libiconv-1.14 tar.gz ftp://ftp.gnu.org/gnu/libiconv/libiconv-1.14.tar.gz
autoconfbuild --with-included-gettext --with-libiconv-prefix=$PREFIX

################################################################################
src libpng-1.6.16 tar.gz https://downloads.sourceforge.net/project/libpng/libpng16/1.6.16/libpng-1.6.16.tar.gz
autoconfbuild

################################################################################
download jpegsrc.v9a.tar.gz http://www.ijg.org/files/jpegsrc.v9a.tar.gz
cd ${BUILDD}
tar xzf ${SRCDIR}/jpegsrc.v9a.tar.gz
cd jpeg-9a
autoconfbuild

################################################################################
src libogg-1.3.2 tar.gz http://downloads.xiph.org/releases/ogg/libogg-1.3.2.tar.gz
autoconfbuild

################################################################################
src libvorbis-1.3.4 tar.gz http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.4.tar.gz
autoconfbuild --disable-examples --disable-oggtest --with-ogg=${PREFIX}

################################################################################
src libtheora-1.1.1 tar.bz2 http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.bz2
cp configure configure.bak
sed -i '' 's/-fforce-addr //' configure
autoconfbuild --disable-sdltest --disable-vorbistest --disable-oggtest --disable-asm --disable-examples --with-ogg=${PREFIX} --with-vorbis=${PREFIX}

################################################################################
src yasm-1.2.0 tar.gz http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
autoconfbuild

################################################################################
function x264build {
CFLAGS="-arch $1 ${OSXCOMPAT}" \
LDFLAGS="-arch $1 ${OSXCOMPAT} -headerpad_max_install_names" \
./configure --host=$1-macosx-darwin --enable-shared --disable-cli
make $MAKEFLAGS
DYL=`ls libx264.*.dylib`
cp ${DYL} ${DYL}-$1
}

### ftp://ftp.videolan.org/pub/x264/snapshots/last_x264.tar.bz2
### ftp://ftp.videolan.org/pub/x264/snapshots/last_stable_x264.tar.bz2
download x264.tar.bz2 ftp://ftp.videolan.org/pub/x264/snapshots/last_stable_x264.tar.bz2 # XXX
cd ${BUILDD}
#git clone --depth 1 git://git.videolan.org/x264.git
tar xjf  ${SRCDIR}/x264.tar.bz2
cd x264*
x264build i386
make install prefix=${PREFIX}
make clean
x264build x86_64
if echo "$HVARCH" | grep -q "ppc"; then
	make clean
	x264build ppc
fi

DYL=`ls libx264.*.dylib`
lipo -create -output ${PREFIX}/lib/${DYL} ${DYL}-*
install_name_tool -id ${PREFIX}/lib/${DYL} ${PREFIX}/lib/${DYL}

################################################################################
download lame-3.99.5.tar.gz http://sourceforge.net/projects/lame/files/lame/3.99/lame-3.99.5.tar.gz/download
cd ${BUILDD}
tar xzf ${SRCDIR}/lame-3.99.5.tar.gz
cd lame-3.99.5
autoconfbuild


################################################################################
src libvpx-v1.3.0 tar.bz2 http://downloads.webmproject.org/releases/webm/libvpx-v1.3.0.tar.bz2

function buildvpx {
cd ${BUILDD}/libvpx-v1.3.0
./configure --prefix=$PREFIX --target=$1
make clean
make $MAKEFLAGS && make install
make clean
}

################################################################################
FFVERSION=2.8.2
download ffmpeg-${FFVERSION}.tar.bz2 http://www.ffmpeg.org/releases/ffmpeg-${FFVERSION}.tar.bz2
cd ${BUILDD}
tar xjf ${SRCDIR}/ffmpeg-${FFVERSION}.tar.bz2
cd ffmpeg-${FFVERSION}/
ed configure << EOF
%s/jack_jack_h/xxjack_jack_h/
%s/enabled jack_indev/enabled xxjack_indev/
%s/sdl_outdev_deps="sdl"/sdl_outdev_deps="xxxsdl"/
%s/enabled sdl/enabled xxsdl/
wq
EOF

rm -rf ${PREFIX}/fflipo
mkdir ${PREFIX}/fflipo

buildvpx x86-darwin9-gcc
cd ${BUILDD}/ffmpeg-${FFVERSION}/

./configure --prefix=${PREFIX} \
	--enable-libx264 --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-libvpx \
	--enable-shared --enable-gpl --disable-static --disable-debug --disable-doc \
	--disable-ffserver --disable-ffplay --disable-iconv \
	--arch=x86_32 --target-os=darwin --cpu=i686 --enable-cross-compile \
	--extra-cflags="-arch i386 ${OSXCOMPAT}  -I${PREFIX}/include" \
	--extra-ldflags="-arch i386 ${OSXCOMPAT} -L${PREFIX}/lib -headerpad_max_install_names"
make $MAKEFLAGS
make install

find . -iname "*dylib" -type f -exec echo cp -v {} ${PREFIX}/fflipo/\`basename {}\`-i386 \; | bash -
cp ffprobe ${PREFIX}/fflipo/ffprobe-i386
cp ffmpeg ${PREFIX}/fflipo/ffmpeg-i386
make clean

buildvpx x86_64-darwin9-gcc
cd ${BUILDD}/ffmpeg-${FFVERSION}/
./configure --prefix=${PREFIX} \
	--enable-libx264 --enable-libvpx \
	--enable-libtheora --enable-libvorbis --enable-libmp3lame \
	--enable-shared --enable-gpl --disable-static --disable-debug --disable-doc \
	--disable-ffserver --disable-ffplay --disable-iconv \
	--arch=x86_64 \
	--extra-cflags="-arch x86_64 ${OSXCOMPAT}  -I${PREFIX}/include" \
	--extra-ldflags="-arch x86_64 ${OSXCOMPAT} -L${PREFIX}/lib -headerpad_max_install_names"
make $MAKEFLAGS
find . -iname "*dylib" -type f -exec echo cp -v {} ${PREFIX}/fflipo/\`basename {}\`-x86_64 \; | bash -
cp ffprobe ${PREFIX}/fflipo/ffprobe-x86_64
cp ffmpeg ${PREFIX}/fflipo/ffmpeg-x86_64
make clean

if echo "$HVARCH" | grep -q "ppc"; then
buildvpx ppc32-darwin9-gcc
cd ${BUILDD}/ffmpeg-${FFVERSION}/
./configure --prefix=${PREFIX} \
	--enable-libx264 --enable-libtheora --enable-libvorbis --enable-libmp3lame --enable-libvpx \
	--enable-shared --enable-gpl --disable-static --disable-debug --disable-doc \
	--disable-ffserver --disable-ffplay --disable-iconv \
	--arch=ppc \
	--extra-cflags="-arch ppc ${OSXCOMPAT}  -I${PREFIX}/include" \
	--extra-ldflags="-arch ppc ${OSXCOMPAT} -L${PREFIX}/lib -headerpad_max_install_names"
make $MAKEFLAGS
find . -iname "*dylib" -type f -exec echo cp -v {} ${PREFIX}/fflipo/\`basename {}\`-ppc \; | bash -
cp ffprobe ${PREFIX}/fflipo/ffprobe-ppc
cp ffmpeg ${PREFIX}/fflipo/ffmpeg-ppc
fi

for file in ${PREFIX}/fflipo/*.dylib-i386; do
  BN=$(basename $file -i386)
  TN=$(readlink ${PREFIX}/lib/${BN})
  lipo -create -output ${PREFIX}/lib/${TN} ${PREFIX}/fflipo/${BN}-*
done

lipo -create -o "${PREFIX}/bin/ffmpeg" ${PREFIX}/fflipo/ffmpeg-*
lipo -create -o "${PREFIX}/bin/ffprobe" ${PREFIX}/fflipo/ffprobe-*

rm -rf ${PREFIX}/fflipo

################################################################################
if test -n "$DOCLEAN"; then
	rm -rf ${BUILDD}
	mkdir ${BUILDD}
fi
################################################################################
cd ${BUILDD}
rm -rf harvid
git clone -b master --single-branch git://github.com/x42/harvid.git
cd harvid

export HVARCH
export OSXCOMPAT
./x-osx-bundle.sh