From a3be07c81ae42faca30bee706edc90f992a35be3 Mon Sep 17 00:00:00 2001
From: Ger van Diepen <diepen@astron.nl>
Date: Fri, 31 Aug 2007 09:39:48 +0000
Subject: [PATCH] BugID: 1100 Fixed little errors and typos. Changed some
 templates to adhere to new standards.

---
 LCS/Tools/src/makeClass.py                    | 63 +++++++++++--------
 LCS/Tools/src/makePackage.py                  | 16 +++--
 LCS/Tools/src/makeTest.py                     | 31 ++++-----
 LCS/Tools/src/templates/header.cc_template    |  1 +
 LCS/Tools/src/templates/header.h_template     | 11 +++-
 .../include_pkg_makefile.am_template          |  2 +-
 .../templates/package_lofarconf.in_template   |  3 +-
 .../templates/package_makefile.am_template    |  6 +-
 .../src/templates/src_makefile.am_template    |  4 ++
 .../src/templates/templated_header.h_template | 14 +++--
 LCS/Tools/src/templates/test.cc_template      |  8 +--
 .../src/templates/test_makefile.am_template   | 18 +-----
 12 files changed, 100 insertions(+), 77 deletions(-)

diff --git a/LCS/Tools/src/makeClass.py b/LCS/Tools/src/makeClass.py
index a23b91a9f48..69ff651b5cd 100755
--- a/LCS/Tools/src/makeClass.py
+++ b/LCS/Tools/src/makeClass.py
@@ -15,7 +15,7 @@
 #                           makeClass -t T,U className
 #       d,--diy             Do it yourself (manual template instanciation)
 #                           Only together with -t
-#       m,--main            This is a main class
+#       m,--main            This is a main program for a class
 #
 # Revisions:
 #
@@ -181,14 +181,14 @@ def makeDefaultClass(lofarDir,className,packageName,srcDir,incDir,subDirName):
   replacePackageAndClassName(readFile,writeFile,packageName,className,subDirName)
   writeFile.close()
   readFile.close()
-  addToMakefile("h",className,incDir,subDirName)
+  addToMakefile("h",packageName,className,incDir,subDirName)
   #default.cc file
   readFile=openFile(lofarDir+"/LCS/Tools/src/templates/header.cc_template","r")
   writeFile=openFile(className+".cc","w")
   replacePackageAndClassName(readFile,writeFile,packageName,className,subDirName)
   writeFile.close()
   readFile.close()
-  addToMakefile("cc",className,srcDir,subDirName)
+  addToMakefile("cc",packageName,className,srcDir,subDirName)
 
 def makeTemplatedClass(lofarDir,className,packageName,templateList,autoTemplate,srcDir,incDir,subDirName):
   #default h file
@@ -200,7 +200,7 @@ def makeTemplatedClass(lofarDir,className,packageName,templateList,autoTemplate,
   addTemplates("h",readFile,writeFile,className,packageName,templateList,autoTemplate,subDirName)
   writeFile.close()
   readFile.close()
-  addToMakefile("h",className,incDir,subDirName)
+  addToMakefile("h",packageName,className,incDir,subDirName)
 
   #default tcc template file
   readFile=openFile(lofarDir+"/LCS/Tools/src/templates/templated_header.tcc_template","r")
@@ -208,7 +208,7 @@ def makeTemplatedClass(lofarDir,className,packageName,templateList,autoTemplate,
   addTemplates("tcc",readFile,writeFile,className,packageName,templateList,autoTemplate,subDirName)
   writeFile.close()
   readFile.close()
-  addToMakefile("tcc",className,incDir,subDirName)
+  addToMakefile("tcc",packageName,className,incDir,subDirName)
 
   if autoTemplate==0:
     #default diy-cc template file
@@ -217,7 +217,7 @@ def makeTemplatedClass(lofarDir,className,packageName,templateList,autoTemplate,
     addTemplates("diy",readFile,writeFile,className,packageName,templateList,autoTemplate,subDirName)
     writeFile.close()
     readFile.close()
-    addToMakefile("diy",className,srcDir,subDirName)
+    addToMakefile("diy",packageName,className,srcDir,subDirName)
 
 def makeMainClass(lofarDir,className,packageName,srcDir,subDirName):
   readFile=openFile(lofarDir+"/LCS/Tools/src/templates/main.cc_template","r")
@@ -225,10 +225,10 @@ def makeMainClass(lofarDir,className,packageName,srcDir,subDirName):
   replacePackageAndClassName(readFile,writeFile,packageName,className,subDirName)
   writeFile.close()
   readFile.close()
-  addToMakefile("maincc",className+"Main",srcDir,subDirName)
+  addToMakefile("maincc",packageName,className+"Main",srcDir,subDirName)
 
 
-def addToMakefile(type,className,srcDir,subDirName):
+def addToMakefile(type,packageName,className,srcDir,subDirName):
   hPattern=re.compile('^([ \t]*)INSTHDRS[ \t]*=.*$',re.IGNORECASE)
   ccPattern=re.compile('^(.*)_la_SOURCES[ \t]*=.*$',re.IGNORECASE)
   mainccPattern=re.compile('^(.*)bin_PROGRAMS[ \t]*=.*$',re.IGNORECASE)
@@ -248,7 +248,7 @@ def addToMakefile(type,className,srcDir,subDirName):
     if type == "h":
       # find INSTHDRS to start inserting headerfiles
       if hPattern.search(aLine):
-        #find / to see if the line allready contains another header
+        #find / to see if the line already contains another header
         front,end = aLine.split("=")
         if re.search("[a-zA-Z]",end):
           writeFile.write(front+" = "+extendedClassName+".h \\\n")
@@ -264,7 +264,7 @@ def addToMakefile(type,className,srcDir,subDirName):
     elif type == "cc" or type == "diy":
       # find _la_SOURCES to start inserting sourcefiles
       if ccPattern.search(aLine):
-        #find / to see if the line allready contains another source
+        #find / to see if the line already contains another source
         front,end = aLine.split("=")
         if re.search("[a-zA-Z]",end):
           writeFile.write(front+" = "+extendedClassName+".cc \\\n")
@@ -278,36 +278,49 @@ def addToMakefile(type,className,srcDir,subDirName):
         writeFile.write(aLine)
 
     elif type == "maincc":
+      pkgLower=packageName.lower()
       # find bin_PROGRAMS to start inserting mainsourcefiles
+      # they are inserted in reverse order
       if mainccPattern.search(aLine):        
-        #find / to see if the line allready contains another source
         front,end = aLine.split("=")
+        # the line already contains another source, so that becomes next line
         if re.search("[a-zA-Z]",end):
           writeFile.write(front+" = "+extendedClassName+" \\\n")
           writeFile.write("\t"+end)
-          searchEnd=1
+          if end.find('\\') > -1:
+            # a backslash, so search further (for more program names)
+            searchEnd=1
         elif end.find('\\') > -1:
-          writeFile.write(front+" = "+extendedClassName+" \\\n")
+          # only a backslash (no name), so write and search further
+          writeFile.write(front+"="+end);
+          writeFile.write("\t"+extendedClassName+" \\\n")
           searchEnd=1
-        else :
-          writeFile.write(front+" = "+className+"\n")
-          writeFile.write(className+"_SOURCES = "+extendedClassName+".cc\n")
+        else:
+          # nothing yet, so write program name
+          writeFile.write(front+" = "+extendedClassName+"\n")
+        if searchEnd == 0:
+          writeFile.write("\n")
+          writeFile.write(className+"_SOURCES      = "+extendedClassName+".cc\n")
+          writeFile.write(className+"_LDADD        = lib"+pkgLower+".la\n")
+          writeFile.write(className+"_DEPENDENCIES = lib"+pkgLower+".la $(LOFAR_DEPEND)\n")
 
       elif searchEnd > 0:
         # there have been other mainprograms, so we need to look
-        # for the end of all programName_SOURCES line to include our
-        # new mainprogram SOURCES line
-        if aLine.find("_SOURCES") < 0:
-          writeFile.write(className+"_SOURCES = "+extendedClassName+".cc\n")
+        # for the last program name (thus without backslash).
+        writeFile.write(aLine)
+        if aLine.find('\\') < 0:
+          writeFile.write("\n")
+          writeFile.write(className+"_SOURCES      = "+extendedClassName+".cc\n")
+          writeFile.write(className+"_LDADD        = lib"+pkgLower+".la\n")
+          writeFile.write(className+"_DEPENDENCIES = lib"+pkgLower+".la $(LOFAR_DEPEND)\n")
           searchEnd=0
-        writeFile.write(aLine)  
       else:
         writeFile.write(aLine)
 
     elif type == "tcc":
       # find TCCHDRS to start inserting templatefiles
       if tccPattern.search(aLine):
-        #find / to see if the line allready contains another source
+        #find / to see if the line already contains another source
         front,end = aLine.split("=")
         if re.search("[a-zA-Z]",end):
           writeFile.write(front+" = "+extendedClassName+".tcc \\\n")
@@ -333,7 +346,7 @@ def addToMakefile(type,className,srcDir,subDirName):
 def usage():
   print "usage: "+sys.argv[0]+" [-h] [-m | -t list [-d]] className [className...]"
   print "args:  -h,--help               - print usage"
-  print "       -m,--main               - make main class" 
+  print "       -m,--main               - make main program for a class" 
   print "       -t,--templated list     - automated templated class"
   print "                                 list can contain a comma seperated list"
   print "                                 with the template parameters. Example:"
@@ -443,10 +456,10 @@ def main(argv):
       if templateList == "":
         print "No templates provided, so only default template class will be created."
     if noMain==0:
-      print "Trying to set up main class " + className + " for package " + packageName
+      print "Trying to set up main class program " + className + " for package " + packageName
 
     #
-    # Check of given class name allready exists in the working directory as
+    # Check of given class name already exists in the working directory as
     # directory or as file
     #
     if noMain: 
diff --git a/LCS/Tools/src/makePackage.py b/LCS/Tools/src/makePackage.py
index 535f0d1bf75..77ea4dabd46 100755
--- a/LCS/Tools/src/makePackage.py
+++ b/LCS/Tools/src/makePackage.py
@@ -70,7 +70,9 @@ def createPackageDoc(packageName,dirLevel):
     if dirLevel>0:
       baseGroup=os.path.basename(os.environ["PWD"])
       writeFile.write("// \ingroup "+baseGroup+"\n")
-    writeFile.write("// \defgroup "+packageName+" "+packageName+" Description\n")
+    writeFile.write("// \defgroup "+packageName+" "+packageName+"\n")
+    writeFile.write("//\n")
+    writeFile.write("//  ... description ...\n")
     writeFile.close()
 
 def replacePackageName(readFile,writeFile,packageName,dirLevel):
@@ -201,15 +203,17 @@ def main(argv):
   #
   # get Lofar base dir
   #
+  file= os.popen("echo $PWD | sed -e 's%/LOFAR/.*%/LOFAR%'")
+  baseLofarDir=str.replace(file.readline(),"\n","")
+  file.close()
   if "LOFARROOT" in os.environ:
     lofarDir = os.environ["LOFARROOT"] + "/share"
   else:
     file= os.popen("echo $PWD | sed -e 's%/LOFAR/.*%/LOFAR%'")
-    lofarDir=str.replace(file.readline(),"\n","")
-    file.close()
+    lofarDir=baseLofarDir
 
   # find out the directory sublevel
-  dirLevel=len(baseDir.split('/'))-len(lofarDir.split('/'))
+  dirLevel=len(baseDir.split('/'))-len(baseLofarDir.split('/'))
 
   # Get lofar data dir.
   if "LOFARDATAROOT" in os.environ:
@@ -242,11 +246,11 @@ def main(argv):
       print "Trying to set up Super Package: " + baseDir + "/" + packageName +"\n"
       
     #
-    # Check of given package name allready exists in the working directory as
+    # Check of given package name already exists in the working directory as
     # directory or as file
     #
     if os.path.isdir(packageName) | os.path.isfile(packageName):
-      print "Sorry, that name allready exists. Please take another one\n"
+      print "Sorry, that name already exists. Please take another one\n"
       sys.exit(1)
 
     #
diff --git a/LCS/Tools/src/makeTest.py b/LCS/Tools/src/makeTest.py
index 6cb52316397..676c942ac04 100755
--- a/LCS/Tools/src/makeTest.py
+++ b/LCS/Tools/src/makeTest.py
@@ -136,8 +136,7 @@ def makeTestFiles(lofarDir,testName,packageName,testDir,subDirName,shortName,dir
 
 def addToMakefile(type,testName,testDir,subDirName,packageName,dirLevel):
   checkPattern=re.compile('^([ \t]*)check_PROGRAMS[ \t]*=.*$',re.IGNORECASE)
-  checkToolPattern=re.compile('^([ \t]*)CHECKTOOLPROGS[ \t]*=.*$',re.IGNORECASE)
-  testPattern=re.compile('^([ \t]*)TESTS[ \t]*=.*$',re.IGNORECASE)
+  testPattern=re.compile('^([ \t]*)TESTSCRIPTS[ \t]*=.*$',re.IGNORECASE)
 
   startPattern=re.compile('^([ \t]*)XFAIL_TESTS[ \t]*=.*$',re.IGNORECASE)
   
@@ -159,9 +158,9 @@ def addToMakefile(type,testName,testDir,subDirName,packageName,dirLevel):
       extendedTestName=testName
       
     if type == "cc":
-      # add testprogram to check_PROGRAMS and CHECKTOOLPROGRAMS
-      if checkPattern.search(aLine) or checkToolPattern.search(aLine):
-        #find / to see if the line allready contains another source
+      # add testprogram to check_PROGRAMS
+      if checkPattern.search(aLine):
+        #find / to see if the line already contains another source
         front,end = aLine.split("=")
         if re.search("[a-zA-Z]",end):
           writeFile.write(front+" = "+extendedTestName+" \\\n")
@@ -170,8 +169,9 @@ def addToMakefile(type,testName,testDir,subDirName,packageName,dirLevel):
           writeFile.write(front+" = "+extendedTestName+"\n")
       elif startPattern.search(aLine):
         writeFile.write(aLine)
-        writeFile.write(testName+"_SOURCES = "+extendedTestName+".cc\n")
-        writeFile.write(testName+"_LDADD = "+levelString+"src/lib"+packageName+".la\n")
+        writeFile.write("\n")
+        writeFile.write(testName+"_SOURCES      = "+extendedTestName+".cc\n")
+        writeFile.write(testName+"_LDADD        = "+levelString+"src/lib"+packageName+".la\n")
         writeFile.write(testName+"_DEPENDENCIES = "+levelString+"src/lib"+packageName+".la $(LOFAR_DEPEND)\n")        
 
       else:
@@ -179,9 +179,9 @@ def addToMakefile(type,testName,testDir,subDirName,packageName,dirLevel):
 
 
     if type == "sh":
-      # add testprogram  script to TESTS
+      # add testprogram  script to TESTSCRIPTS
       if testPattern.search(aLine):
-        #find / to see if the line allready contains another source
+        #find / to see if the line already contains another source
         front,end = aLine.split("=")
         if re.search("[a-zA-Z]",end):
           writeFile.write(front+" = "+extendedTestName+".sh \\\n")
@@ -214,9 +214,12 @@ def main(argv):
   #
   # get Lofar base dir
   #
-  file= os.popen("echo $PWD | sed -e 's%/LOFAR/.*%/LOFAR%'")
-  lofarDir=str.replace(file.readline(),"\n","")
-  file.close()
+  if "LOFARROOT" in os.environ:
+    lofarDir = os.environ["LOFARROOT"] + "/share"
+  else:
+    file= os.popen("echo $PWD | sed -e 's%/LOFAR/.*%/LOFAR%'")
+    lofarDir=str.replace(file.readline(),"\n","")
+    file.close()
   baseDir = os.environ["PWD"]
   subDirName = ""
   packageName = ""
@@ -273,12 +276,12 @@ def main(argv):
     print "Trying to set up test files and programs for " + shortName + " in package " + packageName
 
     #
-    # Check of given testname allready exists in the working directory as
+    # Check of given testname already exists in the working directory as
     # directory or as file
     #
   
     if os.path.isfile(testName+".cc"):
-      print "Sorry, that test allready exists. Please take another name"
+      print "Sorry, that test already exists. Please take another name"
       sys.exit(1)
 
     #
diff --git a/LCS/Tools/src/templates/header.cc_template b/LCS/Tools/src/templates/header.cc_template
index c4b5a61b3d2..23c58d31e49 100644
--- a/LCS/Tools/src/templates/header.cc_template
+++ b/LCS/Tools/src/templates/header.cc_template
@@ -38,6 +38,7 @@ namespace LOFAR {
 
     // Remove lines or remove comments for copy constructor and assignment.
     ////%CLASS%::%CLASS% (const %CLASS%& that)
+    ////:      //... initialize members ...
     ////{}
     ////%CLASS%& %CLASS%::operator= (const %CLASS%& that)
     ////{
diff --git a/LCS/Tools/src/templates/header.h_template b/LCS/Tools/src/templates/header.h_template
index b840fb6d0fa..8410c80fed3 100644
--- a/LCS/Tools/src/templates/header.h_template
+++ b/LCS/Tools/src/templates/header.h_template
@@ -47,16 +47,21 @@ namespace LOFAR
     class %CLASS%
     {
     public:
+      // Default constructor.
       %CLASS%();
+
+      // Destructor.
       ~%CLASS%();
 
+    //// Remove this private line if copying is allowed.
     private:
-      // Copying is not allowed
+      // Copy constructor is not allowed.
       %CLASS% (const %CLASS%& that);
+      // Assignment is not allowed.
       %CLASS%& operator= (const %CLASS%& that);
 
-      //# Datamembers
-
+    private:
+      //# Data members
     };
 
     // @}
diff --git a/LCS/Tools/src/templates/include_pkg_makefile.am_template b/LCS/Tools/src/templates/include_pkg_makefile.am_template
index cc59db7d99d..0625092bd92 100644
--- a/LCS/Tools/src/templates/include_pkg_makefile.am_template
+++ b/LCS/Tools/src/templates/include_pkg_makefile.am_template
@@ -8,7 +8,7 @@ NOINSTHDRS =
 
 TCCHDRS =
 
-nobase_pkginclude_HEADERS = $(INSTHDRS) $(TCCHDRS)
+pkginclude_HEADERS = $(INSTHDRS) $(TCCHDRS)
 
 noinst_HEADERS = $(NOINSTHDRS)
 
diff --git a/LCS/Tools/src/templates/package_lofarconf.in_template b/LCS/Tools/src/templates/package_lofarconf.in_template
index 3d62c8760e0..65e25c3a9f7 100644
--- a/LCS/Tools/src/templates/package_lofarconf.in_template
+++ b/LCS/Tools/src/templates/package_lofarconf.in_template
@@ -1,4 +1,3 @@
 #
-# Add packagenames from pacakages that resort under this Superclass
-# here. Insert a oneline comment
+# Add names of packages that resort under this Super package.
 #
diff --git a/LCS/Tools/src/templates/package_makefile.am_template b/LCS/Tools/src/templates/package_makefile.am_template
index 8d88183eef4..7cfbf27b103 100644
--- a/LCS/Tools/src/templates/package_makefile.am_template
+++ b/LCS/Tools/src/templates/package_makefile.am_template
@@ -1,7 +1,7 @@
-SUBDIRS=src test include
+SUBDIRS=include src test
 
-DISTCHECK_CONFIGURE_FLAGS=\
-      --with-common=$(prefix)
+pkgextdir     = $(prefix)/config/$(PACKAGE)
+pkgext_DATA   = pkgext pkgextcppflags pkgextcxxflags pkgextldflags
 
 EXTRA_DIST = \
       Makefile.common \
diff --git a/LCS/Tools/src/templates/src_makefile.am_template b/LCS/Tools/src/templates/src_makefile.am_template
index 13b732ac4e1..7e057c6478c 100644
--- a/LCS/Tools/src/templates/src_makefile.am_template
+++ b/LCS/Tools/src/templates/src_makefile.am_template
@@ -31,3 +31,7 @@ scriptdir = $(bindir)
 dist_script_SCRIPTS = 
 
 include $(top_srcdir)/Makefile.common
+
+# if HAVE_SHMEM
+# libcommon_la_LIBADD   = shmem/libshmem.la
+# endif
diff --git a/LCS/Tools/src/templates/templated_header.h_template b/LCS/Tools/src/templates/templated_header.h_template
index fa73c5aef0d..7db6a1df5e5 100644
--- a/LCS/Tools/src/templates/templated_header.h_template
+++ b/LCS/Tools/src/templates/templated_header.h_template
@@ -47,22 +47,28 @@ namespace LOFAR {
     class %CLASS%
     {
     public:
+      // Default constructor.
       %CLASS%();
+
+      // Destructor.
       ~%CLASS%();
 
+    //// Remove this private line if copying is allowed.
     private:
-      // Copying is not allowed
-      %CLASS% (const %CLASS%%TEMPLATEPARAM%& that);
-      %CLASS%%TEMPLATEPARAM%& operator= (const %CLASS%%TEMPLATEPARAM%& that);
+      // Copy constructor is not allowed.
+      %CLASS% (const %CLASS%& that);
+      // Assignment is not allowed.
+      %CLASS%& operator= (const %CLASS%& that);
 
+    private:
       //# Datamembers
-
     };
 
     // @}
   } // namespace %PACKAGE%
 } // namespace LOFAR
 
+// Include the .tcc file for automatic template instantiation.
 %INCLUDETCC%
 
 #endif
diff --git a/LCS/Tools/src/templates/test.cc_template b/LCS/Tools/src/templates/test.cc_template
index 1a6ebb1aa99..20a46edf184 100644
--- a/LCS/Tools/src/templates/test.cc_template
+++ b/LCS/Tools/src/templates/test.cc_template
@@ -43,7 +43,7 @@ int main (int argc, char* argv[]) {
 
   // Check invocation syntax
   if (argc < 3) {
-    LOG_FATAL_STR ("Invocation error, syntax: " << progName <<
+    LOG_FATAL_STR ("Invocation error, run as: " << progName <<
                    " param1 param2");
     return (-1);
   }
@@ -55,13 +55,13 @@ int main (int argc, char* argv[]) {
     ... do work ...
     LOG_INFO_STR("Shutting down: " << argv[0]);
   }
-  catch (LOFAR::Exception& ex) {
-    LOG_FATAL_STR("Caught exception: " << ex << endl);
+  catch (std::exception& ex) {
+    LOG_FATAL_STR("Caught exception: " << ex.what() << endl);
     LOG_FATAL_STR(argv[0] << " terminated by exception!");
     return (1);
   }
 
-  LOG_INFO_STR(argv[0] << " terminated normally");
+  LOG_INFO_STR(argv[0] << " ended normally");
   return (0);
 
 }
diff --git a/LCS/Tools/src/templates/test_makefile.am_template b/LCS/Tools/src/templates/test_makefile.am_template
index dfa5b075531..9a9193931f8 100644
--- a/LCS/Tools/src/templates/test_makefile.am_template
+++ b/LCS/Tools/src/templates/test_makefile.am_template
@@ -1,11 +1,10 @@
-check_PROGRAMS        =
+check_PROGRAMS        = 
 
 # programs to run through supplied checktools
-CHECKTOOLPROGS        =
-#ENDCHECKTOOLPROGS
+CHECKTOOLPROGS        = $(check_PROGRAMS)
 
 # scripts used to run tests
-TESTSCRIPTS           =
+TESTSCRIPTS           = 
 
 # scripts and possible programs to run tests
 TESTS	              = $(TESTSCRIPTS)
@@ -15,16 +14,5 @@ XFAIL_TESTS           =
 # all files (.run, .stdout, .in, .log_prop, etc.) needed to run tests
 EXTRA_DIST            = $(TESTSCRIPTS)
 
-# Lines to build a test program testprg
-#testprg_SOURCES		= testprg.cc
-#testprg_LDADD			= ../src/lib%PACKAGELOWER%.la
-#testprg_DEPENDENCIES		= ../src/lib%PACKAGELOWER%.la $(LOFAR_DEPEND)
-
-TESTS_ENVIRONMENT		= lofar_sharedir=$(lofar_sharedir) \
-				  srcdir=$(srcdir) \
-				  LOFARROOT=$(LOFARROOT) \
-				  LOFARDATAROOT=$(LOFARDATAROOT) \
-				  MPIBIN=$(MPIBIN)
-
 
 include $(top_srcdir)/Makefile.common
-- 
GitLab