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