0c4db274d61e867f17d9b928be116c6b23c87d79
[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/getopt/libgetopt.a \
100         src/share/utf8/.libs/libutf8.a \
101         src/share/replaygain_analysis/.libs/libreplaygain_analysis.a \
102         src/share/replaygain_synthesis/.libs/libreplaygain_synthesis.a \
103         src/share/grabbag/.libs/libgrabbag.a \
104         src/test_libs_common/.libs/libtest_libs_common.a
105 inc_giflib="lib"
106 add_library giflib \
107         lib/.libs/libgif.a \
108         util/libgetarg.a
109 inc_ilmbase="Iex Half Imath config IlmThread"
110 add_library ilmbase \
111         Iex/.libs/libIex.a \
112         IexMath/.libs/libIexMath.a \
113         Half/.libs/libHalf.a \
114         Imath/.libs/libImath.a \
115         IlmThread/.libs/libIlmThread.a
116 inc_ladspa=""
117 add_library ladspa
118 inc_lame="include"
119 add_library lame \
120         libmp3lame/.libs/libmp3lame.a \
121         mpglib/.libs/libmpgdecoder.a
122 inc_libavc1394="."
123 add_library libavc1394 \
124         libavc1394/.libs/libavc1394.a \
125         librom1394/.libs/librom1394.a \
126         common/.libs/libraw1394util.a
127 inc_libdv="."
128 add_library libdv \
129         libdv/.libs/libdv.a
130 inc_libiec61883="src"
131 add_library libiec61883 \
132         src/.libs/libiec61883.a
133 inc_libjpeg="."
134 add_library libjpeg \
135         .libs/libjpeg.a \
136         .libs/libturbojpeg.a \
137         simd/.libs/libsimd.a
138 inc_openjpeg="src/lib/openmj2"
139 add_library openjpeg \
140         bin/libopenmj2.a
141 inc_libogg="include"
142 add_library libogg \
143         src/.libs/libogg.a
144 inc_libraw1394="."
145 add_library libraw1394 \
146         src/.libs/libraw1394.a
147 inc_libsndfile="."
148 add_library libsndfile \
149         src/.libs/libsndfile.a \
150         src/.libs/libcommon.a \
151         src/G72x/.libs/libg72x.a \
152         src/GSM610/.libs/libgsm.a
153 inc_libtheora="."
154 add_library libtheora \
155         lib/.libs/libtheora.a \
156         lib/.libs/libtheoradec.a \
157         lib/.libs/libtheoraenc.a
158 inc_libuuid="."
159 add_library libuuid \
160         .libs/libuuid.a
161 inc_libvorbis="include ."
162 add_library libvorbis \
163         lib/.libs/libvorbis.a \
164         lib/.libs/libvorbisenc.a \
165         lib/.libs/libvorbisfile.a
166 inc_mjpegtools=". lavtools utils"
167 add_library mjpegtools \
168         utils/mmxsse/.libs/libmmxsse.a \
169         utils/.libs/libmjpegutils.a \
170         lavtools/.libs/liblavfile.a \
171         lavtools/.libs/liblavjpeg.a \
172         yuvfilters/.libs/libyuvfilters.a \
173         mpeg2enc/.libs/libmpeg2encpp.a \
174         mplex/.libs/libmplex2.a
175 inc_openexr="IlmImf config"
176 add_library openexr \
177         IlmImf/.libs/libIlmImf.a \
178         IlmImfUtil/.libs/libIlmImfUtil.a
179 inc_speech_tools="."
180 add_library speech_tools \
181         lib/libestools.a \
182         lib/libeststring.a \
183         lib/libestbase.a
184 inc_tiff="."
185 add_library tiff \
186         libtiff/.libs/libtiff.a \
187         libtiff/.libs/libtiffxx.a \
188         port/.libs/libport.a
189 inc_twolame="libtwolame"
190 add_library twolame \
191         libtwolame/.libs/libtwolame.a
192 inc_x264="."
193 add_library x264 \
194         libx264.a
195 inc_x265=". source"
196 add_library x265 \
197         libx265.a
198 inc_libvpx="."
199 add_library libvpx \
200         libvpx.a \
201
202 n=0
203 for lib in $LIBS; do
204   echo -n " $lib"
205   if [ $(((n+=1) % 8)) = 0 ]; then echo ""; fi
206 done
207 if [ $((n % 8)) != 0 ]; then echo ""; fi
208 echo ""
209
210 # dynamic library paths
211 probe() {
212   local name="$1"
213   local headers="$2"
214   local func="$3"
215   shift 3
216
217   : ${TMPDIR:=$TEMPDIR}
218   : ${TMPDIR:=$TMP}
219   : ${TMPDIR:=/tmp}
220
221   local exe=$(mktemp -u "${TMPDIR}/cine-${name}.XXXXXXXX")
222   trap "rm -f -- ${exe}" EXIT
223
224   {
225     for hdr in $headers; do
226       test "${hdr%.h}" = "${hdr}" &&
227         echo "#include $hdr"    ||
228         echo "#include <$hdr>"
229     done
230     for func in $func; do
231       echo "long check_$func(void) { return (long) $func; }"
232     done
233     echo "int main(void) { return 0; }"
234   } | cc -x c - -o $exe $@ >& /dev/null
235   ret=$?
236   rm -f "${exe}"
237   if [ $ret = 0 ]; then
238     eval $name=\"shared $*\"
239     echo "exists shared $name"
240     return 0
241   fi
242   local sta_libs=sta_$name
243   eval $name=\"static ${!sta_libs}\"
244   echo "build  static $name"
245   return 1
246 }
247
248 # test for shared libs/header files
249 probe audiofile "audiofile.h" afOpenFile -laudiofile
250 probe faac "stdint.h faac.h" faacEncGetVersion -lfaac
251 probe faad2 "faad.h" NeAACDecInit -lfaad
252 # dont build festival in shared build
253 if [ "$STATIC_LIBRARIES" = "n" ]; then festival="shared"; fi
254 if [ "$STATIC_LIBRARIES" = "n" ]; then speech_tools="shared"; fi
255 probe fftw "fftw3.h" fftw_execute -lfftw3
256 probe flac "FLAC/stream_decoder.h" FLAC__stream_decoder_new -lFLAC
257 probe lame "lame/lame.h" hip_decode_init -lmp3lame
258 probe libavc1394 "libavc1394/avc1394.h librom1394/rom1394.h" avc1394_init_target -lavc1394
259 probe libdv "libdv/dv.h" dv_init -ldv
260 probe libiec61883 "libiec61883/iec61883.h" iec61883_mpeg2_recv_init -liec61883
261 probe libjpeg "stdio.h unistd.h jpeglib.h" jpeg_start_decompress -ljpeg
262 probe libogg "ogg/ogg.h" ogg_stream_init -logg
263 probe openjpeg "openjpeg.h" opj_version -lopenmj2 -DOPJ_STATIC || \
264 probe openjpeg "openjpeg-1.5/openjpeg.h" opj_version -lopenjpeg -DOPJ_STATIC || \
265 probe openjpeg "openjpeg.h" opj_version -lopenjpeg -DOPJ_STATIC
266 probe libraw1394 "libraw1394/raw1394.h" raw1394_iso_recv_init -lraw1394
267 probe libsndfile "sndfile.h" sf_open -lsndfile
268 probe ilmbase "OpenEXR/ImfCRgbaFile.h" ImfOpenInputFile -lIlmImf -lIlmThread -lIex
269 probe openexr "OpenEXR/ImfCRgbaFile.h" ImfOpenInputFile -lIlmImf -lIlmThread -lIex
270 probe libtheora "theora/theoraenc.h" th_info_init -ltheora -ltheoraenc -ltheoradec -logg
271 probe libvorbis "vorbis/vorbisenc.h" vorbis_info_init -lvorbisenc -lvorbis -lvorbisfile -logg
272 probe libvpx "vpx/vpx_decoder.h" vpx_codec_decode -lvpx
273 probe tiff "tiff.h tiffio.h" TIFFOpen -ltiff
274 probe twolame "twolame.h" twolame_encode_buffer_float32_interleaved -ltwolame
275 probe x264 "stdint.h x264.h" x264_encoder_encode -lx264
276 probe x265 "x265.h" x265_encoder_encode -lx265
277
278 echo ""
279 # for ffmpeg link/broken disto libs
280 forced_libs="encore ffmpeg giflib libuuid"
281 for name in $LIBS; do
282   if is_in $name $forced_libs; then
283     set - ${!name}
284     typ="$1"
285     shift 1
286     if [ "$typ" = "shared" ]; then
287       echo "warn: $name forced static"
288       sta_libs=sta_$name
289       eval $name=\"static ${!sta_libs}\"
290     fi
291   fi
292 done
293
294 # add dependencies (order matters)
295 for dep in \
296         ffmpeg/faac ffmpeg/faad2 ffmpeg/twolame ffmpeg/lame ffmpeg/openjpeg \
297         ffmpeg/libvorbis ffmpeg/libtheora ffmpeg/x264 ffmpeg/fdk \
298         libiec61883/libraw1394 libavc1394/librom1394 \
299         openexr/ilmbase ilmbase/libogg \
300         libtheora/libogg libtheora/libvorbis ; do
301   lib="${dep%%/*}"
302   needs="${dep##*/}"
303   if is_in $lib $shared; then
304     if is_in $needs $shared; then continue; fi
305     if is_in $needs $static; then
306       echo warn: shared $lib using static $needs
307       continue
308     fi
309     append shared $needs
310   fi
311   if is_in $lib $static; then
312     if is_in $needs $static; then continue; fi
313     if is_in $needs $shared; then
314       echo warn: static $lib using shared $needs
315       continue
316     fi
317     append static $needs
318   fi
319 done
320
321 echo ""
322 # check for static libs which may conflicting header files
323 if [ "$STATIC_LIBRARIES" = "y" ]; then
324   for name in $LIBS; do
325     set - ${!name}
326     typ="$1"
327     shift 1
328     if [ "$typ" = "shared" ]; then
329       echo "warn: $name is shared and static"
330     fi
331     sta_libs=sta_$name
332     eval $name=\"static ${!sta_libs}\"
333   done
334 fi
335
336 # any unknowns are static
337 for name in $LIBS; do
338   if [ -z "${!name}" ]; then
339     sta_libs=sta_$name
340     eval $name=\"static ${!sta_libs}\"
341   fi
342 done
343
344 # dont build festival
345 festival="shared"
346 speech_tools="shared"
347
348 shared=""
349 static=""
350 for lib in $LIBS; do
351   set - ${!lib}
352   typ="$1"
353   append $typ $lib
354 done
355
356 echo "thirdparty :=$LIBS"    > config.mak
357 echo "shared_libs :=$shared" >> config.mak
358 echo "static_libs :=$static" >> config.mak
359
360 for lib in $LIBS; do
361   echo "$lib := ${!lib}"
362   inc_lib=inc_$lib
363   echo "inc_$lib := ${!inc_lib}"
364 done >> config.mak
365
366 echo >> config.mak '
367 # translate config.mak into libs/incs
368
369 pkg_path=$(lastword $(wildcard $(THIRDPARTY)/$(1)*))
370 lib_static=$(call pkg_path,$(1))/$(2)
371 lib_shared=$(2)
372 inc_static=-I$(1)/$(2)
373 inc_shared=
374 lib_typ=$(firstword $(1))
375 lib_refs=$(wordlist 2,$(words $(1)),$(1))
376
377 $(foreach lib,$(thirdparty), \
378   $(eval pkg_$(lib) := $(call pkg_path,$(lib))) \
379   $(eval typ_$(lib) := $(call lib_typ,$($(lib)))) \
380   $(eval lib_$(lib) := \
381     $(foreach ref, $(call lib_refs,$($(lib))), \
382        $(call lib_$(typ_$(lib)),$(lib),$(ref)))) \
383   $(eval inc_$(lib) := \
384     $(foreach inc, $(inc_$(lib)), \
385        $(call inc_$(typ_$(lib)),$(pkg_$(lib)),$(inc)))))
386
387 #list libs/incs
388 ifeq ($(MAKECMDGOALS),list)
389 $(foreach lib,$(thirdparty),$(info $(lib) := $(typ_$(lib)) $(pkg_$(lib))) \
390    $(foreach ref,$(lib_$(lib)), $(info == $(ref))) \
391    $(foreach ref,$(inc_$(lib)), $(info -- $(ref))))
392 .PHONY: list
393 list:
394
395 endif
396
397 static_includes := $(foreach lib,$(static_libs), $(inc_$(lib)))
398 static_libraries := $(foreach lib,$(static_libs),$(lib_$(lib)))
399 shared_libraries := $(foreach lib,$(shared_libs),$(lib_$(lib)))
400 thirdparty_libraries := $(static_libraries) $(shared_libraries)
401 '
402