VC-1 importer: Apply refined bytestream reader.
[L-SMASH.git] / configure
blob407243d774d7ad7bb374a6299421e95cecea55a5
1 #!/bin/bash
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="$(cd $(dirname $0); pwd)"
70 test "$SRCDIR" = "$(pwd)" && SRCDIR=.
71 test -n "$(echo $SRCDIR | grep ' ')" && \
72 error_exit "out-of-tree builds are impossible with whitespace in source path"
74 prefix=""
75 exec_prefix=""
76 bindir=""
77 libdir=""
78 includedir=""
79 DESTDIR=""
81 TARGET_OS=""
82 CROSS=""
84 SYSROOT=""
85 CC="gcc"
86 AR="ar"
87 LD="gcc"
88 RANLIB="ranlib"
89 STRIP="strip"
91 DEBUG=""
93 EXT=""
95 STATIC_NAME="liblsmash"
96 STATIC_EXT=".a"
97 STATICLIB="enabled"
99 SHARED_NAME="liblsmash"
100 SHARED_EXT=".so"
101 SHAREDLIB=""
102 IMPLIB=""
104 TOOLS=""
106 CFLAGS="-Wshadow -Wall -std=c99 -pedantic -I. -I$SRCDIR"
107 LDFLAGS="-L."
108 SO_LDFLAGS='-shared -Wl,-soname,$@'
109 LIBS="-lm"
111 DEMUXER="enabled"
113 for opt; do
114 optarg="${opt#*=}"
115 case "$opt" in
116 --prefix=*)
117 prefix="$optarg"
119 --exec-prefix=*)
120 exec_prefix="$optarg"
122 --bindir=*)
123 bindir="$optarg"
125 --libdir=*)
126 libdir="$optarg"
128 --includedir=*)
129 includedir="$optarg"
131 --destdir=*)
132 DESTDIR="$optarg"
134 --cc=*)
135 CC="$optarg"
136 LD="$optarg"
138 --target-os=*)
139 TARGET_OS="$optarg"
141 --cross-prefix=*)
142 CROSS="$optarg"
144 --sysroot=*)
145 CFLAGS="$CFLAGS --sysroot=$optarg"
146 LDFLAGS="$LDFLAGS --sysroot=$optarg"
148 --disable-static)
149 STATICLIB=""
150 SHAREDLIB="enabled"
152 --enable-shared)
153 SHAREDLIB="enabled"
155 --enable-debug)
156 DEBUG="enabled"
158 --extra-cflags=*)
159 XCFLAGS="$optarg"
161 --extra-ldflags=*)
162 XLDFLAGS="$optarg"
164 --extra-libs=*)
165 XLIBS="$optarg"
167 # "--disable-demuxer" is the special option only for developpers.
168 --disable-demuxer)
169 DEMUXER=""
172 error_exit "unknown option $opt"
174 esac
175 done
177 test -n "$prefix" || prefix="/usr/local"
178 test -n "$exec_prefix" || exec_prefix='${prefix}'
179 test -n "$bindir" || bindir='${exec_prefix}/bin'
180 test -n "$libdir" || libdir='${exec_prefix}/lib'
181 test -n "$includedir" || includedir='${prefix}/include'
184 CC="${CROSS}${CC}"
185 AR="${CROSS}${AR}"
186 LD="${CROSS}${LD}"
187 RANLIB="${CROSS}${RANLIB}"
188 STRIP="${CROSS}${STRIP}"
189 for f in "$CC" "$AR" "$LD" "$RANLIB" "$STRIP"; do
190 test -n "$(which $f 2> /dev/null)" || error_exit "$f is not executable"
191 done
194 if test -n "$TARGET_OS"; then
195 TARGET_OS=$(echo $TARGET_OS | tr '[A-Z]' '[a-z]')
196 else
197 TARGET_OS=$($CC -dumpmachine | tr '[A-Z]' '[a-z]')
199 case "$TARGET_OS" in
200 *mingw*)
201 EXT=".exe"
202 SHARED_EXT=".dll"
203 IMPLIB="liblsmash.dll.a"
204 SO_LDFLAGS="-shared -Wl,--out-implib,$IMPLIB"
205 CFLAGS="$CFLAGS -D__USE_MINGW_ANSI_STDIO=1"
207 *cygwin*)
208 EXT=".exe"
209 SHARED_NAME="cyglsmash"
210 SHARED_EXT=".dll"
211 IMPLIB="liblsmash.dll.a"
212 SO_LDFLAGS="-shared -Wl,--out-implib,$IMPLIB"
214 *darwin*)
215 SHARED_EXT=".dylib"
216 SO_LDFLAGS="-dynamiclib -Wl,-undefined,suppress -Wl,-read_only_relocs,suppress -Wl,-flat_namespace"
218 *solaris*)
219 #patches welcome
220 SHAREDLIB=""
223 if test -n "$SHAREDLIB"; then
224 CFLAGS="$CFLAGS -fPIC"
225 LDFLAGS="$LDFLAGS -fPIC"
228 esac
231 STATICLIBNAME="${STATIC_NAME}${STATIC_EXT}"
232 SHAREDLIBNAME="${SHARED_NAME}${SHARED_EXT}"
233 test -n "$STATICLIB" && STATICLIB="$STATICLIBNAME"
234 test -n "$SHAREDLIB" && SHAREDLIB="$SHAREDLIBNAME"
235 test -z "$STATICLIB" -a -z "$SHAREDLIB" && \
236 error_exit "--disable-static requires --enable-shared were specified"
237 test -z "$SHAREDLIB" && SO_LDFLAGS=""
240 CFLAGS="$CFLAGS $XCFLAGS"
241 LDFLAGS="$LDFLAGS $XLDFLAGS"
242 LIBS="$LIBS $XLIBS"
245 # In order to avoid some compiler bugs, we don't use "-O3" for the default.
246 # "-Os" unites "-O2" and "-finline-funtions" on x86/x86_64 in the latest GCC.
247 # As a result of taking these into consideration, we make "-Os" a rated value.
248 # And, we don't care about architecture related options.
249 # If you want them, set up by yourself like --extra-cflags="-O3 -march=native".
250 if test -n "$DEBUG"; then
251 CFLAGS="$CFLAGS -g3 -O0"
252 STRIP=""
253 else
254 CFLAGS="-Os -ffast-math $CFLAGS"
258 if ! cc_check "$CFLAGS" "$LDFLAGS"; then
259 error_exit "invalid CFLAGS/LDFLAGS"
262 if cc_check "$CFLAGS -fexcess-precision=fast" "$LDFLAGS"; then
263 CFLAGS="$CFLAGS -fexcess-precision=fast"
266 if cc_check "$CFLAGS" "$LDFLAGS -Wl,--large-address-aware"; then
267 LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
271 #=============================================================================
272 # Notation for developpers.
273 # Be sure to modified this block when you add/delete source files.
274 SRCS="common/alloc.c common/utils.c common/bstream.c common/list.c \
275 common/osdep.c codecs/mp4sys.c codecs/mp4a.c codecs/dts.c codecs/a52.c \
276 codecs/h264.c codecs/hevc.c codecs/vc1.c codecs/alac.c \
277 codecs/description.c core/isom.c core/fragment.c core/summary.c \
278 core/print.c core/read.c core/timeline.c core/chapter.c core/meta.c \
279 core/write.c core/box.c"
281 TOOLS_ALL="muxer remuxer boxdumper timelineeditor"
282 TOOLS_NAME=""
283 SRC_TOOLS="cli/cli.c cli/importer.c"
284 if test -n "$DEMUXER"; then
285 CFLAGS="$CFLAGS -DLSMASH_DEMUXER_ENABLED"
286 TOOLS="$TOOLS_ALL"
287 else
288 TOOLS="muxer"
290 for tool in $TOOLS; do
291 SRC_TOOLS="$SRC_TOOLS cli/${tool}.c"
292 TOOLS_NAME="$TOOLS_NAME cli/${tool}${EXT}"
293 done
294 #=============================================================================
296 pushd $SRCDIR
297 MAJVER=$(grep -e '#define LSMASH_VERSION_MAJOR' lsmash.h|sed -e 's/#define LSMASH_VERSION_MAJOR //;s/ //g')
298 MINVER=$(grep -e '#define LSMASH_VERSION_MINOR' lsmash.h|sed -e 's/#define LSMASH_VERSION_MINOR //;s/ //g')
299 MICVER=$(grep -e '#define LSMASH_VERSION_MICRO' lsmash.h|sed -e 's/#define LSMASH_VERSION_MICRO //;s/ //g')
300 VER=$MAJVER.$MINVER.$MICVER
301 REV="$(git rev-list HEAD 2> /dev/null | wc -l)"
302 if test $REV -ne 0; then
303 VER_STRING="$VER rev.$REV"
304 else
305 VER_STRING="$VER"
307 HASH="$(git describe --always 2> /dev/null)"
308 popd
309 cat >> config.h << EOF
310 #define LSMASH_REV "$REV"
311 #define LSMASH_GIT_HASH "$HASH"
315 cat >> liblsmash.pc << EOF
316 prefix=$prefix
317 exec_prefix=$exec_prefix
318 libdir=$libdir
319 includedir=$includedir
321 Name: liblsmash
322 Description: Loyal to Spec of MPEG4, and Ad-hock Simple Hackwork
323 Version: $VER_STRING
324 Requires:
325 URL: https://github.com/l-smash/l-smash
326 Libs: -L${libdir} -llsmash $LIBS
327 Libs.private:
328 Cflags: -I${includedir}
332 cat >> config.mak << EOF
333 SRCDIR = $SRCDIR
334 DESTDIR = $DESTDIR
335 prefix = $prefix
336 exec_prefix = $exec_prefix
337 bindir = $bindir
338 libdir = $libdir
339 includedir = $includedir
340 CC = $CC
341 AR = $AR
342 LD = $LD
343 RANLIB = $RANLIB
344 STRIP = $STRIP
345 STATICLIBNAME = $STATICLIBNAME
346 STATICLIB = $STATICLIB
347 SHAREDLIBNAME = $SHAREDLIBNAME
348 SHAREDLIB = $SHAREDLIB
349 IMPLIB = $IMPLIB
350 CFLAGS = $CFLAGS
351 LDFLAGS = $LDFLAGS
352 SO_LDFLAGS = $SO_LDFLAGS
353 LIBS = $LIBS
356 cat config.mak
358 cat >> config.mak << EOF
359 SRCS = $SRCS
360 SRC_TOOLS = $SRC_TOOLS
361 TOOLS_ALL = $TOOLS_ALL
362 TOOLS = $TOOLS_NAME
366 for tool in $TOOLS; do
367 cat >> config.mak2 << EOF
368 cli/${tool}${EXT}: cli/${tool}.o cli/cli.o cli/importer.o $STATICLIB $SHAREDLIB
369 \$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$< cli/cli.o cli/importer.o -llsmash \$(LIBS)
370 -@ \$(if \$(STRIP), \$(STRIP) \$@)
373 done
376 test "$SRCDIR" = "." || ln -sf ${SRCDIR}/Makefile .
377 mkdir -p cli codecs common core
380 cat << EOF
382 configure finished
384 type 'make' : compile library and tools
385 type 'make install' : install all into system
386 type 'make lib' : compile library only
387 type 'make install-lib' : install library and header into system
391 exit 0