summaryrefslogtreecommitdiffstats
path: root/cpukit/sapi
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2017-11-07 16:43:11 +1100
committerChris Johns <chrisj@rtems.org>2017-11-10 13:34:06 +1100
commit6f3fb8a547f5700416744a7dc82b3cb83177c7a8 (patch)
tree5a5869b9dcf63196c0c1ef06b2ccdc4006d48f05 /cpukit/sapi
parentpppd/Makefile.am: Add support/include (diff)
downloadrtems-6f3fb8a547f5700416744a7dc82b3cb83177c7a8.tar.bz2
cpukit: Add a Version API.
Provide functions to get the version string, major, minor and revision numbers and the version control identifer that is a unique tag for the version control system. Update #3199.
Diffstat (limited to 'cpukit/sapi')
-rw-r--r--cpukit/sapi/Makefile.am38
-rw-r--r--cpukit/sapi/include/rtems/version.h77
-rw-r--r--cpukit/sapi/preinstall.am4
-rw-r--r--cpukit/sapi/src/version.c63
-rwxr-xr-xcpukit/sapi/vc-key.sh39
-rw-r--r--cpukit/sapi/version-vc-key.h.in7
6 files changed, 227 insertions, 1 deletions
diff --git a/cpukit/sapi/Makefile.am b/cpukit/sapi/Makefile.am
index 50d065be7e..a38d86374e 100644
--- a/cpukit/sapi/Makefile.am
+++ b/cpukit/sapi/Makefile.am
@@ -22,6 +22,7 @@ include_rtems_HEADERS += include/rtems/rbtree.h
include_rtems_HEADERS += include/rtems/scheduler.h
include_rtems_HEADERS += include/rtems/timecounter.h
include_rtems_HEADERS += include/rtems/timespec.h
+include_rtems_HEADERS += include/rtems/version.h
EXTRA_DIST = include/rtems/README
@@ -34,7 +35,7 @@ libsapi_a_SOURCES = src/extension.c src/extensioncreate.c \
src/getversionstring.c \
src/chainappendnotify.c src/chaingetnotify.c src/chaingetwait.c \
src/chainprependnotify.c src/rbheap.c src/interrtext.c \
- src/fatalsrctext.c
+ src/fatalsrctext.c src/version.c
libsapi_a_SOURCES += src/chainprotected.c
libsapi_a_SOURCES += src/cpucounterconverter.c
libsapi_a_SOURCES += src/delayticks.c
@@ -47,5 +48,40 @@ libsapi_a_SOURCES += src/profilingreportxml.c
libsapi_a_SOURCES += src/tcsimpleinstall.c
libsapi_a_CPPFLAGS = $(AM_CPPFLAGS)
+#
+# Create a new Version VC Key header if the VC state has changed.
+#
+vc_key_stamp = $(am__leading_dot)vc-key-stamp
+
+libsapi_a_CPPFLAGS += -I.
+
+BUILT_SOURCES = version-vc-key.h
+
+.PHONY: $(vc_key_stamp)
+
+$(vc_key_stamp):
+
+version-vc-key.h: $(vc_key_stamp)
+ @+current_vc_key=""; \
+ if test -f $(vc_key_stamp); then \
+ current_vc_key=`cat $(vc_key_stamp)`; \
+ fi; \
+ vc_key=`$(top_srcdir)/sapi/vc-key.sh $(top_srcdir) $$current_vc_key`; \
+ if test "$$vc_key" != "matches"; then \
+ echo "Generating version-vc-key.h"; \
+ if test "$$vc_key" == "release"; then \
+ vc_header_key="\/\* No version control key found; release\? \*\/"; \
+ else \
+ vc_header_key="#define RTEMS_VERSION_VC_KEY \"$$vc_key\""; \
+ fi; \
+ cat $(top_srcdir)/sapi/version-vc-key.h.in | \
+ sed -e "s/@VERSION_VC_KEY@/$$vc_header_key/g" > version-vc-key.h; \
+ echo "$$vc_key" > $(vc_key_stamp); \
+ fi
+
+version.$(OBJEXT):$ version-vc-key.h
+
+all-local: version-vc-key.h
+
include $(srcdir)/preinstall.am
include $(top_srcdir)/automake/local.am
diff --git a/cpukit/sapi/include/rtems/version.h b/cpukit/sapi/include/rtems/version.h
new file mode 100644
index 0000000000..b806cb8c2f
--- /dev/null
+++ b/cpukit/sapi/include/rtems/version.h
@@ -0,0 +1,77 @@
+/**
+ * @file
+ *
+ * @brief Version API.
+ */
+
+/*
+ * Copyright (C) 2017.
+ * Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#ifndef _RTEMS_VERSION_H
+#define _RTEMS_VERSION_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @defgroup ClassicVersion Version
+ *
+ * @ingroup ClassicVersion
+ *
+ * @brief The Version API provides functions to return the version or parts of
+ * the version of RTEMS you are using.
+ */
+/**@{**/
+
+/**
+ * @brief Returns the version string.
+ *
+ * @retval text The version as a string.
+ */
+const char *rtems_version( void );
+
+/**
+ * @brief Returns the version's major number.
+ *
+ * @retval int The version's major number.
+ */
+int rtems_version_major( void );
+
+/**
+ * @brief Returns the version's minor number.
+ *
+ * @retval int The version's minor number.
+ */
+int rtems_version_minor( void );
+
+/**
+ * @brief Returns the version's revision number.
+ *
+ * @retval int The version's revision number.
+ */
+int rtems_version_revision( void );
+
+/**
+ * @brief Returns the version control key for the current version of code that
+ * has been built. The key is specific to the version control system being used
+ * and allows the built version to be identified.
+ *
+ * @retval int The version's version control key.
+ */
+const char *rtems_version_control_key( void );
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+/* end of include file */
diff --git a/cpukit/sapi/preinstall.am b/cpukit/sapi/preinstall.am
index b1bdf48ac2..a6b0ba30df 100644
--- a/cpukit/sapi/preinstall.am
+++ b/cpukit/sapi/preinstall.am
@@ -94,3 +94,7 @@ $(PROJECT_INCLUDE)/rtems/timespec.h: include/rtems/timespec.h $(PROJECT_INCLUDE)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/timespec.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/timespec.h
+$(PROJECT_INCLUDE)/rtems/version.h: include/rtems/version.h $(PROJECT_INCLUDE)/rtems/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/rtems/version.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/rtems/version.h
+
diff --git a/cpukit/sapi/src/version.c b/cpukit/sapi/src/version.c
new file mode 100644
index 0000000000..d240b1b0df
--- /dev/null
+++ b/cpukit/sapi/src/version.c
@@ -0,0 +1,63 @@
+/**
+ * @file
+ *
+ * @brief Creates the version strings from the various pieces of version
+ * information. The main version number is part of the build system and is
+ * stamped into rtems/score/cpuopts.h. The version control key string is
+ * extracted from the version control tool when the code is being built and is
+ * updated if it has changed. The key may indicate there are local
+ * modification.
+ *
+ * @ingroup ClassicVersion
+ */
+
+/*
+ * Copyright (C) 2017.
+ * Chris Johns <chrisj@rtems.org>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.org/license/LICENSE.
+ */
+
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <rtems.h>
+#include <rtems/version.h>
+
+#include "version-vc-key.h"
+
+const char *rtems_version( void )
+{
+#ifdef RTEMS_VERSION_VC_KEY
+ return RTEMS_VERSION "." RTEMS_VERSION_VC_KEY;
+#else
+ return RTEMS_VERSION;
+#endif
+}
+
+int rtems_version_major( void )
+{
+ return __RTEMS_MAJOR__;
+}
+
+int rtems_version_minor( void )
+{
+ return __RTEMS_MINOR__;
+}
+
+int rtems_version_revision( void )
+{
+ return __RTEMS_REVISION__;
+}
+
+const char *rtems_version_control_key( void )
+{
+#ifdef RTEMS_VERSION_VC_KEY
+ return RTEMS_VERSION_VC_KEY;
+#else
+ return NULL;
+#endif
+}
diff --git a/cpukit/sapi/vc-key.sh b/cpukit/sapi/vc-key.sh
new file mode 100755
index 0000000000..c628a1e26d
--- /dev/null
+++ b/cpukit/sapi/vc-key.sh
@@ -0,0 +1,39 @@
+#! /bin/sh
+
+git=$(command -v git)
+
+#
+# Git command not found or not a valid git repo is a release.
+#
+vc_ident="release"
+
+if test $# -ge 1; then
+ repo=$1
+ shift
+ if test -d $repo; then
+ cwd=$(pwd)
+ cd $repo
+ if test -n ${git}; then
+ git rev-parse --git-dir > /dev/null 2>&1
+ if test $? == 0; then
+ git status > /dev/null 2>&1
+ if git diff-index --quiet HEAD --; then
+ modified=""
+ else
+ modified="-modified"
+ fi
+ vc_ident="$(git rev-parse --verify HEAD)${modified}"
+ if test $# -ge 1; then
+ if test "${vc_ident}" == "$1"; then
+ vc_ident="matches"
+ fi
+ fi
+ fi
+ fi
+ cd $cwd
+ fi
+fi
+
+echo ${vc_ident}
+
+exit 0
diff --git a/cpukit/sapi/version-vc-key.h.in b/cpukit/sapi/version-vc-key.h.in
new file mode 100644
index 0000000000..738e24d19d
--- /dev/null
+++ b/cpukit/sapi/version-vc-key.h.in
@@ -0,0 +1,7 @@
+/*
+ * Automatically generated. Do not edit.
+ */
+#if !defined(_RTEMS_VERSION_VC_KEY_H_)
+#define _RTEMS_VERSION_VC_KEY_H_
+@VERSION_VC_KEY@
+#endif