Merge CV, ver=5.1; ops/methods from HV, and interface from CV where possible
[goodguy/history.git] / cinelerra-5.1 / thirdparty / configure
1 #!/bin/bash
2
3 if [ "$1" = "static" ]; then
4   STATIC_LIBRARIES="y"
5 elif [ "$1" = "shared" ]; then
6   STATIC_LIBRARIES="n"
7 elif [ "$1" = "cv" ]; then
8   STATIC_LIBRARIES="n"
9   libs="libogg libtheora libvorbis openexr libdv libjpeg tiff x264 mjpegtools a52dec lame libsndfile faac faad2"
10   forced_libs="mjpegtools x264"
11 else
12   echo "usage: $0 <static | shared | cv>"
13   exit 1
14 fi
15
16 #thirdparty libraries
17
18 echo "configuring thirdparty library build"
19 echo ""
20 echo "required libraries:"
21
22 append() {
23   var=$1
24   shift
25   eval "$var+=\" $*\""
26 }
27
28 is_in() {
29   value=$1
30   shift
31   for var in $*; do
32     [ $var = $value ] && return 0
33   done
34   return 1
35 }
36
37 add_library() {
38   local lib=$1
39   shift 1
40   append LIBS $lib
41   sta_lib=sta_$lib
42   append $sta_lib $@
43 }
44
45 inc_a52dec="include"
46 add_library a52dec \
47         liba52/.libs/liba52.a
48 inc_audiofile="."
49 add_library audiofile \
50         libaudiofile/.libs/libaudiofile.a \
51         libaudiofile/modules/.libs/libmodules.a \
52         libaudiofile/alac/.libs/libalac.a
53 inc_encore="."
54 add_library encore \
55         `uname -m`/libencore.a
56 inc_esound="."
57 add_library esound \
58         .libs/libesd.a \
59         .libs/libesddsp.a
60 inc_faac="include"
61 add_library faac \
62         libfaac/.libs/libfaac.a \
63         common/mp4v2/libmp4v2.a
64 inc_faad2="include"
65 add_library faad2 \
66         libfaad/.libs/libfaad.a \
67         common/mp4ff/libmp4ff.a
68 # fdk replaces faac/faad2, but is experimental...
69 inc_fdk="libAACdec/include libAACenc/include libSYS/include"
70 add_library fdk \
71         .libs/libfdk-aac.a
72 inc_festival="src"
73 add_library festival \
74         src/lib/libFestival.a
75 inc_ffmpeg="."
76 add_library ffmpeg \
77         libavutil/libavutil.a \
78         libavcodec/libavcodec.a \
79         libpostproc/libpostproc.a \
80         libavdevice/libavdevice.a \
81         libavformat/libavformat.a \
82         libswscale/libswscale.a \
83         libavfilter/libavfilter.a \
84         libswresample/libswresample.a
85 inc_fftw="api"
86 add_library fftw \
87         .libs/libfftw3.a \
88         libbench2/libbench2.a \
89         rdft/scalar/r2cb/.libs/librdft_scalar_r2cb.a \
90         rdft/scalar/r2r/.libs/librdft_scalar_r2r.a \
91         rdft/scalar/.libs/librdft_scalar.a \
92         rdft/scalar/r2cf/.libs/librdft_scalar_r2cf.a \
93         rdft/.libs/librdft.a \
94         api/.libs/libapi.a \
95         reodft/.libs/libreodft.a \
96         dft/scalar/codelets/.libs/libdft_scalar_codelets.a \
97         dft/scalar/.libs/libdft_scalar.a \
98         dft/.libs/libdft.a \
99         kernel/.libs/libkernel.a \
100         simd-support/.libs/libsimd_support.a \
101         simd-support/.libs/libsimd_sse2_nonportable.a
102 inc_flac="include"
103 add_library flac \
104         src/libFLAC/.libs/libFLAC.a \
105         src/libFLAC++/.libs/libFLAC++.a \
106         src/share/utf8/.libs/libutf8.a \
107         src/share/replaygain_analysis/.libs/libreplaygain_analysis.a \
108         src/share/replaygain_synthesis/.libs/libreplaygain_synthesis.a \
109         src/share/grabbag/.libs/libgrabbag.a \
110         src/test_libs_common/.libs/libtest_libs_common.a
111 inc_giflib="lib"
112 add_library giflib \
113         lib/.libs/libgif.a \
114         util/libgetarg.a
115 inc_ilmbase="Iex Half Imath config IlmThread"
116 add_library ilmbase \
117         Iex/.libs/libIex.a \
118         IexMath/.libs/libIexMath.a \
119         Half/.libs/libHalf.a \
120         Imath/.libs/libImath.a \
121         IlmThread/.libs/libIlmThread.a
122 inc_ladspa=""
123 add_library ladspa
124 inc_lame="include"
125 add_library lame \
126         libmp3lame/.libs/libmp3lame.a \
127         mpglib/.libs/libmpgdecoder.a
128 inc_libavc1394="."
129 add_library libavc1394 \
130         libavc1394/.libs/libavc1394.a \
131         librom1394/.libs/librom1394.a \
132         common/.libs/libraw1394util.a
133 inc_libdv="."
134 add_library libdv \
135         libdv/.libs/libdv.a
136 inc_libiec61883="src"
137 add_library libiec61883 \
138         src/.libs/libiec61883.a
139 inc_libjpeg="."
140 add_library libjpeg \
141         .libs/libjpeg.a \
142         .libs/libturbojpeg.a \
143         simd/.libs/libsimd.a
144 inc_openjpeg="src/lib/openjp2"
145 add_library openjpeg \
146         bin/libopenjp2.a
147 inc_libogg="include"
148 add_library libogg \
149         src/.libs/libogg.a
150 inc_libraw1394="."
151 add_library libraw1394 \
152         src/.libs/libraw1394.a
153 inc_libsndfile="."
154 add_library libsndfile \
155         src/.libs/libsndfile.a \
156         src/.libs/libcommon.a \
157         src/G72x/.libs/libg72x.a \
158         src/GSM610/.libs/libgsm.a
159 inc_libtheora="."
160 add_library libtheora \
161         lib/.libs/libtheora.a \
162         lib/.libs/libtheoradec.a \
163         lib/.libs/libtheoraenc.a
164 inc_libuuid="."
165 add_library libuuid \
166         .libs/libuuid.a
167 inc_libvorbis="include ."
168 add_library libvorbis \
169         lib/.libs/libvorbis.a \
170         lib/.libs/libvorbisenc.a \
171         lib/.libs/libvorbisfile.a
172 inc_mjpegtools=". lavtools utils"
173 add_library mjpegtools \
174         utils/mmxsse/.libs/libmmxsse.a \
175         utils/.libs/libmjpegutils.a \
176         lavtools/.libs/liblavfile.a \
177         lavtools/.libs/liblavjpeg.a \
178         yuvfilters/.libs/libyuvfilters.a \
179         mpeg2enc/.libs/libmpeg2encpp.a \
180         mplex/.libs/libmplex2.a
181 inc_openexr="IlmImf config"
182 add_library openexr \
183         IlmImf/.libs/libIlmImf.a \
184         IlmImfUtil/.libs/libIlmImfUtil.a
185 inc_speech_tools="."
186 add_library speech_tools \
187         lib/libestools.a \
188         lib/libeststring.a \
189         lib/libestbase.a
190 inc_tiff="."
191 add_library tiff \
192         libtiff/.libs/libtiff.a \
193         libtiff/.libs/libtiffxx.a \
194         port/.libs/libport.a
195 inc_twolame="libtwolame"
196 add_library twolame \
197         libtwolame/.libs/libtwolame.a
198 inc_x264="."
199 add_library x264 \
200         libx264.a
201 inc_x265=". source"
202 add_library x265 \
203         libx265.a
204 inc_libvpx="."
205 add_library libvpx \
206         libvpx.a \
207
208 echo ""
209 if [ -n "$libs" ]; then
210   LIBS="$libs"
211 fi
212
213 n=0
214 for lib in $LIBS; do
215   echo -n " $lib"
216   if [ $(((n+=1) % 8)) = 0 ]; then echo ""; fi
217 done
218 if [ $((n % 8)) != 0 ]; then echo ""; fi
219 echo ""
220
221 # dynamic library paths
222 probe() {
223   if ! `echo $LIBS | grep -qw $1`; then return 0; fi
224   local name="$1"
225   local headers="$2"
226   local func="$3"
227   shift 3
228
229   : ${TMPDIR:=$TEMPDIR}
230   : ${TMPDIR:=$TMP}
231   : ${TMPDIR:=/tmp}
232
233   local exe=$(mktemp -u "${TMPDIR}/cine-${name}.XXXXXXXX")
234   trap "rm -f -- ${exe}" EXIT
235
236   {
237     for hdr in $headers; do
238       test "${hdr%.h}" = "${hdr}" &&
239         echo "#include $hdr"    ||
240         echo "#include <$hdr>"
241     done
242     for func in $func; do
243       echo "long check_$func(void) { return (long) $func; }"
244     done
245     echo "int main(void) { return 0; }"
246   } | cc -x c - -o $exe $@ >& /dev/null
247   ret=$?
248   rm -f "${exe}"
249   if [ $ret = 0 ]; then
250     eval $name=\"shared $*\"
251     echo "exists shared $name"
252     return 0
253   fi
254   local sta_libs=sta_$name
255   eval $name=\"static ${!sta_libs}\"
256   echo "build  static $name"
257   return 1
258 }
259
260 # test for shared libs/header files
261 probe a52dec "a52.h" a52_init -la52
262 probe audiofile "audiofile.h" afOpenFile -laudiofile
263 probe faac "stdint.h faac.h" faacEncGetVersion -lfaac
264 probe faad2 "faad.h" NeAACDecInit -lfaad
265 # dont build festival in shared build
266 if [ "$STATIC_LIBRARIES" = "n" ]; then festival="shared"; fi
267 if [ "$STATIC_LIBRARIES" = "n" ]; then speech_tools="shared"; fi
268 probe fftw "fftw3.h" fftw_execute -lfftw3
269 probe flac "FLAC/stream_decoder.h" FLAC__stream_decoder_new -lFLAC
270 probe lame "lame/lame.h" hip_decode_init -lmp3lame
271 probe libavc1394 "libavc1394/avc1394.h librom1394/rom1394.h" avc1394_init_target -lavc1394
272 probe libdv "libdv/dv.h" dv_init -ldv
273 probe libiec61883 "libiec61883/iec61883.h" iec61883_mpeg2_recv_init -liec61883
274 probe libjpeg "stdio.h unistd.h jpeglib.h" jpeg_start_decompress -ljpeg
275 probe libogg "ogg/ogg.h" ogg_stream_init -logg
276 probe openjpeg "openjpeg.h" opj_version -lopenjp2 -DOPJ_STATIC || \
277 probe openjpeg "openjpeg-1.5/openjpeg.h" opj_version -lopenjpeg -DOPJ_STATIC || \
278 probe openjpeg "openjpeg.h" opj_version -lopenjpeg -DOPJ_STATIC
279 probe libraw1394 "libraw1394/raw1394.h" raw1394_iso_recv_init -lraw1394
280 probe libsndfile "sndfile.h" sf_open -lsndfile
281 probe ilmbase "OpenEXR/ImfCRgbaFile.h" ImfOpenInputFile -lIlmImf -lIlmThread -lIex
282 probe openexr "OpenEXR/ImfCRgbaFile.h" ImfOpenInputFile -lIlmImf -lIlmThread -lIex
283 probe libtheora "theora/theoraenc.h" th_info_init -ltheora -ltheoraenc -ltheoradec -logg
284 probe libvorbis "vorbis/vorbisenc.h" vorbis_info_init -lvorbisenc -lvorbis -lvorbisfile -logg
285 probe libvpx "vpx/vpx_decoder.h" vpx_codec_decode -lvpx
286 probe tiff "tiff.h tiffio.h" TIFFOpen -ltiff
287 probe twolame "twolame.h" twolame_encode_buffer_float32_interleaved -ltwolame
288 probe x264 "stdint.h x264.h" x264_encoder_encode -lx264
289 probe x265 "x265.h" x265_encoder_encode -lx265
290
291 if [ -n "$forced_libs" ]; then
292   forced_libs="encore ffmpeg giflib libuuid"
293 fi
294
295 # for ffmpeg link/broken disto libs
296 for name in $LIBS; do
297   if is_in $name $forced_libs; then
298     set - ${!name}
299     typ="$1"
300     shift 1
301     if [ "$typ" = "shared" ]; then
302       echo "warn: $name forced static"
303       sta_libs=sta_$name
304       eval $name=\"static ${!sta_libs}\"
305     fi
306   fi
307 done
308
309 # add dependencies (order matters)
310 for dep in \
311         ffmpeg/faac ffmpeg/faad2 ffmpeg/twolame ffmpeg/lame ffmpeg/openjpeg \
312         ffmpeg/libvorbis ffmpeg/libtheora ffmpeg/x264 ffmpeg/fdk \
313         libiec61883/libraw1394 libavc1394/librom1394 \
314         openexr/ilmbase ilmbase/libogg \
315         libtheora/libogg libtheora/libvorbis ; do
316   lib="${dep%%/*}"
317   needs="${dep##*/}"
318   if is_in $lib $shared; then
319     if is_in $needs $shared; then continue; fi
320     if is_in $needs $static; then
321       echo warn: shared $lib using static $needs
322       continue
323     fi
324     append shared $needs
325   fi
326   if is_in $lib $static; then
327     if is_in $needs $static; then continue; fi
328     if is_in $needs $shared; then
329       echo warn: static $lib using shared $needs
330       continue
331     fi
332     append static $needs
333   fi
334 done
335
336 echo ""
337 # check for static libs which may conflicting header files
338 if [ "$STATIC_LIBRARIES" = "y" ]; then
339   for name in $LIBS; do
340     set - ${!name}
341     typ="$1"
342     shift 1
343     if [ "$typ" = "shared" ]; then
344       echo "warn: $name is shared and static"
345     fi
346     sta_libs=sta_$name
347     eval $name=\"static ${!sta_libs}\"
348   done
349 fi
350
351 # any unknowns are static
352 for name in $LIBS; do
353   if [ -z "${!name}" ]; then
354     sta_libs=sta_$name
355     eval $name=\"static ${!sta_libs}\"
356   fi
357 done
358
359 # dont build festival
360 festival="shared"
361 speech_tools="shared"
362
363 shared=""
364 static=""
365 for lib in $LIBS; do
366   set - ${!lib}
367   typ="$1"
368   append $typ $lib
369 done
370
371 echo "thirdparty :=$LIBS"    > config.mak
372 echo "shared_libs :=$shared" >> config.mak
373 echo "static_libs :=$static" >> config.mak
374
375 for lib in $LIBS; do
376   echo "$lib := ${!lib}"
377   inc_lib=inc_$lib
378   echo "inc_$lib := ${!inc_lib}"
379 done >> config.mak
380
381 echo >> config.mak '
382 # translate config.mak into libs/incs
383
384 pkg_path=$(lastword $(wildcard $(THIRDPARTY)/$(1)*))
385 lib_static=$(call pkg_path,$(1))/$(2)
386 lib_shared=$(2)
387 inc_static=-I$(1)/$(2)
388 inc_shared=
389 lib_typ=$(firstword $(1))
390 lib_refs=$(wordlist 2,$(words $(1)),$(1))
391
392 $(foreach lib,$(thirdparty), \
393   $(eval pkg_$(lib) := $(call pkg_path,$(lib))) \
394   $(eval typ_$(lib) := $(call lib_typ,$($(lib)))) \
395   $(eval lib_$(lib) := \
396     $(foreach ref, $(call lib_refs,$($(lib))), \
397        $(call lib_$(typ_$(lib)),$(lib),$(ref)))) \
398   $(eval inc_$(lib) := \
399     $(foreach inc, $(inc_$(lib)), \
400        $(call inc_$(typ_$(lib)),$(pkg_$(lib)),$(inc)))))
401
402 #list libs/incs
403 ifeq ($(MAKECMDGOALS),list)
404 $(foreach lib,$(thirdparty),$(info $(lib) := $(typ_$(lib)) $(pkg_$(lib))) \
405    $(foreach ref,$(lib_$(lib)), $(info == $(ref))) \
406    $(foreach ref,$(inc_$(lib)), $(info -- $(ref))))
407 .PHONY: list
408 list:
409
410 endif
411
412 static_includes := $(foreach lib,$(static_libs), $(inc_$(lib)))
413 static_libraries := $(foreach lib,$(static_libs),$(lib_$(lib)))
414 shared_libraries := $(foreach lib,$(shared_libs),$(lib_$(lib)))
415 thirdparty_libraries := $(static_libraries) $(shared_libraries)
416 '
417