LArRecodnnNewDirs.sh
Go to the documentation of this file.
1 #!/bin/bash
2 # Program name
3 prog=${0##*/}
4 # ======================================================================
5 function usage() {
6  cat 1>&2 <<EOF
7 usage: $prog [--one-file <file>] <top-dir>
8 EOF
9 }
10 
11 get_this_dir()
12 {
13  ( cd / ; /bin/pwd -P ) >/dev/null 2>&1
14  if (( $? == 0 )); then
15  pwd_P_arg="-P"
16  fi
17  reldir=`dirname ${0}`
18  thisdir=`cd ${reldir} && /bin/pwd ${pwd_P_arg}`
19 }
20 
21 ## perl -wapi\~ -f fix-header-locs.pl "${F}" >/dev/null 2>&1 && rm -f "${F}~"
22 
23 function one_file() {
24  local F=$1
25  printf "$F ... "
26  # Optionally fix whitespace
27  (( ${fix_whitespace:-0} )) && ed "$F" < fix-whitespace.ed > /dev/null 2>&1
28  # Fix includes
29  perl -wapi\~ -f ${thisdir}/fix_headers_new_dnn.pl "${F}" >/dev/null 2>&1 && rm -f "${F}~"
30 }
31 
32 function cmake_file() {
33  local F=$1
34  printf "$F ... "
35  # Optionally fix whitespace
36  (( ${fix_whitespace:-0} )) && ed "$F" < fix-whitespace.ed > /dev/null 2>&1
37  # Fix CMakeLists.txt
38  perl -wapi\~ -f ${thisdir}/fix_cmake_new_dnn.pl "${F}" >/dev/null 2>&1 && rm -f "${F}~"
39 }
40 
41 # ======================================================================
42 # Prepare:
43 getopt -T >/dev/null 2>&1
44 if (( $? != 4 )); then
45  echo "ERROR: GNU getopt required! Check SETUP_GETOPT and PATH." 1>&2
46  exit 1
47 fi
48 
49 TEMP=`getopt -n "$prog" -o a --long all-lumi-cases --long one-file: --long no-fix-pset -- "${@}"`
50 eval set -- "$TEMP"
51 while true; do
52  case $1 in
53  --fix-whitespace)
54  fix_whitespace=1
55  shift
56  ;;
57  --one-file)
58  file=$2
59  shift 2
60  ;;
61  --)
62  shift
63  break
64  ;;
65  *)
66  echo "Bad argument \"$OPT\"" 1>&2
67  usage
68  exit 1
69  esac
70 done
71 
72 TOP=${1}
73 
74 get_this_dir
75 
76 # ======================================================================
77 # Run scripts to update
78 
79 TMP=`mktemp -t update_sources.sh.XXXXXX`
80 trap "rm $TMP* 2>/dev/null" EXIT
81 
82 if [[ -n "${file}" ]]; then
83  if ! [[ -r "${file}" ]]; then
84  echo "ERROR: ${file} does not exist or is not readable." 1>&2
85  exit 1
86  else
87  one_file "$file"
88  fi
89 else
90  for F in `find "${TOP:-.}" \( -name "*.c*" -o -name "*.C*" -o -name "*.icc" -o -name "*.h*" -o -name "*.H*" \) -print`; do
91  one_file "$F"
92  done
93  for F in `find "${TOP:-.}" -name CMakeLists.txt -print`; do
94  cmake_file "$F"
95  done
96 fi