Skip to content

Commit

Permalink
build: autogen version.mk, and fix versioning in Makefile
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
outscale-mgo committed Feb 21, 2020
1 parent 915ec1a commit a98e2fb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
11 changes: 6 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
include config.mk
include npf.mk
include tests.mk
include version.mk

PG_SOURCES = \
src/queue.c\
Expand Down Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
20 changes: 20 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ function check_compiler {
fi
}

function compile_version_mk {
echo "Make tmp file version_.c"
echo '#include <stdio.h>' > version_.c
echo '#include <packetgraph/common.h>' >> 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]"
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions include/packetgraph/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
#include <sys/prctl.h>
#include <linux/seccomp.h>

#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,
Expand Down

0 comments on commit a98e2fb

Please sign in to comment.