media: Fix the presence of sample dependency type table when demuxing.
[L-SMASH.git] / configure
blob8f61dc03ce4f0659545893d5e9650920ce878541
1 #!/bin/sh
3 #----------------------------------------------------------------------------
4 # configure script for L-SMASH
6 # Currently, this script is considering only GCC.
7 # If you want to use other compiler based on C99 standerd (e.g. llvm),
8 # we just say to you "patches welcome."
9 #----------------------------------------------------------------------------
11 if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
12 cat << EOF
13 Usage: ./configure [options]
15 options:
16 -h, --help print this message
18 --prefix=PREFIX install architecture-independent files into PREFIX
19 [/usr/local]
20 --exec-prefix=EPREFIX install architecture-dependent files into EPREFIX
21 [PREFIX]
22 --bindir=DIR install binaries in DIR [EPREFIX/bin]
23 --libdir=DIR install libs in DIR [EPREFIX/lib]
24 --includedir=DIR install headers in DIR [PREFIX/include]
26 --cc=CC use a defined compiler for compilation and linking [gcc]
27 --target-os=OS build programs to run on OS [auto]
28 --cross-prefix=PREFIX use PREFIX for compilation tools [none]
29 --sysroot=DIR specify toolchain's directory [none]
30 --disable-static doesn't compile static library
31 --enable-shared also compile shared library besides static library
32 --enable-debug compile with debug symbols and never strip
34 --extra-cflags=XCFLAGS add XCFLAGS to CFLAGS
35 --extra-ldflags=XLDFLAGS add XLDFLAGS to LDFLAGS
36 --extra-libs=XLIBS add XLIBS to LIBS
37 EOF
38 exit 1
41 #-----------------------------------------------------------------------------
43 error_exit()
45 echo error: $1
46 exit 1
49 #Currently, this is used only for the flag check of compiler.
50 cc_check()
52 echo 'int main(void){return 0;}' > conftest.c
53 $CC conftest.c $1 $2 -o conftest 2> /dev/null
54 ret=$?
55 rm -f conftest*
56 return $ret
59 is_64bit()
61 echo 'int main(void){int a[2*(sizeof(void *)>4)-1]; return 0;}' > conftest.c
62 $CC conftest.c -o conftest 2> /dev/null
63 ret=$?
64 rm -f conftest*
65 return $ret
68 #-----------------------------------------------------------------------------
70 rm -f config.* .depend conftest* liblsmash.pc *.ver
73 echo
74 echo generating config.mak ...
75 echo
78 SRCDIR=$(dirname "$0")
79 SRCDIR=$(cd "$SRCDIR"; pwd)
80 test "$SRCDIR" = "$(pwd)" && SRCDIR=.
81 test -n "$(echo $SRCDIR | grep ' ')" && \
82 error_exit "out-of-tree builds are impossible with whitespace in source path"
84 prefix=""
85 exec_prefix=""
86 bindir=""
87 libdir=""
88 includedir=""
89 DESTDIR=""
91 TARGET_OS=""
92 CROSS=""
94 SYSROOT=""
95 CC="gcc"
96 AR="ar"
97 LD="gcc"
98 RANLIB="ranlib"
99 STRIP="strip"
101 DEBUG=""
103 EXT=""
105 STATIC_NAME="liblsmash"
106 STATIC_EXT=".a"
107 STATICLIB="enabled"
109 SHARED_NAME="liblsmash"
110 SHARED_EXT=".so"
111 SHAREDLIB=""
112 IMPLIB=""
114 TOOLS=""
116 CFLAGS="-Wshadow -Wall -std=c99 -pedantic -I. -I$SRCDIR"
117 LDFLAGS="-L."
118 SO_LDFLAGS='-shared -Wl,-soname,$@ -Wl,--version-script,liblsmash.ver'
119 LIBS="-lm"
121 for opt; do
122 optarg="${opt#*=}"
123 case "$opt" in
124 --prefix=*)
125 prefix="$optarg"
127 --exec-prefix=*)
128 exec_prefix="$optarg"
130 --bindir=*)
131 bindir="$optarg"
133 --libdir=*)
134 libdir="$optarg"
136 --includedir=*)
137 includedir="$optarg"
139 --destdir=*)
140 DESTDIR="$optarg"
142 --cc=*)
143 CC="$optarg"
144 LD="$optarg"
146 --target-os=*)
147 TARGET_OS="$optarg"
149 --cross-prefix=*)
150 CROSS="$optarg"
152 --sysroot=*)
153 CFLAGS="$CFLAGS --sysroot=$optarg"
154 LDFLAGS="$LDFLAGS --sysroot=$optarg"
156 --disable-static)
157 STATICLIB=""
158 SHAREDLIB="enabled"
160 --enable-shared)
161 SHAREDLIB="enabled"
163 --enable-debug)
164 DEBUG="enabled"
166 --extra-cflags=*)
167 XCFLAGS="$optarg"
169 --extra-ldflags=*)
170 XLDFLAGS="$optarg"
172 --extra-libs=*)
173 XLIBS="$optarg"
176 error_exit "unknown option $opt"
178 esac
179 done
181 test -n "$prefix" || prefix="/usr/local"
182 test -n "$exec_prefix" || exec_prefix='${prefix}'
183 test -n "$bindir" || bindir='${exec_prefix}/bin'
184 test -n "$libdir" || libdir='${exec_prefix}/lib'
185 test -n "$includedir" || includedir='${prefix}/include'
188 CC="${CROSS}${CC}"
189 AR="${CROSS}${AR}"
190 LD="${CROSS}${LD}"
191 RANLIB="${CROSS}${RANLIB}"
192 STRIP="${CROSS}${STRIP}"
193 for f in "$CC" "$AR" "$LD" "$RANLIB" "$STRIP"; do
194 test -n "$(which $f 2> /dev/null)" || error_exit "$f is not executable"
195 done
198 MAJVER=$(grep -e '#define LSMASH_VERSION_MAJOR' $SRCDIR/lsmash.h | sed -e 's/#define LSMASH_VERSION_MAJOR //;s/ //g')
199 MINVER=$(grep -e '#define LSMASH_VERSION_MINOR' $SRCDIR/lsmash.h | sed -e 's/#define LSMASH_VERSION_MINOR //;s/ //g')
200 MICVER=$(grep -e '#define LSMASH_VERSION_MICRO' $SRCDIR/lsmash.h | sed -e 's/#define LSMASH_VERSION_MICRO //;s/ //g')
202 if test -n "$TARGET_OS"; then
203 TARGET_OS=$(echo $TARGET_OS | tr '[A-Z]' '[a-z]')
204 else
205 TARGET_OS=$($CC -dumpmachine | tr '[A-Z]' '[a-z]')
207 case "$TARGET_OS" in
208 *mingw*)
209 EXT=".exe"
210 SHARED_NAME="liblsmash-$MAJVER"
211 SHARED_EXT=".dll"
212 DEFNAME="${SHARED_NAME}.def"
213 IMPLIB="liblsmash.dll.a"
214 SO_LDFLAGS="-shared -Wl,--output-def,$DEFNAME -Wl,--out-implib,$IMPLIB -Wl,--version-script,liblsmash.ver"
215 CFLAGS="$CFLAGS -D__USE_MINGW_ANSI_STDIO=1"
216 LIBARCH=i386
217 if lib.exe --list > /dev/null 2>&1 ; then
218 if is_64bit ; then
219 LIBARCH=x64
221 SLIB_CMD='sed -i "s/ @[^ ]*//" $(DEFNAME); lib.exe -machine:$(LIBARCH) -def:$(DEFNAME) -out:lsmash.lib'
222 elif genlib -V > /dev/null 2>&1 ; then
223 if is_64bit ; then
224 LIBARCH=x86_64
225 else
226 LIBARCH=x86
228 SLIB_CMD='sed -i "s/ @[^ ]*//" $(DEFNAME); genlib -a $(LIBARCH) -o lsmash.lib -d $(SHAREDLIBNAME) $(DEFNAME)'
229 elif ${CROSS}dlltool --version > /dev/null 2>&1 ; then
230 if is_64bit ; then
231 LIBARCH="i386:x86-64"
233 SLIB_CMD="sed -i \"s/ @[^ ]*//\" \$(DEFNAME); ${CROSS}dlltool -m \$(LIBARCH) -d \$(DEFNAME) -l lsmash.lib -D \$(SHAREDLIBNAME)"
236 *cygwin*)
237 EXT=".exe"
238 SHARED_NAME="cyglsmash"
239 SHARED_EXT=".dll"
240 IMPLIB="liblsmash.dll.a"
241 SO_LDFLAGS="-shared -Wl,--out-implib,$IMPLIB -Wl,--version-script,liblsmash.ver"
243 *darwin*)
244 SHARED_EXT=".dylib"
245 SO_LDFLAGS="-dynamiclib -Wl,-undefined,suppress -Wl,-read_only_relocs,suppress -Wl,-flat_namespace -Wl,--version-script,liblsmash.ver"
247 *solaris*)
248 #patches welcome
249 SHAREDLIB=""
252 SHARED_NAME="liblsmash"
253 SHARED_EXT=".so.$MAJVER"
254 if test -n "$SHAREDLIB"; then
255 CFLAGS="$CFLAGS -fPIC"
256 LDFLAGS="$LDFLAGS -fPIC"
259 esac
262 STATICLIBNAME="${STATIC_NAME}${STATIC_EXT}"
263 SHAREDLIBNAME="${SHARED_NAME}${SHARED_EXT}"
264 test -n "$STATICLIB" && STATICLIB="$STATICLIBNAME"
265 test -n "$SHAREDLIB" && SHAREDLIB="$SHAREDLIBNAME"
266 test -z "$STATICLIB" -a -z "$SHAREDLIB" && \
267 error_exit "--disable-static requires --enable-shared were specified"
268 test -z "$SHAREDLIB" && SO_LDFLAGS=""
271 CFLAGS="$CFLAGS $XCFLAGS"
272 LDFLAGS="$LDFLAGS $XLDFLAGS"
273 LIBS="$LIBS $XLIBS"
276 # In order to avoid some compiler bugs, we don't use "-O3" for the default.
277 # "-Os" unites "-O2" and "-finline-funtions" on x86/x86_64 in the latest GCC.
278 # As a result of taking these into consideration, we make "-Os" a rated value.
279 # And, we don't care about architecture related options.
280 # If you want them, set up by yourself like --extra-cflags="-O3 -march=native".
281 if test -n "$DEBUG"; then
282 CFLAGS="$CFLAGS -g3 -O0"
283 STRIP=""
284 else
285 CFLAGS="-Os -ffast-math $CFLAGS"
289 if ! cc_check "$CFLAGS" "$LDFLAGS"; then
290 error_exit "invalid CFLAGS/LDFLAGS"
293 if cc_check "$CFLAGS -fexcess-precision=fast" "$LDFLAGS"; then
294 CFLAGS="$CFLAGS -fexcess-precision=fast"
297 if cc_check "$CFLAGS" "$LDFLAGS -Wl,--large-address-aware"; then
298 LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
302 #=============================================================================
303 # Notation for developpers.
304 # Be sure to modified this block when you add/delete source files.
305 SRC_COMMON=" \
306 alloc.c \
307 bits.c \
308 bytes.c \
309 list.c \
310 multibuf.c \
311 osdep.c \
312 utils.c"
314 SRC_CODECS=" \
315 a52.c \
316 alac.c \
317 description.c \
318 dts.c \
319 h264.c \
320 hevc.c \
321 id.c \
322 mp4sys.c \
323 mp4a.c \
324 mp4v.c \
325 nalu.c \
326 qt_wfex.c \
327 vc1.c \
328 wma.c"
330 SRC_IMPORTER=" \
331 a52_imp.c \
332 adts_imp.c \
333 als_imp.c \
334 amr_imp.c \
335 dts_imp.c \
336 importer.c \
337 isobm_imp.c \
338 mp3_imp.c \
339 nalu_imp.c \
340 vc1_imp.c \
341 wave_imp.c"
343 SRC_CORE=" \
344 box.c \
345 chapter.c \
346 file.c \
347 fragment.c \
348 isom.c \
349 meta.c \
350 print.c \
351 read.c \
352 summary.c \
353 timeline.c \
354 write.c"
356 SRCS=""
358 for src in $SRC_COMMON; do
359 SRCS="$SRCS common/$src"
360 done
362 for src in $SRC_CODECS; do
363 SRCS="$SRCS codecs/$src"
364 done
366 for src in $SRC_IMPORTER; do
367 SRCS="$SRCS importer/$src"
368 done
370 for src in $SRC_CORE; do
371 SRCS="$SRCS core/$src"
372 done
374 SRC_CLI="cli.c"
376 SRC_TOOLS=""
377 OBJ_TOOLS=""
379 for src in $SRC_CLI; do
380 SRC_TOOLS="$SRC_TOOLS cli/$src"
381 done
383 for src in $SRC_TOOLS; do
384 OBJ_TOOLS="$OBJ_TOOLS ${src%.c}.o"
385 done
387 TOOLS_ALL="muxer remuxer boxdumper timelineeditor"
388 TOOLS_NAME=""
389 TOOLS="$TOOLS_ALL"
391 for tool in $TOOLS; do
392 SRC_TOOLS="$SRC_TOOLS cli/${tool}.c"
393 TOOLS_NAME="$TOOLS_NAME cli/${tool}${EXT}"
394 done
395 #=============================================================================
397 CURDIR="$PWD"
398 cd $SRCDIR
399 VER=$MAJVER.$MINVER.$MICVER
400 if test -d .git && type git > /dev/null 2>&1 ; then
401 REV="$(git rev-list HEAD 2> /dev/null | wc -l)"
402 HASH="$(git describe --always 2> /dev/null)"
403 else
404 REV=0
405 HASH=
407 if test $REV -ne 0; then
408 VER_STRING="$VER rev.$REV"
409 else
410 VER_STRING="$VER"
412 cd "$CURDIR"
413 cat >> config.h << EOF
414 #define LSMASH_REV "$REV"
415 #define LSMASH_GIT_HASH "$HASH"
419 sed "s/\\\$MAJOR/$MAJVER/" $SRCDIR/liblsmash.v > liblsmash.ver
420 # Add non-public symbols which have lsmash_* prefix to local.
421 find $SRCDIR/common/ $SRCDIR/importer/ -name "*.h" | xargs sed -e 's/^[ ]*//g' | \
422 grep "^\(void\|lsmash_bits_t\|uint64_t\|int\|int64_t\|lsmash_bs_t\|uint8_t\|uint16_t\|uint32_t\|lsmash_entry_list_t\|lsmash_entry_t\|lsmash_multiple_buffers_t\|double\|float\|FILE\).*lsmash_" | \
423 sed -e "s/.*\(lsmash_.*\)(.*/\1/g" -e "s/.*\(lsmash_.*\)/\1;/g" | xargs -I% sed -i "/^};$/i \ %" liblsmash.ver
424 # Get rid of non-public symbols for the cli tools from local.
425 sed -i -e '/lsmash_win32_fopen/d' \
426 -e '/lsmash_string_from_wchar/d' \
427 -e '/lsmash_importer_open/d' \
428 -e '/lsmash_importer_close/d' \
429 -e '/lsmash_importer_get_access_unit/d' \
430 -e '/lsmash_importer_get_last_delta/d' \
431 -e '/lsmash_importer_construct_timeline/d' \
432 -e '/lsmash_importer_get_track_count/d' \
433 -e '/lsmash_duplicate_summary/d' liblsmash.ver
436 cat >> liblsmash.pc << EOF
437 prefix=$prefix
438 exec_prefix=$exec_prefix
439 libdir=$libdir
440 includedir=$includedir
442 Name: liblsmash
443 Description: Loyal to Spec of MPEG4, and Ad-hock Simple Hackwork
444 Version: $VER_STRING
445 Requires:
446 URL: https://github.com/l-smash/l-smash
447 Libs: -L${libdir} -llsmash $(test -z "$SHAREDLIB" && echo $LIBS)
448 Libs.private: $(test -n "$SHAREDLIB" && echo $LIBS)
449 Cflags: -I${includedir}
453 cat >> config.mak << EOF
454 SRCDIR = $SRCDIR
455 DESTDIR = $DESTDIR
456 prefix = $prefix
457 exec_prefix = $exec_prefix
458 bindir = $bindir
459 libdir = $libdir
460 includedir = $includedir
461 CC = $CC
462 AR = $AR
463 LD = $LD
464 RANLIB = $RANLIB
465 STRIP = $STRIP
466 STATICLIBNAME = $STATICLIBNAME
467 STATICLIB = $STATICLIB
468 SHAREDLIBNAME = $SHAREDLIBNAME
469 SHAREDLIB = $SHAREDLIB
470 IMPLIB = $IMPLIB
471 CFLAGS = $CFLAGS
472 LDFLAGS = $LDFLAGS
473 SO_LDFLAGS = $SO_LDFLAGS
474 LIBS = $LIBS
475 LIBARCH = $LIBARCH
476 DEFNAME = $DEFNAME
477 SLIB_CMD = $SLIB_CMD
480 cat config.mak
482 cat >> config.mak << EOF
483 SRCS = $SRCS
484 SRC_TOOLS = $SRC_TOOLS
485 TOOLS_ALL = $TOOLS_ALL
486 TOOLS = $TOOLS_NAME
487 MAJVER = $MAJVER
491 for tool in $TOOLS; do
492 cat >> config.mak2 << EOF
493 cli/${tool}${EXT}: cli/${tool}.o $OBJ_TOOLS $STATICLIB $SHAREDLIB
494 \$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$< $OBJ_TOOLS -llsmash \$(LIBS)
495 -@ \$(if \$(STRIP), \$(STRIP) \$@)
498 done
501 test "$SRCDIR" = "." || ln -sf ${SRCDIR}/Makefile .
502 mkdir -p cli codecs common core importer
505 cat << EOF
507 configure finished
509 type 'make' : compile library and tools
510 type 'make install' : install all into system
511 type 'make lib' : compile library only
512 type 'make install-lib' : install library and header into system
516 exit 0