From fd534aa751b269af8792ee617ffa26aaf6718b01 Mon Sep 17 00:00:00 2001
From: Ger van Diepen <diepen@astron.nl>
Date: Wed, 26 Mar 2008 08:03:21 +0000
Subject: [PATCH] bug 468: Improved to deal better with SAS/MAC code

---
 autoconf_share/lofar_external.m4 |  6 +--
 autoconf_share/lofar_internal.m4 | 13 ++++-
 autoconf_share/makeversion       | 82 +++++++++++++++++++-------------
 3 files changed, 63 insertions(+), 38 deletions(-)

diff --git a/autoconf_share/lofar_external.m4 b/autoconf_share/lofar_external.m4
index 1b4070e27a7..682970ff9dd 100644
--- a/autoconf_share/lofar_external.m4
+++ b/autoconf_share/lofar_external.m4
@@ -128,6 +128,7 @@ fi
 ## Also determine the given search path.
 ##
 lfr_ext_name=]LOFAR_EXT_LIB[
+external_search=
 enable_external=no
 if test "$lfr_option" = "1"; then
   enable_external=yes
@@ -140,14 +141,11 @@ if test "$with_external" = "no"; then
   fi
 else
   if test "$with_external" = ""; then
-    external_search=
     if test "$lfr_external_libdir" != ""; then
       enable_external=yes
     fi
   else
-    if test "$with_external" = "yes"; then
-      external_search=
-    else
+    if test "$with_external" != "yes"; then
       external_search=$with_external
     fi
     enable_external=yes
diff --git a/autoconf_share/lofar_internal.m4 b/autoconf_share/lofar_internal.m4
index 0dbf4b9ac8d..cda3e842e6f 100644
--- a/autoconf_share/lofar_internal.m4
+++ b/autoconf_share/lofar_internal.m4
@@ -28,24 +28,33 @@
 # internal and external packages.
 #
 # lofar_INTERNAL(package-path, package, [cvs-versiontag],
-#            [option], headerfile, [libraries], [searchpath].
+#            [option], headerfile, [libraries], [searchpath],
 #            [extra_cppflags],[extra_cxxflags],[extra_ldflags],[extra_libs])
 #
 # E.g.
 #   lofar_INTERNAL(LCS/Common, Common, 1.3,, Common/LofarLogger.h)
+#   lofar_INTERNAL(MAC/GCF/TM, GCFTM, 0.9,, GCF/TM/file.h)
 #
 #
 AC_DEFUN([lofar_INTERNAL],dnl
 [dnl
 AC_PREREQ(2.13)dnl
 lfr_pkgnam_intv=$2
+lfr_hdrfile=$5
 lofar_EXTERNAL($2,$4,$5,$6,$7,$8,$9,$10,$11)
 [
+  # Get the include path of the header file.
+  # This will be used for the include path of Package_Version.h.
+  if test "$lfr_hdrfile" = ""; then
+    lfr_hdrpath=$lfr_pkgnam_intv
+  else
+    lfr_hdrpath=`dirname $lfr_hdrfile`
+  fi
   # If this package was configured in, add the statements to get the
   # version of this package.
   # The Tools package is special and not handled.
   if [ "$enable_external" = "yes"  -a  "${lfr_pkgnam_intv}" != Tools ]; then
-    echo "#include \"${lfr_pkgnam_intv}/Package__Version.h\"" >> FillPackage__VersionInc.h
+    echo "#include \"${lfr_hdrpath}/Package__Version.h\"" >> FillPackage__VersionInc.h
     # If the current FillPackage__VersionFunc.h is the same as the old one, copy the
     # old one back, while preserving creation date and time.
     diff FillPackage__VersionInc.h FillPackage__VersionInc.old-h > /dev/null 2>&1
diff --git a/autoconf_share/makeversion b/autoconf_share/makeversion
index 7c2c4a6f411..88ffd4df0bc 100755
--- a/autoconf_share/makeversion
+++ b/autoconf_share/makeversion
@@ -22,14 +22,23 @@
 #
 #  $Id$
 
-# It creates files <package>Version.h and .cc containing a class to
-# return the version and revision of the package.
+# This script creates files <package>Version.h and .cc containing a class
+# to return the version and revision of the package.
 # The .cc fle includes a file which gets created by lofar_init.m4 and filled
 # by lofar_internal.m4 which contains the packages it is dependent on.
 # It also creates an file version<package>.cc which is an executable program
 # to print the version.
 # Optionally the Makefile.am files are changed to build the code.
 
+# The class name used is <package>Version, for eaxmple CommonVersion.
+# makeversion retrieves the package name from the basename of the current
+# directory which works fine for the normal cases. However, MAC uses some
+# special directory structure like GCF/TM/include/GCF/TM. It also detects
+# this and sets in this example the package name to GCFTM (removes the /).
+# In lofar_internal.m4 the package name given as the second argument has
+# to match the package name found here, thus must be GCFTM in this example.
+# lofar_internal.m4 derives the include path from the given header file.
+
 # Determine which parts of the version info have to be made.
 # if the main program versionXXX has to be made.
 #   0 = do not change the Makefile.am (is the default)
@@ -47,32 +56,33 @@ fi
 # Get the package name (also in lower and uppercase).
 fpkg=`pwd`
 pkg=`basename $fpkg`
-lpkg=`echo $pkg | tr A-Z a-z`
-upkg=`echo $pkg | tr a-z A-Z`
 
-# No version info is needed if the package has no src/Makefile.am.
+# No version info is needed if thee is src/Makefile.am or configure.in.
 # Also not needed (in fact, not possible) for Tools.
-if [ ! -e src/Makefile.am  -o  "$pkg" = Tools ]; then
+if [ ! -e src/Makefile.am  -o  ! -e configure.in  -o  "$pkg" = Tools ]; then
   exit 0
 fi
 
-# Get the include directory (which is usually include/package, but can be src).
-# MAC uses something like GCF/TM/include/GCF/TM, thus uses more levels (up to 2).
+# Take the package from the configure.in if defined in there.
+# It looks like: AM_INIT_AUTOMAKE(GCFProtocols, 6.1, no-define)
+tpkg=`grep AM_INIT_AUTOMAKE configure.in | sed -e 's/.*(//' -e 's/[,)].*//' -e 's/ //g'`
+if test "$tpkg" != ""; then
+  pkg=$tpkg
+fi
+
+# If the include directory exists, find the include path from its Makefile.am
+# Otherwise header files are in src and <package> is the include path.
+
 # Exit if both not existing.
-incdir="include/$pkg"
-incpath="$pkg"
-if [ ! -d $incdir ]; then
-  rpkg=`dirname $fpkg`
-  npkg=`basename $rpkg`
-  incdir="include/$npkg/$pkg"
-  incpath="$npkg/$pkg"
-  if [ ! -d  $incdir ]; then
-    incdir=src
-    incpath="$pkg"
+incdir="src"
+incpath=$pkg
+if [ -e include/Makefile.am ]; then
+  incpath=`grep SUBDIRS include/Makefile.am | sed -e 's/.*=//' -e 's/#.*//' -e 's/ //g'`
+  if test "$incpath" = ""; then
+    echo "Could not derive include path fom SUBDIRS in $pkg/include/Makefile.am"
+    exit 1
   fi
-fi
-if [ ! -d $incdir ]; then
-  exit 0
+  incdir=include/$incpath
 fi
 
 # Get version and revision (if possible) from repository.
@@ -82,7 +92,7 @@ rvers=Unknown
 grev=Unknown
 lrev=Unknown
 nrch=0
-svn info 2>&1 > version.svn.tmp
+svn info > version.svn.tmp 2>&1
 hassvn=$?
 if [ $hassvn = 0 ]; then
   # Get version.
@@ -97,7 +107,7 @@ if [ $hassvn = 0 ]; then
   grev=`fgrep 'Revision: ' version.svn.tmp | sed -e 's/.*: *//'`
   lrev=`fgrep 'Last Changed Rev: ' version.svn.tmp | sed -e 's/.*: *//'`
   # Check if there are locally modified files (excluding Makefile.am)
-  svn status | egrep '^M ' | fgrep -v Makefile.am 2>&1 > version.svn.tmp
+  svn status | egrep '^M ' | fgrep -v Makefile.am > version.svn.tmp 2>&1
   if [ $? ]; then
     nrch=`wc -l version.svn.tmp | sed -e 's/^ *//' | sed -e 's/ .*//'`
   fi
@@ -110,6 +120,10 @@ if test -f configure.in; then
   fi
 fi
 
+# Get package name in lower and uppercase
+lpkg=`echo $pkg | tr A-Z a-z`
+upkg=`echo $pkg | tr a-z A-Z`
+
 # Create temporary version.h/cc
 cat > version.h.tmp <<EOF
 //# Get revision info; generated by autoconf_share/makeversion
@@ -157,6 +171,10 @@ EOF
 cat > version.cc.tmp <<EOF
 //# Get revision info; generated by autoconf_share/makeversion
 
+//## pkg=$pkg
+//## incpath=$incpath
+//## incdir=$incdir
+
 #include <${incpath}/Package__Version.h>
 #include <Common/Version.h>
 #include "FillPackage__VersionInc.h"
@@ -214,7 +232,7 @@ if [ ! -e $incdir/Package__Version.h ]; then
   echo "makeversion created $incdir/Package__Version.h"
   cp version.h.tmp $incdir/Package__Version.h
 elif [ $hassvn = 0 ]; then
-  diff version.h.tmp $incdir/Package__Version.h 2>&1 > /dev/null
+  diff version.h.tmp $incdir/Package__Version.h > /dev/null 2>&1
   if [ $? != 0 ]; then
     echo "makeversion replaced $incdir/Package__Version.h"
     cp version.h.tmp $incdir/Package__Version.h
@@ -225,7 +243,7 @@ if [ ! -e src/Package__Version.cc ]; then
   echo "makeversion created src/Package__Version.cc"
   cp version.cc.tmp src/Package__Version.cc
 elif [ $hassvn = 0 ]; then
-  diff version.cc.tmp src/Package__Version.cc 2>&1 > /dev/null
+  diff version.cc.tmp src/Package__Version.cc > /dev/null 2>&1
   if [ $? != 0 ]; then
     echo "makeversion replaced src/Package__Version.cc"
     cp version.cc.tmp src/Package__Version.cc
@@ -237,7 +255,7 @@ if [ ! -e src/${versmainname}.cc ]; then
   echo "makeversion created src/${versmainname}.cc"
   cp version.mcc.tmp src/${versmainname}.cc
 elif [ $hassvn = 0 ]; then
-  diff version.mcc.tmp src/${versmainname}.cc 2>&1 > /dev/null
+  diff version.mcc.tmp src/${versmainname}.cc > /dev/null 2>&1
   if [ $? != 0 ]; then
     echo "makeversion replaced src/${versmainname}.cc"
     cp version.mcc.tmp src/${versmainname}.cc
@@ -270,9 +288,9 @@ if [ "$libnm" = "" ]; then
 fi
 
 # Add lines to Makefile.am files as needed.
-fgrep Package__Version.h $incdir/Makefile.am 2>&1 > /dev/null
+fgrep Package__Version.h $incdir/Makefile.am > /dev/null 2>&1
 if [ $? != 0 ]; then
-  fgrep pkginclude_HEADERS $incdir/Makefile.am 2>&1 > /dev/null
+  fgrep pkginclude_HEADERS $incdir/Makefile.am > /dev/null 2>&1
   if [ $? = 0 ]; then
     sed -e "s/\(pkginclude_HEADERS.*\)=/\1= Package__Version.h /" $incdir/Makefile.am > version.mf.tmp
   else
@@ -286,9 +304,9 @@ EOF
   echo "makeversion added Package__Version.h to $incdir/Makefile.am"
 fi
 
-fgrep Package__Version.cc src/Makefile.am 2>&1 > /dev/null
+fgrep Package__Version.cc src/Makefile.am > /dev/null 2>&1
 if [ $? != 0 ]; then
-  fgrep lib_LTLIBRARIES src/Makefile.am 2>&1 > /dev/null
+  fgrep lib_LTLIBRARIES src/Makefile.am > /dev/null 2>&1
   if [ $? = 0 ]; then
     sed -e "s/\(${libnm}_la_SOURCES.*\)=/\1= Package__Version.cc /" src/Makefile.am > version.mf.tmp
   else
@@ -303,9 +321,9 @@ EOF
   echo "makeversion added Package__Version.cc to src/Makefile.am"
 fi
 
-fgrep "${versmainname}.cc" src/Makefile.am 2>&1  > /dev/null
+fgrep "${versmainname}.cc" src/Makefile.am > /dev/null 2>&1
 if [ $? != 0 ]; then
-  fgrep "bin_PROGRAMS" src/Makefile.am 2>&1 > /dev/null
+  fgrep "bin_PROGRAMS" src/Makefile.am > /dev/null 2>&1
   if [ $? != 0 ]; then
 # To insert newlines, the expression has to be enclosed in single quotes.
 # However, that means that the env.var. are not replaced.
-- 
GitLab