From a98e2fb5eee6b2069f0d94eb09d2041f5ae43d0c Mon Sep 17 00:00:00 2001 From: Matthias Gatto Date: Fri, 21 Feb 2020 14:38:58 +0100 Subject: [PATCH] build: autogen version.mk, and fix versioning in Makefile Until recently packetgraph version was hardcoded in the Makefile, and we had no way to ghet the version in C. It's now resolve by adding 4 define in "common.h" those defines are: PG_VERSION_YEAR: year of last DPDK release on which packetgraph is bases PG_VERSION_MONTH: month of DPDK release PG_VERSION_REVISION: number of revisions on the release PG_VERSION: number containing all information above As we need to got thoses informations for the linker in the makefile, we are compiling an intermediate program in the configure that ghenerate a version.mk which is then use in the makefile. So we are now generating a libpacketgraph.so.19.2.0 instead of libpacketgraph.so.17.5.0. Signed-off-by: Matthias Gatto --- Makefile | 11 ++++++----- configure | 20 ++++++++++++++++++++ include/packetgraph/common.h | 6 ++++++ 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index fbf556bb1..6e4775211 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,7 @@ include config.mk include npf.mk include tests.mk +include version.mk PG_SOURCES = \ src/queue.c\ @@ -59,7 +60,7 @@ PG_HEADERS = \ PG_LIBADD = $(RTE_SDK_LIBS) $(GLIB_LIBS) #FIXME '^pg_[^_]' does not take all symbols needed (i.e. __pg_error_*) -PG_LDFLAGS = -version-info 17:5:0 -export-symbols-regex 'pg_[^_]' -no-undefined --export-all-symbols $(PG_COV_LFLAGS) +PG_LDFLAGS = -version-info $(PG_VERSION1) -export-symbols-regex 'pg_[^_]' -no-undefined --export-all-symbols $(PG_COV_LFLAGS) PG_CFLAGS = $(EXTRA_CFLAGS) -march=$(PG_MARCH) -fmessage-length=0 -Werror -Wall -Wextra -Winit-self -Wpointer-arith -Wstrict-aliasing -Wformat -Wmissing-declarations -Wmissing-include-dirs -Wno-unused-parameter -Wuninitialized -Wold-style-definition -Wstrict-prototypes -Wmissing-prototypes -fPIC -std=gnu11 $(GLIB_CFLAGS) $(RTE_SDK_CFLAGS) $(PG_ASAN_CFLAGS) -Wno-implicite-fallthrough -Wno-unknown-warning-option -Wno-deprecated-declarations -Wno-address-of-packed-member $(PG_COV_CFLAGS) @@ -82,7 +83,7 @@ all: dev $(PG_NAME) $(PG_NAME): lpm cdb nvlist thmap qsbr sljit bpfjit npf npfkern $(PG_OBJECTS) ar rcv $(PG_NAME).a $(PG_OBJECTS) $(lpm_OBJECTS) $(cdb_OBJECTS) $(nvlist_OBJECTS) $(thmap_OBJECTS) $(qsbr_OBJECTS) $(sljit_OBJECTS) $(bpfjit_OBJECTS) $(npf_OBJECTS) $(npfkern_OBJECTS) - $(CC) -shared -Wl,-soname,$(PG_NAME).so.17 -o $(PG_NAME).so.17.5.0 $(PG_OBJECTS) $(lpm_OBJECTS) $(cdb_OBJECTS) $(qsbr_OBJECTS) $(sljit_OBJECTS) $(bpfjit_OBJECTS) $(npf_OBJECTS) $(npfkern_OBJECTS) -lc + $(CC) -shared -Wl,-soname,$(PG_NAME).so.$(PG_VERSION_YEAR) -o $(PG_NAME).so.$(PG_VERSION) $(PG_OBJECTS) $(lpm_OBJECTS) $(cdb_OBJECTS) $(qsbr_OBJECTS) $(sljit_OBJECTS) $(bpfjit_OBJECTS) $(npf_OBJECTS) $(npfkern_OBJECTS) -lc echo $(PG_NAME)" compiled" $(PG_OBJECTS) : src/%.o : src/%.c @@ -108,7 +109,7 @@ check: dev: lpm cdb nvlist thmap qsbr sljit bpfjit npf npfkern $(PG_dev_OBJECTS) ar rcv $(PG_NAME)-dev.a $(PG_dev_OBJECTS) $(lpm_OBJECTS) $(cdb_OBJECTS) $(nvlist_OBJECTS) $(thmap_OBJECTS) $(qsbr_OBJECTS) $(sljit_OBJECTS) $(bpfjit_OBJECTS) $(npf_OBJECTS) $(npfkern_OBJECTS) - $(CC) -shared -Wl,-soname,$(PG_NAME)-dev.so.17 -o $(PG_NAME)-dev.so.17.5.0 $(PG_dev_OBJECTS) $(lpm_OBJECTS) $(cdb_OBJECTS) $(qsbr_OBJECTS) $(sljit_OBJECTS) $(bpfjit_OBJECTS) $(npf_OBJECTS) $(npfkern_OBJECTS) -lc + $(CC) -shared -Wl,-soname,$(PG_NAME)-dev.so.$(PG_VERSION_YEAR) -o $(PG_NAME)-dev.so.$(PG_VERSION) $(PG_dev_OBJECTS) $(lpm_OBJECTS) $(cdb_OBJECTS) $(qsbr_OBJECTS) $(sljit_OBJECTS) $(bpfjit_OBJECTS) $(npf_OBJECTS) $(npfkern_OBJECTS) -lc echo "$(PG_CFLAGS)-dev compiled" clean: clean_npf testcleanobj @@ -131,8 +132,8 @@ endif fclean: clean fclean_npf testclean @rm -fv $(PG_NAME).a @rm -fv $(PG_dev_NAME).a - @rm -fv $(PG_NAME).so.17.5.0 - @rm -fv $(PG_dev_NAME).so.17.5.0 + @rm -fv $(PG_NAME).so.$(PG_VERSION) + @rm -fv $(PG_dev_NAME).so.$(PG_VERSION) ifdef BENCHMARK $(MAKE) benchfclean endif diff --git a/configure b/configure index e6691a278..021fecbc3 100755 --- a/configure +++ b/configure @@ -39,6 +39,23 @@ function check_compiler { fi } +function compile_version_mk { + echo "Make tmp file version_.c" + echo '#include ' > version_.c + echo '#include ' >> version_.c + echo "int main(void) {" >> version_.c + echo 'printf("PG_VERSION = %d.%d.%d\n", PG_VERSION_YEAR, PG_VERSION_MONTH, PG_VERSION_REVISION);' >> version_.c + echo 'printf("PG_VERSION1 = %d:%d:%d\n", PG_VERSION_YEAR, PG_VERSION_MONTH, PG_VERSION_REVISION);' >> version_.c + echo 'printf("PG_VERSION_YEAR = %d\n", PG_VERSION_YEAR);' >> version_.c + echo "}" >> version_.c + + echo "Compile it to tmp program get-mk-version" + $CC -I$srcdir/include/ -std=c99 version_.c -o get-mk-version + ./get-mk-version > version.mk + rm -v version_.c + rm -v get-mk-version +} + function print_help { echo " --- HELP --- " echo "Usage : ./configure [options] [variable]" @@ -249,6 +266,9 @@ if $doCheckCompiler; then fi export CC="$CC" var_add CC + +compile_version_mk + if $addAsan;then if [[ "$CC" == "gcc" ]]; then var_add PG_ASAN_CFLAGS "-fsanitize=address -fsanitize=leak -fsanitize=undefined -fno-sanitize=alignment --param asan-globals=0" diff --git a/include/packetgraph/common.h b/include/packetgraph/common.h index b17341a0d..dbfa19cd4 100644 --- a/include/packetgraph/common.h +++ b/include/packetgraph/common.h @@ -21,6 +21,12 @@ #include #include +#define PG_VERSION_YEAR 19 +#define PG_VERSION_MONTH 2 +#define PG_VERSION_REVISION 0 + +#define PG_VERSION 190200 + enum pg_side { PG_WEST_SIDE = 0, PG_EAST_SIDE = 1,