On Mon, 4 Jul 2022 at 16:50, Daniel P. Berrangé <[email protected]> wrote: > > On Mon, Jul 04, 2022 at 04:47:16PM +0100, Peter Maydell wrote: > > On Mon, 4 Jul 2022 at 16:23, Daniel P. Berrangé <[email protected]> wrote: > > > > > > Signed-off-by: Daniel P. Berrangé <[email protected]> > > > > > + > > > +sc_c_file_osdep_h: > > > + @require='#include "qemu/osdep.h"' \ > > > + in_vc_files='\.c$$' \ > > > + halt='all C files must include qemu/osdep.h' \ > > > + $(_sc_search_regexp) > > > > The rule is not just "included in all C files", but "included > > as the *first* include in all C files". > > Oh right, so we can copy a rule from libvirt to validate that. > > It would look like this, but s,config.h,qemu/osdep.h, > > > # Print each file name for which the first #include does not match > # $(config_h_header). Like grep -m 1, this only looks at the first match. > perl_config_h_first_ = \ > -e 'BEGIN {$$ret = 0}' \ > -e 'if (/^\# *include\b/) {' \ > -e ' if (not m{^\# *include $(config_h_header)}) {' \ > -e ' print "$$ARGV\n";' \ > -e ' $$ret = 1;' \ > -e ' }' \ > -e ' \# Move on to next file after first include' \ > -e ' close ARGV;' \ > -e '}' \ > -e 'END {exit $$ret}' > > # You must include <config.h> before including any other header file. > # This can possibly be via a package-specific header, if given by > syntax-check.mk. > sc_require_config_h_first: > @if $(VC_LIST_EXCEPT) | $(GREP) '\.c$$' > /dev/null; then \ > files=$$($(VC_LIST_EXCEPT) | $(GREP) '\.c$$') && \ > perl -n $(perl_config_h_first_) $$files || \ > { echo 'the above files include some other header' \ > 'before <config.h>' 1>&2; exit 1; } || :; \ > else :; \ > fi
As an example syntax checking rule I think this makes a pretty convincing case for the argument "make is the wrong language/framework for this job"... thanks -- PMM
