From 6a49b17ddeeea21150d548d3696b0e97dbccdf79 Mon Sep 17 00:00:00 2001 From: Douglas Clowes Date: Wed, 19 Sep 2012 11:11:13 +1000 Subject: [PATCH] augment and refactor SICS_* defines r3738 | dcl | 2012-09-19 11:11:13 +1000 (Wed, 19 Sep 2012) | 1 line --- site_ansto/Makefile | 13 +++++++++--- site_ansto/extract_version.sh | 38 +++++++++++++++++++++++++++++++++++ site_ansto/site_ansto.c | 14 ++++++++++--- 3 files changed, 59 insertions(+), 6 deletions(-) create mode 100755 site_ansto/extract_version.sh diff --git a/site_ansto/Makefile b/site_ansto/Makefile index 09a7a99d..d7fca454 100644 --- a/site_ansto/Makefile +++ b/site_ansto/Makefile @@ -93,12 +93,19 @@ ifeq (,$(LIB_HTTP)) $(warning LIB_HTTP not found) endif -REVISION = $(shell svn info --recursive .. | grep "Revision:" | sort -u | cut -d ' ' -f 2) +SICS_SITE = $(shell bash extract_version.sh SITE) +SICS_VERSION = $(shell bash extract_version.sh VERSION) +SICS_REVISION = $(shell bash extract_version.sh REVISION) $(shell touch site_ansto.c) -$(info Revision text is "${REVISION}") +$(info Site text is "${SICS_SITE}") +$(info Version text is "${SICS_VERSION}") +$(info Revision text is "${SICS_REVISION}") # DEBUGFLAGS = -Wall -Wextra -Wno-unused -Wno-comment -Wno-switch -CFLAGS = -g $(INCFLAGS) $(DEBUGFLAGS) -std=gnu99 -DREVISION='"${REVISION}"' +CFLAGS = -g $(INCFLAGS) $(DEBUGFLAGS) -std=gnu99 +CFLAGS += -DSICS_SITE='"${SICS_SITE}"' +CFLAGS += -DSICS_VERSION='"${SICS_VERSION}"' +CFLAGS += -DSICS_REVISION='"${SICS_REVISION}"' SRC = ./../.. SITENAME = _ansto diff --git a/site_ansto/extract_version.sh b/site_ansto/extract_version.sh new file mode 100755 index 00000000..11fc0da4 --- /dev/null +++ b/site_ansto/extract_version.sh @@ -0,0 +1,38 @@ +#!/bin/bash +case "${1^^}" in +"ALL"|"") TARGET=ALL;; +"SITE") TARGET=SITE;; +"BRANCH"|"VERSION") TARGET=BRANCH;; +"REVISION") TARGET=REVISION;; +*) TARGET=ALL +esac +function get_branch { + path="$1" + base="UNKNOWN" + while [ "$path" != "http:" ] + do + resp=$base + if [ "$base" == "trunk" ] + then + echo "trunk" + return 0 + fi + base=$(basename $path) + if [ "$base" == "branches" ] + then + echo "${resp}" + return 0 + fi + path=$(dirname $path) + done +} +SICS_VER="$(svn info .. | grep "URL:" | sort -u | cut -d ' ' -f 2 | head -n 1 | xargs basename)" +if [ "sics" == "${SICS_VER}" ] +then + SICS_VER="$(svn info .. | grep "URL:" | sort -u | cut -d ' ' -f 2 | head -n 1 | xargs dirname | xargs basename)" +fi +SICS_VER="$(get_branch "$(svn info .. | grep "URL:" | sort -u | cut -d ' ' -f 2 | head -n 1 )")" +SICS_REV="$(svn info --recursive .. | grep "Revision:" | sort -u | cut -d ' ' -f 2)" +if [[ ${TARGET} == "SITE" || ${TARGET} == "ALL" ]]; then echo "ANSTO"; fi +if [[ ${TARGET} == "BRANCH" || ${TARGET} == "ALL" ]]; then echo "${SICS_VER}"; fi +if [[ ${TARGET} == "REVISION" || ${TARGET} == "ALL" ]]; then echo "${SICS_REV}"; fi diff --git a/site_ansto/site_ansto.c b/site_ansto/site_ansto.c index 7cb5fb3a..da801e53 100644 --- a/site_ansto/site_ansto.c +++ b/site_ansto/site_ansto.c @@ -72,7 +72,11 @@ extern int ANSTO_MakeHistMemory(SConnection *pCon, SicsInterp *pSics, void *pDat int SICS_Site(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]) { char line[132]; +#ifdef SICS_SITE + snprintf(line, 132, "SICS_Site = %s", SICS_SITE); +#else snprintf(line, 132, "SICS_Site = ANSTO"); +#endif SCWrite(pCon, line, eValue); return OKOK; }; @@ -80,7 +84,11 @@ int SICS_Site(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char int SICS_Version(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]) { char line[132]; - snprintf(line, 132, "SICS_Version = BRANCH-2.5"); +#ifdef SICS_VERSION + snprintf(line, 132, "SICS_Version = %s", SICS_VERSION); +#else + snprintf(line, 132, "SICS_Version = UNKNOWN"); +#endif SCWrite(pCon, line, eValue); return OKOK; }; @@ -88,8 +96,8 @@ int SICS_Version(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, ch int SICS_Revision(SConnection *pCon, SicsInterp *pSics, void *pData, int argc, char *argv[]) { char line[132]; -#ifdef REVISION - snprintf(line, 132, "SICS_Revision = %s", REVISION); +#ifdef SICS_REVISION + snprintf(line, 132, "SICS_Revision = %s", SICS_REVISION); #else snprintf(line, 132, "SICS_Revision = UNKNOWN"); #endif