summaryrefslogtreecommitdiffstats
path: root/build-root/autowank
blob: 21a440df484f306fa870ad0af4b2fe3b4ad9ed03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151

@media only all and (prefers-color-scheme: dark) {
.highlight .hll { background-color: #49483e }
.highlight .c { color: #75715e } /* Comment */
.highlight .err { color: #960050; background-color: #1e0010 } /* Error */
.highlight .k { color: #66d9ef } /* Keyword */
.highlight .l { color: #ae81ff } /* Literal */
.highlight .n { color: #f8f8f2 } /* Name */
.highlight .o { color: #f92672 } /* Operator */
.highlight .p { color: #f8f8f2 } /* Punctuation */
.highlight .ch { color: #75715e } /* Comment.Hashbang */
.highlight .cm { color: #75715e } /* Comment.Multiline */
.highlight .cp { color: #75715e } /* Comment.Preproc */
.highlight .cpf { color: #75715e } /* Comment.PreprocFile */
.highlight .c1 { color: #75715e } /* Comment.Single */
.highlight .cs { color: #75715e } /* Comment.Special */
.highlight .gd { color: #f92672 } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gi { color: #a6e22e } /* Generic.Inserted */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #75715e } /* Generic.Subheading */
.highlight .kc { color: #66d9ef } /* Keyword.Constant */
.highlight .kd { color: #66d9ef } /* Keyword.Declaration */
.highlight .kn { color: #f92672 } /* Keyword.Namespace */
.highlight .kp { color: #66d9ef } /* Keyword.Pseudo */
.highlight .kr { color: #66d9ef } /* Keyword.Reserved */
.highlight .kt { color: #66d9ef } /* Keyword.Type */
.highlight .ld { color: #e6db74 } /* Literal.Date */
.highlight .m { color: #ae81ff } /* Literal.Number */
.highlight .s { color: #e6db74 } /* Literal.String */
.highlight .na { color: #a6e22e } /* Name.Attribute */
.highlight .nb { color: #f8f8f2 } /* Name.Builtin */
.highlight .nc { color: #a6e22e } /* Name.Class */
.highlight .no { color: #66d9ef } /* Name.Constant */
.highlight .nd { color: #a6e22e } /* Name.Decorator */
.highlight .ni { color: #f8f8f2 } /* Name.Entity */
.highlight .ne { color: #a6e22e } /* Name.Exception */
.highlight .nf { color: #a6e22e } /* Name.Function */
.highlight .nl { color: #f8f8f2 } /* Name.Label */
.highlight .nn { color: #f8f8f2 } /* Name.Namespace */
.highlight .nx { color: #a6e22e } /* Name.Other */
.highlight .py { color: #f8f8f2 } /* Name.Property */
.highlight .nt { color: #f92672 } /* Name.Tag */
.highlight .nv { color: #f8f8f2 } /* Name.Variable */
.highlight .ow { color: #f92672 } /* Operator.Word */
.highlight .w { color: #f8f8f2 } /* Text.Whitespace */
.highlight .mb { color: #ae81ff } /* Literal.Number.Bin */
.highlight .mf { color: #ae81ff } /* Literal.Number.Float */
.highlight .mh { color: #ae81ff } /* Literal.Number.Hex */
.highlight .mi { color: #ae81ff } /* Literal.Number.Integer */
.highlight .mo { color: #ae81ff } /* Literal.Number.Oct */
.highlight .sa { color: #e6db74 } /* Literal.String.Affix */
.highlight .sb { color: #e6db74 } /* Literal.String.Backtick */
.highlight .sc { color: #e6db74 } /* Literal.String.Char */
.highlight .dl { color: #e6db74 } /* Literal.String.Delimiter */
.highlight .sd { color: #e6db74 } /* Literal.String.Doc */
.highlight .s2 { color: #e6db74 } /* Literal.String.Double */
.highlight .se { color: #ae81ff } /* Literal.String.Escape */
.highlight .sh { color: #e6db74 } /* Literal.String.Heredoc */
.highlight .si { color: #e6db74 } /* Literal.String.Interpol */
.highlight .sx { color: #e6db74 } /* Literal.String.Other */
.highlight .sr { color: #e6db74 } /* Literal.String.Regex */
.highlight .s1 { color: #e6db74 } /* Literal.String.Single */
.highlight .ss { color: #e6db74 } /* Literal.String.Symbol */
.highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #a6e22e } /* Name.Function.Magic */
.highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */
.highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */
.highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */
.highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */
.highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */
}
@media (prefers-color-scheme: light) {
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* 
#!/bin/bash

# Copyright (c) 2015 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This aptly-named script verifies and fixes time ordering
# problems with Makefile.{am,in} aclocal.m4 configure* files.

set -eu
#set -vx

touch=""
commit=""
comma_v=""
aclocal=""
optimize=""

# The old autowank scheme used "touch <foo> ; sleep 1"
# to ensure differentiable, ordered timestamps. Worked, but
# took N seconds given N files to fix. We have an example
# which wastes multiple minutes given the old scheme.
#
# This version generates a sequence of timestamps 
# starting an hour ago. That gives us
# lots to play with, in case some obnoxious program feels the need
# to complain about timestamps in the future.

# If we're in UTC+N land, generate UTC+(N+1) 
# If we're in UTC-N land, generate UTC-(N-1)

my_tz=`date +%z`
sign=`echo $my_tz | sed -n -e 's/^\(.\{1\}\).*$/\1/p'`
t=`echo $my_tz | sed -n -e 's/^\(.\{1\}\)//p'`
tz_hour=`echo $t | sed -n -e 's/^\(.\{2\}\).*$/\1/p'`
tz_hour=`echo $tz_hour | sed 's/^0//'`

if [ $sign = "-" ] ; then
    sign="+"
    let tz_hour=$tz_hour+1
    if [[ $tz_hour -ge "24" ]] ; then
        tz_hour=0
    fi
else
    sign="-"
    let tz_hour=$tz_hour-1 || true
    if [[ $tz_hour -lt "0" ]] ; then
        tz_hour=23
    fi
fi

# Timestamp, an hour ago:
ts_begin=`TZ=UTC${sign}${tz_hour} date +%Y%m%d%H%M.%S`

# break into constituent parts
year=`echo $ts_begin | sed -n -e 's/^\(.\{4\}\).*$/\1/p'`
t=`echo $ts_begin | sed -n -e 's/^\(.\{4\}\)//p'`
month=`echo $t | sed -n -e 's/^\(.\{2\}\).*$/\1/p'`
t=`echo $t | sed -n -e 's/^\(.\{2\}\)//p'`
day=`echo $t | sed -n -e 's/^\(.\{2\}\).*$/\1/p'`
t=`echo $t | sed -n -e 's/^\(.\{2\}\)//p'`
hour=`echo $t | sed -n -e 's/^\(.\{2\}\).*$/\1/p'`
t=`echo $t | sed -n -e 's/^\(.\{2\}\)//p'`
min=`echo $t | sed -n -e 's/^\(.\{2\}\).*$/\1/p'`
t=`echo $t | sed -n -e 's/^\(.\{2\}\)//p'`
sec=`echo $t | sed -n -e 's/\.//p'`

# How many days in the current month?
# Good until someone changes the calendar rules
days_in_current_month() {
    if [[ $month -eq 9 || $month -eq 4 \
        || $month -eq 6 || $month -eq 11 ]] ; then
	return 30;
    fi
    if [[ $month -eq 2 ]] ; then
	let t=($year/400)*400
	if [[ $t -eq $year ]] ; then
	    return 29;
	fi
	let t=($year/100)*100
	if [[ $t -eq $year ]] ; then
	    return 28;
	fi
	let t=($year/4)*4
	if [[ $t -eq $year ]] ; then
	    return 29;
	fi
	return 28;
    fi
    return 31;
}

# The next timestamp to issue via touch
# A real hemorrhoid because bash isnt easily convinced
# that 08 is a decimal number
next_ts() {
    sec=`echo $sec | sed 's/^0//'`
    let sec=$sec+1
    if [[ "$sec" -lt "60" ]] ; then
        if [[ "$sec" -lt "10" ]] ; then
            sec=0$sec
        fi
	return 0;
    fi
    sec="00"
    min=`echo $min | sed 's/^0//'`
    let min=$min+1
    if [[ "$min" -lt "60" ]] ; then
        if [[ "$min" -lt "10" ]] ; then
            min=0$min
        fi
	return 0;
    fi
    min="00"
    hour=`echo $hour | sed 's/^0//'`
    let hour=$hour+1
    if [[ "$hour" -lt "24" ]] ; then
        if [[ "$hour" -lt "10" ]] ; then
            hour=0$hour
        fi
	return 0;
    fi
    hour="00"
    days_in_current_month
    days_in_month=$?
    if [[ "$day" -lt "$days_in_month" ]] ; then
        day=`echo $day | sed 's/^0//'`
	let day=$day+1
        if [[ "$day" -lt "10" ]] ; then
            day=0$day
        fi
	return 0;
    fi
    day="01"
    month=`echo $month | sed 's/^0//'`
    let month=$month+1
    if [[ "$month" -lt "13" ]] ; then
        if [[ "$month" -lt "10" ]] ; then
            month=0$month
        fi
	return 0;
    fi
    month="01"
    let year=$year+1
    return 0;
}

while [ $# != 0 ] ; do
  case "$1" in
    (--commav) comma_v=",v" ;;
    (--touch) touch=yes ;;
    (--aclocal) aclocal=yes ;;
    (--nooptimize) optimize="" ;;
    (--commit=*) commit="$1" ;;
    (*) echo "$0: usage [--touch|--commit|]" > /dev/stderr
        exit 17 ;;
  esac
  shift
done

if [ "${aclocal}" != "" ] ; then
    if [ -f aclocal.m4 ] ; then
        echo touching aclocal.m4
        sleep 1
        touch aclocal.m4
    else
        echo aclocal.m4 not found
    fi
fi

if [ "${comma_v}" != "" -a "${commit}" != "" ] ; then
  echo "No, you may NOT molest ,v files directly.  Go away." > /dev/stderr
  exit 1
fi

function touchme ()
{
  local victim="${1}"
  shift
  local touchmebaby=""
  local sein="is"
  local newer="no"
  local older="no"

  if [ ! -r "$victim" ] ; then
    return
  fi

  while [ $# != 0 ] ; do
    if [ "${1}" -nt "${victim}" ] ; then
        newer="yes"
    fi
    if [ "${1}" -ot "${victim}" ] ; then
        older="yes"
    fi
    if [ "${newer}" = "no" -a "${older}" = "no" ] ; then
        newer="yes"
    fi

    if [ "${newer}" = "yes" ] ; then
      if [ "${touchmebaby}" = "" ] ; then
        touchmebaby="${1}"
      else
        sein="are"
        touchmebaby="${touchmebaby} ${1}"
      fi
    fi
    shift
  done
  if [ -n "${touchmebaby}" ] ; then
    echo "*** ${touchmebaby} ${sein} newer than ${victim}  "
    if [ -n "${touch}" ] ; then
      # 
      # This is the old version, in case something backfires...
      if [ "${optimize}" != "yes" ] ; then 
          echo "Fixing " ;touch -c "$victim" ; sleep 1
      else
          echo "Fixing "
      # echo touch -c -t $year$month$day$hour$min.$sec "$victim"
          touch -c -t $year$month$day$hour$min.$sec "$victim"
          next_ts
      fi
    fi
  fi
}

makefileins="`/usr/bin/find . -name Attic -prune -o -name Makefile.in${comma_v}`"

# aclocal.m4 depends on ***/Makefile.am, configure.ac, acinclude.m4, *.m4 crap
touchme aclocal.m4${comma_v} \
        `/usr/bin/find . -name Attic -prune -o -name Makefile.am${comma_v}` \
        "configure.in${comma_v}" "configure.ac${comma_v}" \
        "acinclude.m4${comma_v}"

# Makefile.in must be newer than Makefile.am
for f in $makefileins ; do
  d="`dirname ${f}`"
  touchme "${d}/Makefile.in${comma_v}" "${d}/Makefile.am${comma_v}"
done

# Makefile.in depends on aclocal.m4
for f in $makefileins ; do
  d="`dirname $f`"
  touchme "${d}/Makefile.in${comma_v}" "aclocal.m4${comma_v}"
done

# config.in must be newer than aclocal.m4 and configure.ac
if [ -f "config.in${comma_v}" ] ; then
  touchme "config.in${comma_v}" "aclocal.m4${comma_v}" \
                                "configure.ac${comma_v}" \
                                "configure.in${comma_v}"
fi

# config.h.in (or More Thoroughly Modern configh.in)
# must be newer than aclocal.m4 and (obsolete) acconfig.h
for c_h_in in config.h.in configh.in ; do
  if [ -f "${c_h_in}${comma_v}" ]; then
    touchme "${c_h_in}${comma_v}" "aclocal.m4${comma_v}" "acconfig.h${comma_v}"
    #>>>> WTF?  Why?  This is nonsensical
    ## ***/Makefile.in must be newer than config.h.in
    #for f in $makefileins ; do
    #  touchme "$f" "${c_h_in}${comma_v}"
    #done
  fi
done

# configure must be newer than everything
# touchme configure $makefileins -- why would this be needed?
touchme "configure${comma_v}" "aclocal.m4${comma_v}" "acconfig.h${comma_v}" \
                              "config.in${comma_v}" "config.h.in${comma_v}" \
                              "configh.in${comma_v}"

if [ -n "${commit}" ] ; then
  commit="${commit:9}" # strip off "--commit="
  # First ***/Makefile.am,
  # configure.in, configure.ac,
  # ***/*.m4
  # acconfig.h
  cvs commit -m "${commit}" \
             `for f in ${makefileins} ; do \
                [ -f "$${f%.in}.am" ] && echo "$${f%.in}.am" ; \
              done` \
             `[ -f configure.in ] && echo configure.in` \
             `[ -f configure.ac ] && echo configure.ac` \
             `[ -f acconfig.h ] && echo acconfig.h` \
             `/usr/bin/find . -name '*.m4' -mindepth 2`

  # Next aclocal.m4
  [ -f "aclocal.m4" ] && cvs commit -m "${commit}" aclocal.m4

  # Next config.in, config.h.in, configh.in
  [ -f "config.in" ] && cvs commit -m "${commit}" config.in
  [ -f "config.h.in" ] && cvs commit -m "${commit}" config.h.in
  [ -f "configh.in" ] && cvs commit -m "${commit}" configh.in

  # Last ***/Makefile.in, configure
  cvs commit -m "${commit}" ${makefileins} configure
fi