Merge ../mlt
[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="17887"
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   --avformat-no-codecs    - Disable the producer and consumer to avoid the FFmpeg codecs
24   --avformat-no-filters   - Disable the filters to make a codecs+muxers-only plugin
25
26   NOTE: The recommended version of FFmpeg is SVN-r$svn_rev.
27
28 EOF
29
30 else
31         targetos=$(uname -s)
32         case $targetos in
33         Darwin)
34                 export LIBSUF=.dylib
35                 ;;
36         Linux|FreeBSD)
37                 export LIBSUF=.so
38                 ;;
39         *)
40                 ;;
41         esac
42                 
43         bits=$(uname -m)
44         case $bits in
45         x86_64)
46                 [ -d /usr/lib/lib64 ] && export LIBDIR=lib64 || export LIBDIR=lib
47                 ;;
48         *)
49                 export LIBDIR=lib
50                 ;;
51         esac
52
53         echo > config.mak
54
55         export static_ffmpeg=
56         export shared_ffmpeg=$(pkg-config --variable=prefix libavformat)
57         export extra_libs=
58         export svn_ffmpeg=
59         export svn_ffmpeg_extra=
60         export avformat_suffix=
61         export swscale=
62         export codecs=true
63         export filters=true
64
65         for i in "$@"
66         do
67                 case $i in
68                         --avformat-static=* )   static_ffmpeg="${i#--avformat-static=}" ;;
69                         --avformat-shared=* )   shared_ffmpeg="${i#--avformat-shared=}" ;;
70                         --avformat-ldextra=* )  extra_libs="${i#--avformat-ldextra=}" ;;
71                         --avformat-svn )                svn_ffmpeg=true ;;
72                         --avformat-svn-extra=* ) svn_ffmpeg_extra="${i#--avformat-svn-extra=}" ;;
73                         --avformat-cvs )                svn_ffmpeg=true ;;
74                         --avformat-suffix=* )   avformat_suffix="${i#--avformat-suffix=}" ;;
75                         --avformat-swscale )    swscale=true ;;
76                         --avformat-swscaler )   swscale=true ;;
77                         --avformat-no-codecs )  codecs=false ;;
78                         --avformat-no-filters ) filters=false ;;
79                 esac
80         done
81
82         if [ "$svn_ffmpeg" != "" ]
83         then
84                 if [ "$gpl" = "true" ]
85                 then
86                         enable_gpl="--enable-gpl"
87                         [ "$swscale" != "" ] && [ "$svn_rev" = "17887" ] &&
88                                 enable_swscale="--enable-swscale"
89                 fi
90                 if [ ! -d "ffmpeg" ]
91                 then
92                         echo
93                         echo "Checking out ffmpeg/avformat revision $svn_rev - no password required"
94                         echo
95                         if [ "$svn_rev" = "17887" ]; then
96                                 svn checkout -r $svn_rev svn://svn.mplayerhq.hu/ffmpeg/branches/0.5 ffmpeg
97                         else
98                                 svn checkout -r $svn_rev svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg
99                         fi
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" >> config.mak
104                 echo "LDFLAGS+=-L`pwd`/ffmpeg/libavformat -L`pwd`/ffmpeg/libavcodec -L`pwd`/ffmpeg/libavutil -L`pwd`/ffmpeg/libavdevice" >> config.mak
105                 if [ "$swscale" != "" ] || [ "$svn_rev" = "HEAD" ]
106                 then
107                         echo "CFLAGS+=-I`pwd`/ffmpeg/libswscale" >> config.mak
108                         echo "LDFLAGS+=-L`pwd`/ffmpeg/libswscale" >> config.mak
109                         echo "SWSCALE=1" >> config.mak
110                 fi
111                 [ $targetos = "Darwin" ] &&
112                         echo "LDFLAGS+=-single_module" >> config.mak
113                 echo "LOCAL_FFMPEG=1" >> config.mak
114                 echo "LDFLAGS+=-Wl,-Bsymbolic" >> config.mak
115                 extra_libs="$extra_libs -lz -lbz2"
116         elif [ "$static_ffmpeg" != "" ]
117         then 
118                 if [ -d "$static_ffmpeg" ]
119                 then
120                         echo "CFLAGS+=-I$static_ffmpeg/libavformat -I$static_ffmpeg/libavcodec -I$static_ffmpeg/libavutil -I$static_ffmpeg/libavdevice" >> config.mak
121                         echo "LDFLAGS+=-L$static_ffmpeg/libavformat -L$static_ffmpeg/libavcodec -L$static_ffmpeg/libavutil -L$static_ffmpeg/libavdevice" >> config.mak
122                         [ $targetos = "Darwin" ] &&
123                                 echo "LDFLAGS+=-single_module" >> config.mak
124                         if [ "$swscale" != "" ]
125                         then
126                                 echo "CFLAGS+=-I$static_ffmpeg/libswscale" >> config.mak
127                                 echo "LDFLAGS+=-L$static_ffmpeg/libswscale" >> config.mak
128                                 echo "SWSCALE=1" >> config.mak
129                         fi
130                         echo "LDFLAGS+=-Wl,-Bsymbolic" >> config.mak
131                         extra_libs="$extra_libs -lz"
132                 else
133                         echo "avformat: Invalid path specified: $static_ffmpeg"
134                         touch ../disable-avformat
135                         echo 0
136                 fi
137         elif [ "$shared_ffmpeg" != "" ]
138         then
139                 echo "PREFIX=$shared_ffmpeg" >> config.mak
140                 echo "CFLAGS+=$(pkg-config --cflags libavformat) $TMP_CFLAGS" >> config.mak
141                 echo "LDFLAGS+=$(pkg-config --libs libavformat)" >> config.mak
142                 [ -d "$shared_ffmpeg/include/ffmpeg/libavformat" ] &&
143                         echo "CFLAGS+=-I$shared_ffmpeg/include/ffmpeg/libavformat -I$shared_ffmpeg/include/ffmpeg/libavcodec" >> config.mak
144                 [ -d "$shared_ffmpeg/include/libavformat" ] &&
145                         echo "CFLAGS+=-I$shared_ffmpeg/include/libavformat -I$shared_ffmpeg/include/libavcodec" >> config.mak
146                 avcodec_version=$(pkg-config --modversion libavcodec)
147                 if [ "$swscale" != "" ] || ( [ $(echo $avcodec_version | cut -d. -f1) -ge 52 ] && [ $(echo $avcodec_version | cut -d. -f2) -ge 21 ] )
148                 then
149                         [ -d "$shared_ffmpeg/include/ffmpeg/libswscale" ] &&
150                                 echo "CFLAGS+=-I$shared_ffmpeg/include/ffmpeg/libswscale" >> config.mak
151                         [ -d "$shared_ffmpeg/include/libswscale" ] &&
152                                 echo "CFLAGS+=-I$shared_ffmpeg/include/libswscale" >> config.mak
153                         echo "SWSCALE=1" >> config.mak
154                 fi
155         else
156                 echo "avformat: No build environment found. "
157                 echo "          Try configuring mlt with --avformat-svn."
158                 touch ../disable-avformat
159                 exit 0
160         fi
161
162         echo "EXTRA_LIBS=$extra_libs" >> config.mak
163         echo "AVFORMAT_SUFFIX=$avformat_suffix" >> config.mak
164         [ "$codecs" = "true" ] && echo "CODECS=1" >> config.mak
165         [ "$filters" = "true" ] && echo "FILTERS=1" >> config.mak
166         exit 0
167
168 fi