From f10ff96c5c51e51335bbcbda1096203d4eec3b1d Mon Sep 17 00:00:00 2001 From: Mark Bishop Date: Tue, 30 Jan 2024 13:11:40 -0500 Subject: [PATCH] Add build date from git and dont add debug info by default (#264) --- .gitignore | 3 ++- Makefile.am | 5 ++++- configure.ac | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index a000016..6ccaa20 100644 --- a/.gitignore +++ b/.gitignore @@ -44,4 +44,5 @@ test.conf __pycache__/ Vagrantfile .isort.cfg -.vagrant/ \ No newline at end of file +.vagrant/ +build-date diff --git a/Makefile.am b/Makefile.am index 7f9e81b..fcba0ba 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,6 +8,7 @@ # ACLOCAL_AMFLAGS = -I autotools +SOURCE_DATE_EPOCH=$(shell cat $(builddir)/build-date) SUBDIRS = compat lib login_duo duo_unix_support @@ -18,7 +19,7 @@ endif SUBDIRS += tests SUBDIRS += tests/unity_tests -dist_doc_DATA = README.md CONTRIBUTING.md AUTHORS CHANGES $(wildcard sbom.spdx) +dist_doc_DATA = README.md CONTRIBUTING.md AUTHORS CHANGES $(wildcard $(builddir)/build-date) $(wildcard sbom.spdx) LICENSES = $(wildcard LICENSES/*.txt) @@ -30,3 +31,5 @@ DISTCHECK_CONFIGURE_FLAGS = --sysconfdir='$${prefix}/etc' if PAM DISTCHECK_CONFIGURE_FLAGS += --with-pam='$${prefix}/lib/security' endif + +DISTCLEANFILES = $(builddir)/build-date diff --git a/configure.ac b/configure.ac index 207d2cb..4cb3f8a 100644 --- a/configure.ac +++ b/configure.ac @@ -41,6 +41,36 @@ AC_PROG_INSTALL AC_PROG_MKDIR_P LT_INIT +AC_MSG_NOTICE(checking if we can establish a build date) +AC_PATH_TOOL(GIT,[git]) +AS_IF([test x"$GIT" != x], [ + AC_MSG_CHECKING(are we configuring inside a git repository) + $GIT rev-parse 2>/dev/null + is_git_repo=$? + AS_IF([test $is_git_repo == 0], [ + AC_MSG_RESULT(yes) + AC_MSG_CHECKING(is the current working tree clean) + $GIT update-index --really-refresh + $GIT diff-index --quiet HEAD + AS_IF([test $? == 0], + [ + AC_MSG_RESULT(yes) + source_date_epoch=`$GIT show -s --format=%ct` + AC_MSG_NOTICE(setting build-date to $source_date_epoch) + echo "$source_date_epoch" > build-date + ], + [ + AC_MSG_RESULT(no current working tree is dirty) + AC_MSG_NOTICE(removing build-date) + rm -f build-date + ] + ) + ], + [ + AC_MSG_RESULT(no) + ]) +]) + # Set third party library versions unity_version=Unity-2.5.2 AC_DEFINE_DIR([UNITY_VERSION], [unity_version], [Unity directory name]) @@ -127,6 +157,20 @@ AS_IF([test "x$with_coverage" != "xno"], [ AC_MSG_NOTICE([--coverage enabled in CFLAGS]) ]) +AC_ARG_WITH(debug, + AS_HELP_STRING([--with-debug=DBG],[build with debug info]), + [], + [ with_debug=no ] +) +AM_CONDITIONAL([DEBUG], [ test "x$with_debug" != "xno" ]) +AS_IF([test "x$with_debug" != "xno"], [ + CFLAGS="$CFLAGS -g2" + AC_MSG_NOTICE([debugging enabled in CFLAGS]) +]) +AS_IF([test "x$with_debug" == "xno"], [ + CFLAGS="$CFLAGS -g0" +]) + # Check PAM AC_ARG_WITH(pam, AS_HELP_STRING([--with-pam=DIR],[build PAM module (and optionally override the default install DIR)]),