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