]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - tools/checkconfig.sh
sfdisk: add -J between mutually exclusive options
[thirdparty/util-linux.git] / tools / checkconfig.sh
index ff38bac7d0a335f5c73607f3a7342c68ec66b8cd..5f2063ad491f3c83554b96c4813e3c1fededeb5e 100755 (executable)
@@ -1,37 +1,63 @@
-#!/bin/bash
+#!/bin/sh
 
 #
 # This script checks for HAVE_ and ENABLE_ macros which are
 # not included in config.h.in
 #
+# Usage:   checkconfig.sh <top_srcdir> <srcfile> [<srcfile> ...]
+#
 # Copyright (C) 2007 Matthias Koenig <mkoenig@suse.de>
+# Copyright (C) 2008 Karel Zak <kzak@redhat.com>
 #
 
-srcdir=$1
 
-if [ ! "$srcdir" ]; then
-       srcdir=$PWD
-fi
+die() {
+       echo "error: $1"
+       exit 1
+}
+
+usage() {
+       echo "Usage:"
+       echo " $0 <top_srcdir> <srcfile> [<srcfile> ...]"
+       echo "Example:"
+       echo " find . -name '*.c' | xargs $0 \$(git rev-parse --show-toplevel)"
+}
 
-CONFIG="$srcdir/config.h.in"
-if [ ! -f "$CONFIG" ]; then
-       echo "config.h.in is needed"
+if [ $# -eq 0 ]; then
+       usage
        exit 1
 fi
+srcdir=$1
+config="$srcdir/config.h.in"
+
+[ -d "$srcdir" ] || die "$srcdir: not such directory."
+[ -f "$config" ] || die "$config: not such file."
+
+shift
 
-SOURCES=$(find $srcdir -name "*.c")
+while [ "$#" -ne 0 ]; do
+       srcfile=$1
+       shift
 
-for f in $SOURCES; do
+       [ ! -f "$srcfile" ] && continue;
+
+       # Note that we use HAVE_ macros since util-linux-ng-2.14. The
+       # previous version also have used ENABLE_ too.
+       #
+       # ENABLE_ and HAVE_ macros shouldn't be used for any other pupose that
+       # for config/build options.
+       #
        DEFINES=$(sed -n -e 's/.*[ \t(]\+\(HAVE_[[:alnum:]]\+[^ \t);]*\).*/\1/p' \
-                         -e 's/.*[ \t(]\+\(ENABLE_[[:alnum:]]\+[^ \t);]*\).*/\1/p' \
-                         $f | sort -u)
+                        -e 's/.*[ \t(]\+\(ENABLE_[[:alnum:]]\+[^ \t);]*\).*/\1/p' \
+                         $srcfile | sort -u)
        [ -z "$DEFINES" ] && continue
 
        for d in $DEFINES; do
                case $d in
-               HAVE_CONFIG_H) continue;;
-               *) grep -q "$d\( \|\>\)" $CONFIG || echo $(echo $f | sed 's:'$srcdir/'::') ": $d"
-
+               HAVE_CONFIG_H) continue
+                  ;;
+               *) grep -q "$d\( \|\>\)" $config || \
+                    echo $(echo $srcfile | sed 's:\\'$srcdir/'::') ": $d"
                   ;;
                esac
        done