write: Fix type size for mdcv luminance
[L-SMASH.git] / configure
blobde5faed47392862605e0f63bb2999f7e12cbc7c7
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 box_default.c \
346 box_type.c \
347 chapter.c \
348 file.c \
349 fragment.c \
350 isom.c \
351 meta.c \
352 print.c \
353 read.c \
354 summary.c \
355 timeline.c \
356 write.c"
358 SRCS=""
360 for src in $SRC_COMMON; do
361 SRCS="$SRCS common/$src"
362 done
364 for src in $SRC_CODECS; do
365 SRCS="$SRCS codecs/$src"
366 done
368 for src in $SRC_IMPORTER; do
369 SRCS="$SRCS importer/$src"
370 done
372 for src in $SRC_CORE; do
373 SRCS="$SRCS core/$src"
374 done
376 SRC_CLI="cli.c"
378 SRC_TOOLS=""
379 OBJ_TOOLS=""
381 for src in $SRC_CLI; do
382 SRC_TOOLS="$SRC_TOOLS cli/$src"
383 done
385 for src in $SRC_TOOLS; do
386 OBJ_TOOLS="$OBJ_TOOLS ${src%.c}.o"
387 done
389 TOOLS_ALL="muxer remuxer boxdumper timelineeditor"
390 TOOLS_NAME=""
391 TOOLS="$TOOLS_ALL"
393 for tool in $TOOLS; do
394 SRC_TOOLS="$SRC_TOOLS cli/${tool}.c"
395 TOOLS_NAME="$TOOLS_NAME cli/${tool}${EXT}"
396 done
397 #=============================================================================
399 CURDIR="$PWD"
400 cd $SRCDIR
401 VER=$MAJVER.$MINVER.$MICVER
402 if test -d .git && type git > /dev/null 2>&1 ; then
403 REV="$(git rev-list HEAD 2> /dev/null | wc -l)"
404 HASH="$(git describe --always 2> /dev/null)"
405 else
406 REV=0
407 HASH=
409 if test $REV -ne 0; then
410 VER_STRING="$VER rev.$REV"
411 else
412 VER_STRING="$VER"
414 cd "$CURDIR"
415 cat >> config.h << EOF
416 #define LSMASH_REV "$REV"
417 #define LSMASH_GIT_HASH "$HASH"
421 sed "s/\\\$MAJOR/$MAJVER/" $SRCDIR/liblsmash.v > liblsmash.ver
422 # Add non-public symbols which have lsmash_* prefix to local.
423 find $SRCDIR/common/ $SRCDIR/importer/ -name "*.h" | xargs sed -e 's/^[ ]*//g' | \
424 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\) \+\*\{0,1\}lsmash_" | \
425 sed -e "s/.*\(lsmash_.*\)(.*/\1/g" -e "s/.*\(lsmash_.*\)/\1;/g" | xargs -I% sed -i "/^};$/i \ %" liblsmash.ver
426 # Get rid of non-public symbols for the cli tools from local.
427 sed -i -e '/lsmash_win32_fopen/d' \
428 -e '/lsmash_string_from_wchar/d' \
429 -e '/lsmash_importer_open/d' \
430 -e '/lsmash_importer_close/d' \
431 -e '/lsmash_importer_get_access_unit/d' \
432 -e '/lsmash_importer_get_last_delta/d' \
433 -e '/lsmash_importer_construct_timeline/d' \
434 -e '/lsmash_importer_get_track_count/d' \
435 -e '/lsmash_duplicate_summary/d' liblsmash.ver
438 cat >> liblsmash.pc << EOF
439 prefix=$prefix
440 exec_prefix=$exec_prefix
441 libdir=$libdir
442 includedir=$includedir
444 Name: liblsmash
445 Description: Loyal to Spec of MPEG4, and Ad-hock Simple Hackwork
446 Version: $VER_STRING
447 Requires:
448 URL: https://github.com/l-smash/l-smash
449 Libs: -L${libdir} -llsmash $(test -z "$SHAREDLIB" && echo $LIBS)
450 Libs.private: $(test -n "$SHAREDLIB" && echo $LIBS)
451 Cflags: -I${includedir}
455 cat >> config.mak << EOF
456 SRCDIR = $SRCDIR
457 DESTDIR = $DESTDIR
458 prefix = $prefix
459 exec_prefix = $exec_prefix
460 bindir = $bindir
461 libdir = $libdir
462 includedir = $includedir
463 CC = $CC
464 AR = $AR
465 LD = $LD
466 RANLIB = $RANLIB
467 STRIP = $STRIP
468 STATICLIBNAME = $STATICLIBNAME
469 STATICLIB = $STATICLIB
470 SHAREDLIBNAME = $SHAREDLIBNAME
471 SHAREDLIB = $SHAREDLIB
472 IMPLIB = $IMPLIB
473 CFLAGS = $CFLAGS
474 LDFLAGS = $LDFLAGS
475 SO_LDFLAGS = $SO_LDFLAGS
476 LIBS = $LIBS
477 LIBARCH = $LIBARCH
478 DEFNAME = $DEFNAME
479 SLIB_CMD = $SLIB_CMD
482 cat config.mak
484 cat >> config.mak << EOF
485 SRCS = $SRCS
486 SRC_TOOLS = $SRC_TOOLS
487 TOOLS_ALL = $TOOLS_ALL
488 TOOLS = $TOOLS_NAME
489 MAJVER = $MAJVER
493 for tool in $TOOLS; do
494 cat >> config.mak2 << EOF
495 cli/${tool}${EXT}: cli/${tool}.o $OBJ_TOOLS $STATICLIB $SHAREDLIB
496 \$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$< $OBJ_TOOLS -llsmash \$(LIBS)
497 -@ \$(if \$(STRIP), \$(STRIP) \$@)
500 done
503 test "$SRCDIR" = "." || ln -sf ${SRCDIR}/Makefile .
504 mkdir -p cli codecs common core importer
507 cat << EOF
509 configure finished
511 type 'make' : compile library and tools
512 type 'make install' : install all into system
513 type 'make lib' : compile library only
514 type 'make install-lib' : install library and header into system
518 exit 0