[Libvir] [PATCH] * qemud/remote.c: Don't include <getopt.h>. Not used.

Jim Meyering jim at meyering.net
Wed Mar 19 13:21:26 UTC 2008


"Richard W.M. Jones" <rjones at redhat.com> wrote:

> On Wed, Mar 19, 2008 at 02:08:44PM +0100, Jim Meyering wrote:
>> I had a few in-progress changes from a week or two ago,
>> and am clearing the decks.
>>
>> I added a new build-checking rule (coming separately)
>> and it exposed an unnecessary include:
>
> +1
>
> So we have a way to find header files which are unused?

For some simple ones, yes.
See the rules like sc_prohibit_assert_without_use in
the existing Makefile.maint.  Yesterday I factored out
the core of those four rules and now have the following.
(a patch to update this is coming up)

The hard part is coming up with a regular expression to
indicate whether a particular header is used.  The following
are simple-minded, but so far they seem to do the job...
However, for a header with many functions and macros, the
required regexp will be a lot more complicated.

# To use this "command" macro, you must first define two shell variables:
# h: the header, enclosed in <> or ""
# re: a regular expression that matches IFF something provided by $h is used.
define _header_without_use
  h_esc=`echo "$$h"|sed 's/\./\\./'`;					\
  if $(CVS_LIST_EXCEPT) | grep '\.c$$' > /dev/null; then		\
    files=$$(grep -l '^# *include '"$$h_esc"				\
	     $$($(CVS_LIST_EXCEPT) | grep '\.c$$')) &&			\
    grep -LE "$$re" $$files | grep . &&					\
      { echo "$(ME): the above files include $$h but don't use it"	\
	1>&2; exit 1; } || :;						\
  else :;								\
  fi
endef

# Prohibit the inclusion of assert.h without an actual use of assert.
sc_prohibit_assert_without_use:
	@h='<assert.h>' re='\<assert *\(' $(_header_without_use)

# Prohibit the inclusion of getopt.h without an actual use.
sc_prohibit_getopt_without_use:
	@h='<getopt.h>' re='\<getopt(_long)? *\(' $(_header_without_use)

# Don't include quotearg.h unless you use one of its functions.
sc_prohibit_quotearg_without_use:
	@h='"quotearg.h"' re='\<quotearg(_[^ ]+)? *\(' $(_header_without_use)

# Don't include quote.h unless you use one of its functions.
sc_prohibit_quote_without_use:
	@h='"quote.h"' re='\<quote(_n)? *\(' $(_header_without_use)




More information about the libvir-list mailing list