Ethereal-dev: Re: [ethereal-dev] Automatically generating "proto_register_XXX()" calls
> (GDB's Makefile actually looks for the relevant ".o" files and generates
> the list of ".c" files to scan based on that; I'm not sure why they did
> that.)
They did that so that if there's a ".c" file that's not built in your
configuration, it won't include its "init" routines.
We have to do the same; I've attached a new patch - unfortunately, the
Makefiles that come from it say that "init.c" depends on *all* the ".o"
files for Ethereal, *including* "init.o". The GNU "make" I'm using
realizes that makes no sense, and just warns
make[2]: Circular init.c <- init.o dependency dropped.
and drives on. There may be a better way to do this.
Note also that GDB's grepping scheme requires that the function
1) have a name that begins with "proto_register"
and
2) have its name appear at the beginning of the line in the file
in which it's defined.
This patch is against the vanilla version of "Makefile.am"; back out the
change to "Makefile.am" from my previous patch (but not any of the other
changes from it).
Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/ethereal/Makefile.am,v
retrieving revision 1.89
diff -r1.89 Makefile.am
53a54
> init.c \
172a174,201
>
> # We do this by grepping through sources. If that turns out to be too slow,
> # maybe we could just require every .o file to have an initialization routine
> # of a given name (packet-aarp.o -> proto_register_aarp, etc.).
> #
> # Formatting conventions: The name of the proto_register_* routines must start
> # in column zero, and must not be inside #if.
> #
> # Note that the set of files with init functions might change, or the names
> # of the functions might change, so this files needs to depend on all the
> # object files that will be linked into Ethereal.
>
> init.c: $(ethereal_OBJECTS) $(ethereal_LDADD)
> @echo Making init.c
> @rm -f init.c-tmp
> @echo '/* Do not modify this file. */' >init.c-tmp
> @echo '/* It is created automatically by the Makefile. */'>>init.c-tmp
> @echo '#include "init.h"' >>init.c-tmp
> @echo 'void initialize_all_protocols(void) {' >>init.c-tmp
> @-echo $(ethereal_SOURCES:.c=.o) | \
> tr ' ' '\012' | \
> sed -n -e '/^packet.*\.o/s/\.o/.c/p' | \
> while read f; do grep '^proto_register_[a-z_0-9A-Z]* *(' $$f 2>/dev/null; done | \
> sed -e 's/^.*://' -e 's/^\([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>init.c-tmp
> @echo '}' >>init.c-tmp
> @mv init.c-tmp init.c
>
> .PRECIOUS: init.c