Skip to content

Commit

Permalink
build: Rework the autotools setup prototype
Browse files Browse the repository at this point in the history
Changes:
- uses subdirectories/recursive builds
- boost is bootstrapped as part of autogen.sh
- boost libraries are only built when needed
- Boost::JSON is statically linked instead of using the
  header-only version of the library

Ticket: MEN-5795
Changelog: None

Signed-off-by: Vratislav Podzimek <[email protected]>
  • Loading branch information
vpodzime committed Dec 14, 2022
1 parent efb0bc4 commit 11253e4
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 67 deletions.
20 changes: 10 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
*.lcov

# Autotools files
/Makefile
/Makefile.in
*Makefile
*Makefile.in
/aclocal.m4
/ar-lib
/autom4te.cache/
Expand All @@ -30,23 +30,23 @@
/install-sh
/libtool
/ltmain.sh
/m4/libtool.m4
/m4/ltoptions.m4
/m4/ltsugar.m4
/m4/ltversion.m4
/m4/lt~obsolete.m4
/missing
/stamp-h1
/m4/
*.deps
*.dirstamp
/common/.libs/

# Test binaries
*_test

# Binaries
# Build artifacts
/mender
/men-authd
/men-updated
/mender-auth/men-authd
/mender-update/men-updated
/common/json/impl/boost/libjson_la-boost_json.lo
/common/libjson.la
/vendor/libboost_json.built

# Test reports
/reports
31 changes: 1 addition & 30 deletions Makefile.am
Original file line number Diff line number Diff line change
@@ -1,32 +1,3 @@
AUTOMAKE_OPTIONS = subdir-objects

ACLOCAL_AMFLAGS = -I m4

AM_CXXFLAGS = -std=c++11 -Wall -Werror
AM_CPPFLAGS = \
-I$(srcdir)/common/json \
-I$(srcdir)/vendor/boost/install/include

# Two daemons
bin_PROGRAMS = men-authd men-updated

# Headers for libraries and utils under common to be listed here
COMMON_SOURCES = common/json/json.hpp \
common/json/impl/boost/boost_json.hpp

# Libraries objects to be listed here
noinst_LIBRARIES = \
libjson.a

# For each library, set the source(s)
libjson_a_SOURCES = common/json/impl/boost/boost_json.cpp

# Auth daemon
AUTH_SOURCES = mender-auth/main.cpp
men_authd_SOURCES = $(COMMON_SOURCES) $(AUTH_SOURCES)
men_authd_LDADD = $(LIBRARIES)

# Update daemon
UPDATE_SOURCES = mender-update/main.cpp
men_updated_SOURCES = $(COMMON_SOURCES) $(UPDATE_SOURCES)
men_updated_LDADD = $(LIBRARIES)
SUBDIRS = common vendor mender-auth mender-update
12 changes: 7 additions & 5 deletions autogen.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
#!/bin/sh
set -e

if [ ! -f "$(dirname "$0")/vendor/googletest/README.md" ] ; then
echo "Please run the following to clone submodules first:"
echo " git submodule update --init"
exit 1
fi

if [ ! -f "$(dirname "$0")/vendor/boost/libs/json/README.md" ] ; then
echo "Please initialize and build required Boost libraries with:"
echo " ./bootstrap_boost.sh"
exit 1
if [ ! -f "$(dirname "$0")/vendor/boost/b2" ] ; then
$(dirname "$0")/bootstrap_boost.sh
fi

( cd "$(dirname "$0")" && autoreconf -i )
cd "$(dirname "$0")"
aclocal --install
autoreconf --install

2 changes: 1 addition & 1 deletion bootstrap_boost.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ JSON_LIB_DEPENDS_SUBMODULES=" \
libs/throw_exception \
"

echo "==== Bootstrapping boost ===="
(
cd "$(dirname "$0")/vendor/boost"
git submodule init
git submodule update tools/build tools/boost_install
git submodule update $JSON_LIB_DEPENDS_SUBMODULES
./bootstrap.sh
./b2 --build-dir=build --prefix=install link=static install
)
15 changes: 15 additions & 0 deletions common/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
AUTOMAKE_OPTIONS = subdir-objects

BUILT_SOURCES = $(builddir)/../vendor/libboost_json.built

$(builddir)/../vendor/libboost_%.built:
$(MAKE) -C $(builddir)/../vendor libboost_$*.built

# Libraries objects to be listed here
noinst_LTLIBRARIES = \
libjson.la

# For each library, set the source(s)
libjson_la_SOURCES = $(srcdir)/json/impl/boost/boost_json.cpp
libjson_la_CPPFLAGS = $(BOOST_CPPFLAGS) -I $(srcdir)/../
libjson_la_LIBADD = $(BOOST_JSON_LIB)
4 changes: 3 additions & 1 deletion common/json/impl/boost/boost_json.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <iostream>
#include <boost/json/value.hpp>
#include <boost/json/serializer.hpp>

#include <common/json/impl/boost/boost_json.hpp>
#include <boost/json/src.hpp>

namespace json
{
Expand Down
55 changes: 35 additions & 20 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
m4_define([version], m4_normalize(m4_esyscmd([git describe --exact HEAD 2>/dev/null || git rev-parse --short HEAD])))
AC_INIT([mender], [version], [[email protected]])
m4_define([mender_version], m4_normalize(m4_esyscmd([git describe --exact HEAD 2>/dev/null || git rev-parse --short HEAD])))
AC_INIT([mender], [mender_version], [[email protected]])
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([-Wall -Werror foreign])
AM_SILENT_RULES([yes])
AM_INIT_AUTOMAKE([-Wall -Werror -Wno-portability foreign])

dnl Use the m4 directory for m4 macros (convention):
AC_CONFIG_MACRO_DIR([m4])

AM_SILENT_RULES([yes])

AM_PROG_AR
LT_INIT([disable-shared])

Expand All @@ -17,26 +18,40 @@ dnl (Make these variables available for use in Makefile.am)
AM_CONDITIONAL([LINUX], [test -n "`echo ${target_os} | grep linux`"])
AM_CONDITIONAL([MACOSX], [test -n "`echo ${target_os} | grep darwin`"])


dnl TODO: Switch to Boost from OS packages and configure the build with:
dnl https://www.gnu.org/software/autoconf-archive/ax_boost_base.html
dnl https://www.gnu.org/software/autoconf-archive/ax_boost_json.html
dnl
dnl AX_BOOST_BASE([1.75.0],
dnl [AC_SUBST([boost_CPPFLAGS], [${BOOST_CPPFLAGS}])
dnl AC_MSG_NOTICE([boost_CPPFLAGS : ${boost_CPPFLAGS}])
dnl AC_MSG_NOTICE([boost_LDFLAGS : ${boost_LDFLAGS}])],
dnl [AC_MSG_ERROR([Boost 1.75.0 or later is required but was not found.])])
dnl AX_BOOST_JSON
dnl AC_SUBST([boost_json_LIBS], [${BOOST_JSON_LIB}])
dnl AC_MSG_NOTICE([boost_json_LIBS : ${boost_json_LIBS}])
BOOST_VENDOR_DIR="`cd $(dirname $0); pwd`/vendor/boost"
AC_CACHE_CHECK([whether Boost was bootstrapped (at ${BOOST_VENDOR_DIR})],
ax_cv_boost_bootstrapped,
AS_IF([test -f "${BOOST_VENDOR_DIR}/b2"],
[ax_cv_boost_bootstrapped=yes],
[ax_cv_boost_bootstrapped=no]
)
)
AS_IF([test "x$ax_cv_boost_bootstrapped" != "xyes"],
[AC_MSG_ERROR([Boost at ${BOOST_VENDOR_DIR} not boostrapped])]
)

BOOST_INSTALL_DIR="${BOOST_VENDOR_DIR}/install"
BOOST_CPPFLAGS="-I ${BOOST_INSTALL_DIR}/include"
BOOST_LDFLAGS="-L${BOOST_INSTALL_DIR}/lib"
AC_SUBST(BOOST_CPPFLAGS)
AC_SUBST(BOOST_LDFLAGS)
AC_MSG_NOTICE([BOOST_CPPFLAGS : ${BOOST_CPPFLAGS}])
AC_MSG_NOTICE([BOOST_LDFLAGS : ${BOOST_LDFLAGS}])

BOOST_JSON_LIB="-lboost_json"
AC_SUBST(BOOST_JSON_LIB)
AC_MSG_NOTICE([BOOST_JSON_LIB : ${BOOST_JSON_LIB}])

AC_CONFIG_HEADERS([config.h])
AC_CONFIG_FILES([
Makefile
Makefile
common/Makefile
vendor/Makefile
mender-auth/Makefile
mender-update/Makefile
])

dnl Set C++ standard
CXXFLAGS="$CXXFLAGS -std=c++11"
dnl Set C++ standard and a few nice compiler options
CXXFLAGS="$CXXFLAGS -std=c++11 -Wall -Werror"

AC_OUTPUT
12 changes: 12 additions & 0 deletions mender-auth/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
AUTOMAKE_OPTIONS = subdir-objects

ACLOCAL_AMFLAGS = -I m4

AM_CPPFLAGS = -I $(srcdir)/..

bin_PROGRAMS = men-authd

# Auth daemon
men_authd_SOURCES = main.cpp
men_authd_LDFLAGS = $(BOOST_LDFLAGS)
men_authd_LDADD = $(builddir)/../common/libjson.la
12 changes: 12 additions & 0 deletions mender-update/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
AUTOMAKE_OPTIONS = subdir-objects

ACLOCAL_AMFLAGS = -I m4

AM_CPPFLAGS = -I$(srcdir)/..

bin_PROGRAMS = men-updated

# Auth daemon
men_updated_SOURCES = main.cpp
men_updated_LDFLAGS = $(BOOST_LDFLAGS)
men_updated_LDADD = $(builddir)/../common/libjson.la
12 changes: 12 additions & 0 deletions vendor/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
AUTOMAKE_OPTIONS = subdir-objects

libboost_%.built:
$(SHELL) -c "cd $(srcdir)/boost; ./b2 --build-dir=build --prefix=install --with-$* link=static install"
touch libboost_$*.built

clean-local:
$(SHELL) -c "cd $(srcdir)/boost; git clean -df"
rm -f libboost_*.built

distclean-local:
$(SHELL) -c "cd $(srcdir)/boost; git clean -xdf"

0 comments on commit 11253e4

Please sign in to comment.