remuxer: Re-indent after previous commit
[L-SMASH.git] / configure
blob14b3b20154812c93805d7a49be52c44f29b9fe2e
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 for opt; do
113 optarg="${opt#*=}"
114 case "$opt" in
115 --prefix=*)
116 prefix="$optarg"
118 --exec-prefix=*)
119 exec_prefix="$optarg"
121 --bindir=*)
122 bindir="$optarg"
124 --libdir=*)
125 libdir="$optarg"
127 --includedir=*)
128 includedir="$optarg"
130 --destdir=*)
131 DESTDIR="$optarg"
133 --cc=*)
134 CC="$optarg"
135 LD="$optarg"
137 --target-os=*)
138 TARGET_OS="$optarg"
140 --cross-prefix=*)
141 CROSS="$optarg"
143 --sysroot=*)
144 CFLAGS="$CFLAGS --sysroot=$optarg"
145 LDFLAGS="$LDFLAGS --sysroot=$optarg"
147 --disable-static)
148 STATICLIB=""
149 SHAREDLIB="enabled"
151 --enable-shared)
152 SHAREDLIB="enabled"
154 --enable-debug)
155 DEBUG="enabled"
157 --extra-cflags=*)
158 XCFLAGS="$optarg"
160 --extra-ldflags=*)
161 XLDFLAGS="$optarg"
163 --extra-libs=*)
164 XLIBS="$optarg"
167 error_exit "unknown option $opt"
169 esac
170 done
172 test -n "$prefix" || prefix="/usr/local"
173 test -n "$exec_prefix" || exec_prefix='${prefix}'
174 test -n "$bindir" || bindir='${exec_prefix}/bin'
175 test -n "$libdir" || libdir='${exec_prefix}/lib'
176 test -n "$includedir" || includedir='${prefix}/include'
179 CC="${CROSS}${CC}"
180 AR="${CROSS}${AR}"
181 LD="${CROSS}${LD}"
182 RANLIB="${CROSS}${RANLIB}"
183 STRIP="${CROSS}${STRIP}"
184 for f in "$CC" "$AR" "$LD" "$RANLIB" "$STRIP"; do
185 test -n "$(which $f 2> /dev/null)" || error_exit "$f is not executable"
186 done
189 MAJVER=$(grep -e '#define LSMASH_VERSION_MAJOR' $SRCDIR/lsmash.h | sed -e 's/#define LSMASH_VERSION_MAJOR //;s/ //g')
190 MINVER=$(grep -e '#define LSMASH_VERSION_MINOR' $SRCDIR/lsmash.h | sed -e 's/#define LSMASH_VERSION_MINOR //;s/ //g')
191 MICVER=$(grep -e '#define LSMASH_VERSION_MICRO' $SRCDIR/lsmash.h | sed -e 's/#define LSMASH_VERSION_MICRO //;s/ //g')
193 if test -n "$TARGET_OS"; then
194 TARGET_OS=$(echo $TARGET_OS | tr '[A-Z]' '[a-z]')
195 else
196 TARGET_OS=$($CC -dumpmachine | tr '[A-Z]' '[a-z]')
198 case "$TARGET_OS" in
199 *mingw*)
200 EXT=".exe"
201 SHARED_EXT=".dll"
202 IMPLIB="liblsmash.dll.a"
203 SO_LDFLAGS="-shared -Wl,--out-implib,$IMPLIB"
204 CFLAGS="$CFLAGS -D__USE_MINGW_ANSI_STDIO=1"
206 *cygwin*)
207 EXT=".exe"
208 SHARED_NAME="cyglsmash"
209 SHARED_EXT=".dll"
210 IMPLIB="liblsmash.dll.a"
211 SO_LDFLAGS="-shared -Wl,--out-implib,$IMPLIB"
213 *darwin*)
214 SHARED_EXT=".dylib"
215 SO_LDFLAGS="-dynamiclib -Wl,-undefined,suppress -Wl,-read_only_relocs,suppress -Wl,-flat_namespace"
217 *solaris*)
218 #patches welcome
219 SHAREDLIB=""
222 SHARED_NAME="liblsmash"
223 SHARED_EXT=".so.$MAJVER"
224 if test -n "$SHAREDLIB"; then
225 CFLAGS="$CFLAGS -fPIC"
226 LDFLAGS="$LDFLAGS -fPIC"
229 esac
232 STATICLIBNAME="${STATIC_NAME}${STATIC_EXT}"
233 SHAREDLIBNAME="${SHARED_NAME}${SHARED_EXT}"
234 test -n "$STATICLIB" && STATICLIB="$STATICLIBNAME"
235 test -n "$SHAREDLIB" && SHAREDLIB="$SHAREDLIBNAME"
236 test -z "$STATICLIB" -a -z "$SHAREDLIB" && \
237 error_exit "--disable-static requires --enable-shared were specified"
238 test -z "$SHAREDLIB" && SO_LDFLAGS=""
241 CFLAGS="$CFLAGS $XCFLAGS"
242 LDFLAGS="$LDFLAGS $XLDFLAGS"
243 LIBS="$LIBS $XLIBS"
246 # In order to avoid some compiler bugs, we don't use "-O3" for the default.
247 # "-Os" unites "-O2" and "-finline-funtions" on x86/x86_64 in the latest GCC.
248 # As a result of taking these into consideration, we make "-Os" a rated value.
249 # And, we don't care about architecture related options.
250 # If you want them, set up by yourself like --extra-cflags="-O3 -march=native".
251 if test -n "$DEBUG"; then
252 CFLAGS="$CFLAGS -g3 -O0"
253 STRIP=""
254 else
255 CFLAGS="-Os -ffast-math $CFLAGS"
259 if ! cc_check "$CFLAGS" "$LDFLAGS"; then
260 error_exit "invalid CFLAGS/LDFLAGS"
263 if cc_check "$CFLAGS -fexcess-precision=fast" "$LDFLAGS"; then
264 CFLAGS="$CFLAGS -fexcess-precision=fast"
267 if cc_check "$CFLAGS" "$LDFLAGS -Wl,--large-address-aware"; then
268 LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
272 #=============================================================================
273 # Notation for developpers.
274 # Be sure to modified this block when you add/delete source files.
275 SRC_COMMON=" \
276 alloc.c \
277 bits.c \
278 bytes.c \
279 list.c \
280 multibuf.c \
281 osdep.c \
282 utils.c"
284 SRC_CODECS=" \
285 a52.c \
286 alac.c \
287 description.c \
288 dts.c \
289 h264.c \
290 hevc.c \
291 id.c \
292 mp4sys.c \
293 mp4a.c \
294 mp4v.c \
295 nalu.c \
296 qt_wfex.c \
297 vc1.c \
298 wma.c"
300 SRC_IMPORTER=" \
301 a52_imp.c \
302 adts_imp.c \
303 als_imp.c \
304 amr_imp.c \
305 dts_imp.c \
306 importer.c \
307 isobm_imp.c \
308 mp3_imp.c \
309 nalu_imp.c \
310 vc1_imp.c \
311 wave_imp.c"
313 SRC_CORE=" \
314 box.c \
315 chapter.c \
316 file.c \
317 fragment.c \
318 isom.c \
319 meta.c \
320 print.c \
321 read.c \
322 summary.c \
323 timeline.c \
324 write.c"
326 SRCS=""
328 for src in $SRC_COMMON; do
329 SRCS="$SRCS common/$src"
330 done
332 for src in $SRC_CODECS; do
333 SRCS="$SRCS codecs/$src"
334 done
336 for src in $SRC_IMPORTER; do
337 SRCS="$SRCS importer/$src"
338 done
340 for src in $SRC_CORE; do
341 SRCS="$SRCS core/$src"
342 done
344 SRC_CLI="cli.c"
346 SRC_TOOLS=""
347 OBJ_TOOLS=""
349 for src in $SRC_CLI; do
350 SRC_TOOLS="$SRC_TOOLS cli/$src"
351 done
353 for src in $SRC_TOOLS; do
354 OBJ_TOOLS="$OBJ_TOOLS ${src%.c}.o"
355 done
357 TOOLS_ALL="muxer remuxer boxdumper timelineeditor"
358 TOOLS_NAME=""
359 TOOLS="$TOOLS_ALL"
361 for tool in $TOOLS; do
362 SRC_TOOLS="$SRC_TOOLS cli/${tool}.c"
363 TOOLS_NAME="$TOOLS_NAME cli/${tool}${EXT}"
364 done
365 #=============================================================================
367 CURDIR="$PWD"
368 cd $SRCDIR
369 VER=$MAJVER.$MINVER.$MICVER
370 REV="$(git rev-list HEAD 2> /dev/null | wc -l)"
371 if test $REV -ne 0; then
372 VER_STRING="$VER rev.$REV"
373 else
374 VER_STRING="$VER"
376 HASH="$(git describe --always 2> /dev/null)"
377 cd "$CURDIR"
378 cat >> config.h << EOF
379 #define LSMASH_REV "$REV"
380 #define LSMASH_GIT_HASH "$HASH"
384 cat >> liblsmash.pc << EOF
385 prefix=$prefix
386 exec_prefix=$exec_prefix
387 libdir=$libdir
388 includedir=$includedir
390 Name: liblsmash
391 Description: Loyal to Spec of MPEG4, and Ad-hock Simple Hackwork
392 Version: $VER_STRING
393 Requires:
394 URL: https://github.com/l-smash/l-smash
395 Libs: -L${libdir} -llsmash $LIBS
396 Libs.private:
397 Cflags: -I${includedir}
401 cat >> config.mak << EOF
402 SRCDIR = $SRCDIR
403 DESTDIR = $DESTDIR
404 prefix = $prefix
405 exec_prefix = $exec_prefix
406 bindir = $bindir
407 libdir = $libdir
408 includedir = $includedir
409 CC = $CC
410 AR = $AR
411 LD = $LD
412 RANLIB = $RANLIB
413 STRIP = $STRIP
414 STATICLIBNAME = $STATICLIBNAME
415 STATICLIB = $STATICLIB
416 SHAREDLIBNAME = $SHAREDLIBNAME
417 SHAREDLIB = $SHAREDLIB
418 IMPLIB = $IMPLIB
419 CFLAGS = $CFLAGS
420 LDFLAGS = $LDFLAGS
421 SO_LDFLAGS = $SO_LDFLAGS
422 LIBS = $LIBS
425 cat config.mak
427 cat >> config.mak << EOF
428 SRCS = $SRCS
429 SRC_TOOLS = $SRC_TOOLS
430 TOOLS_ALL = $TOOLS_ALL
431 TOOLS = $TOOLS_NAME
432 MAJVER = $MAJVER
436 for tool in $TOOLS; do
437 cat >> config.mak2 << EOF
438 cli/${tool}${EXT}: cli/${tool}.o $OBJ_TOOLS $STATICLIB $SHAREDLIB
439 \$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$< $OBJ_TOOLS -llsmash \$(LIBS)
440 -@ \$(if \$(STRIP), \$(STRIP) \$@)
443 done
446 test "$SRCDIR" = "." || ln -sf ${SRCDIR}/Makefile .
447 mkdir -p cli codecs common core importer
450 cat << EOF
452 configure finished
454 type 'make' : compile library and tools
455 type 'make install' : install all into system
456 type 'make lib' : compile library only
457 type 'make install-lib' : install library and header into system
461 exit 0