avformat/configure: checkout (--avformat-svn) or recommend (--help) a specific FFmpeg...
[melted] / src / modules / avformat / configure
1 #!/bin/sh
2
3 # Determine whether to recommend/use the HEAD revision of FFmpeg (unreleased)
4 # or a specific revision based upon whether the last digit of our version
5 # is even or odd. An odd MLT version number always represents unreleased.
6 svn_rev="15791"
7 micro_version=$(echo $version | cut -d . -f 3)
8 odd_version=$(($micro_version % 2))
9 [ "$odd_version" -eq "1" ] && svn_rev="HEAD"
10
11 if [ "$help" = "1" ]
12 then
13         cat << EOF
14 FFMPEG/avformat options:
15
16   --avformat-svn          - Obtain ffmpeg from Subversion
17   --avformat-svn-extra    - Add extra configure options for --avformat-svn
18   --avformat-shared=path  - Link against a shared installation of ffmpeg (default)
19   --avformat-static=path  - Link against a static ffmpeg dev tree
20   --avformat-ldextra=libs - Provide additional libs to link with
21   --avformat-suffix=suff  - Specify a custom suffix for an ffmpeg shared build
22   --avformat-swscale      - Use ffmpeg libswcale instead of img_convert
23
24   NOTE: The recommended version of FFmpeg is SVN-r$svn_rev.
25
26 EOF
27
28 else
29         targetos=$(uname -s)
30         case $targetos in
31         Darwin)
32                 export LIBSUF=.dylib
33                 ;;
34         Linux)
35                 export LIBSUF=.so
36                 ;;
37         *)
38                 ;;
39         esac
40                 
41         bits=$(uname -m)
42         case $bits in
43         x86_64)
44                 [ -d /usr/lib/lib64 ] && export LIBDIR=lib64 || export LIBDIR=lib
45                 ;;
46         *)
47                 export LIBDIR=lib
48                 ;;
49         esac
50
51         echo > config.mak
52
53         export static_ffmpeg=
54         export shared_ffmpeg=$(pkg-config --variable=prefix libavformat)
55         export extra_libs=
56         export svn_ffmpeg=
57         export svn_ffmpeg_extra=
58         export avformat_suffix=
59         export swscale=
60
61         for i in "$@"
62         do
63                 case $i in
64                         --avformat-static=* )   static_ffmpeg="${i#--avformat-static=}" ;;
65                         --avformat-shared=* )   shared_ffmpeg="${i#--avformat-shared=}" ;;
66                         --avformat-ldextra=* )  extra_libs="${i#--avformat-ldextra=}" ;;
67                         --avformat-svn )                svn_ffmpeg=true ;;
68                         --avformat-svn-extra=* ) svn_ffmpeg_extra="${i#--avformat-svn-extra=}" ;;
69                         --avformat-cvs )                svn_ffmpeg=true ;;
70                         --avformat-suffix=* )   avformat_suffix="${i#--avformat-suffix=}" ;;
71                         --avformat-swscale )    swscale=true ;;
72                         --avformat-swscaler )   swscale=true ;;
73                 esac
74         done
75
76         if [ "$svn_ffmpeg" != "" ]
77         then
78                 if [ "$gpl" = "true" ]
79                 then
80                         enable_gpl="--enable-gpl"
81                         if [ "$swscale" != "" ]
82                         then
83                                         enable_swscale="--enable-swscale"
84                                         echo "SWSCALE=1" >> config.mak
85                         fi
86                 elif [ "$swscale" != "" ]
87                 then
88                         echo
89                         echo "ERROR        ERROR        ERROR        ERROR        ERROR        ERROR"
90                         echo "--enable-gpl is required to use --avformat-swscale with --avformat-svn!"
91                         echo
92                         exit
93                 fi
94                 if [ ! -d "ffmpeg" ]
95                 then
96                         echo
97                         echo "Checking out ffmpeg/avformat revision $svn_rev - no password required"
98                         echo
99                         svn checkout -r $svn_rev svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
100                 fi
101                 [ -d "ffmpeg" ] && ( cd ffmpeg ; ./configure $enable_gpl $enable_swscale $svn_ffmpeg_extra )
102                 #[ ! -f "ffmpeg/ffmpeg.patch" ] && ( cd ffmpeg ; cp ../ffmpeg.patch . ; patch -p0 < ffmpeg.patch )
103                 echo "CFLAGS+=-I`pwd`/ffmpeg -I`pwd`/ffmpeg/libavformat -I`pwd`/ffmpeg/libavcodec -I`pwd`/ffmpeg/libavutil -I`pwd`/ffmpeg/libavdevice -I`pwd`/ffmpeg/libswscale" >> config.mak
104                 echo "LDFLAGS+=-L`pwd`/ffmpeg/libavformat -L`pwd`/ffmpeg/libavcodec -L`pwd`/ffmpeg/libavutil -L`pwd`/ffmpeg/libavdevice -L`pwd`/ffmpeg/libswscale" >> config.mak
105                 [ $targetos = "Darwin" ] &&
106                         echo "LDFLAGS+=-single_module" >> config.mak
107                 echo "LOCAL_FFMPEG=1" >> config.mak
108                 echo "LDFLAGS+=-Wl,-Bsymbolic" >> config.mak
109                 extra_libs="$extra_libs -lz"
110         elif [ "$static_ffmpeg" != "" ]
111         then 
112                 if [ -d "$static_ffmpeg" ]
113                 then
114                         echo "CFLAGS+=-I$static_ffmpeg/libavformat -I$static_ffmpeg/libavcodec -I$static_ffmpeg/libavutil -I$static_ffmpeg/libavdevice" >> config.mak
115                         echo "LDFLAGS+=-L$static_ffmpeg/libavformat -L$static_ffmpeg/libavcodec -L$static_ffmpeg/libavutil -L$static_ffmpeg/libavdevice" >> config.mak
116                         [ $targetos = "Darwin" ] &&
117                                 echo "LDFLAGS+=-single_module" >> config.mak
118                         if [ "$swscale" != "" ]
119                         then
120                                 echo "CFLAGS+=-I$static_ffmpeg/libswscale" >> config.mak
121                                 echo "LDFLAGS+=-L$static_ffmpeg/libswscale" >> config.mak
122                                 echo "SWSCALE=1" >> config.mak
123                         fi
124                         echo "LDFLAGS+=-Wl,-Bsymbolic" >> config.mak
125                         extra_libs="$extra_libs -lz"
126                 else
127                         echo "avformat: Invalid path specified: $static_ffmpeg"
128                         touch ../disable-avformat
129                         echo 0
130                 fi
131         elif [ "$shared_ffmpeg" != "" ]
132         then
133                 echo "PREFIX=$shared_ffmpeg" >> config.mak
134                 echo "CFLAGS+=$(pkg-config --cflags libavformat) $TMP_CFLAGS" >> config.mak
135                 echo "LDFLAGS+=$(pkg-config --libs libavformat)" >> config.mak
136                 [ -d "$shared_ffmpeg/include/ffmpeg/libavformat" ] &&
137                         echo "CFLAGS+=-I$shared_ffmpeg/include/ffmpeg/libavformat -I$shared_ffmpeg/include/ffmpeg/libavcodec" >> config.mak
138                 [ -d "$shared_ffmpeg/include/libavformat" ] &&
139                         echo "CFLAGS+=-I$shared_ffmpeg/include/libavformat -I$shared_ffmpeg/include/libavcodec" >> config.mak
140                 if [ "$swscale" != "" ]
141                 then
142                         [ -d "$shared_ffmpeg/include/ffmpeg/libswscale" ] &&
143                                 echo "CFLAGS+=-I$shared_ffmpeg/include/ffmpeg/libswscale" >> config.mak
144                         [ -d "$shared_ffmpeg/include/libswscale" ] &&
145                                 echo "CFLAGS+=-I$shared_ffmpeg/include/libswscale" >> config.mak
146                         echo "SWSCALE=1" >> config.mak
147                 fi
148         else
149                 echo "avformat: No build environment found. "
150                 echo "          Try configuring mlt with --avformat-svn."
151                 touch ../disable-avformat
152                 exit 0
153         fi
154
155         echo "EXTRA_LIBS=$extra_libs" >> config.mak
156         echo "AVFORMAT_SUFFIX=$avformat_suffix" >> config.mak
157
158 fi