bytes: remove extra padding in buffer
[L-SMASH.git] / configure
blob061496edfe0c8fbf75cff1ebd269e01408c30323
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 vc1.c \
295 wma.c"
297 SRC_IMPORTER=" \
298 a52_imp.c \
299 adts_imp.c \
300 als_imp.c \
301 amr_imp.c \
302 dts_imp.c \
303 importer.c \
304 isobm_imp.c \
305 mp3_imp.c \
306 nalu_imp.c \
307 vc1_imp.c \
308 wave_imp.c"
310 SRC_CORE=" \
311 box.c \
312 chapter.c \
313 file.c \
314 fragment.c \
315 isom.c \
316 meta.c \
317 print.c \
318 read.c \
319 summary.c \
320 timeline.c \
321 write.c"
323 SRCS=""
325 for src in $SRC_COMMON; do
326 SRCS="$SRCS common/$src"
327 done
329 for src in $SRC_CODECS; do
330 SRCS="$SRCS codecs/$src"
331 done
333 for src in $SRC_IMPORTER; do
334 SRCS="$SRCS importer/$src"
335 done
337 for src in $SRC_CORE; do
338 SRCS="$SRCS core/$src"
339 done
341 SRC_CLI="cli.c"
343 SRC_TOOLS=""
344 OBJ_TOOLS=""
346 for src in $SRC_CLI; do
347 SRC_TOOLS="$SRC_TOOLS cli/$src"
348 done
350 for src in $SRC_TOOLS; do
351 OBJ_TOOLS="$OBJ_TOOLS ${src%.c}.o"
352 done
354 TOOLS_ALL="muxer remuxer boxdumper timelineeditor"
355 TOOLS_NAME=""
356 TOOLS="$TOOLS_ALL"
358 for tool in $TOOLS; do
359 SRC_TOOLS="$SRC_TOOLS cli/${tool}.c"
360 TOOLS_NAME="$TOOLS_NAME cli/${tool}${EXT}"
361 done
362 #=============================================================================
364 CURDIR="$PWD"
365 cd $SRCDIR
366 VER=$MAJVER.$MINVER.$MICVER
367 REV="$(git rev-list HEAD 2> /dev/null | wc -l)"
368 if test $REV -ne 0; then
369 VER_STRING="$VER rev.$REV"
370 else
371 VER_STRING="$VER"
373 HASH="$(git describe --always 2> /dev/null)"
374 cd "$CURDIR"
375 cat >> config.h << EOF
376 #define LSMASH_REV "$REV"
377 #define LSMASH_GIT_HASH "$HASH"
381 cat >> liblsmash.pc << EOF
382 prefix=$prefix
383 exec_prefix=$exec_prefix
384 libdir=$libdir
385 includedir=$includedir
387 Name: liblsmash
388 Description: Loyal to Spec of MPEG4, and Ad-hock Simple Hackwork
389 Version: $VER_STRING
390 Requires:
391 URL: https://github.com/l-smash/l-smash
392 Libs: -L${libdir} -llsmash $LIBS
393 Libs.private:
394 Cflags: -I${includedir}
398 cat >> config.mak << EOF
399 SRCDIR = $SRCDIR
400 DESTDIR = $DESTDIR
401 prefix = $prefix
402 exec_prefix = $exec_prefix
403 bindir = $bindir
404 libdir = $libdir
405 includedir = $includedir
406 CC = $CC
407 AR = $AR
408 LD = $LD
409 RANLIB = $RANLIB
410 STRIP = $STRIP
411 STATICLIBNAME = $STATICLIBNAME
412 STATICLIB = $STATICLIB
413 SHAREDLIBNAME = $SHAREDLIBNAME
414 SHAREDLIB = $SHAREDLIB
415 IMPLIB = $IMPLIB
416 CFLAGS = $CFLAGS
417 LDFLAGS = $LDFLAGS
418 SO_LDFLAGS = $SO_LDFLAGS
419 LIBS = $LIBS
422 cat config.mak
424 cat >> config.mak << EOF
425 SRCS = $SRCS
426 SRC_TOOLS = $SRC_TOOLS
427 TOOLS_ALL = $TOOLS_ALL
428 TOOLS = $TOOLS_NAME
429 MAJVER = $MAJVER
433 for tool in $TOOLS; do
434 cat >> config.mak2 << EOF
435 cli/${tool}${EXT}: cli/${tool}.o $OBJ_TOOLS $STATICLIB $SHAREDLIB
436 \$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$< $OBJ_TOOLS -llsmash \$(LIBS)
437 -@ \$(if \$(STRIP), \$(STRIP) \$@)
440 done
443 test "$SRCDIR" = "." || ln -sf ${SRCDIR}/Makefile .
444 mkdir -p cli codecs common core importer
447 cat << EOF
449 configure finished
451 type 'make' : compile library and tools
452 type 'make install' : install all into system
453 type 'make lib' : compile library only
454 type 'make install-lib' : install library and header into system
458 exit 0