Ethereal-dev: Re: [ethereal-dev] Automatically generating "proto_register_XXX()" calls
Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.
From: Guy Harris <gharris@xxxxxxxxxxxx>
Date: Tue, 19 Oct 1999 00:07:26 -0700 (PDT)
One more patch - this one gets rid of the "init.c depends on init.o" problem by making "init.c" depend only on the "packet*.c" files that will actually be used to build Ethereal (i.e., if SNMP support isn't being compiled in, it won't include "packet-snmp.c", so it won't insert a call to "proto_register_snmp()" if it's not going to be in the program). It also arranges that "init.c" not go into the distribution, as its contents depend on the configuration (i.e., whether SNMP support will be compiled in), and handles dissectors whose "register" routine is defined as void proto_register_XXX(void) rather than void proto_register_XXX(void) (it should be able to handle the opening "{" being on the same line or a subsequent line, and other formatting differences, as well; it currently finds all the "register" routines). It does, however, require that you put "packet-XXX.c" routines in the "DISSECTOR_SOURCES" macro rather than in the "ethereal_SOURCES" macro - if you put them in the latter, they won't get scanned by the commands that generate "init.c". Here's a new patch to "Makefile.am" and "configure.in".
Index: Makefile.am =================================================================== RCS file: /usr/local/cvsroot/ethereal/Makefile.am,v retrieving revision 1.90 diff -c -r1.90 Makefile.am *** Makefile.am 1999/10/19 06:59:23 1.90 --- Makefile.am 1999/10/19 07:06:19 *************** *** 31,58 **** # Any POSIX-compatible YACC should honor the -p flag YFLAGS=-d -p dfilter_ ! ethereal_SOURCES = \ ! alignment.h \ ! capture.c \ ! capture.h \ ! colors.c \ ! colors.h \ ! column.c \ ! column.h \ ! dfilter-int.h \ ! dfilter-grammar.y \ ! dfilter-scanner.l \ ! dfilter.c \ ! dfilter.h \ ! ethertype.c \ ! etypes.h \ ! file.c \ ! file.h \ ! follow.c \ ! follow.h \ ! globals.h \ ! inet_v6defs.h \ ! ipproto.c \ packet-aarp.c \ packet-arp.c \ packet-ascend.c\ --- 31,37 ---- # Any POSIX-compatible YACC should honor the -p flag YFLAGS=-d -p dfilter_ ! DISSECTOR_SOURCES = \ packet-aarp.c \ packet-arp.c \ packet-ascend.c\ *************** *** 126,132 **** packet-vines.h \ packet-x25.c \ packet-yhoo.c \ ! packet-yhoo.h \ packet.c \ packet.h \ prefs.c \ --- 105,136 ---- packet-vines.h \ packet-x25.c \ packet-yhoo.c \ ! packet-yhoo.h ! ! ethereal_SOURCES = \ ! alignment.h \ ! capture.c \ ! capture.h \ ! colors.c \ ! colors.h \ ! column.c \ ! column.h \ ! dfilter-int.h \ ! dfilter-grammar.y \ ! dfilter-scanner.l \ ! dfilter.c \ ! dfilter.h \ ! ethertype.c \ ! etypes.h \ ! file.c \ ! file.h \ ! follow.c \ ! follow.h \ ! globals.h \ ! inet_v6defs.h \ ! init.c \ ! init.h \ ! ipproto.c \ packet.c \ packet.h \ prefs.c \ *************** *** 146,152 **** util.c \ util.h \ xdlc.c \ ! xdlc.h EXTRA_ethereal_SOURCES = \ dfilter-grammar.c \ --- 150,157 ---- util.c \ util.h \ xdlc.c \ ! xdlc.h \ ! $(DISSECTOR_SOURCES) EXTRA_ethereal_SOURCES = \ dfilter-grammar.c \ *************** *** 172,177 **** --- 177,208 ---- wiretap/libwiretap.a gtk/libui.a \ @SNMP_A@ + # 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, or must be preceded only by "void " starting 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: packet.c $(DISSECTOR_SOURCES) @SNMP_C@ + @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 + for f in packet.c $(DISSECTOR_SOURCES) @SNMP_C@; 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 + for f in packet.c $(DISSECTOR_SOURCES) @SNMP_C@; do grep '^void proto_register_[a-z_0-9A-Z]* *(' $$f 2>/dev/null; done | \ + sed -e 's/^.*://' -e 's/^void \([a-z_0-9A-Z]*\).*/ {extern void \1 (void); \1 ();}/' >>init.c-tmp + @echo '}' >>init.c-tmp + @mv init.c-tmp init.c + ps.c: print.ps rdps ./rdps $(srcdir)/print.ps ps.c *************** *** 185,190 **** --- 216,222 ---- $(LINK) -o randpkt randpkt.o wiretap/libwiretap.a `glib-config --libs` -lz DISTCLEANFILES = \ + init.c \ rdps \ ps.c \ *~ *************** *** 208,213 **** --- 240,257 ---- README.win32 \ randpkt.c \ rdps.c + + # + # Oh, yuk. We don't want to include "init.c" in the distribution, as + # its contents depend on the configuration, and therefore we want it + # to be built when the first "make" is done; however, Automake insists + # on putting *all* source into the distribution. + # + # We work around this by having a "disk-hook" rule that deletes + # "init.c", so that "dist" won't pick it up. + # + dist-hook: + @rm -f $(distdir)/init.c SUBDIRS = wiretap gtk @ethereal_SUBDIRS@ Index: configure.in =================================================================== RCS file: /usr/local/cvsroot/ethereal/configure.in,v retrieving revision 1.52 diff -c -r1.52 configure.in *** configure.in 1999/10/14 06:55:08 1.52 --- configure.in 1999/10/19 07:06:19 *************** *** 115,120 **** --- 115,121 ---- [ --enable-snmp use SNMP library, if available. [default=yes]],,enable_snmp=yes) SNMP_A='' + SNMP_C='' SNMP_O='' AC_MSG_CHECKING(whether to use SNMP library if available) if test "x$enable_snmp" = "xno" ; then *************** *** 126,135 **** --- 127,138 ---- AC_CHECK_LIB(snmp, asn_parse_header, [ SNMP_A=-lsnmp + SNMP_C=packet-snmp.c SNMP_O=packet-snmp.o ], ) fi AC_SUBST(SNMP_A) + AC_SUBST(SNMP_C) AC_SUBST(SNMP_O) dnl Checks for typedefs, structures, and compiler characteristics.
- Follow-Ups:
- References:
- Prev by Date: Re: [ethereal-dev] small filtering request - allow filtering on strings, but not con tents
- Next by Date: Re: [ethereal-dev] suggested feature...
- Previous by thread: Re: [ethereal-dev] Automatically generating "proto_register_XXX()" calls
- Next by thread: Re: [ethereal-dev] Automatically generating "proto_register_XXX()" calls
- Index(es):