]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
lib: use C preprocessor to build list of init functions
authorVincent Bernat <vincent@bernat.im>
Wed, 23 Mar 2016 21:09:55 +0000 (22:09 +0100)
committerVincent Bernat <vincent@bernat.im>
Wed, 23 Mar 2016 21:26:32 +0000 (22:26 +0100)
Because some features can be disabled, we cannot just parse the C file,
we need to run the C preprocessor on them. Hopefully, the GNU make stuff
(filter) should be portable enough.

src/lib/Makefile.am
src/lib/atom.c
src/lib/atom.h

index 9ff6c7e9ee8ceba275a6714dfe3a8386d5d5eee9..b41ae794814b5431b7a0e4c9cc6ffe65ee425e3b 100644 (file)
@@ -12,27 +12,27 @@ ATOM_FILES = \
        atoms/config.c atoms/dot1.c atoms/dot3.c \
        atoms/interface.c atoms/med.c atoms/mgmt.c atoms/port.c \
        atoms/custom.c atoms/chassis.c
-NON_ATOM_FILES = \
-       errors.c connection.c atom.c helpers.c
 liblldpctl_la_SOURCES = \
        lldpctl.h atom.h helpers.h \
-       $(NON_ATOM_FILES) \
+       errors.c connection.c atom.c helpers.c \
        $(ATOM_FILES)
 nodist_liblldpctl_la_SOURCES = atom-glue.c
 liblldpctl_la_LIBADD  = $(top_builddir)/src/libcommon-daemon-lib.la libfixedpoint.la
 
 atom-glue.c: $(ATOM_FILES) Makefile
-       $(AM_V_GEN)(cat $^ | \
-               $(SED) -n 's+^ATOM_BUILDER_REGISTER(\([^,]*\), *\([0-9]*\)).*+\2 \1+p' | \
-               sort -n | \
+       $(AM_V_GEN)($(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+               $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(filter %.c,$^) | \
+               $(SED) -n 's+^void init_atom_builder_\([^(]*\)().*, \([0-9]*\)).*+\2 \1+p' | \
+               sort | \
                $(AWK) '{ atoms[$$2] = 1 } \
                         END { for (atom in atoms) { print "void init_atom_builder_"atom"(void);" } \
                               print "void init_atom_builder() {"; \
                                print " static int init = 0; if (init) return; init++;"; \
                               for (atom in atoms) { print " init_atom_builder_"atom"();" } \
                               print "}"; }' && \
-               cat $^ | \
-               $(SED) -n 's+^ATOM_MAP_REGISTER(\([^,]*\), *\([0-9]*\)).*+\2 \1+p' | \
+               $(CPP) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+               $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) $(filter %.c,$^) | \
+               $(SED) -n 's+^void init_atom_map_\([^(]*\)().*, \([0-9]*\)).*+\2 \1+p' | \
                sort -n | \
                $(AWK) '{ atoms[$$2] = 1 } \
                         END { for (atom in atoms) { print "void init_atom_map_"atom"(void);" } \
@@ -41,7 +41,8 @@ atom-glue.c: $(ATOM_FILES) Makefile
                               for (atom in atoms) { print " init_atom_map_"atom"();" } \
                               print "}"; }' ) \
                > $@.tmp
-       @[ -s $@.tmp ]
+       @$(GREP) -q init_atom_builder_ $@.tmp
+       @$(GREP) -q init_atom_map_ $@.tmp
        @mv $@.tmp $@
 CLEANFILES = atom-glue.c
 
index 718a4ad8b07720e56b71b2440b9398c2a3a365f8..d7fd831ca9c18fed04f4301c1cbc9bcb2af873bd 100644 (file)
@@ -523,8 +523,9 @@ lldpctl_key_get_map(lldpctl_key_t key)
        return empty_map;
 }
 
-void atom_map_register(struct atom_map *map)
+void atom_map_register(struct atom_map *map, int prio)
 {
+       (void)prio;
        struct atom_map* iter = &atom_map_list;
 
        while (iter->next)
@@ -537,8 +538,9 @@ static struct atom_builder atom_builder_list = {
        .nextb = NULL
 };
 
-void atom_builder_register(struct atom_builder *builder)
+void atom_builder_register(struct atom_builder *builder, int prio)
 {
+       (void)prio;
        struct atom_builder* iter = &atom_builder_list;
 
        while (iter->nextb)
index c09649ec4a371713121fc4819b95180857b80be6..265c0a79c9a69f16e5cdc7c697285156afe143d9 100644 (file)
@@ -290,10 +290,10 @@ struct atom_map {
        lldpctl_map_t   map[];
 };
 
-void atom_map_register(struct atom_map *map);
+void atom_map_register(struct atom_map *map, int);
 void init_atom_map(void);
 
-#define ATOM_MAP_REGISTER(NAME, PRIO) void init_atom_map_ ## NAME() { atom_map_register(& NAME ); }
+#define ATOM_MAP_REGISTER(NAME, PRIO) void init_atom_map_ ## NAME() { atom_map_register(& NAME, PRIO); }
 
 struct atom_builder {
        atom_t type;    /* Atom type */
@@ -318,7 +318,7 @@ struct atom_builder {
        struct atom_builder  *nextb;
 };
 
-void atom_builder_register(struct atom_builder *builder);
+void atom_builder_register(struct atom_builder *builder, int);
 void init_atom_builder(void);
 
-#define ATOM_BUILDER_REGISTER(NAME, PRIO) void init_atom_builder_ ## NAME() { atom_builder_register(& NAME ); }
+#define ATOM_BUILDER_REGISTER(NAME, PRIO) void init_atom_builder_ ## NAME() { atom_builder_register(& NAME, PRIO); }