push
This commit is contained in:
708
scripts/checks.sh
Normal file
708
scripts/checks.sh
Normal file
@@ -0,0 +1,708 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright 2005-2006 Timo Hirvonen
|
||||
#
|
||||
# This file is licensed under the GPLv2.
|
||||
|
||||
# C compiler
|
||||
# ----------
|
||||
# CC default gcc
|
||||
# LD default $CC
|
||||
# LDFLAGS common linker flags for CC
|
||||
#
|
||||
# C++ Compiler
|
||||
# ------------
|
||||
# CXX default g++
|
||||
# CXXLD default $CXX
|
||||
# CXXLDFLAGS common linker flags for CXX
|
||||
#
|
||||
# Common for C and C++
|
||||
# --------------------
|
||||
# SOFLAGS flags for compiling position independent code (-fPIC)
|
||||
# LDSOFLAGS flags for linking shared libraries
|
||||
# LDDLFLAGS flags for linking dynamically loadable modules
|
||||
|
||||
msg_checking()
|
||||
{
|
||||
printf "checking $@... "
|
||||
}
|
||||
|
||||
msg_result()
|
||||
{
|
||||
echo "$@"
|
||||
}
|
||||
|
||||
msg_error()
|
||||
{
|
||||
echo "*** $@"
|
||||
}
|
||||
|
||||
# @program: program to check
|
||||
# @name: name of variable where to store the full program name (optional)
|
||||
#
|
||||
# returns 0 on success and 1 on failure
|
||||
check_program()
|
||||
{
|
||||
argc check_program $# 1 2
|
||||
msg_checking "for program $1"
|
||||
__cp_file=`path_find "$1"`
|
||||
if test $? -eq 0
|
||||
then
|
||||
msg_result $__cp_file
|
||||
test $# -eq 2 && set_var $2 "$__cp_file"
|
||||
return 0
|
||||
else
|
||||
msg_result "no"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
cc_supports()
|
||||
{
|
||||
$CC $CPPFLAGS $CFLAGS "$@" -S -o /dev/null -x c /dev/null 2> /dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
cxx_supports()
|
||||
{
|
||||
$CXX $CPPFLAGS $CXXFLAGS "$@" -S -o /dev/null -x c /dev/null 2> /dev/null
|
||||
return $?
|
||||
}
|
||||
|
||||
# @flag: option flag(s) to check
|
||||
#
|
||||
# add @flag to EXTRA_CFLAGS if CC accepts it
|
||||
# EXTRA_CFLAGS are added to CFLAGS in the end of configuration
|
||||
check_cc_flag()
|
||||
{
|
||||
argc check_cc_flag $# 1
|
||||
|
||||
test -z "$CC" && die "check_cc_flag: CC not set"
|
||||
msg_checking "for CFLAGS $*"
|
||||
if cc_supports $*
|
||||
then
|
||||
EXTRA_CFLAGS="$EXTRA_CFLAGS $*"
|
||||
msg_result "yes"
|
||||
return 0
|
||||
else
|
||||
msg_result "no"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# @flag: option flag(s) to check
|
||||
#
|
||||
# add @flag to EXTRA_CXXFLAGS if CXX accepts it
|
||||
# EXTRA_CXXFLAGS are added to CXXFLAGS in the end of configuration
|
||||
check_cxx_flag()
|
||||
{
|
||||
argc check_cxx_flag $# 1
|
||||
|
||||
test -z "$CXX" && die "check_cxx_flag: CXX not set"
|
||||
msg_checking "for CXXFLAGS $*"
|
||||
if cxx_supports $*
|
||||
then
|
||||
EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS $*"
|
||||
msg_result "yes"
|
||||
return 0
|
||||
else
|
||||
msg_result "no"
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
cc_cxx_common()
|
||||
{
|
||||
test "$cc_cxx_common_done" && return 0
|
||||
cc_cxx_common_done=yes
|
||||
|
||||
var_default SOFLAGS "-fPIC"
|
||||
var_default LDSOFLAGS "-shared"
|
||||
var_default LDDLFLAGS "-shared"
|
||||
|
||||
common_cf=
|
||||
common_lf=
|
||||
|
||||
case `uname -s` in
|
||||
*BSD)
|
||||
common_cf="$common_cf -I/usr/local/include"
|
||||
common_lf="$common_lf -L/usr/local/lib"
|
||||
;;
|
||||
Darwin)
|
||||
# fink
|
||||
if test -d /sw/lib
|
||||
then
|
||||
common_cf="$common_cf -I/sw/include"
|
||||
common_lf="$common_lf -L/sw/lib"
|
||||
fi
|
||||
# darwinports
|
||||
if test -d /opt/local/lib
|
||||
then
|
||||
common_cf="$common_cf -I/opt/local/include"
|
||||
common_lf="$common_lf -L/opt/local/lib"
|
||||
fi
|
||||
LDSOFLAGS="-dynamic"
|
||||
case ${MACOSX_DEPLOYMENT_TARGET} in
|
||||
10.[012])
|
||||
LDDLFLAGS="-bundle -flat_namespace -undefined suppress"
|
||||
;;
|
||||
10.*)
|
||||
LDDLFLAGS="-bundle -undefined dynamic_lookup"
|
||||
;;
|
||||
*)
|
||||
LDDLFLAGS="-bundle -flat_namespace -undefined suppress"
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
SunOS)
|
||||
common_cf="$common_cf -D__EXTENSIONS__ -I/usr/local/include"
|
||||
common_lf="$common_lf -R/usr/local/lib -L/usr/local/lib"
|
||||
;;
|
||||
esac
|
||||
makefile_vars SOFLAGS LDSOFLAGS LDDLFLAGS
|
||||
}
|
||||
|
||||
# CC, LD, CFLAGS, LDFLAGS, SOFLAGS, LDSOFLAGS, LDDLFLAGS
|
||||
check_cc()
|
||||
{
|
||||
var_default CC ${CROSS}gcc
|
||||
var_default LD $CC
|
||||
var_default CFLAGS "-g -O2 -Wall"
|
||||
var_default LDFLAGS ""
|
||||
check_program $CC || return 1
|
||||
|
||||
cc_cxx_common
|
||||
CFLAGS="$CFLAGS $common_cf"
|
||||
LDFLAGS="$LDFLAGS $common_lf"
|
||||
|
||||
makefile_vars CC LD CFLAGS LDFLAGS
|
||||
__check_lang=c
|
||||
return 0
|
||||
}
|
||||
|
||||
# HOSTCC, HOSTLD, HOST_CFLAGS, HOST_LDFLAGS
|
||||
check_host_cc()
|
||||
{
|
||||
var_default HOSTCC gcc
|
||||
var_default HOSTLD $HOSTCC
|
||||
var_default HOST_CFLAGS "-g -O2 -Wall"
|
||||
var_default HOST_LDFLAGS ""
|
||||
check_program $HOSTCC || return 1
|
||||
makefile_vars HOSTCC HOSTLD HOST_CFLAGS HOST_LDFLAGS
|
||||
__check_lang=c
|
||||
return 0
|
||||
}
|
||||
|
||||
# CXX, CXXLD, CXXFLAGS, CXXLDFLAGS, SOFLAGS, LDSOFLAGS, LDDLFLAGS
|
||||
check_cxx()
|
||||
{
|
||||
var_default CXX ${CROSS}g++
|
||||
var_default CXXLD $CXX
|
||||
var_default CXXFLAGS "-g -O2 -Wall"
|
||||
var_default CXXLDFLAGS ""
|
||||
check_program $CXX || return 1
|
||||
|
||||
cc_cxx_common
|
||||
CXXFLAGS="$CXXFLAGS $common_cf"
|
||||
CXXLDFLAGS="$CXXLDFLAGS $common_lf"
|
||||
|
||||
makefile_vars CXX CXXLD CXXFLAGS CXXLDFLAGS
|
||||
__check_lang=cxx
|
||||
return 0
|
||||
}
|
||||
|
||||
# check if CC can generate dependencies (.dep-*.o files)
|
||||
# always succeeds
|
||||
check_cc_depgen()
|
||||
{
|
||||
msg_checking "if CC can generate dependency information"
|
||||
if cc_supports -MMD -MP -MF /dev/null
|
||||
then
|
||||
EXTRA_CFLAGS="$EXTRA_CFLAGS -MMD -MP -MF .dep-\$(subst /,-,\$@)"
|
||||
msg_result yes
|
||||
else
|
||||
msg_result no
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# check if CXX can generate dependencies (.dep-*.o files)
|
||||
# always succeeds
|
||||
check_cxx_depgen()
|
||||
{
|
||||
msg_checking "if CXX can generate dependency information"
|
||||
if cxx_supports -MMD -MP -MF /dev/null
|
||||
then
|
||||
EXTRA_CXXFLAGS="$EXTRA_CXXFLAGS -MMD -MP -MF .dep-\$(subst /,-,\$@)"
|
||||
msg_result yes
|
||||
else
|
||||
msg_result no
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# adds AR to config.mk
|
||||
check_ar()
|
||||
{
|
||||
var_default AR ${CROSS}ar
|
||||
var_default ARFLAGS "-cr"
|
||||
if check_program $AR
|
||||
then
|
||||
makefile_vars AR ARFLAGS
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
# adds AS to config.mk
|
||||
check_as()
|
||||
{
|
||||
var_default AS ${CROSS}gcc
|
||||
if check_program $AS
|
||||
then
|
||||
makefile_vars AS
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
}
|
||||
|
||||
check_pkgconfig()
|
||||
{
|
||||
if test -z "$PKG_CONFIG"
|
||||
then
|
||||
if check_program pkg-config PKG_CONFIG
|
||||
then
|
||||
makefile_vars PKG_CONFIG
|
||||
else
|
||||
# don't check again
|
||||
PKG_CONFIG="no"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# check for library FOO and add FOO_CFLAGS and FOO_LIBS to config.mk
|
||||
#
|
||||
# @name: variable prefix (e.g. CURSES -> CURSES_CFLAGS, CURSES_LIBS)
|
||||
# @cflags: CFLAGS for the lib
|
||||
# @libs: LIBS to check
|
||||
#
|
||||
# adds @name_CFLAGS and @name_LIBS to config.mk
|
||||
# CFLAGS are not checked, they are assumed to be correct
|
||||
check_library()
|
||||
{
|
||||
argc check_library $# 3 3
|
||||
msg_checking "for ${1}_LIBS ($3)"
|
||||
if try_link $3
|
||||
then
|
||||
msg_result yes
|
||||
makefile_var ${1}_CFLAGS "$2"
|
||||
makefile_var ${1}_LIBS "$3"
|
||||
return 0
|
||||
else
|
||||
msg_result no
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# run pkg-config
|
||||
#
|
||||
# @prefix: variable prefix (e.g. GLIB -> GLIB_CFLAGS, GLIB_LIBS)
|
||||
# @modules: the argument for pkg-config
|
||||
# @cflags: CFLAGS to use if pkg-config failed (optional)
|
||||
# @libs: LIBS to use if pkg-config failed (optional)
|
||||
#
|
||||
# if pkg-config fails and @libs are given check_library is called
|
||||
#
|
||||
# example:
|
||||
# ---
|
||||
# check_glib()
|
||||
# {
|
||||
# pkg_config GLIB "glib-2.0 >= 2.2"
|
||||
# return $?
|
||||
# }
|
||||
#
|
||||
# check check_cc
|
||||
# check check_glib
|
||||
# ---
|
||||
# GLIB_CFLAGS and GLIB_LIBS are automatically added to Makefile
|
||||
pkg_config()
|
||||
{
|
||||
argc pkg_config $# 2 4
|
||||
|
||||
# optional
|
||||
__pc_cflags="$3"
|
||||
__pc_libs="$4"
|
||||
|
||||
check_pkgconfig
|
||||
msg_checking "for ${1}_LIBS (pkg-config)"
|
||||
if test "$PKG_CONFIG" != "no" && $PKG_CONFIG --exists "$2" >/dev/null 2>&1
|
||||
then
|
||||
# pkg-config is installed and the .pc file exists
|
||||
__pc_libs="`$PKG_CONFIG --libs ""$2""`"
|
||||
msg_result "$__pc_libs"
|
||||
|
||||
msg_checking "for ${1}_CFLAGS (pkg-config)"
|
||||
__pc_cflags="`$PKG_CONFIG --cflags ""$2""`"
|
||||
msg_result "$__pc_cflags"
|
||||
|
||||
makefile_var ${1}_CFLAGS "$__pc_cflags"
|
||||
makefile_var ${1}_LIBS "$__pc_libs"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# no pkg-config or .pc file
|
||||
msg_result "no"
|
||||
|
||||
if test -z "$__pc_libs"
|
||||
then
|
||||
if test "$PKG_CONFIG" = "no"
|
||||
then
|
||||
# pkg-config not installed and no libs to check were given
|
||||
msg_error "pkg-config required for $1"
|
||||
else
|
||||
# pkg-config is installed but the required .pc file wasn't found
|
||||
$PKG_CONFIG --errors-to-stdout --print-errors "$2" | sed 's:^:*** :'
|
||||
fi
|
||||
return 1
|
||||
fi
|
||||
|
||||
check_library "$1" "$__pc_cflags" "$__pc_libs"
|
||||
return $?
|
||||
}
|
||||
|
||||
# old name
|
||||
pkg_check_modules()
|
||||
{
|
||||
pkg_config "$@"
|
||||
}
|
||||
|
||||
# run *-config
|
||||
#
|
||||
# @prefix: variable prefix (e.g. ARTS -> ARTS_CFLAGS, ARTS_LIBS)
|
||||
# @program: the -config program
|
||||
#
|
||||
# example:
|
||||
# ---
|
||||
# check_arts()
|
||||
# {
|
||||
# app_config ARTS artsc-config
|
||||
# return $?
|
||||
# }
|
||||
#
|
||||
# check check_cc
|
||||
# check check_arts
|
||||
# ---
|
||||
# ARTS_CFLAGS and ARTS_LIBS are automatically added to config.mk
|
||||
app_config()
|
||||
{
|
||||
argc app_config $# 2 2
|
||||
check_program $2 || return 1
|
||||
|
||||
msg_checking "for ${1}_CFLAGS"
|
||||
__ac_cflags="`$2 --cflags`"
|
||||
msg_result "$__ac_cflags"
|
||||
|
||||
msg_checking "for ${1}_LIBS"
|
||||
__ac_libs="`$2 --libs`"
|
||||
msg_result "$__ac_libs"
|
||||
|
||||
makefile_var ${1}_CFLAGS "$__ac_cflags"
|
||||
makefile_var ${1}_LIBS "$__ac_libs"
|
||||
return 0
|
||||
}
|
||||
|
||||
# @contents: file contents to compile
|
||||
# @cflags: extra cflags (optional)
|
||||
try_compile()
|
||||
{
|
||||
argc try_compile $# 1
|
||||
case $__check_lang in
|
||||
c)
|
||||
__src=`tmp_file prog.c`
|
||||
__obj=`tmp_file prog.o`
|
||||
echo "$1" > $__src || exit 1
|
||||
shift
|
||||
__cmd="$CC -c $CPPFLAGS $CFLAGS $@ $__src -o $__obj"
|
||||
$CC -c $CPPFLAGS $CFLAGS "$@" $__src -o $__obj 2>/dev/null
|
||||
;;
|
||||
cxx)
|
||||
__src=`tmp_file prog.cc`
|
||||
__obj=`tmp_file prog.o`
|
||||
echo "$1" > $__src || exit 1
|
||||
shift
|
||||
__cmd="$CXX -c $CPPFLAGS $CXXFLAGS $@ $__src -o $__obj"
|
||||
$CXX -c $CPPFLAGS $CXXFLAGS "$@" $__src -o $__obj 2>/dev/null
|
||||
;;
|
||||
esac
|
||||
return $?
|
||||
}
|
||||
|
||||
# @contents: file contents to compile and link
|
||||
# @flags: extra flags (optional)
|
||||
try_compile_link()
|
||||
{
|
||||
argc try_compile $# 1
|
||||
case $__check_lang in
|
||||
c)
|
||||
__src=`tmp_file prog.c`
|
||||
__exe=`tmp_file prog`
|
||||
echo "$1" > $__src || exit 1
|
||||
shift
|
||||
__cmd="$CC $__src -o $__exe $CPPFLAGS $CFLAGS $LDFLAGS $@"
|
||||
$CC $__src -o $__exe $CPPFLAGS $CFLAGS $LDFLAGS "$@" 2>/dev/null
|
||||
;;
|
||||
cxx)
|
||||
__src=`tmp_file prog.cc`
|
||||
__exe=`tmp_file prog`
|
||||
echo "$1" > $__src || exit 1
|
||||
shift
|
||||
__cmd="$CXX $__src -o $__exe $CPPFLAGS $CXXFLAGS $CXXLDFLAGS $@"
|
||||
$CXX $__src -o $__exe $CPPFLAGS $CXXFLAGS $CXXLDFLAGS "$@" 2>/dev/null
|
||||
;;
|
||||
esac
|
||||
return $?
|
||||
}
|
||||
|
||||
# optionally used after try_compile or try_compile_link
|
||||
__compile_failed()
|
||||
{
|
||||
warn
|
||||
warn "Failed to compile simple program:"
|
||||
warn "---"
|
||||
cat $__src >&2
|
||||
warn "---"
|
||||
warn "Command: $__cmd"
|
||||
case $__check_lang in
|
||||
c)
|
||||
warn "Make sure your CC and CFLAGS are sane."
|
||||
;;
|
||||
cxx)
|
||||
warn "Make sure your CXX and CXXFLAGS are sane."
|
||||
;;
|
||||
esac
|
||||
exit 1
|
||||
}
|
||||
|
||||
# tries to link against a lib
|
||||
#
|
||||
# @function: some function
|
||||
# @flags: extra flags (optional)
|
||||
check_function()
|
||||
{
|
||||
argc check_function $# 1
|
||||
__func="$1"
|
||||
shift
|
||||
msg_checking "for function $__func"
|
||||
if try_compile_link "extern int $__func(); int (*ptr)() = &$__func; int main() { return 0; }" "$@"
|
||||
then
|
||||
msg_result yes
|
||||
return 0
|
||||
fi
|
||||
|
||||
msg_result no
|
||||
return 1
|
||||
}
|
||||
|
||||
# tries to link against a lib
|
||||
#
|
||||
# @ldadd: something like -L/usr/X11R6/lib -lX11
|
||||
try_link()
|
||||
{
|
||||
try_compile_link "int main(int argc, char *argv[]) { return 0; }" "$@"
|
||||
return $?
|
||||
}
|
||||
|
||||
# compile and run
|
||||
#
|
||||
# @code: simple program code to run
|
||||
run_code()
|
||||
{
|
||||
if test $CROSS
|
||||
then
|
||||
msg_error "cannot run code when cross compiling"
|
||||
exit 1
|
||||
fi
|
||||
try_compile_link "$1" || __compile_failed
|
||||
./$__exe
|
||||
return $?
|
||||
}
|
||||
|
||||
# check if the architecture is big-endian
|
||||
# parts are from autoconf 2.67
|
||||
#
|
||||
# defines WORDS_BIGENDIAN=y/n
|
||||
check_endianness()
|
||||
{
|
||||
msg_checking "byte order"
|
||||
WORDS_BIGENDIAN=n
|
||||
# See if sys/param.h defines the BYTE_ORDER macro.
|
||||
if try_compile_link "
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
int main() {
|
||||
#if ! (defined BYTE_ORDER && defined BIG_ENDIAN \
|
||||
&& defined LITTLE_ENDIAN && BYTE_ORDER && BIG_ENDIAN \
|
||||
&& LITTLE_ENDIAN)
|
||||
bogus endian macros
|
||||
#endif
|
||||
return 0;
|
||||
}"
|
||||
then
|
||||
# It does; now see whether it defined to BIG_ENDIAN or not.
|
||||
if try_compile_link "
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
int main() {
|
||||
#if BYTE_ORDER != BIG_ENDIAN
|
||||
not big endian
|
||||
#endif
|
||||
return 0;
|
||||
}"
|
||||
then
|
||||
WORDS_BIGENDIAN=y
|
||||
fi
|
||||
# See if <limits.h> defines _LITTLE_ENDIAN or _BIG_ENDIAN (e.g., Solaris).
|
||||
elif try_compile_link "
|
||||
#include <limits.h>
|
||||
int main() {
|
||||
#if ! (defined _LITTLE_ENDIAN || defined _BIG_ENDIAN)
|
||||
bogus endian macros
|
||||
#endif
|
||||
return 0;
|
||||
}"
|
||||
then
|
||||
# It does; now see whether it defined to _BIG_ENDIAN or not.
|
||||
if try_compile_link "
|
||||
#include <limits.h>
|
||||
int main() {
|
||||
#ifndef _BIG_ENDIAN
|
||||
not big endian
|
||||
#endif
|
||||
return 0;
|
||||
}"
|
||||
then
|
||||
WORDS_BIGENDIAN=y
|
||||
fi
|
||||
elif run_code "
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
unsigned int i = 1;
|
||||
return *(char *)&i;
|
||||
}"
|
||||
then
|
||||
WORDS_BIGENDIAN=y
|
||||
fi
|
||||
if test "$WORDS_BIGENDIAN" = y
|
||||
then
|
||||
msg_result "big-endian"
|
||||
else
|
||||
msg_result "little-endian"
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
# check if @header can be included
|
||||
#
|
||||
# @header
|
||||
# @cflags -I/some/path (optional)
|
||||
check_header()
|
||||
{
|
||||
argc check_header $# 1
|
||||
__header="$1"
|
||||
shift
|
||||
msg_checking "for header <$__header>"
|
||||
if try_compile "#include <$__header>" "$@"
|
||||
then
|
||||
msg_result yes
|
||||
return 0
|
||||
fi
|
||||
msg_result no
|
||||
return 1
|
||||
}
|
||||
|
||||
# check X11 libs
|
||||
#
|
||||
# adds X11_LIBS (and empty X11_CFLAGS) to config.mk
|
||||
check_x11()
|
||||
{
|
||||
for __libs in "-lX11" "-L/usr/X11R6/lib -lX11"
|
||||
do
|
||||
check_library X11 "" "$__libs" && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
# check posix threads
|
||||
#
|
||||
# adds PTHREAD_CFLAGS and PTHREAD_LIBS to config.mk
|
||||
check_pthread()
|
||||
{
|
||||
for __libs in "$PTHREAD_LIBS" -lpthread -lc_r -lkse
|
||||
do
|
||||
test -z "$__libs" && continue
|
||||
check_library PTHREAD "-D_REENTRANT" "$__libs" && return 0
|
||||
done
|
||||
echo "using -pthread gcc option"
|
||||
makefile_var PTHREAD_CFLAGS "-pthread -D_THREAD_SAFE"
|
||||
makefile_var PTHREAD_LIBS "-pthread"
|
||||
return 0
|
||||
}
|
||||
|
||||
# check dynamic linking loader
|
||||
#
|
||||
# adds DL_LIBS to config.mk
|
||||
check_dl()
|
||||
{
|
||||
for DL_LIBS in "-ldl -Wl,--export-dynamic" "-ldl -rdynamic" "-Wl,--export-dynamic" "-rdynamic" "-ldl"
|
||||
do
|
||||
check_library DL "" "$DL_LIBS" && return 0
|
||||
done
|
||||
echo "assuming -ldl is not needed"
|
||||
DL_LIBS=
|
||||
makefile_vars DL_LIBS DL_CFLAGS
|
||||
return 0
|
||||
}
|
||||
|
||||
# check for iconv
|
||||
#
|
||||
# adds ICONV_CFLAGS and ICONV_LIBS to config.mk
|
||||
check_iconv()
|
||||
{
|
||||
HAVE_ICONV=n
|
||||
if check_library ICONV "" "-liconv"
|
||||
then
|
||||
echo "taking iconv from libiconv"
|
||||
else
|
||||
echo "assuming libc contains iconv"
|
||||
makefile_var ICONV_CFLAGS ""
|
||||
makefile_var ICONV_LIBS ""
|
||||
fi
|
||||
msg_checking "for working iconv"
|
||||
if try_compile_link '
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <iconv.h>
|
||||
int main(int argc, char *argv[]) {
|
||||
char buf[128], *out = buf, *in = argv[1];
|
||||
size_t outleft = 127, inleft = strlen(in);
|
||||
iconv_t cd = iconv_open("UTF-8", "ISO-8859-1");
|
||||
iconv(cd, &in, &inleft, &out, &outleft);
|
||||
*out = 0;
|
||||
printf("%s", buf);
|
||||
iconv_close(cd);
|
||||
return 0;
|
||||
}' $ICONV_CFLAGS $ICONV_LIBS
|
||||
then
|
||||
msg_result "yes"
|
||||
HAVE_ICONV=y
|
||||
else
|
||||
msg_result "no"
|
||||
msg_error "Your system doesn't have iconv!"
|
||||
msg_error "This means that no charset conversion can be done, so all"
|
||||
msg_error "your tracks need to be encoded in your system charset!"
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
229
scripts/configure.sh
Normal file
229
scripts/configure.sh
Normal file
@@ -0,0 +1,229 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright 2005 Timo Hirvonen
|
||||
#
|
||||
# This file is licensed under the GPLv2.
|
||||
|
||||
. scripts/utils.sh || exit 1
|
||||
. scripts/checks.sh || exit 1
|
||||
|
||||
# Usage: parse_command_line "$@"
|
||||
# USAGE string must be defined in configure (used for --help)
|
||||
parse_command_line()
|
||||
{
|
||||
while test $# -gt 0
|
||||
do
|
||||
case $1 in
|
||||
--help)
|
||||
show_usage
|
||||
;;
|
||||
--prefix=*|--bindir=*|--datadir=*|--libdir=*|--mandir=*|--docdir=*)
|
||||
# aliases for compatibility with common autoconf options
|
||||
# https://www.gnu.org/software/autoconf/manual/autoconf-2.67/html_node/Installation-Directory-Variables.html
|
||||
_var=`echo "$1" | sed "s/--//" | sed "s/=.*//"`
|
||||
_val=`echo "$1" | sed "s/--${_var}=//"`
|
||||
set_var "$_var" "$_val"
|
||||
;;
|
||||
-f)
|
||||
shift
|
||||
test $# -eq 0 && die "-f requires an argument"
|
||||
. "$1"
|
||||
;;
|
||||
-*)
|
||||
die "unrecognized option \`$1'"
|
||||
;;
|
||||
*=*)
|
||||
_var=`echo "$1" | sed "s/=.*//"`
|
||||
_val=`echo "$1" | sed "s/${_var}=//"`
|
||||
set_var "$_var" "$_val"
|
||||
;;
|
||||
*)
|
||||
die "unrecognized argument \`$1'"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
# check function [variable]
|
||||
#
|
||||
# Example:
|
||||
# check check_cc
|
||||
# check check_vorbis CONFIG_VORBIS
|
||||
check()
|
||||
{
|
||||
argc check $# 1 2
|
||||
if test $# -eq 1
|
||||
then
|
||||
$1 || die "configure failed."
|
||||
return
|
||||
fi
|
||||
|
||||
# optional feature
|
||||
case `get_var $2` in
|
||||
n)
|
||||
;;
|
||||
y)
|
||||
$1 || die "configure failed."
|
||||
;;
|
||||
a|'')
|
||||
if $1
|
||||
then
|
||||
set_var $2 y
|
||||
else
|
||||
set_var $2 n
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
die "invalid value for $2. 'y', 'n', 'a' or '' expected"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Set and register variable to be added to config.mk
|
||||
#
|
||||
# @name name of the variable
|
||||
# @value value of the variable
|
||||
makefile_var()
|
||||
{
|
||||
argc makefile_var $# 2 2
|
||||
set_var $1 "$2"
|
||||
makefile_vars $1
|
||||
}
|
||||
|
||||
# Register variables to be added to config.mk
|
||||
makefile_vars()
|
||||
{
|
||||
makefile_variables="$makefile_variables $*"
|
||||
}
|
||||
|
||||
# generate config.mk
|
||||
generate_config_mk()
|
||||
{
|
||||
CFLAGS="$CFLAGS $EXTRA_CFLAGS"
|
||||
CXXFLAGS="$CXXFLAGS $EXTRA_CXXFLAGS"
|
||||
if test -z "$GINSTALL"
|
||||
then
|
||||
GINSTALL=`path_find ginstall`
|
||||
test "$GINSTALL" || GINSTALL=install
|
||||
fi
|
||||
# $PWD is useless!
|
||||
topdir=`pwd`
|
||||
makefile_vars GINSTALL topdir
|
||||
|
||||
__tmp=`tmp_file config.mk`
|
||||
for __i in $makefile_variables
|
||||
do
|
||||
echo "$__i = `get_var $__i`"
|
||||
done > $__tmp
|
||||
update_file $__tmp config.mk
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
# Config header generation
|
||||
|
||||
# Simple interface
|
||||
#
|
||||
# Guesses variable types:
|
||||
# y or n -> bool
|
||||
# [0-9]+ -> int
|
||||
# anything else -> str
|
||||
#
|
||||
# Example:
|
||||
# CONFIG_FOO=y # bool
|
||||
# VERSION=2.0.1 # string
|
||||
# DEBUG=1 # int
|
||||
# config_header config.h CONFIG_FOO VERSION DEBUG
|
||||
config_header()
|
||||
{
|
||||
argc config_header $# 2
|
||||
config_header_begin "$1"
|
||||
shift
|
||||
while test $# -gt 0
|
||||
do
|
||||
__var=`get_var $1`
|
||||
case "$__var" in
|
||||
[yn])
|
||||
config_bool $1
|
||||
;;
|
||||
*)
|
||||
if test "$__var" && test "$__var" = "`echo $__var | sed 's/[^0-9]//g'`"
|
||||
then
|
||||
config_int $1
|
||||
else
|
||||
config_str $1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
config_header_end
|
||||
}
|
||||
|
||||
# Low-level interface
|
||||
#
|
||||
# Example:
|
||||
# config_header_begin config.h
|
||||
# config_str PACKAGE VERSION
|
||||
# config_bool CONFIG_ALSA
|
||||
# config_header_end
|
||||
|
||||
config_header_begin()
|
||||
{
|
||||
argc config_header_begin $# 1 1
|
||||
config_header_file="$1"
|
||||
config_header_tmp=`tmp_file config_header`
|
||||
|
||||
__def=`echo $config_header_file | to_upper | sed 's/[-\.\/]/_/g'`
|
||||
cat <<EOF > "$config_header_tmp"
|
||||
#ifndef $__def
|
||||
#define $__def
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
config_str()
|
||||
{
|
||||
while test $# -gt 0
|
||||
do
|
||||
echo "#define $1 \"`get_var $1`\"" >> "$config_header_tmp"
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
config_int()
|
||||
{
|
||||
while test $# -gt 0
|
||||
do
|
||||
echo "#define $1 `get_var $1`" >> "$config_header_tmp"
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
config_bool()
|
||||
{
|
||||
while test $# -gt 0
|
||||
do
|
||||
case "`get_var $1`" in
|
||||
n)
|
||||
echo "/* #define $1 */" >> "$config_header_tmp"
|
||||
;;
|
||||
y)
|
||||
echo "#define $1 1" >> "$config_header_tmp"
|
||||
;;
|
||||
*)
|
||||
die "bool '$1' has invalid value '`get_var $1`'"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
}
|
||||
|
||||
config_header_end()
|
||||
{
|
||||
argc config_header_end $# 0 0
|
||||
echo "" >> "$config_header_tmp"
|
||||
echo "#endif" >> "$config_header_tmp"
|
||||
mkdir -p `dirname "$config_header_file"`
|
||||
update_file "$config_header_tmp" "$config_header_file"
|
||||
}
|
||||
220
scripts/ffmpeg_test.sh
Executable file
220
scripts/ffmpeg_test.sh
Executable file
@@ -0,0 +1,220 @@
|
||||
#!/bin/bash
|
||||
# vim: set expandtab shiftwidth=4:
|
||||
#
|
||||
# Copyright 2010-2013 Various Authors
|
||||
# Copyright 2012 Johannes Weißl
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 2 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# many (!) FFmpeg versions will be installed here, at least 25GB
|
||||
FFMPEG_BUILD_DIR=$HOME/cmus_ffmpeg_test/ffmpeg_builds
|
||||
|
||||
# ffmpeg/libav source will be cloned into this directory
|
||||
FFMPEG_SRC_DIR=$HOME/cmus_ffmpeg_test/ffmpeg_src
|
||||
|
||||
# source code of cmus is expected here
|
||||
CMUS_SRC_DIR=$HOME/cmus_ffmpeg_test/cmus_src
|
||||
|
||||
# cmus versions will be installed here
|
||||
CMUS_BUILD_DIR=$HOME/cmus_ffmpeg_test/cmus_builds
|
||||
|
||||
FFMPEG_CLONE_URL=git://source.ffmpeg.org/ffmpeg.git
|
||||
LIBAV_CLONE_URL=git://git.libav.org/libav.git
|
||||
|
||||
# headers of ffmpeg that are relevant to cmus compilation
|
||||
HEADERS="avcodec.h avformat.h avio.h mathematics.h version.h"
|
||||
|
||||
# argument to make -j
|
||||
MAKE_J=$(grep -c "^processor" /proc/cpuinfo 2>/dev/null || echo 1)
|
||||
|
||||
print_usage () {
|
||||
echo "Usage: $progname build_ffmpeg | build_libav | build_cmus | test_cmus"
|
||||
echo
|
||||
echo "build_{ffmpeg,libav}:"
|
||||
echo " 1. clone/pull source into $FFMPEG_SRC_DIR/{ffmpeg,libav}"
|
||||
echo " 2. build and install (necessary) revisions into $FFMPEG_BUILD_DIR"
|
||||
echo " can take days and needs up to 25 GB hard disk (!)"
|
||||
echo " you can use ctrl-c to stop the script and run it later to continue"
|
||||
echo
|
||||
echo "build_cmus:"
|
||||
echo " 1. expects cmus source in $CMUS_SRC_DIR"
|
||||
echo " 2. build cmus for every revision in $FFMPEG_BUILD_DIR and install"
|
||||
echo " to $CMUS_BUILD_DIR"
|
||||
echo
|
||||
echo "test_cmus:"
|
||||
echo " test ffmpeg plugin of every cmus build in $CMUS_BUILD_DIR"
|
||||
}
|
||||
|
||||
function get_commits () {
|
||||
for name in "$@" ; do
|
||||
find -type f -name "$name" -exec git log --follow --pretty=format:"%H%n" {} \;
|
||||
done
|
||||
for tag in $(git tag) ; do
|
||||
git show "$tag" | sed -n "s/^commit //p"
|
||||
done
|
||||
}
|
||||
|
||||
function uniq_stable () {
|
||||
nl -ba | sort -suk2 | sort -n | cut -f2-
|
||||
}
|
||||
|
||||
DONE=
|
||||
trap 'DONE=1' SIGINT
|
||||
|
||||
function build_to_prefix () {
|
||||
prefix=$1
|
||||
cur=$2
|
||||
all=$3
|
||||
cur_name=$4
|
||||
build_cmd=$5
|
||||
echo -n "[$((cur*100/all))%] "
|
||||
if [ -e "$prefix.broken" ] ; then
|
||||
echo "skip $cur_name, broken"
|
||||
elif [ -e "$prefix.part" ] ; then
|
||||
echo "skip $cur_name, is being build"
|
||||
else
|
||||
if [ -e "$prefix" ] ; then
|
||||
echo "skip $cur_name, already built"
|
||||
else
|
||||
echo -n "build and install to $prefix: "
|
||||
echo $build_cmd >"$prefix.log"
|
||||
(mkdir -p "$prefix.part" && eval $build_cmd && mv "$prefix.part/$prefix" "$prefix" && rm -rf "$prefix.part") >>"$prefix.log" 2>&1 && echo "ok" ||
|
||||
(touch "$prefix.broken" ; echo "FAILED:" ; echo $build_cmd)
|
||||
fi
|
||||
fi
|
||||
[ -n "$DONE" ] && rm -rvf "$prefix" "$prefix".part "$prefix".broken
|
||||
}
|
||||
|
||||
function build_revisions () {
|
||||
name=$1
|
||||
url=$2
|
||||
mkdir -p "$FFMPEG_SRC_DIR" "$FFMPEG_BUILD_DIR"
|
||||
FFMPEG_SRC_DIR=$FFMPEG_SRC_DIR/$name
|
||||
if [ -e "$FFMPEG_SRC_DIR" ] ; then
|
||||
echo "pull $url in $FFMPEG_SRC_DIR"
|
||||
pushd "$FFMPEG_SRC_DIR" >/dev/null
|
||||
git reset --hard origin/master >/dev/null
|
||||
git clean -fxd >/dev/null
|
||||
git pull >/dev/null
|
||||
else
|
||||
echo "clone $url in $FFMPEG_SRC_DIR"
|
||||
git clone "$url" "$FFMPEG_SRC_DIR" >/dev/null
|
||||
pushd "$FFMPEG_SRC_DIR" >/dev/null
|
||||
fi
|
||||
commits=$(get_commits $HEADERS | uniq_stable)
|
||||
commits_count=$(echo $commits | wc -w)
|
||||
i=0
|
||||
for c in $commits ; do
|
||||
i=$((i+1))
|
||||
git reset --hard "$c" >/dev/null
|
||||
git clean -fxd >/dev/null
|
||||
prefix="$FFMPEG_BUILD_DIR/$c"
|
||||
build_to_prefix "$prefix" "$i" "$commits_count" "$c" \
|
||||
"./configure --prefix=\"$prefix.part\" --enable-shared --disable-static && make -j$MAKE_J && make install"
|
||||
[ -n "$DONE" ] && break
|
||||
done
|
||||
popd >/dev/null
|
||||
}
|
||||
|
||||
build_cmus () {
|
||||
pushd "$CMUS_SRC_DIR" >/dev/null
|
||||
mkdir -p "$CMUS_BUILD_DIR"
|
||||
revdirs=$(find "$FFMPEG_BUILD_DIR" -mindepth 1 -maxdepth 1 -type d ! -name "*.part")
|
||||
revdirs_count=$(echo $revdirs | wc -w)
|
||||
i=0
|
||||
for revdir in $revdirs ; do
|
||||
i=$((i+1))
|
||||
rev=$(basename "$revdir")
|
||||
prefix="$CMUS_BUILD_DIR/$rev"
|
||||
make distclean >/dev/null 2>&1
|
||||
build_to_prefix "$prefix" "$i" "$revdirs_count" "$rev" \
|
||||
"CFLAGS=\"-I$revdir/include\" LDFLAGS=\"-L$revdir/lib\" ./configure prefix=\"$prefix\" CONFIG_FFMPEG=y DEBUG=2 && make -j$MAKE_J && make install DESTDIR=\"$prefix.part\""
|
||||
[ -n "$DONE" ] && break
|
||||
done
|
||||
popd >/dev/null
|
||||
}
|
||||
|
||||
test_cmus () {
|
||||
mkdir -p "$CMUS_BUILD_DIR"
|
||||
revdirs=$(find "$CMUS_BUILD_DIR" -mindepth 1 -maxdepth 1 -type d ! -name "*.part")
|
||||
revdirs_count=$(echo $revdirs | wc -w)
|
||||
i=0
|
||||
for revdir in $revdirs ; do
|
||||
i=$((i+1))
|
||||
rev=$(basename "$revdir")
|
||||
tmpdir=$(mktemp -d)
|
||||
lib_prefix=$FFMPEG_BUILD_DIR/$rev
|
||||
echo -n "[$((i*100/revdirs_count))%] test $revdir: "
|
||||
if CMUS_HOME=$tmpdir LD_LIBRARY_PATH=$lib_prefix/lib:$LD_LIBRARY_PATH "$revdir"/bin/cmus --plugins | grep -q "^ *ffmpeg" ; then
|
||||
echo "working"
|
||||
else
|
||||
echo "not working: "
|
||||
echo "CMUS_HOME=$tmpdir LD_LIBRARY_PATH=$lib_prefix/lib:$LD_LIBRARY_PATH \"$revdir\"/bin/cmus --plugins"
|
||||
cat $tmpdir/cmus-debug.txt
|
||||
fi
|
||||
rm "$tmpdir"/cmus-debug.txt
|
||||
rmdir "$tmpdir"
|
||||
[ -n "$DONE" ] && break
|
||||
done
|
||||
}
|
||||
|
||||
progname=$(basename "$0")
|
||||
|
||||
while [ $# -gt 0 ] ; do
|
||||
case "$1" in
|
||||
-h | --help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
--)
|
||||
shift ; break
|
||||
;;
|
||||
-*)
|
||||
echo >&2 "$progname: unrecognized option \`$1'"
|
||||
echo >&2 "Try \`$0 --help' for more information."
|
||||
exit 1
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ $# -eq 0 ] ; then
|
||||
print_usage
|
||||
exit 0
|
||||
elif [ $# -gt 1 ] ; then
|
||||
echo >&2 "$progname: too many arguments"
|
||||
echo >&2 "Try \`$0 --help' for more information."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$1" in
|
||||
build_ffmpeg)
|
||||
build_revisions ffmpeg "$FFMPEG_CLONE_URL"
|
||||
;;
|
||||
build_libav)
|
||||
build_revisions libav "$LIBAV_CLONE_URL"
|
||||
;;
|
||||
build_cmus)
|
||||
build_cmus
|
||||
;;
|
||||
test_cmus)
|
||||
test_cmus
|
||||
;;
|
||||
*)
|
||||
echo >&2 "$progname: unrecognized command \`$1'"
|
||||
echo >&2 "Try \`$0 --help' for more information."
|
||||
exit 1
|
||||
esac
|
||||
174
scripts/gen_decomp.py
Executable file
174
scripts/gen_decomp.py
Executable file
@@ -0,0 +1,174 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2010-2013 Various Authors
|
||||
# Copyright 2010 Johannes Weißl
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License as
|
||||
# published by the Free Software Foundation; either version 2 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but
|
||||
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
# General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import sys
|
||||
import re
|
||||
import os.path
|
||||
import urllib2
|
||||
from optparse import OptionParser
|
||||
|
||||
# Some letters don't have a decomposition, but can't be composed on all
|
||||
# keyboards. This dictionary maps them to an ASCII character which
|
||||
# *looks* similar.
|
||||
special_decompositions = {
|
||||
u'Æ': u'A',
|
||||
u'Ð': u'D',
|
||||
u'×': u'x',
|
||||
u'Ø': u'O',
|
||||
u'Þ': u'P',
|
||||
u'ß': u'B',
|
||||
u'æ': u'a',
|
||||
u'ð': u'd',
|
||||
u'ø': u'o',
|
||||
u'þ': u'p',
|
||||
# Various punctation/quotation characters
|
||||
u'‐': u'-',
|
||||
u'‒': u'-',
|
||||
u'–': u'-',
|
||||
u'−': u'-',
|
||||
u'—': u'-',
|
||||
u'―': u'-',
|
||||
u'‘': u"'",
|
||||
u'’': u"'",
|
||||
u'′': u"'",
|
||||
u'“': u'"',
|
||||
u'”': u'"',
|
||||
u'″': u'"',
|
||||
u'〃': u'"',
|
||||
u'…': u'.',
|
||||
}
|
||||
|
||||
def parse_unidata(f):
|
||||
u = {}
|
||||
for line in f:
|
||||
d = line.rstrip('\n').split(';')
|
||||
cp = int(d[0], 16)
|
||||
u[cp] = {}
|
||||
u[cp]['name'] = d[1]
|
||||
decomp = d[5]
|
||||
if decomp:
|
||||
m = re.match(r'<.*> (.*)', decomp)
|
||||
u[cp]['compat'] = bool(m)
|
||||
if m:
|
||||
decomp = m.group(1)
|
||||
u[cp]['decomp'] = [int(x, 16) for x in decomp.split(' ')]
|
||||
else:
|
||||
u[cp]['decomp'] = []
|
||||
return u
|
||||
|
||||
def unidata_expand_decomp(unidata):
|
||||
def recurse(k):
|
||||
if k not in unidata or not unidata[k]['decomp']:
|
||||
return [k]
|
||||
exp = []
|
||||
for d in unidata[k]['decomp']:
|
||||
exp += recurse(d)
|
||||
return exp
|
||||
for k in unidata.keys():
|
||||
exp = recurse(k)
|
||||
if exp != [k]:
|
||||
unidata[k]['decomp'] = exp
|
||||
|
||||
def unidata_add_mapping(unidata, mapping):
|
||||
for k, v in mapping.items():
|
||||
unidata[ord(k)]['decomp'] = [ord(v)]
|
||||
|
||||
def is_diacritical_mark(c):
|
||||
return c >= 0x0300 and c <= 0x036F
|
||||
|
||||
def filter_unidata(unidata, include):
|
||||
for k, v in unidata.items():
|
||||
if k in include:
|
||||
continue
|
||||
if not v['decomp']:
|
||||
del unidata[k]
|
||||
continue
|
||||
b = v['decomp'][0]
|
||||
if unichr(b) == u' ' or is_diacritical_mark(b):
|
||||
del unidata[k]
|
||||
continue
|
||||
has_accents = False
|
||||
for d in v['decomp'][1:]:
|
||||
if is_diacritical_mark(d):
|
||||
has_accents = True
|
||||
break
|
||||
if not has_accents:
|
||||
del unidata[k]
|
||||
|
||||
def output(unidata, f):
|
||||
buf = '''/* This file is automatically generated. DO NOT EDIT!
|
||||
Instead, edit %s and re-run. */
|
||||
|
||||
static struct {
|
||||
uchar composed;
|
||||
uchar base;
|
||||
} unidecomp_map[] = {
|
||||
''' % os.path.basename(sys.argv[0])
|
||||
for k in sorted(unidata.keys()):
|
||||
b = unidata[k]['decomp'][0]
|
||||
buf += ('\t{ %#6x, %#6x },\t// %s -> %s,\t%s' % \
|
||||
(k, b,
|
||||
unichr(k).encode('utf-8'),
|
||||
unichr(b).encode('utf-8'),
|
||||
', '.join([' %s (%x)' %
|
||||
(unichr(d).encode('utf-8'), d)
|
||||
for d in unidata[k]['decomp'][1:]]))).rstrip() + '\n'
|
||||
buf += '};'
|
||||
f.write(buf+'\n')
|
||||
|
||||
def main(argv=None):
|
||||
|
||||
if not argv:
|
||||
argv = sys.argv
|
||||
|
||||
parser = OptionParser(usage='usage: %prog [-w] [-o unidecomp.h]')
|
||||
parser.add_option('-w', '--wget', action='store_true',
|
||||
help='get unicode data from unicode.org')
|
||||
parser.add_option('-o', '--output',
|
||||
help='output file, default stdout')
|
||||
(options, args) = parser.parse_args(argv[1:])
|
||||
|
||||
urlbase = 'http://unicode.org/Public/UNIDATA/'
|
||||
unidata_filename = 'UnicodeData.txt'
|
||||
|
||||
if not os.path.exists(unidata_filename) and not options.wget:
|
||||
parser.error('''need %s in the current directory, download
|
||||
from unicode.org or use `--wget' option.''' % unidata_filename)
|
||||
|
||||
if options.wget:
|
||||
unidata_file = urllib2.urlopen(urlbase+unidata_filename)
|
||||
else:
|
||||
unidata_file = open(unidata_filename, 'rb')
|
||||
|
||||
unidata = parse_unidata(unidata_file)
|
||||
unidata_file.close()
|
||||
|
||||
unidata_add_mapping(unidata, special_decompositions)
|
||||
unidata_expand_decomp(unidata)
|
||||
filter_unidata(unidata, [ord(x) for x in special_decompositions])
|
||||
|
||||
outfile = sys.stdout
|
||||
if options.output:
|
||||
outfile = open(options.output, 'wb')
|
||||
output(unidata, outfile)
|
||||
if options.output:
|
||||
outfile.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
sys.exit(main())
|
||||
32
scripts/install
Executable file
32
scripts/install
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright 2005-2006 Timo Hirvonen
|
||||
#
|
||||
# This file is licensed under the GPLv2.
|
||||
|
||||
flags=""
|
||||
while test $# -gt 0
|
||||
do
|
||||
case $1 in
|
||||
-*)
|
||||
flags="$flags $1"
|
||||
;;
|
||||
*)
|
||||
break
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
test $# -lt 2 && exit 0
|
||||
|
||||
to="${DESTDIR}${1}"
|
||||
shift
|
||||
$GINSTALL -d -m755 "${to}"
|
||||
for i in "$@"
|
||||
do
|
||||
dest="${to}/`basename ${i}`"
|
||||
test "$INSTALL_LOG" && echo "$dest" >> "$INSTALL_LOG"
|
||||
echo "INSTALL ${dest}"
|
||||
$GINSTALL $flags "$i" "${to}"
|
||||
done
|
||||
148
scripts/lib.mk
Normal file
148
scripts/lib.mk
Normal file
@@ -0,0 +1,148 @@
|
||||
#
|
||||
# Copyright 2005-2006 Timo Hirvonen
|
||||
#
|
||||
# This file is licensed under the GPLv2.
|
||||
#
|
||||
# cmd macro copied from kbuild (Linux kernel build system)
|
||||
|
||||
# Build verbosity:
|
||||
# make V=0 silent
|
||||
# make V=1 clean (default)
|
||||
# make V=2 verbose
|
||||
|
||||
# build verbosity (0-2), default is 1
|
||||
ifneq ($(origin V),command line)
|
||||
V := 1
|
||||
endif
|
||||
ifneq ($(findstring s,$(MAKEFLAGS)),)
|
||||
V := 0
|
||||
endif
|
||||
|
||||
ifeq ($(V),2)
|
||||
quiet =
|
||||
Q =
|
||||
else
|
||||
ifeq ($(V),1)
|
||||
quiet = quiet_
|
||||
Q = @
|
||||
else
|
||||
quiet = silent_
|
||||
Q = @
|
||||
endif
|
||||
endif
|
||||
|
||||
# simple wrapper around install(1)
|
||||
#
|
||||
# - creates directories automatically
|
||||
# - adds $(DESTDIR) to front of files
|
||||
INSTALL := @$(topdir)/scripts/install
|
||||
INSTALL_LOG := $(topdir)/.install.log
|
||||
|
||||
dependencies := $(wildcard .dep-*)
|
||||
clean := $(dependencies)
|
||||
distclean :=
|
||||
|
||||
LC_ALL := C
|
||||
LANG := C
|
||||
|
||||
export INSTALL_LOG LC_ALL LANG GINSTALL
|
||||
|
||||
# remove files generated by make
|
||||
clean:
|
||||
rm -f $(clean)
|
||||
|
||||
# remove files generated by make and configure
|
||||
distclean: clean
|
||||
rm -f $(distclean)
|
||||
|
||||
uninstall:
|
||||
@$(topdir)/scripts/uninstall
|
||||
|
||||
%.o: %.S
|
||||
$(call cmd,as)
|
||||
|
||||
# object files for programs and static libs
|
||||
%.o: %.c
|
||||
$(call cmd,cc)
|
||||
|
||||
%.o: %.cc
|
||||
$(call cmd,cxx)
|
||||
|
||||
%.o: %.cpp
|
||||
$(call cmd,cxx)
|
||||
|
||||
# object files for shared libs
|
||||
%.lo: %.c
|
||||
$(call cmd,cc_lo)
|
||||
|
||||
%.lo: %.cc
|
||||
$(call cmd,cxx_lo)
|
||||
|
||||
%.lo: %.cpp
|
||||
$(call cmd,cxx_lo)
|
||||
|
||||
# CC for program object files (.o)
|
||||
quiet_cmd_cc = CC $@
|
||||
cmd_cc = $(CC) -c $(CPPFLAGS) $(CFLAGS) -o $@ $<
|
||||
|
||||
# HOSTCC for program object files (.o)
|
||||
quiet_cmd_hostcc = HOSTCC $@
|
||||
cmd_hostcc = $(HOSTCC) -c $(HOST_CFLAGS) -o $@ $<
|
||||
|
||||
# CC for shared library and dynamically loadable module objects (.lo)
|
||||
quiet_cmd_cc_lo = CC $@
|
||||
cmd_cc_lo = $(CC) -c $(CPPFLAGS) $(CFLAGS) $(SOFLAGS) -o $@ $<
|
||||
|
||||
# LD for programs, optional parameter: libraries
|
||||
quiet_cmd_ld = LD $@
|
||||
cmd_ld = $(LD) $(LDFLAGS) -o $@ $^ $(1)
|
||||
|
||||
# HOSTLD for programs, optional parameter: libraries
|
||||
quiet_cmd_hostld = HOSTLD $@
|
||||
cmd_hostld = $(HOSTLD) $(HOST_LDFLAGS) -o $@ $^ $(1)
|
||||
|
||||
# LD for shared libraries, optional parameter: libraries
|
||||
quiet_cmd_ld_so = LD $@
|
||||
cmd_ld_so = $(LD) $(LDSOFLAGS) $(LDFLAGS) -o $@ $^ $(1)
|
||||
|
||||
# LD for dynamically loadable modules, optional parameter: libraries
|
||||
quiet_cmd_ld_dl = LD $@
|
||||
cmd_ld_dl = $(LD) $(LDDLFLAGS) $(LDFLAGS) -o $@ $^ $(1)
|
||||
|
||||
# CXX for program object files (.o)
|
||||
quiet_cmd_cxx = CXX $@
|
||||
cmd_cxx = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
|
||||
|
||||
# CXX for shared library and dynamically loadable module objects (.lo)
|
||||
quiet_cmd_cxx_lo = CXX $@
|
||||
cmd_cxx_lo = $(CXX) -c $(CPPFLAGS) $(CXXFLAGS) $(SOFLAGS) -o $@ $<
|
||||
|
||||
# CXXLD for programs, optional parameter: libraries
|
||||
quiet_cmd_cxxld = CXXLD $@
|
||||
cmd_cxxld = $(CXXLD) $(CXXLDFLAGS) -o $@ $^ $(1)
|
||||
|
||||
# CXXLD for shared libraries, optional parameter: libraries
|
||||
quiet_cmd_cxxld_so = CXXLD $@
|
||||
cmd_cxxld_so = $(CXXLD) $(LDSOFLAGS) $(CXXLDFLAGS) -o $@ $^ $(1)
|
||||
|
||||
# CXXLD for dynamically loadable modules, optional parameter: libraries
|
||||
quiet_cmd_cxxld_dl = CXXLD $@
|
||||
cmd_cxxld_dl = $(CXXLD) $(LDDLFLAGS) $(CXXLDFLAGS) -o $@ $^ $(1)
|
||||
|
||||
# create archive
|
||||
quiet_cmd_ar = AR $@
|
||||
cmd_ar = $(AR) $(ARFLAGS) $@ $^
|
||||
|
||||
# assembler
|
||||
quiet_cmd_as = AS $@
|
||||
cmd_as = $(AS) -c $(ASFLAGS) -o $@ $<
|
||||
|
||||
cmd = @$(if $($(quiet)cmd_$(1)),echo ' $(call $(quiet)cmd_$(1),$(2))' &&) $(call cmd_$(1),$(2))
|
||||
|
||||
ifneq ($(dependencies),)
|
||||
-include $(dependencies)
|
||||
endif
|
||||
|
||||
.SECONDARY:
|
||||
|
||||
.PHONY: clean distclean uninstall
|
||||
12
scripts/uninstall
Executable file
12
scripts/uninstall
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
|
||||
test -f "$INSTALL_LOG" || exit 0
|
||||
|
||||
sort "$INSTALL_LOG" | uniq | \
|
||||
while read file
|
||||
do
|
||||
echo "RM $file"
|
||||
rm -f "$file"
|
||||
rmdir -p "`dirname $file`" 2>/dev/null
|
||||
done
|
||||
rm -f "$INSTALL_LOG"
|
||||
201
scripts/utils.sh
Normal file
201
scripts/utils.sh
Normal file
@@ -0,0 +1,201 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# Copyright 2005 Timo Hirvonen
|
||||
#
|
||||
# This file is licensed under the GPLv2.
|
||||
|
||||
# initialization {{{
|
||||
|
||||
LC_ALL=C
|
||||
LANG=C
|
||||
|
||||
export LC_ALL LANG
|
||||
|
||||
if test "$CDPATH"
|
||||
then
|
||||
echo "Exporting CDPATH is dangerous and unnecessary!"
|
||||
echo
|
||||
fi
|
||||
unset CDPATH
|
||||
|
||||
__cleanup()
|
||||
{
|
||||
if test "$DEBUG_CONFIGURE" = y
|
||||
then
|
||||
echo
|
||||
echo "DEBUG_CONFIGURE=y, not removing temporary files"
|
||||
ls .tmp-[0-9]*-*
|
||||
else
|
||||
rm -rf .tmp-[0-9]*-*
|
||||
fi
|
||||
}
|
||||
|
||||
__abort()
|
||||
{
|
||||
# can't use "die" because stderr is often redirected to /dev/null
|
||||
# (stdout could also be redirected but it's not so common)
|
||||
echo
|
||||
echo
|
||||
echo "Aborting. configure failed."
|
||||
# this executes __cleanup automatically
|
||||
exit 1
|
||||
}
|
||||
|
||||
# clean temporary files on exit
|
||||
trap '__cleanup' 0
|
||||
|
||||
# clean temporary files and die with error message if interrupted
|
||||
trap '__abort' 1 2 3 13 15
|
||||
|
||||
# }}}
|
||||
|
||||
# config.mk variable names
|
||||
makefile_variables=""
|
||||
|
||||
# cross compilation, prefix for CC, LD etc.
|
||||
# CROSS=
|
||||
|
||||
# argc function_name $# min [max]
|
||||
argc()
|
||||
{
|
||||
if test $# -lt 3 || test $# -gt 4
|
||||
then
|
||||
die "argc: expecting 3-4 arguments (got $*)"
|
||||
fi
|
||||
|
||||
if test $# -eq 3
|
||||
then
|
||||
if test $2 -lt $3
|
||||
then
|
||||
die "$1: expecting at least $3 arguments"
|
||||
fi
|
||||
else
|
||||
if test $2 -lt $3 || test $2 -gt $4
|
||||
then
|
||||
die "$1: expecting $3-$4 arguments"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# print warning message (all parameters)
|
||||
warn()
|
||||
{
|
||||
echo "$@" >&2
|
||||
}
|
||||
|
||||
# print error message (all parameters) and exit
|
||||
die()
|
||||
{
|
||||
warn "$@"
|
||||
exit 1
|
||||
}
|
||||
|
||||
# usage: 'tmp_file .c'
|
||||
# get filename for temporary file
|
||||
tmp_file()
|
||||
{
|
||||
if test -z "$__tmp_file_counter"
|
||||
then
|
||||
__tmp_file_counter=0
|
||||
fi
|
||||
|
||||
while true
|
||||
do
|
||||
__tmp_filename=.tmp-${__tmp_file_counter}-${1}
|
||||
__tmp_file_counter=`expr $__tmp_file_counter + 1`
|
||||
test -f "$__tmp_filename" || break
|
||||
done
|
||||
echo "$__tmp_filename"
|
||||
}
|
||||
|
||||
# get variable value
|
||||
#
|
||||
# @name: name of the variable
|
||||
get_var()
|
||||
{
|
||||
eval echo '"$'${1}'"'
|
||||
}
|
||||
|
||||
# set variable by name
|
||||
#
|
||||
# @name: name of the variable
|
||||
# @value: value of the variable
|
||||
set_var()
|
||||
{
|
||||
eval $1='$2'
|
||||
}
|
||||
|
||||
# set variable @name to @default IF NOT SET OR EMPTY
|
||||
#
|
||||
# @name: name of the variable
|
||||
# @value: value of the variable
|
||||
var_default()
|
||||
{
|
||||
test "`get_var $1`" || set_var $1 "$2"
|
||||
}
|
||||
|
||||
# usage: echo $foo | to_upper
|
||||
to_upper()
|
||||
{
|
||||
# stupid solaris tr doesn't understand ranges
|
||||
tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
|
||||
}
|
||||
|
||||
# portable which command
|
||||
path_find()
|
||||
{
|
||||
case $1 in
|
||||
*/*)
|
||||
if test -x "$1"
|
||||
then
|
||||
echo "$1"
|
||||
return 0
|
||||
fi
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
|
||||
_ifs="$IFS"
|
||||
IFS=:
|
||||
for __pf_i in $PATH
|
||||
do
|
||||
if test -x "$__pf_i/$1"
|
||||
then
|
||||
IFS="$_ifs"
|
||||
echo "$__pf_i/$1"
|
||||
return 0
|
||||
fi
|
||||
done
|
||||
IFS="$_ifs"
|
||||
return 1
|
||||
}
|
||||
|
||||
show_usage()
|
||||
{
|
||||
cat <<EOF
|
||||
Usage ./configure [-f FILE] [--prefix|bindir|datadir|libdir|mandir|docdir=VALUE] [OPTION=VALUE]...
|
||||
|
||||
-f FILE Read OPTION=VALUE list from FILE (sh script)
|
||||
$USAGE
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
|
||||
# @tmpfile: temporary file
|
||||
# @file: file to update
|
||||
#
|
||||
# replace @file with @tmpfile if their contents differ
|
||||
update_file()
|
||||
{
|
||||
if test -f "$2"
|
||||
then
|
||||
if cmp "$2" "$1" 2>/dev/null 1>&2
|
||||
then
|
||||
return 0
|
||||
fi
|
||||
echo "updating $2"
|
||||
else
|
||||
echo "creating $2"
|
||||
fi
|
||||
mv -f "$1" "$2"
|
||||
}
|
||||
Reference in New Issue
Block a user