build: shave it!
authorMarc-André Lureau <marc-andre.lureau@nokia.com>
Mon, 23 Feb 2009 21:20:19 +0000 (23:20 +0200)
committerMarc-André Lureau <marc-andre.lureau@nokia.com>
Tue, 24 Feb 2009 00:48:46 +0000 (02:48 +0200)
http://damien.lespiau.name/blog/2009/02/18/shave-making-the-autotools-output-sane/

bootstrap.sh
configure.ac
m4/shave.m4 [new file with mode: 0644]
shave-libtool.in [new file with mode: 0644]
shave.in [new file with mode: 0644]

index e64f342..4e223e3 100755 (executable)
@@ -49,6 +49,10 @@ if ! pkg-config --version &>/dev/null; then
     exit 1
 fi
 
+if type -p colorgcc > /dev/null ; then
+   export CC=colorgcc
+fi
+
 if [ "x$1" = "xam" ] ; then
     run_versioned automake "$VERSION" -a -c --foreign
     ./config.status
@@ -73,7 +77,7 @@ else
     run_versioned automake "$VERSION" --copy --foreign --add-missing
 
     if test "x$NOCONFIGURE" = "x"; then
-        CFLAGS="-g -O0" ./configure --sysconfdir=/etc --localstatedir=/var --enable-force-preopen "$@"
+        CFLAGS="-g -O0" ./configure --sysconfdir=/etc --localstatedir=/var --enable-force-preopen --enable-shave "$@"
         make clean
     fi
 fi
index 11b091b..aab7e2d 100644 (file)
@@ -1261,6 +1261,8 @@ AM_CONDITIONAL([FORCE_PREOPEN], [test "x$FORCE_PREOPEN" = "xyes"])
 
 AC_CONFIG_FILES([
 Makefile
+shave
+shave-libtool
 src/Makefile
 man/Makefile
 libpulse.pc
@@ -1272,7 +1274,10 @@ doxygen/doxygen.conf
 src/pulse/version.h
 po/Makefile.in
 ])
+
+SHAVE_INIT
 AC_OUTPUT
+SHAVE_OUTPUT
 
 # ==========================================================================
 ENABLE_X11=no
diff --git a/m4/shave.m4 b/m4/shave.m4
new file mode 100644 (file)
index 0000000..44d3908
--- /dev/null
@@ -0,0 +1,69 @@
+dnl Make automake/libtool output more friendly to humans
+dnl
+dnl SHAVE_INIT([shavedir])
+dnl
+dnl shavedir: the directory where the shave scripts are, it defaults to
+dnl           $(top_builddir)
+dnl
+dnl * SHAVE_INIT should be called late in your configure.(ac|in) file (just
+dnl   before AC_CONFIG_FILE/AC_OUTPUT is perfect.  This macro rewrites CC and
+dnl   LIBTOOL, you don't want the configure tests to have these variables
+dnl   re-defined.
+dnl * This macro requires GNU make's -s option.
+
+AC_DEFUN([SHAVE_INIT],
+[
+  dnl enable/disable shave
+  AC_ARG_ENABLE([shave],
+    AS_HELP_STRING([--enable-shave],
+                   [use shave to make the build pretty [[default=no]]]),,
+    [enable_shave=no])
+
+  if test x"$enable_shave" = xyes; then
+    dnl where can we find the shave scripts?
+    m4_if([$1],,
+      [shavedir='$(top_builddir)'],
+      [shavedir='$(top_builddir)'/$1])
+    AC_SUBST(shavedir)
+
+    dnl make is now quiet
+    AC_SUBST([MAKEFLAGS], [-s])
+    AC_SUBST([AM_MAKEFLAGS], ['`test -z $V && echo -s`'])
+
+    dnl we need sed
+    AC_CHECK_PROG(SED,sed,sed,false)
+
+    dnl substitute libtool
+    SHAVE_SAVED_LIBTOOL=$LIBTOOL
+    AC_SUBST(SHAVE_SAVED_LIBTOOL)
+    LIBTOOL="\$(SHELL) \$(shavedir)/shave-libtool '\$(SHAVE_SAVED_LIBTOOL)'"
+    AC_SUBST(LIBTOOL)
+
+    dnl substitute cc/cxx
+    SHAVE_SAVED_CC=$CC
+    SHAVE_SAVED_CXX=$CXX
+    AC_SUBST(SHAVE_SAVED_CC)
+    AC_SUBST(SHAVE_SAVED_CXX)
+    CC="\$(SHELL) \$(shavedir)/shave cc '\$(SHAVE_SAVED_CC)'"
+    CXX="\$(SHELL) \$(shavedir)/shave cxx '\$(SHAVE_SAVED_CXX)'"
+    AC_SUBST(CC)
+    AC_SUBST(CXX)
+
+    V=@
+  else
+    V=1
+  fi
+  Q='$(V:1=)'
+  AC_SUBST(V)
+  AC_SUBST(Q)
+])
+
+AC_DEFUN([SHAVE_OUTPUT],
+[
+  if test x"$enable_shave" = xyes; then
+    dnl small workaround to fix libtool itself
+    dnl it's shokingly hard to find a better way, really! wtf...
+    test -f $srcdir/libtool && (tmpfile=`mktemp` && cat $srcdir/libtool | sed "s,^LTCC=.*$,LTCC=\"$SHELL $ac_pwd/shave cc $SHAVE_SAVED_CC\"," > $tmpfile && mv $tmpfile $srcdir/libtool)
+  fi
+
+])
diff --git a/shave-libtool.in b/shave-libtool.in
new file mode 100644 (file)
index 0000000..30e6f13
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/sh
+
+# we need sed
+SED=@SED@
+if test -z "$SED" ; then
+SED=sed
+fi
+
+lt_unmangle ()
+{
+   last_result=`echo $1 | $SED -e 's#.libs/##' -e 's#[0-9a-zA-Z_]\*_la-##'`
+}
+
+# the real libtool to use
+LIBTOOL="$1"
+shift
+
+# if 1, don't print anything, the underlaying wrapper will do it
+pass_though=0
+
+# scan the arguments, keep the right ones for libtool, and discover the mode
+preserved_args=
+while test "$#" -gt 0; do
+    opt="$1"
+    shift
+
+    case $opt in
+    --mode=*)
+        mode=`echo $opt | $SED -e 's/[-_a-zA-Z0-9]*=//'`
+        preserved_args="$preserved_args $opt"
+        ;;
+    -o)
+        lt_output="$1"
+        preserved_args="$preserved_args $opt"
+       ;;
+    *)
+        preserved_args="$preserved_args $opt"
+        ;;
+      esac
+done
+
+case "$mode" in
+compile)
+    # shave will be called and print the actual CC/CXX/LINK line
+    preserved_args="$preserved_args --shave-mode=$mode"
+    pass_though=1
+    ;;
+link)
+    preserved_args="$preserved_args --shave-mode=$mode"
+    Q="  LINK  "
+    ;;
+*)
+    # let's u
+    # echo "*** libtool: Unimplemented mode: $mode, fill a bug report"
+    ;;
+esac
+
+lt_unmangle "$lt_output"
+output=$last_result
+
+if test -z $V; then
+    if test $pass_though -eq 0; then
+        echo "$Q$output"
+    fi
+    $LIBTOOL --silent $preserved_args
+else
+    echo $LIBTOOL $preserved_args
+    $LIBTOOL $preserved_args
+fi
diff --git a/shave.in b/shave.in
new file mode 100644 (file)
index 0000000..dc46ec9
--- /dev/null
+++ b/shave.in
@@ -0,0 +1,70 @@
+#!/bin/sh
+
+# we need sed
+SED=@SED@
+if test -z "$SED" ; then
+SED=sed
+fi
+
+lt_unmangle ()
+{
+   last_result=`echo $1 | $SED -e 's#.libs/##' -e 's#[0-9a-zA-Z_]\*_la-##'`
+}
+
+# the tool to wrap (cc, cxx, ar, ranlib, ..)
+tool="$1"
+shift
+
+# the reel tool (to call)
+REEL_TOOL="$1"
+shift
+
+pass_through=0
+preserved_args=
+while test "$#" -gt 0; do
+    opt="$1"
+    shift
+
+    case $opt in
+    --shave-mode=*)
+        mode=`echo $opt | $SED -e 's/[-_a-zA-Z0-9]*=//'`
+       ;;
+    -o)
+        lt_output="$1"
+        preserved_args="$preserved_args $opt"
+       ;;
+    *)
+        preserved_args="$preserved_args $opt"
+        ;;
+      esac
+done
+
+# mode=link is handled in the libtool wrapper
+case "$mode,$tool" in
+link,*)
+    pass_through=1
+    ;;
+*,cxx)
+    Q="  CXX   "
+    ;;
+*,cc)
+    Q="  CC    "
+    ;;
+*,*)
+    # should not happen
+    Q="  CC    "
+    ;;
+esac
+
+lt_unmangle "$lt_output"
+output=$last_result
+
+if test -z $V; then
+    if test $pass_through -eq 0; then
+        echo "$Q$output"
+    fi
+    $REEL_TOOL $preserved_args
+else
+    echo $REEL_TOOL $preserved_args
+    $REEL_TOOL $preserved_args
+fi