From 6bf4d138cbef0108a071029195926ea0f259a951 Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Wed, 4 Jan 2012 17:25:24 +0100 Subject: [PATCH] add --version option Signed-off-by: Sven Verdoolaege --- Makefile.am | 8 ++++++++ configure.ac | 3 +++ m4/ax_detect_git_head.m4 | 27 +++++++++++++++++++++++++++ options.c | 7 +++++++ version.c | 6 ++++++ version.h | 1 + 6 files changed, 52 insertions(+) create mode 100644 m4/ax_detect_git_head.m4 create mode 100644 version.c create mode 100644 version.h diff --git a/Makefile.am b/Makefile.am index 1f931f0..b2416fa 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,6 +39,8 @@ libpet_la_SOURCES = \ scop.c \ scop_plus.h \ scop_plus.cc \ + version.h \ + version.c \ pet.cc libpet_la_LDFLAGS = -version-info @versioninfo@ $(AM_LDFLAGS) libpet_la_LIBADD = -lclangFrontend -lclangParse -lclangSema -lclangAnalysis \ @@ -63,3 +65,9 @@ pet_scop_cmp_SOURCES = \ scop_yaml.h \ parse.c \ pet_scop_cmp.c + +dist-hook: + echo @GIT_HEAD_VERSION@ > $(distdir)/GIT_HEAD_ID + +gitversion.h: @GIT_HEAD@ + $(AM_V_GEN)echo '#define GIT_HEAD_ID "'@GIT_HEAD_VERSION@'"' > $@ diff --git a/configure.ac b/configure.ac index ee1c552..7dae5bf 100644 --- a/configure.ac +++ b/configure.ac @@ -92,6 +92,9 @@ PACKAGE_CFLAGS="$PACKAGE_CFLAGS_ISL" PACKAGE_LIBS="-lpet -lisl" AX_CREATE_PKGCONFIG_INFO +AX_DETECT_GIT_HEAD +echo '#define GIT_HEAD_ID "'$GIT_HEAD_ID'"' > gitversion.h + AC_CONFIG_HEADERS(config.h) AC_CONFIG_FILES(Makefile) AC_CONFIG_FILES([pet_test.sh], [chmod +x pet_test.sh]) diff --git a/m4/ax_detect_git_head.m4 b/m4/ax_detect_git_head.m4 new file mode 100644 index 0000000..d585983 --- /dev/null +++ b/m4/ax_detect_git_head.m4 @@ -0,0 +1,27 @@ +AC_DEFUN([AX_DETECT_GIT_HEAD], [ + AC_SUBST(GIT_HEAD_ID) + AC_SUBST(GIT_HEAD) + AC_SUBST(GIT_HEAD_VERSION) + if test -f $srcdir/.git/HEAD; then + GIT_HEAD="$srcdir/.git/index" + GIT_REPO="$srcdir/.git" + GIT_HEAD_ID=`GIT_DIR=$GIT_REPO git describe` + elif test -f $srcdir/GIT_HEAD_ID; then + GIT_HEAD_ID=`cat $srcdir/GIT_HEAD_ID` + else + mysrcdir=`(cd $srcdir; pwd)` + head=`basename $mysrcdir | sed -e 's/.*-//'` + head2=`echo $head | sed -e 's/[^0-9a-f]//'` + head3=`echo $head2 | sed -e 's/........................................//'` + if test "x$head3" = "x" -a "x$head" = "x$head2"; then + GIT_HEAD_ID="$head" + else + GIT_HEAD_ID="UNKNOWN" + fi + fi + if test -z "$GIT_REPO" ; then + GIT_HEAD_VERSION="$GIT_HEAD_ID" + else + GIT_HEAD_VERSION="\`GIT_DIR=$GIT_REPO git describe\`" + fi +]) diff --git a/options.c b/options.c index ec66ac2..ca363be 100644 --- a/options.c +++ b/options.c @@ -32,6 +32,12 @@ */ #include "options.h" +#include "version.h" + +static void print_version(void) +{ + printf("%s", pet_version()); +} ISL_ARGS_START(struct pet_options, pet_options_args) ISL_ARG_BOOL(struct pet_options, autodetect, 0, "autodetect", 0, NULL) @@ -39,6 +45,7 @@ ISL_ARG_STR_LIST(struct pet_options, n_path, paths, 'I', "include-path", "path", NULL) ISL_ARG_STR_LIST(struct pet_options, n_define, defines, 'D', NULL, "macro[=defn]", NULL) +ISL_ARG_VERSION(print_version) ISL_ARGS_END ISL_ARG_DEF(pet_options, struct pet_options, pet_options_args) diff --git a/version.c b/version.c new file mode 100644 index 0000000..fdb600b --- /dev/null +++ b/version.c @@ -0,0 +1,6 @@ +#include "gitversion.h" + +const char *pet_version(void) +{ + return GIT_HEAD_ID"\n"; +} diff --git a/version.h b/version.h new file mode 100644 index 0000000..2d0801c --- /dev/null +++ b/version.h @@ -0,0 +1 @@ +const char *pet_version(void); -- 2.11.4.GIT