Fix build of libmvcp.
[melted] / configure
1 #!/bin/sh
2
3 export version=0.3.9
4 export soversion=2
5
6 show_help()
7 {
8         cat << EOF
9 Non-autotool config script for Melted.
10
11 Help options:
12
13   --help                  - this information
14
15 General build options:
16
17   --prefix=directory      - install prefix for path (default: $prefix)
18   --libdir=directory      - lib directory (default: $prefix/lib)
19   --enable-gpl            - Enable GPL components
20   --disable-debug         - Compile without debug support (default: on)
21   --disable-mmx           - Compile without MMX support (default: on)
22   --disable-sse           - Compile without SSE support (default: on)
23   --arch='arch'           - Compile for a specific architecture (default: none)
24   --cpu='cpu'             - Compile for a specific CPU (default: none)
25
26 Module disables options:
27
28 EOF
29
30         for i in src/modules/*
31         do
32                 [ -d $i ] && [ "`basename $i`" != "CVS" ] && echo `basename $i` `[ -f $i/gpl ] && echo [GPL]`
33         done |
34         awk '{ printf( "  --disable-%-14.14s- Disable the %s module %s\n", $1, $1, $2 ); }'
35
36         echo
37         echo "  NOTE: libraries marked [GPL] will not be built unless --enable-gpl is stipulated."
38         echo
39 }
40
41 build_config()
42 {
43         (
44                 echo "version=$version"
45                 echo "soversion=$soversion"
46                 echo "prefix=$prefix"
47                 echo "libdir=$libdir"
48                 echo "bindir=$prefix/bin"
49                 echo "targetos=$targetos"
50
51                 [ "$mmx" = "true" ] && 
52                 echo "MMX_FLAGS=-DUSE_MMX"
53
54                 [ "$sse" = "true" ] && 
55                 echo "SSE_FLAGS=-DUSE_SSE"
56
57                 [ "$debug" = "true" ] && 
58                 echo "DEBUG_FLAGS=-g"
59
60                 echo "LARGE_FILE=-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE"
61
62                 [ "$arch" != "" ] && echo "TARGETARCH=-march=$arch"
63                 [ "$cpu" != "" ] && echo "TARGETCPU=-mcpu=$cpu"
64                 echo "OPTIMISATIONS=-O2 -pipe -fomit-frame-pointer"
65
66                 echo "CFLAGS+=-Wall -fPIC -DPIC \$(TARGETARCH) \$(TARGETCPU) \$(OPTIMISATIONS) \$(MMX_FLAGS) \$(SSE_FLAGS) \$(DEBUG_FLAGS) \$(LARGE_FILE)"
67
68                 case $targetos in
69                 Darwin)
70                 sysctl -a hw | grep "x86_64: 1" > /dev/null && echo "ARCH_X86_64=1" && echo "CFLAGS+=-DARCH_X86_64"
71                 echo "CFLAGS+=-D__DARWIN__ `sdl-config --cflags`"
72                 echo "SHFLAGS=-dynamiclib"
73                 echo "LDFLAGS+=`sdl-config --libs`"
74                 ;;
75                 Linux)
76                 [ "$(uname -m)" = "x86_64" ] && echo "ARCH_X86_64=1" && echo "CFLAGS+=-DARCH_X86_64"
77                 echo "OPTIMISATIONS+=-ffast-math"
78                 echo "CFLAGS+=-pthread"
79                 echo "SHFLAGS=-shared"
80                 echo "LIBDL=-ldl"
81                 echo "RDYNAMIC=-rdynamic"
82                 ;;
83                 FreeBSD)
84                 [ "$(uname -m)" = "x86_64" ] && echo "ARCH_X86_64=1" && echo "CFLAGS+=-DARCH_X86_64"
85                 echo "OPTIMISATIONS+=-ffast-math"
86                 echo "CFLAGS+=-pthread"
87                 echo "SHFLAGS=-shared"
88                 echo "RDYNAMIC=-rdynamic"
89                 ;;
90                 *)
91                 ;;
92                 esac
93                 echo "LIBSUF=$LIBSUF"
94                 
95                 echo "CFLAGS += `pkg-config --cflags mlt-framework`"
96                 echo "LDFLAGS += `pkg-config --libs mlt-framework`"
97
98         ) > config.mak
99
100         echo -n > packages.dat
101 }
102
103 build_pkgconfig()
104 {
105         for i in mvcp melted melted++
106         do
107                 echo prefix="$prefix" > mlt-$i.pc
108                 (
109                         echo exec_prefix=$prefix
110                         echo libdir=$libdir
111                         echo includedir=$prefix/include
112                         echo version=$version
113                         echo cflags=`grep ^$i packages.dat | cut -f 2`
114                         echo libs=`grep ^$i packages.dat | cut -f 3`
115                 ) >> mlt-$i.pc
116                 cat mlt-$i.pc.in >>mlt-$i.pc
117         done
118 }
119
120 # Debug mode
121 set +x
122
123 # Define build directory for scripts called
124 export build_dir=`dirname $0`
125 export prefix=/usr/local
126 export libdir=""
127 export help=0
128 export debug=true
129 export mmx=true
130 export sse=true
131 export gpl=false
132 export arch=
133 export cpu=
134 export targetos=
135
136 # Determine OS
137 targetos=$(uname -s)
138 # Chose appropriate suffix for libraries
139 case $targetos in
140         Darwin)
141         LIBSUF=".dylib"
142         ;;
143         Linux|FreeBSD)
144         LIBSUF=".so"
145         ;;
146         *)
147         LIBSUF=".so"
148         ;;
149 esac
150 export LIBSUF
151
152 # Iterate through arguments
153 for i in "$@"
154 do
155         case $i in
156                 --help )                        help=1 ;;
157                 --prefix=* )            prefix="${i#--prefix=}" ;;
158                 --libdir=* )            libdir="${i#--libdir=}" ;;
159                 --disable-debug )       debug=false ;;
160                 --disable-mmx )         mmx=false; sse=false ;;
161                 --disable-sse )         sse=false ;;
162                 --enable-gpl )          gpl=true ;;
163                 --arch=* )                      arch="${i#--arch=}" ;;
164                 --cpu=* )                       cpu="${i#--cpu=}" ;;
165         esac
166 done
167
168 # Determine the libdir if it's not specified in the args
169 [ "$libdir" = "" ] && libdir=$prefix/lib
170
171 # Double check MMX (Darwin, Linux and FreeBSD supported, may end up disabling MMX on other platforms incorrectly)
172 if [ "$mmx" = "true" ]
173 then
174         case $targetos in
175                 Darwin)
176                 sysctl -a hw | grep "mmx: 1" > /dev/null || mmx=false
177                 ;;
178                 Linux)
179                 grep mmx /proc/cpuinfo > /dev/null 2>&1 || mmx=false
180                 ;;
181                 FreeBSD)
182                 [ "$(make -V MACHINE_CPU:Mmmx)" ] || mmx=false
183                 ;;
184                 *)
185                 grep mmx /proc/cpuinfo > /dev/null 2>&1 || mmx=false
186                 ;;
187         esac
188 fi
189
190 # Double check SSE (Darwin, Linux and FreeBSD supported, may end up disabling SSE on other platforms incorrectly)
191 if [ "$sse" = "true" ]
192 then
193         case $targetos in
194                 Darwin)
195                 sysctl -a hw | grep "sse: 1" > /dev/null || sse=false
196                 ;;
197                 Linux)
198                 grep sse /proc/cpuinfo > /dev/null 2>&1 || sse=false
199                 ;;
200                 FreeBSD)
201                 [ "$(make -V MACHINE_CPU:Msse)" ] || sse=false
202                 ;;
203                 *)
204                 grep sse /proc/cpuinfo > /dev/null 2>&1 || sse=false
205                 ;;
206         esac
207 fi
208
209 # Show help if requested
210 if [ $help = 1 ]
211 then
212         show_help
213 else
214         # Log the configuration history
215         date >> config.log
216         echo "$0 $@" >> config.log
217
218         build_config
219 fi
220
221 # Iterate through each of the components
222 for i in mvcp melted melted++ mvcp-client modules
223 do
224         if [ "$gpl" = "true" -o ! -f src/$i/gpl ]
225         then
226                 if [ -x src/$i/configure ]
227                 then
228                         [ $help = 0 ] && echo "Configuring `basename $i`:"
229                         olddir=`pwd`
230                         cd src/$i
231                         ./configure "$@"
232                         [ $? != 0 ] && exit 1
233                         cd $olddir
234                 fi
235         fi
236 done
237
238 # Build the pkg-config files
239 build_pkgconfig
240
241 # Report GPL Usage
242 [ $help != 1 ] && 
243 ( [ "$gpl" = "false" ] && 
244 echo "GPL Components are disabled" || 
245 echo "GPL License Used" )