#! /bin/sh
#  newPackage.sh
#  Time-stamp: <2002-03-07 01:08:14 yuji>
#  This script make a framework for your new package
#  header file, module.cc and its test file

if [ "$1" = "" ]; then
  cat <<EOT
Usage: newPackage.sh [Packagename]
EOT
exit
fi

package=$1;
echo "creating package $1 ..."
mkdir -p ${package}
mkdir -p ${package}/${package}
mkdir -p ${package}/src
mkdir -p ${package}/test
mkdir -p ${package}/doc
(cd include; ln -fs ../${package}/${package} .)
touch ${package}/src/.refresh
touch ${package}/test/.refresh
touch ${package}/test/.binclean

#######################################################################
#################  ${package}/README   ################################
#######################################################################
echo "creating ${package}/README ..."
cat <<EOT00 > ${package}/README
This package ${package} is created at `date` by $0.
EOT00

#######################################################################
#################  ${package}/GNUmakefile  ############################
#######################################################################
echo "creating ${package}/GNUmakefile ..."
cat <<EOT01 > ${package}/GNUmakefile
# SoftRelTools GNUmakefile for ${package} top level 

# Compile the files in src subdirectory
SUBDIRS=src test

################################
include SoftRelTools/standard.mk
EOT01


#######################################################################
################  ${package}/src/GNUmakefile  #########################
#######################################################################
echo "creating ${package}/src/GNUmakefile ..."
cat <<EOT02 > ${package}/src/GNUmakefile
# Package/src/GNUmakefile

LIB = lib${package}.a

skip_files = 

LIBCFILES = \$(filter-out \$(skip_files),\$(wildcard *.c))
LIBFFILES = \$(filter-out \$(skip_files),\$(wildcard *.f) \$(wildcard *.F))
LIBCCFILES = \$(filter-out \$(skip_files),\$(wildcard *.cc))

include PackageList/link_all.mk
include SoftRelTools/standard.mk
include SoftRelTools/refresh.mk

####################################
# If you are using full ROOT, include this:
#   include SoftRelTools/arch_spec_root.mk
# else if you are using the EDM, include this:

include SoftRelTools/arch_spec_root_minedm.mk

# Don't forget to put the appropriate entry in link_Package.mk:
#   override LINK_root += Package
# or 
#   override LINK_root_edm += Package
####################################
EOT02

#######################################################################
#################  ${package}/test/GNUmakefile  #######################
#######################################################################
echo "creating ${package}/test/GNUmakefile ..."
cat <<EOT03 > ${package}/test/GNUmakefile
#############################################################
#
# example Makefile for CDF packages
#
# uses SoftRelTools/standard.mk
#
#############################################################
# file lists (standard names, local contents)

# include file products
INC = 
 
# library product
LIB =
 
# library contents 
#   Note: source files with main() definitions do not go
#   into the library.
#   Any file copied from AppUserBuild_template.cc should
#   also be skipped.

# subdirectories
SUBDIRS = 

# binary products
BINS = 

TBINS = ${package}Test

SIMPLEBINS := \$(BINS) \$(TBINS)

# override LDFLAGS   += -v
override LINK_FrameMods       += ${package}_test
override LINK_${package}      += ${package}_test

# this FrameMods_root is needed to use RootHepTuple
override LINK_FrameMods_root  += ${package}_test


PACKAGELIST += ${package}
ifneq (\$(LINK_${package}),)
  override LOADLIBES += -l${package}
endif

include PackageList/link_all.mk
include SoftRelTools/standard.mk
include SoftRelTools/binclean.mk

include SoftRelTools/refresh.mk
include SoftRelTools/arch_spec_root_minedm.mk
EOT03


#######################################################################
###############  ${package}/${package}/${package}.hh  #################
#######################################################################
echo "creating ${package}/${package}/${package}.hh ..."
cat <<EOT04 > ${package}/${package}/${package}.hh
//--------------------------------------------------------------------------
// File and Version Information:
//      created at `date` by newPackage.sh
// Description:
//      Class ${package}
//
// Environment:
//
// Author List:
//
// Copyright Information:
//
//------------------------------------------------------------------------

#ifndef ${package}_HH
#define ${package}_HH

//----------------------
// Base Class Headers --
//----------------------
#include "Framework/APPModule.hh"
#ifdef CDF
#include "BaBar/Cdf.hh"
#endif
//              ---------------------
//              -- Class Interface --
//              ---------------------

class ${package} : public AppModule {

//--------------------
// Instance Members --
//--------------------

public:
  // Constructors
  ${package}( const char* const theName = "${package}",
            const char* const theDescription = "${package} module");

    // Destructor
  virtual ~${package}();

    // Operations
  virtual AppResult beginJob( AbsEvent* aJob );
  virtual AppResult beginRun( AbsEvent* aRun );
  virtual AppResult event( AbsEvent* anEvent );
  virtual AppResult other( AbsEvent* anOther );
  virtual AppResult endRun( AbsEvent* aRun );
  virtual AppResult endJob( AbsEvent* aJob );
  virtual AppResult abortJob( AbsEvent* aJob );

  virtual AppModule* clone(const char* cloneName);

  const char*  rcsId( ) const;
};
#endif
EOT04

#######################################################################
###############  ${package}/src/${package}.cc  ########################
#######################################################################
echo "creating ${package}/src/${package}.cc ..."
cat <<EOT05 > ${package}/src/${package}.cc
//--------------------------------------------------------------------------
// File and Version Information:
//      created at `date` by newPackage.sh
// Description:
//	Class ${package}
//
// Environment:
//
// Author List:
//
// Copyright Information:
//
//------------------------------------------------------------------------

//------------------------
// String Header First  --
//------------------------
#include <string>

//-----------------------
// This Class's Header --
//-----------------------
#include "${package}/${package}.hh"
//-------------
// C Headers --
//-------------
#include <assert.h>
#include <time.h>
//---------------
// C++ Headers --
//---------------
#include <iostream.h>

//-------------------------------
// Collaborating Class Headers --
//-------------------------------
#include "Edm/ConstHandle.hh"
#include "AbsEnv/AbsEnv.hh"

//-----------------------------------------------------------------------
// Local Macros, Typedefs, Structures, Unions and Forward Declarations --
//-----------------------------------------------------------------------

static const char rcsid[] = "\$Id: \$";

//----------------
// Constructors --
//----------------
${package}::${package}( 
		   const char* const theName, 
		   const char* const theDescription ) :
  AppModule( theName, theDescription )
{
}

//--------------
// Destructor --
//--------------
${package}::~${package}()
{
}

//--------------
// Operations --
//--------------
AppResult ${package}::beginJob( AbsEvent* aJob )
{
  cout << name( ) << " begin Job" << endl;
  return AppResult::OK;
}

AppResult ${package}::beginRun( AbsEvent* aRun )
{
  cout << name( ) << " begin Run" << endl;
  return AppResult::OK;
}

AppResult ${package}::event( AbsEvent* anEvent )
{
  cout << name( ) << " event entry" << endl;
  return AppResult::OK;
}

AppResult ${package}::other( AbsEvent* )
{
  cout << name( ) << " other" << endl;
  return AppResult::OK;
}

AppResult ${package}::endRun( AbsEvent* aRun )
{
  cout << name( ) << " end Run" << endl;
  return AppResult::OK;
}

AppResult ${package}::endJob( AbsEvent* aJob )
{
  cout << name( ) << " end Job" << endl;
  return AppResult::OK;
}

AppResult ${package}::abortJob( AbsEvent* aJob )
{
  cout << name( ) << " abort Job" << endl;
  return AppResult::OK;
}

AppModule* ${package}::clone(const char* cloneName)
{
  return new ${package}(cloneName,"this module is a clone ${package}");
}

const char* ${package}::rcsId( ) const
{
  return rcsid;
}
EOT05

#######################################################################
###############  ${package}/test/${package}Test.cc  ###################
#######################################################################
echo "creating ${package}/test/${package}Test.cc ..."
cat <<EOT06 > ${package}/test/${package}Test.cc
//--------------------------------------------------------------------------
// File and Version Information:
//      created at `date` by newPackage.sh
// Description:
//      Class AppUserBuild. This class must be provided by the user of
//      the framework in order to build an application. It must define
//      the modules that are to form the basis of the application.
//
// Environment:
//      Software developed for the BaBar Detector at the SLAC B-Factory.
//
// Author List:
//
// Copyright Information:
//
//------------------------------------------------------------------------

//-----------------------
// This Class's Header --
//-----------------------
#include "Framework/APPUserBuild.hh"

//-------------------------------
// Collaborating Class Headers --
//-------------------------------
#include "FrameMods/addCDFrequiredModules.hh"
#include "FrameMods/addAllStorableObjects.hh"

// TEST Modules
#include "${package}/${package}.hh"

//-----------------------------------------------------------------------
// Local Macros, Typedefs, Structures, Unions and Forward Declarations --
//-----------------------------------------------------------------------

static const char rcsid[] = "\$Id: \$";

//----------------
// Constructors --
//----------------

AppUserBuild::AppUserBuild( AppFramework* theFramework )
    : AppBuild( theFramework )
{

    addCDFrequiredModules( this );
    addAllStorableObjects( );
    AppModule* aModule;

    // Append Modules
    aModule = new ${package}();
    add( aModule );
}

//--------------
// Destructor --
//--------------

AppUserBuild::~AppUserBuild( )
{
}
const char * AppUserBuild::rcsId( ) const
{
   return rcsid;
}
EOT06

#######################################################################
###############  ${package}/test/${package}Test.tcl  ##################
#######################################################################
echo "creating ${package}/test/${package}Test.tcl ..."
cat <<EOT07 > ${package}/test/${package}Test.tcl
path enable AllPath
###############################################################
module input DHInput
  mod talk DHInput
#  input file /cdf/data08/_APHYSR.0000/ar01e79e.0001phys
exit
###############################################################
#mod talk GeometryManager
#  DetectorMenu
#    enableAll set true
#  exit
#exit

path list

ev begin -nev 10
exit
EOT07

##### EOF #####
