From 5ca68910306b807b3309f7a2e11c620e303eb8e2 Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Sat, 20 Oct 2012 14:08:52 +0000 Subject: [PATCH] build: check for a decent version of sed (ie. not the shitty BSD one). --- build/check-source.sh | 30 ++++++++++++++++++++++-------- configure.ac | 27 ++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/build/check-source.sh b/build/check-source.sh index 63c74c7d..6605e8c9 100755 --- a/build/check-source.sh +++ b/build/check-source.sh @@ -28,15 +28,28 @@ done error() { if [ "$quiet" != true ]; then echo "E: $1"; fi } info() { if [ "$quiet" != true ]; then echo "I: $1"; fi } +# Ensure the system tools do not attempt to perform multibyte conversions +export LANG=C + # Find out where the top directory is and go there top_srcdir="$(cd "$(dirname $0)"; cd ..; pwd)" cd "$top_srcdir" # Check for working tools -#if [ "$(echo foo | grep -c foo)" != 1 ]; then -# error "grep -c does not appear to work, cancelling" -# exit 0 -#fi +if [ "$(echo foo | grep -c foo)" != 1 ]; then + error "grep -c does not appear to work, cancelling" + exit 0 +fi + +SED=sed +if gsed --version >/dev/null 2>&1; then + SED=gsed +fi +if [ "$(echo 'x\x' | $SED 's/.*[^x\t]//')" != x ]; then + error "sed does not appear to work, cancelling" + exit 0 +fi + if d2u -h >/dev/null 2>&1; then d2u=d2u elif dos2unix -h >/dev/null 2>&1; then @@ -73,7 +86,8 @@ total_spaces=0 total_tabs=0 OIFS="$IFS" -IFS=$'\n' +IFS=' +' if [ "$repo" = git ]; then FILES="`git ls-files`" else @@ -118,12 +132,12 @@ for file in $FILES; do fi # Check for trailing spaces - nspaces="$(LANG=C sed 's/.*[^ \t]//' "$file" | tr -cd '\t ' | wc -c)" + nspaces="$($SED 's/.*[^ \t]//' "$file" | tr -cd '\t ' | wc -c)" total_spaces="$(($total_spaces + $nspaces))" if [ "$nspaces" -gt 0 ]; then clean=false if [ "$fix" = true ]; then - LANG=C sed -i 's/[[:space:]][[:space:]]*$//g' "$file" + $SED -i 's/[[:space:]][[:space:]]*$//g' "$file" info "$file has $nspaces trailing spaces" else error "$file has $nspaces trailing spaces" @@ -136,7 +150,7 @@ for file in $FILES; do if [ "$ntabs" -gt 0 ]; then clean=false if [ "$fix" = true ]; then - LANG=C sed -i 's/\t/ /g' "$file" + $SED -i 's/\t/ /g' "$file" info "$file has $ntabs tabs" else error "$file has $ntabs tabs" diff --git a/configure.ac b/configure.ac index f9854e32..fd9cd57f 100644 --- a/configure.ac +++ b/configure.ac @@ -49,6 +49,18 @@ dnl PKG_PROG_PKG_CONFIG which needs to be called first. AC_EGREP_CPP(yes, foo) PKG_PROG_PKG_CONFIG() + +dnl Check for a working implementation of sed +AC_PROG_SED +AC_MSG_CHECKING(for a sed that understands \t) +if test "$(echo 'x\x' | "${SED}" 's/.*@<:@^x\t@:>@//')" != x; then + AC_MSG_RESULT(no) + AC_MSG_ERROR([[consider installing GNU sed]]) +else + AC_MSG_RESULT(yes) +fi + + AM_CONDITIONAL(USE_GLEW, test "${ac_cv_my_have_glew}" != "no") dnl conditional builds AC_ARG_ENABLE(debug, @@ -225,7 +237,20 @@ AM_CONDITIONAL(USE_SDL_IMAGE, test "${ac_cv_my_have_sdl_image}" = "yes") dnl Use Flex's FlexLexer.h or ours? ac_cv_my_have_flexlexer_h="no" AC_LANG_PUSH(C++) -AC_CHECK_HEADERS(FlexLexer.h, [ac_cv_my_have_flexlexer_h="yes"]) +AC_CHECK_HEADERS(FlexLexer.h, + dnl Ensure that FlexLexer::yleng is of type int, and not size_t like + dnl on recent Apple systems. It would break all our existing code. + [AC_MSG_CHECKING(for FlexLexer.h validity) + AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM([#include + class Foo : public FlexLexer + { + Foo() { int &test = yyleng; } + }], + [])], + [AC_MSG_RESULT(yes) + ac_cv_my_have_flexlexer_h="yes"], + [AC_MSG_RESULT(no)])]) AC_LANG_POP(C++) if test "x${ac_cv_my_have_flexlexer_h}" = "xno"; then LOL_CFLAGS="$LOL_CFLAGS -I\$(top_srcdir)/external/flex-2.5.35/include"