read: Skip weird extra bytes of 'chan' box.
[L-SMASH.git] / configure
blob25c4e15bf02aa7a6a491d9e346d816c2eb7faa12
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 #-----------------------------------------------------------------------------
61 rm -f config.* .depend conftest* liblsmash.pc
64 echo
65 echo generating config.mak ...
66 echo
69 SRCDIR=$(dirname "$0")
70 SRCDIR=$(cd "$SRCDIR"; pwd)
71 test "$SRCDIR" = "$(pwd)" && SRCDIR=.
72 test -n "$(echo $SRCDIR | grep ' ')" && \
73 error_exit "out-of-tree builds are impossible with whitespace in source path"
75 prefix=""
76 exec_prefix=""
77 bindir=""
78 libdir=""
79 includedir=""
80 DESTDIR=""
82 TARGET_OS=""
83 CROSS=""
85 SYSROOT=""
86 CC="gcc"
87 AR="ar"
88 LD="gcc"
89 RANLIB="ranlib"
90 STRIP="strip"
92 DEBUG=""
94 EXT=""
96 STATIC_NAME="liblsmash"
97 STATIC_EXT=".a"
98 STATICLIB="enabled"
100 SHARED_NAME="liblsmash"
101 SHARED_EXT=".so"
102 SHAREDLIB=""
103 IMPLIB=""
105 TOOLS=""
107 CFLAGS="-Wshadow -Wall -std=c99 -pedantic -I. -I$SRCDIR"
108 LDFLAGS="-L."
109 SO_LDFLAGS='-shared -Wl,-soname,$@'
110 LIBS="-lm"
112 DEMUXER="enabled"
114 for opt; do
115 optarg="${opt#*=}"
116 case "$opt" in
117 --prefix=*)
118 prefix="$optarg"
120 --exec-prefix=*)
121 exec_prefix="$optarg"
123 --bindir=*)
124 bindir="$optarg"
126 --libdir=*)
127 libdir="$optarg"
129 --includedir=*)
130 includedir="$optarg"
132 --destdir=*)
133 DESTDIR="$optarg"
135 --cc=*)
136 CC="$optarg"
137 LD="$optarg"
139 --target-os=*)
140 TARGET_OS="$optarg"
142 --cross-prefix=*)
143 CROSS="$optarg"
145 --sysroot=*)
146 CFLAGS="$CFLAGS --sysroot=$optarg"
147 LDFLAGS="$LDFLAGS --sysroot=$optarg"
149 --disable-static)
150 STATICLIB=""
151 SHAREDLIB="enabled"
153 --enable-shared)
154 SHAREDLIB="enabled"
156 --enable-debug)
157 DEBUG="enabled"
159 --extra-cflags=*)
160 XCFLAGS="$optarg"
162 --extra-ldflags=*)
163 XLDFLAGS="$optarg"
165 --extra-libs=*)
166 XLIBS="$optarg"
168 # "--disable-demuxer" is the special option only for developers.
169 --disable-demuxer)
170 DEMUXER=""
173 error_exit "unknown option $opt"
175 esac
176 done
178 test -n "$prefix" || prefix="/usr/local"
179 test -n "$exec_prefix" || exec_prefix='${prefix}'
180 test -n "$bindir" || bindir='${exec_prefix}/bin'
181 test -n "$libdir" || libdir='${exec_prefix}/lib'
182 test -n "$includedir" || includedir='${prefix}/include'
185 CC="${CROSS}${CC}"
186 AR="${CROSS}${AR}"
187 LD="${CROSS}${LD}"
188 RANLIB="${CROSS}${RANLIB}"
189 STRIP="${CROSS}${STRIP}"
190 for f in "$CC" "$AR" "$LD" "$RANLIB" "$STRIP"; do
191 test -n "$(which $f 2> /dev/null)" || error_exit "$f is not executable"
192 done
195 MAJVER=$(grep -e '#define LSMASH_VERSION_MAJOR' $SRCDIR/lsmash.h | sed -e 's/#define LSMASH_VERSION_MAJOR //;s/ //g')
196 MINVER=$(grep -e '#define LSMASH_VERSION_MINOR' $SRCDIR/lsmash.h | sed -e 's/#define LSMASH_VERSION_MINOR //;s/ //g')
197 MICVER=$(grep -e '#define LSMASH_VERSION_MICRO' $SRCDIR/lsmash.h | sed -e 's/#define LSMASH_VERSION_MICRO //;s/ //g')
199 if test -n "$TARGET_OS"; then
200 TARGET_OS=$(echo $TARGET_OS | tr '[A-Z]' '[a-z]')
201 else
202 TARGET_OS=$($CC -dumpmachine | tr '[A-Z]' '[a-z]')
204 case "$TARGET_OS" in
205 *mingw*)
206 EXT=".exe"
207 SHARED_EXT=".dll"
208 IMPLIB="liblsmash.dll.a"
209 SO_LDFLAGS="-shared -Wl,--out-implib,$IMPLIB"
210 CFLAGS="$CFLAGS -D__USE_MINGW_ANSI_STDIO=1"
212 *cygwin*)
213 EXT=".exe"
214 SHARED_NAME="cyglsmash"
215 SHARED_EXT=".dll"
216 IMPLIB="liblsmash.dll.a"
217 SO_LDFLAGS="-shared -Wl,--out-implib,$IMPLIB"
219 *darwin*)
220 SHARED_EXT=".dylib"
221 SO_LDFLAGS="-dynamiclib -Wl,-undefined,suppress -Wl,-read_only_relocs,suppress -Wl,-flat_namespace"
223 *solaris*)
224 #patches welcome
225 SHAREDLIB=""
228 SHARED_NAME="liblsmash"
229 SHARED_EXT=".so.$MAJVER"
230 if test -n "$SHAREDLIB"; then
231 CFLAGS="$CFLAGS -fPIC"
232 LDFLAGS="$LDFLAGS -fPIC"
235 esac
238 STATICLIBNAME="${STATIC_NAME}${STATIC_EXT}"
239 SHAREDLIBNAME="${SHARED_NAME}${SHARED_EXT}"
240 test -n "$STATICLIB" && STATICLIB="$STATICLIBNAME"
241 test -n "$SHAREDLIB" && SHAREDLIB="$SHAREDLIBNAME"
242 test -z "$STATICLIB" -a -z "$SHAREDLIB" && \
243 error_exit "--disable-static requires --enable-shared were specified"
244 test -z "$SHAREDLIB" && SO_LDFLAGS=""
247 CFLAGS="$CFLAGS $XCFLAGS"
248 LDFLAGS="$LDFLAGS $XLDFLAGS"
249 LIBS="$LIBS $XLIBS"
252 # In order to avoid some compiler bugs, we don't use "-O3" for the default.
253 # "-Os" unites "-O2" and "-finline-funtions" on x86/x86_64 in the latest GCC.
254 # As a result of taking these into consideration, we make "-Os" a rated value.
255 # And, we don't care about architecture related options.
256 # If you want them, set up by yourself like --extra-cflags="-O3 -march=native".
257 if test -n "$DEBUG"; then
258 CFLAGS="$CFLAGS -g3 -O0"
259 STRIP=""
260 else
261 CFLAGS="-Os -ffast-math $CFLAGS"
265 if ! cc_check "$CFLAGS" "$LDFLAGS"; then
266 error_exit "invalid CFLAGS/LDFLAGS"
269 if cc_check "$CFLAGS -fexcess-precision=fast" "$LDFLAGS"; then
270 CFLAGS="$CFLAGS -fexcess-precision=fast"
273 if cc_check "$CFLAGS" "$LDFLAGS -Wl,--large-address-aware"; then
274 LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
278 #=============================================================================
279 # Notation for developpers.
280 # Be sure to modified this block when you add/delete source files.
281 SRC_COMMON=" \
282 alloc.c \
283 bits.c \
284 bytes.c \
285 list.c \
286 multibuf.c \
287 osdep.c \
288 utils.c"
290 SRC_CODECS=" \
291 a52.c \
292 alac.c \
293 description.c \
294 dts.c \
295 h264.c \
296 hevc.c \
297 id.c \
298 mp4sys.c \
299 mp4a.c \
300 vc1.c \
301 wma.c"
303 SRC_IMPORTER=" \
304 a52_imp.c \
305 adts_imp.c \
306 als_imp.c \
307 amr_imp.c \
308 dts_imp.c \
309 importer.c \
310 isobm_imp.c \
311 mp3_imp.c \
312 nalu_imp.c \
313 vc1_imp.c \
314 wave_imp.c"
316 SRC_CORE=" \
317 box.c \
318 chapter.c \
319 file.c \
320 fragment.c \
321 isom.c \
322 meta.c \
323 print.c \
324 read.c \
325 summary.c \
326 timeline.c \
327 write.c"
329 SRCS=""
331 for src in $SRC_COMMON; do
332 SRCS="$SRCS common/$src"
333 done
335 for src in $SRC_CODECS; do
336 SRCS="$SRCS codecs/$src"
337 done
339 for src in $SRC_IMPORTER; do
340 SRCS="$SRCS importer/$src"
341 done
343 for src in $SRC_CORE; do
344 SRCS="$SRCS core/$src"
345 done
347 SRC_CLI="cli.c"
349 SRC_TOOLS=""
350 OBJ_TOOLS=""
352 for src in $SRC_CLI; do
353 SRC_TOOLS="$SRC_TOOLS cli/$src"
354 done
356 for src in $SRC_TOOLS; do
357 OBJ_TOOLS="$OBJ_TOOLS ${src%.c}.o"
358 done
360 TOOLS_ALL="muxer remuxer boxdumper timelineeditor"
361 TOOLS_NAME=""
363 if test -n "$DEMUXER"; then
364 CFLAGS="$CFLAGS -DLSMASH_DEMUXER_ENABLED"
365 TOOLS="$TOOLS_ALL"
366 else
367 TOOLS="muxer"
370 for tool in $TOOLS; do
371 SRC_TOOLS="$SRC_TOOLS cli/${tool}.c"
372 TOOLS_NAME="$TOOLS_NAME cli/${tool}${EXT}"
373 done
374 #=============================================================================
376 CURDIR="$PWD"
377 cd $SRCDIR
378 VER=$MAJVER.$MINVER.$MICVER
379 REV="$(git rev-list HEAD 2> /dev/null | wc -l)"
380 if test $REV -ne 0; then
381 VER_STRING="$VER rev.$REV"
382 else
383 VER_STRING="$VER"
385 HASH="$(git describe --always 2> /dev/null)"
386 cd "$CURDIR"
387 cat >> config.h << EOF
388 #define LSMASH_REV "$REV"
389 #define LSMASH_GIT_HASH "$HASH"
393 cat >> liblsmash.pc << EOF
394 prefix=$prefix
395 exec_prefix=$exec_prefix
396 libdir=$libdir
397 includedir=$includedir
399 Name: liblsmash
400 Description: Loyal to Spec of MPEG4, and Ad-hock Simple Hackwork
401 Version: $VER_STRING
402 Requires:
403 URL: https://github.com/l-smash/l-smash
404 Libs: -L${libdir} -llsmash $LIBS
405 Libs.private:
406 Cflags: -I${includedir}
410 cat >> config.mak << EOF
411 SRCDIR = $SRCDIR
412 DESTDIR = $DESTDIR
413 prefix = $prefix
414 exec_prefix = $exec_prefix
415 bindir = $bindir
416 libdir = $libdir
417 includedir = $includedir
418 CC = $CC
419 AR = $AR
420 LD = $LD
421 RANLIB = $RANLIB
422 STRIP = $STRIP
423 STATICLIBNAME = $STATICLIBNAME
424 STATICLIB = $STATICLIB
425 SHAREDLIBNAME = $SHAREDLIBNAME
426 SHAREDLIB = $SHAREDLIB
427 IMPLIB = $IMPLIB
428 CFLAGS = $CFLAGS
429 LDFLAGS = $LDFLAGS
430 SO_LDFLAGS = $SO_LDFLAGS
431 LIBS = $LIBS
434 cat config.mak
436 cat >> config.mak << EOF
437 SRCS = $SRCS
438 SRC_TOOLS = $SRC_TOOLS
439 TOOLS_ALL = $TOOLS_ALL
440 TOOLS = $TOOLS_NAME
441 MAJVER = $MAJVER
445 for tool in $TOOLS; do
446 cat >> config.mak2 << EOF
447 cli/${tool}${EXT}: cli/${tool}.o $OBJ_TOOLS $STATICLIB $SHAREDLIB
448 \$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$< $OBJ_TOOLS -llsmash \$(LIBS)
449 -@ \$(if \$(STRIP), \$(STRIP) \$@)
452 done
455 test "$SRCDIR" = "." || ln -sf ${SRCDIR}/Makefile .
456 mkdir -p cli codecs common core
459 cat << EOF
461 configure finished
463 type 'make' : compile library and tools
464 type 'make install' : install all into system
465 type 'make lib' : compile library only
466 type 'make install-lib' : install library and header into system
470 exit 0