From e011b04c6b2e31bdc46320e5d8a4f48715681f15 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Wed, 12 Jan 2022 02:58:02 +0100 Subject: libosmo-gtlv: add C code generator for IE structs and arrays Defining a protocol of message types with lists of IEs bears a lot of repetitive, copy-paste-error-prone writing out of data structures. Add a third layer to libosmo-gtlv, which allows helpful code generation. By non-repetitive data structures that briefly describe the protocol's messages and IEs, generate possibly repetitive IE list arrays and decoded-struct definitions automatically, avoiding grunt work errors. I tried C macros for this at first, but it became too convoluted. Generating C code that can be read and grepped makes things easier. A usage example is found in tests/libosmo-gtlv/test_gtlv_gen/. Related: SYS#5599 Change-Id: Ifb3ea54d2797ce060b95834aa117725ec2d6c4cf --- tests/libosmo-gtlv/test_gtlv_gen/Makefile.am | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/libosmo-gtlv/test_gtlv_gen/Makefile.am (limited to 'tests/libosmo-gtlv/test_gtlv_gen/Makefile.am') diff --git a/tests/libosmo-gtlv/test_gtlv_gen/Makefile.am b/tests/libosmo-gtlv/test_gtlv_gen/Makefile.am new file mode 100644 index 0000000..0d27292 --- /dev/null +++ b/tests/libosmo-gtlv/test_gtlv_gen/Makefile.am @@ -0,0 +1,60 @@ +AM_CPPFLAGS = \ + $(all_includes) \ + -I$(top_srcdir)/include \ + -I$(bulddir) \ + $(NULL) + +AM_CFLAGS = \ + -Wall \ + $(LIBOSMOCORE_CFLAGS) \ + $(NULL) + +noinst_PROGRAMS = \ + gen__myproto_ies_auto \ + gtlv_gen_test \ + $(NULL) + +EXTRA_DIST = \ + myproto_ies_custom.h \ + gtlv_gen_test.ok \ + $(NULL) + +BUILT_SOURCES = \ + myproto_ies_auto.h \ + myproto_ies_auto.c \ + $(NULL) + +CLEANFILES = \ + myproto_ies_auto.h \ + myproto_ies_auto.c \ + $(NULL) + +gen__myproto_ies_auto_SOURCES = \ + gen__myproto_ies_auto.c \ + myproto_ies_custom.c \ + $(NULL) + +gen__myproto_ies_auto_LDADD = \ + $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.a \ + $(LIBOSMOCORE_LIBS) \ + $(NULL) + +myproto_ies_auto.h: $(builddir)/gen__myproto_ies_auto + $(builddir)/gen__myproto_ies_auto h > $(builddir)/myproto_ies_auto.h +myproto_ies_auto.c: $(builddir)/gen__myproto_ies_auto + $(builddir)/gen__myproto_ies_auto c > $(builddir)/myproto_ies_auto.c + +gtlv_gen_test_SOURCES = \ + gtlv_gen_test.c \ + myproto_ies_custom.c \ + myproto_ies_auto.c \ + $(NULL) + +gtlv_gen_test_LDADD = \ + $(top_builddir)/src/libosmo-gtlv/libosmo-gtlv.a \ + $(LIBOSMOCORE_LIBS) \ + $(NULL) + +.PHONY: update_exp +update_exp: + $(builddir)/gtlv_gen_test >$(srcdir)/gtlv_gen_test.ok -- cgit v1.2.3