update_for_nutools.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-nutools.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 
39 # ======================================================================
40 # Prepare:
41 getopt -T >/dev/null 2>&1
42 if (( $? != 4 )); then
43  echo "ERROR: GNU getopt required! Check SETUP_GETOPT and PATH." 1>&2
44  exit 1
45 fi
46 
47 TEMP=`getopt -n "$prog" -o a --long all-lumi-cases --long one-file: --long no-fix-pset -- "${@}"`
48 eval set -- "$TEMP"
49 while true; do
50  case $1 in
51  --fix-whitespace)
52  fix_whitespace=1
53  shift
54  ;;
55  --one-file)
56  file=$2
57  shift 2
58  ;;
59  --)
60  shift
61  break
62  ;;
63  *)
64  echo "Bad argument \"$OPT\"" 1>&2
65  usage
66  exit 1
67  esac
68 done
69 
70 TOP=${1}
71 
72 get_this_dir
73 
74 # ======================================================================
75 # Run scripts to update
76 
77 TMP=`mktemp -t update_sources.sh.XXXXXX`
78 trap "rm $TMP* 2>/dev/null" EXIT
79 
80 if [[ -n "${file}" ]]; then
81  if ! [[ -r "${file}" ]]; then
82  echo "ERROR: ${file} does not exist or is not readable." 1>&2
83  exit 1
84  else
85  one_file "$file"
86  fi
87 else
88  for F in `find $TOP \( -name "*.c*" -o -name "*.C*" -o -name "*.icc" -o -name "*.h*" -o -name "*.H*" \) -print`; do
89  one_file "$F"
90  done
91  echo
92  for F in `find $TOP -name CMakeLists.txt -print`; do
93  cmake_file "$F"
94  done
95  echo
96 fi