updateLAr_v3_39.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 function one_file() {
22  local F=$1
23  printf "$F \n"
24  # Optionally fix whitespace
25  (( ${fix_whitespace:-0} )) && ed "$F" < fix-whitespace.ed > /dev/null 2>&1
26  # Fix includes
27  perl -wapi\~ -f ${thisdir}/fix-header-locs-ifdh.pl "${F}" >/dev/null 2>&1 && rm -f "${F}~"
28 }
29 
30 function cmake_file() {
31  local F=$1
32  printf "$F \n"
33  # Optionally fix whitespace
34  (( ${fix_whitespace:-0} )) && ed "$F" < fix-whitespace.ed > /dev/null 2>&1
35  # Fix CMakeLists.txt
36  perl -wapi\~ -f ${thisdir}/fix-cmake-nutools.pl "${F}" >/dev/null 2>&1 && rm -f "${F}~"
37 }
38 function cmake_file_2() {
39  local F=$1
40  printf "$F \n"
41  # Optionally fix whitespace
42  (( ${fix_whitespace:-0} )) && ed "$F" < fix-whitespace.ed > /dev/null 2>&1
43  # Fix CMakeLists.txt
44  perl -wapi\~ -f ${thisdir}/fix-cmake-ifdh.pl "${F}" >/dev/null 2>&1 && rm -f "${F}~"
45 }
46 function cmake_file_3() {
47  local F=$1
48  printf "$F \n"
49  # Optionally fix whitespace
50  (( ${fix_whitespace:-0} )) && ed "$F" < fix-whitespace.ed > /dev/null 2>&1
51  # Fix CMakeLists.txt
52  perl -wapi\~ -f ${thisdir}/fix-cmake-genie.pl "${F}" >/dev/null 2>&1 && rm -f "${F}~"
53 }
54 
55 # ======================================================================
56 # Prepare:
57 getopt -T >/dev/null 2>&1
58 if (( $? != 4 )); then
59  echo "ERROR: GNU getopt required! Check SETUP_GETOPT and PATH." 1>&2
60  exit 1
61 fi
62 
63 TEMP=`getopt -n "$prog" -o a --long all-lumi-cases --long one-file: --long no-fix-pset -- "${@}"`
64 eval set -- "$TEMP"
65 while true; do
66  case $1 in
67  --fix-whitespace)
68  fix_whitespace=1
69  shift
70  ;;
71  --one-file)
72  file=$2
73  shift 2
74  ;;
75  --)
76  shift
77  break
78  ;;
79  *)
80  echo "Bad argument \"$OPT\"" 1>&2
81  usage
82  exit 1
83  esac
84 done
85 
86 TOP=${1}
87 
88 get_this_dir
89 
90 # ======================================================================
91 # Run scripts to update
92 
93 TMP=`mktemp -t update_sources.sh.XXXXXX`
94 trap "rm $TMP* 2>/dev/null" EXIT
95 
96 if [[ -n "${file}" ]]; then
97  if ! [[ -r "${file}" ]]; then
98  echo "ERROR: ${file} does not exist or is not readable." 1>&2
99  exit 1
100  else
101  cmake_file "$file"
102  cmake_file_2 "$file"
103  cmake_file_3 "$file"
104  fi
105 else
106 ## for F in `find $TOP \( -name "*.c*" -o -name "*.C*" -o -name "*.icc" -o -name "*.h*" -o -name "*.H*" \) -print`; do
107 ## one_file "$F"
108 ## done
109 ## echo
110  for F in `find $TOP -name CMakeLists.txt -print`; do
111  cmake_file "$F"
112  cmake_file_2 "$F"
113  cmake_file_3 "$F"
114  done
115  echo
116 fi