Skip to content

Commit

Permalink
external_libs: build deps sys, add libcdada
Browse files Browse the repository at this point in the history
This commit does two major things:

1) Adds external_libs/ folder, and prepares the build system to
   accept building, as part of pmacct's `make` process, external
   dependencies. These external dependencies are in the form of
   git submodules, which are cloned and checkedout as part of
   the build process.
2) Adds libcdada submodule as a dependency of pmacct, and also
   as a showcase of the build system, to later be used by the
   code.

A bit more details on 2). `src/external_libs/Makefile.am` contains
the basics that do the "work" of cloning the subrepos, checking out
the commits and compiling the dependencies. These dependencies are
compiled before any pmacct object is attempted to be compiled.

Dependencies _shall_ be compiled and linked by pmacct daemons
statically, as they are NOT distributed as part of pmacct binaries,
just statically linked.

Dependencies will only be attempted to be compiled if the git
submodule commit hash changes, or it hasn't been built before. To
do so, a "mark" file is created under $(builddir)/src/external_libs/.

The dependency build system puts the results under
$(builddir)/src/external_libs/rootfs, with the typical structure
of:

* bin/
* include/
* lib/

When compiled in-tree, this directory, and the compilation marks
are git ignored.

If pmacct is compiled from a tarball (no git repository), dependency
building is skipped. There will be more refinement on this later on
  • Loading branch information
msune committed Nov 4, 2020
1 parent 577ca36 commit bef40e4
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ Makefile

# JetBrains IDE files
.idea/

# Submodule deps build marks
src/external_libs/.*mark

# Submodule deps tmp install directory
src/external_libs/rootfs
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "src/external_libs/libcdada"]
path = src/external_libs/libcdada
url = https://github.com/msune/libcdada.git
11 changes: 10 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1091,6 +1091,10 @@ AC_ARG_ENABLE(st-bins,
]
)

dnl libcdada requires C++ (and needs to add libstdc++ to LDFLAGS
AC_PROG_CXX
LDFLAGS="-lcdada -lstdc++ ${LDFLAGS}"

dnl Checks for library functions.
AC_TYPE_SIGNAL

Expand Down Expand Up @@ -1128,6 +1132,10 @@ AC_ARG_ENABLE(debug,
dnl Necessary for autogenerated build string
INCLUDES="${INCLUDES} -I$(pwd)/src"

dnl Compiled-in dependencies
INCLUDES="${INCLUDES} -I$(pwd)/src -I${ac_pwd}/src/external_libs/rootfs/include"
LDFLAGS="-L${ac_pwd}/src/external_libs/rootfs/lib ${LDFLAGS}"

dnl final checks
dnl trivial solution to portability issue
AC_DEFINE_UNQUOTED(COMPILE_ARGS, "$COMPILE_ARGS")
Expand Down Expand Up @@ -1180,7 +1188,8 @@ AM_CONDITIONAL([USING_BGP_BINS], [test x"$USING_BGP_BINS" = x"yes"])
AM_CONDITIONAL([USING_BMP_BINS], [test x"$USING_BMP_BINS" = x"yes"])
AM_CONDITIONAL([USING_ST_BINS], [test x"$USING_ST_BINS" = x"yes"])
AC_OUTPUT([ Makefile \
src/Makefile src/nfprobe_plugin/Makefile \
src/Makefile src/external_libs/Makefile \
src/nfprobe_plugin/Makefile \
src/sfprobe_plugin/Makefile src/bgp/Makefile \
src/tee_plugin/Makefile src/isis/Makefile \
src/bmp/Makefile src/rpki/Makefile \
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBDIRS = nfprobe_plugin sfprobe_plugin bgp tee_plugin isis bmp telemetry rpki filters
SUBDIRS = external_libs nfprobe_plugin sfprobe_plugin bgp tee_plugin isis bmp telemetry rpki filters
sbin_PROGRAMS =
bin_PROGRAMS =
EXTRA_PROGRAMS =
Expand Down
51 changes: 51 additions & 0 deletions src/external_libs/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#Build all submodule deps
BUILT_SOURCES = submodule_deps
CLEANFILES = .libcdada_mark

#NOTE make sure Makefile targets don't have the same name of the folder

##
## LIBCDADA
##
_libcdada:
@if [[ -z "$(shell git rev-parse HEAD 2> /dev/null)" ]]; then \
echo "[dep: libcdada] Skipping, not a git repository!"; \
exit 0;\
fi;\
echo "[dep: libcdada] Checking..."; \
if [[ ! -f "$(abs_srcdir)/libcdada/.git" ]]; then \
echo "[dep: libcdada] Cloning and checking out commit..";\
git submodule update --init --recursive libcdada; \
if [ $$? != 0 ]; then exit 1; fi;\
fi;\
if [[ ( ! -f $(abs_builddir)/.libcdada_mark ) || "$(shell cat $(abs_builddir)/.libcdada_mark 2> /dev/null)" != "$(shell cd $(abs_srcdir)/libcdada && git rev-parse HEAD)" ]]; then \
echo "[dep: libcdada] Building...";\
mkdir -p $(abs_builddir)/libcdada/build || true; \
cd $(abs_srcdir)/libcdada/ && \
./autogen.sh &&\
cd $(abs_builddir)/libcdada/build && \
$(abs_srcdir)/libcdada/configure --disable-shared \
--prefix=$(abs_builddir)/rootfs && make $(MAKE_JOBS) install;\
if [ $$? != 0 ]; then exit 1; fi; \
echo "$(shell cd $(abs_srcdir)/libcdada && git rev-parse HEAD)" > $(abs_builddir)/.libcdada_mark;\
if [ $$? != 0 ]; then exit 1; fi; \
echo "[dep: libcdada] Done!";\
else\
echo "[dep: libcdada] Up-to-date!";\
fi

_libcdada_maintainer_clean:
@rm -rf $(builddir)/libcdada/build/*

submodule_prep:
@mkdir -p $(builddir)/rootfs

#List all of them here
submodule_deps: submodule_prep _libcdada

#Deep cleanup
maintainer-clean-local: _libcdada_maintainer_clean
rm -rf $(abs_builddir)/rootfs

#Placed abnormally here, just because vim syntax highlighter has a bug
MAKE_JOBS := $(shell ps T | sed -n 's/.*$(MAKE_PID).*$(MAKE).* \(-j\|--jobs=\) *\([0-9][0-9]*\).*/-j \2/p')
1 change: 1 addition & 0 deletions src/external_libs/libcdada
Submodule libcdada added at 834146

0 comments on commit bef40e4

Please sign in to comment.