-
Notifications
You must be signed in to change notification settings - Fork 1
/
lsmash_configure_mac
525 lines (441 loc) · 13.4 KB
/
lsmash_configure_mac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
#!/bin/sh
#----------------------------------------------------------------------------
# configure script for L-SMASH
#
# Currently, this script is considering only GCC.
# If you want to use other compiler based on C99 standerd (e.g. llvm),
# we just say to you "patches welcome."
#----------------------------------------------------------------------------
if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
cat << EOF
Usage: ./configure [options]
options:
-h, --help print this message
--prefix=PREFIX install architecture-independent files into PREFIX
[/usr/local]
--exec-prefix=EPREFIX install architecture-dependent files into EPREFIX
[PREFIX]
--bindir=DIR install binaries in DIR [EPREFIX/bin]
--libdir=DIR install libs in DIR [EPREFIX/lib]
--includedir=DIR install headers in DIR [PREFIX/include]
--cc=CC use a defined compiler for compilation and linking [gcc]
--target-os=OS build programs to run on OS [auto]
--cross-prefix=PREFIX use PREFIX for compilation tools [none]
--sysroot=DIR specify toolchain's directory [none]
--disable-static doesn't compile static library
--enable-shared also compile shared library besides static library
--enable-debug compile with debug symbols and never strip
--extra-cflags=XCFLAGS add XCFLAGS to CFLAGS
--extra-ldflags=XLDFLAGS add XLDFLAGS to LDFLAGS
--extra-libs=XLIBS add XLIBS to LIBS
EOF
exit 1
fi
#-----------------------------------------------------------------------------
error_exit()
{
echo error: $1
exit 1
}
#Currently, this is used only for the flag check of compiler.
cc_check()
{
echo 'int main(void){return 0;}' > conftest.c
$CC conftest.c $1 $2 -o conftest 2> /dev/null
ret=$?
rm -f conftest*
return $ret
}
is_64bit()
{
echo 'int main(void){int a[2*(sizeof(void *)>4)-1]; return 0;}' > conftest.c
$CC conftest.c -o conftest 2> /dev/null
ret=$?
rm -f conftest*
return $ret
}
#-----------------------------------------------------------------------------
rm -f config.* .depend conftest* liblsmash.pc *.ver
echo
echo generating config.mak ...
echo
SRCDIR=$(dirname "$0")
SRCDIR=$(cd "$SRCDIR"; pwd)
test "$SRCDIR" = "$(pwd)" && SRCDIR=.
test -n "$(echo $SRCDIR | grep ' ')" && \
error_exit "out-of-tree builds are impossible with whitespace in source path"
prefix=""
exec_prefix=""
bindir=""
libdir=""
includedir=""
DESTDIR=""
TARGET_OS=""
CROSS=""
SYSROOT=""
CC="gcc"
AR="ar"
LD="gcc"
RANLIB="ranlib"
STRIP="strip"
DEBUG=""
EXT=""
STATIC_NAME="liblsmash"
STATIC_EXT=".a"
STATICLIB="enabled"
SHARED_NAME="liblsmash"
SHARED_EXT=".so"
SHAREDLIB=""
IMPLIB=""
TOOLS=""
CFLAGS="-Wshadow -Wall -std=c99 -pedantic -I. -I$SRCDIR"
LDFLAGS="-L."
SO_LDFLAGS='-shared -Wl,-soname,$@ -Wl,--version-script,liblsmash.ver'
LIBS="-lm"
for opt; do
optarg="${opt#*=}"
case "$opt" in
--prefix=*)
prefix="$optarg"
;;
--exec-prefix=*)
exec_prefix="$optarg"
;;
--bindir=*)
bindir="$optarg"
;;
--libdir=*)
libdir="$optarg"
;;
--includedir=*)
includedir="$optarg"
;;
--destdir=*)
DESTDIR="$optarg"
;;
--cc=*)
CC="$optarg"
LD="$optarg"
;;
--target-os=*)
TARGET_OS="$optarg"
;;
--cross-prefix=*)
CROSS="$optarg"
;;
--sysroot=*)
CFLAGS="$CFLAGS --sysroot=$optarg"
LDFLAGS="$LDFLAGS --sysroot=$optarg"
;;
--disable-static)
STATICLIB=""
SHAREDLIB="enabled"
;;
--enable-shared)
SHAREDLIB="enabled"
;;
--enable-debug)
DEBUG="enabled"
;;
--extra-cflags=*)
XCFLAGS="$optarg"
;;
--extra-ldflags=*)
XLDFLAGS="$optarg"
;;
--extra-libs=*)
XLIBS="$optarg"
;;
*)
error_exit "unknown option $opt"
;;
esac
done
test -n "$prefix" || prefix="/usr/local"
test -n "$exec_prefix" || exec_prefix='${prefix}'
test -n "$bindir" || bindir='${exec_prefix}/bin'
test -n "$libdir" || libdir='${exec_prefix}/lib'
test -n "$includedir" || includedir='${prefix}/include'
CC="${CROSS}${CC}"
AR="${CROSS}${AR}"
LD="${CROSS}${LD}"
RANLIB="${CROSS}${RANLIB}"
STRIP="${CROSS}${STRIP}"
for f in "$CC" "$AR" "$LD" "$RANLIB" "$STRIP"; do
test -n "$(which $f 2> /dev/null)" || error_exit "$f is not executable"
done
MAJVER=$(grep -e '#define LSMASH_VERSION_MAJOR' $SRCDIR/lsmash.h | sed -e 's/#define LSMASH_VERSION_MAJOR //;s/ //g')
MINVER=$(grep -e '#define LSMASH_VERSION_MINOR' $SRCDIR/lsmash.h | sed -e 's/#define LSMASH_VERSION_MINOR //;s/ //g')
MICVER=$(grep -e '#define LSMASH_VERSION_MICRO' $SRCDIR/lsmash.h | sed -e 's/#define LSMASH_VERSION_MICRO //;s/ //g')
if test -n "$TARGET_OS"; then
TARGET_OS=$(echo $TARGET_OS | tr '[A-Z]' '[a-z]')
else
TARGET_OS=$($CC -dumpmachine | tr '[A-Z]' '[a-z]')
fi
case "$TARGET_OS" in
*mingw*)
EXT=".exe"
SHARED_NAME="liblsmash-$MAJVER"
SHARED_EXT=".dll"
DEFNAME="${SHARED_NAME}.def"
IMPLIB="liblsmash.dll.a"
SO_LDFLAGS="-shared -Wl,--output-def,$DEFNAME -Wl,--out-implib,$IMPLIB -Wl,--version-script,liblsmash.ver"
CFLAGS="$CFLAGS -D__USE_MINGW_ANSI_STDIO=1"
LIBARCH=i386
if lib.exe --list > /dev/null 2>&1 ; then
if is_64bit ; then
LIBARCH=x64
fi
SLIB_CMD='sed -i "s/ @[^ ]*//" $(DEFNAME); lib.exe -machine:$(LIBARCH) -def:$(DEFNAME) -out:lsmash.lib'
elif genlib -V > /dev/null 2>&1 ; then
if is_64bit ; then
LIBARCH=x86_64
else
LIBARCH=x86
fi
SLIB_CMD='sed -i "s/ @[^ ]*//" $(DEFNAME); genlib -a $(LIBARCH) -o lsmash.lib -d $(SHAREDLIBNAME) $(DEFNAME)'
elif ${CROSS}dlltool --version > /dev/null 2>&1 ; then
if is_64bit ; then
LIBARCH="i386:x86-64"
fi
SLIB_CMD="sed -i \"s/ @[^ ]*//\" \$(DEFNAME); ${CROSS}dlltool -m \$(LIBARCH) -d \$(DEFNAME) -l lsmash.lib -D \$(SHAREDLIBNAME)"
fi
;;
*cygwin*)
EXT=".exe"
SHARED_NAME="cyglsmash"
SHARED_EXT=".dll"
IMPLIB="liblsmash.dll.a"
SO_LDFLAGS="-shared -Wl,--out-implib,$IMPLIB -Wl,--version-script,liblsmash.ver"
;;
*darwin*)
SHARED_EXT=".dylib"
SO_LDFLAGS="-dynamiclib -Wl,-undefined,suppress -Wl,-read_only_relocs,suppress -Wl,-flat_namespace -Wl,--version-script,liblsmash.ver"
;;
*solaris*)
#patches welcome
SHAREDLIB=""
;;
*)
SHARED_NAME="liblsmash"
SHARED_EXT=".so.$MAJVER"
if test -n "$SHAREDLIB"; then
CFLAGS="$CFLAGS -fPIC"
LDFLAGS="$LDFLAGS -fPIC"
fi
;;
esac
STATICLIBNAME="${STATIC_NAME}${STATIC_EXT}"
SHAREDLIBNAME="${SHARED_NAME}${SHARED_EXT}"
test -n "$STATICLIB" && STATICLIB="$STATICLIBNAME"
test -n "$SHAREDLIB" && SHAREDLIB="$SHAREDLIBNAME"
test -z "$STATICLIB" -a -z "$SHAREDLIB" && \
error_exit "--disable-static requires --enable-shared were specified"
test -z "$SHAREDLIB" && SO_LDFLAGS=""
CFLAGS="$CFLAGS $XCFLAGS"
LDFLAGS="$LDFLAGS $XLDFLAGS"
LIBS="$LIBS $XLIBS"
# In order to avoid some compiler bugs, we don't use "-O3" for the default.
# "-Os" unites "-O2" and "-finline-funtions" on x86/x86_64 in the latest GCC.
# As a result of taking these into consideration, we make "-Os" a rated value.
# And, we don't care about architecture related options.
# If you want them, set up by yourself like --extra-cflags="-O3 -march=native".
if test -n "$DEBUG"; then
CFLAGS="$CFLAGS -g3 -O0"
STRIP=""
else
CFLAGS="-Os -ffast-math $CFLAGS"
fi
if ! cc_check "$CFLAGS" "$LDFLAGS"; then
error_exit "invalid CFLAGS/LDFLAGS"
fi
if cc_check "$CFLAGS -fexcess-precision=fast" "$LDFLAGS"; then
CFLAGS="$CFLAGS -fexcess-precision=fast"
fi
if cc_check "$CFLAGS" "$LDFLAGS -Wl,--large-address-aware"; then
LDFLAGS="$LDFLAGS -Wl,--large-address-aware"
fi
#=============================================================================
# Notation for developpers.
# Be sure to modified this block when you add/delete source files.
SRC_COMMON=" \
alloc.c \
bits.c \
bytes.c \
list.c \
multibuf.c \
osdep.c \
utils.c"
SRC_CODECS=" \
a52.c \
alac.c \
description.c \
dts.c \
h264.c \
hevc.c \
id.c \
mp4sys.c \
mp4a.c \
mp4v.c \
nalu.c \
qt_wfex.c \
vc1.c \
wma.c"
SRC_IMPORTER=" \
a52_imp.c \
adts_imp.c \
als_imp.c \
amr_imp.c \
dts_imp.c \
importer.c \
isobm_imp.c \
mp3_imp.c \
nalu_imp.c \
vc1_imp.c \
wave_imp.c"
SRC_CORE=" \
box.c \
box_default.c \
box_type.c \
chapter.c \
file.c \
fragment.c \
isom.c \
meta.c \
print.c \
read.c \
summary.c \
timeline.c \
write.c"
SRCS=""
for src in $SRC_COMMON; do
SRCS="$SRCS common/$src"
done
for src in $SRC_CODECS; do
SRCS="$SRCS codecs/$src"
done
for src in $SRC_IMPORTER; do
SRCS="$SRCS importer/$src"
done
for src in $SRC_CORE; do
SRCS="$SRCS core/$src"
done
SRC_CLI="cli.c"
SRC_TOOLS=""
OBJ_TOOLS=""
for src in $SRC_CLI; do
SRC_TOOLS="$SRC_TOOLS cli/$src"
done
for src in $SRC_TOOLS; do
OBJ_TOOLS="$OBJ_TOOLS ${src%.c}.o"
done
TOOLS_ALL="muxer remuxer boxdumper timelineeditor"
TOOLS_NAME=""
TOOLS="$TOOLS_ALL"
for tool in $TOOLS; do
SRC_TOOLS="$SRC_TOOLS cli/${tool}.c"
TOOLS_NAME="$TOOLS_NAME cli/${tool}${EXT}"
done
#=============================================================================
CURDIR="$PWD"
cd $SRCDIR
VER=$MAJVER.$MINVER.$MICVER
if test -d .git && type git > /dev/null 2>&1 ; then
REV="$(git rev-list HEAD 2> /dev/null | wc -l)"
HASH="$(git describe --always 2> /dev/null)"
else
REV=0
HASH=
fi
if test $REV -ne 0; then
VER_STRING="$VER rev.$REV"
else
VER_STRING="$VER"
fi
cd "$CURDIR"
cat >> config.h << EOF
#define LSMASH_REV "$REV"
#define LSMASH_GIT_HASH "$HASH"
EOF
sed "s/\\\$MAJOR/$MAJVER/" $SRCDIR/liblsmash.v > liblsmash.ver
# Add non-public symbols which have lsmash_* prefix to local.
# find $SRCDIR/common/ $SRCDIR/importer/ -name "*.h" | xargs sed -e 's/^[ ]*//g' | \
# 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_" | \
# sed -e "s/.*\(lsmash_.*\)(.*/\1/g" -e "s/.*\(lsmash_.*\)/\1;/g" | xargs -I% sed -i "/^};$/i \ %" liblsmash.ver
find $SRCDIR/common/ $SRCDIR/importer/ -name "*.h" -exec grep -oE '^[[:space:]]*(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)[[:space:]]*\*?[[:space:]]*lsmash_\w+' {} + | \
sed -E 's/.*\(lsmash_(.*)\).*/\1;/' >> liblsmash.ver
# Get rid of non-public symbols for the cli tools from local.
sed -i "" -e '/lsmash_win32_fopen/d' \
-e '/lsmash_string_from_wchar/d' \
-e '/lsmash_importer_open/d' \
-e '/lsmash_importer_close/d' \
-e '/lsmash_importer_get_access_unit/d' \
-e '/lsmash_importer_get_last_delta/d' \
-e '/lsmash_importer_construct_timeline/d' \
-e '/lsmash_importer_get_track_count/d' \
-e '/lsmash_duplicate_summary/d' liblsmash.ver
cat >> liblsmash.pc << EOF
prefix=$prefix
exec_prefix=$exec_prefix
libdir=$libdir
includedir=$includedir
Name: liblsmash
Description: Loyal to Spec of MPEG4, and Ad-hock Simple Hackwork
Version: $VER_STRING
Requires:
URL: https://github.com/l-smash/l-smash
Libs: -L${libdir} -llsmash $(test -z "$SHAREDLIB" && echo $LIBS)
Libs.private: $(test -n "$SHAREDLIB" && echo $LIBS)
Cflags: -I${includedir}
EOF
cat >> config.mak << EOF
SRCDIR = $SRCDIR
DESTDIR = $DESTDIR
prefix = $prefix
exec_prefix = $exec_prefix
bindir = $bindir
libdir = $libdir
includedir = $includedir
CC = $CC
AR = $AR
LD = $LD
RANLIB = $RANLIB
STRIP = $STRIP
STATICLIBNAME = $STATICLIBNAME
STATICLIB = $STATICLIB
SHAREDLIBNAME = $SHAREDLIBNAME
SHAREDLIB = $SHAREDLIB
IMPLIB = $IMPLIB
CFLAGS = $CFLAGS
LDFLAGS = $LDFLAGS
SO_LDFLAGS = $SO_LDFLAGS
LIBS = $LIBS
LIBARCH = $LIBARCH
DEFNAME = $DEFNAME
SLIB_CMD = $SLIB_CMD
EOF
cat config.mak
cat >> config.mak << EOF
SRCS = $SRCS
SRC_TOOLS = $SRC_TOOLS
TOOLS_ALL = $TOOLS_ALL
TOOLS = $TOOLS_NAME
MAJVER = $MAJVER
EOF
for tool in $TOOLS; do
cat >> config.mak2 << EOF
cli/${tool}${EXT}: cli/${tool}.o $OBJ_TOOLS $STATICLIB $SHAREDLIB
\$(CC) \$(CFLAGS) \$(LDFLAGS) -o \$@ \$< $OBJ_TOOLS -llsmash \$(LIBS)
-@ \$(if \$(STRIP), \$(STRIP) \$@)
EOF
done
test "$SRCDIR" = "." || ln -sf ${SRCDIR}/Makefile .
mkdir -p cli codecs common core importer
cat << EOF
configure finished
type 'make' : compile library and tools
type 'make install' : install all into system
type 'make lib' : compile library only
type 'make install-lib' : install library and header into system
EOF
exit 0