3 # Copyright (c) 2015 Cisco and/or its affiliates.
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at:
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
16 # This aptly-named script verifies and fixes time ordering
17 # problems with Makefile.{am,in} aclocal.m4 configure* files.
28 # The old autowank scheme used "touch <foo> ; sleep 1"
29 # to ensure differentiable, ordered timestamps. Worked, but
30 # took N seconds given N files to fix. We have an example
31 # which wastes multiple minutes given the old scheme.
33 # This version generates a sequence of timestamps
34 # starting an hour ago. That gives us
35 # lots to play with, in case some obnoxious program feels the need
36 # to complain about timestamps in the future.
38 # If we're in UTC+N land, generate UTC+(N+1)
39 # If we're in UTC-N land, generate UTC-(N-1)
42 sign=`echo $my_tz | sed -n -e 's/^\(.\{1\}\).*$/\1/p'`
43 t=`echo $my_tz | sed -n -e 's/^\(.\{1\}\)//p'`
44 tz_hour=`echo $t | sed -n -e 's/^\(.\{2\}\).*$/\1/p'`
45 tz_hour=`echo $tz_hour | sed 's/^0//'`
47 if [ $sign = "-" ] ; then
49 let tz_hour=$tz_hour+1
50 if [[ $tz_hour -ge "24" ]] ; then
55 let tz_hour=$tz_hour-1 || true
56 if [[ $tz_hour -lt "0" ]] ; then
61 # Timestamp, an hour ago:
62 ts_begin=`TZ=UTC${sign}${tz_hour} date +%Y%m%d%H%M.%S`
64 # break into constituent parts
65 year=`echo $ts_begin | sed -n -e 's/^\(.\{4\}\).*$/\1/p'`
66 t=`echo $ts_begin | sed -n -e 's/^\(.\{4\}\)//p'`
67 month=`echo $t | sed -n -e 's/^\(.\{2\}\).*$/\1/p'`
68 t=`echo $t | sed -n -e 's/^\(.\{2\}\)//p'`
69 day=`echo $t | sed -n -e 's/^\(.\{2\}\).*$/\1/p'`
70 t=`echo $t | sed -n -e 's/^\(.\{2\}\)//p'`
71 hour=`echo $t | sed -n -e 's/^\(.\{2\}\).*$/\1/p'`
72 t=`echo $t | sed -n -e 's/^\(.\{2\}\)//p'`
73 min=`echo $t | sed -n -e 's/^\(.\{2\}\).*$/\1/p'`
74 t=`echo $t | sed -n -e 's/^\(.\{2\}\)//p'`
75 sec=`echo $t | sed -n -e 's/\.//p'`
77 # How many days in the current month?
78 # Good until someone changes the calendar rules
79 days_in_current_month() {
80 if [[ $month -eq 9 || $month -eq 4 \
81 || $month -eq 6 || $month -eq 11 ]] ; then
84 if [[ $month -eq 2 ]] ; then
86 if [[ $t -eq $year ]] ; then
90 if [[ $t -eq $year ]] ; then
94 if [[ $t -eq $year ]] ; then
102 # The next timestamp to issue via touch
103 # A real hemorrhoid because bash isnt easily convinced
104 # that 08 is a decimal number
106 sec=`echo $sec | sed 's/^0//'`
108 if [[ "$sec" -lt "60" ]] ; then
109 if [[ "$sec" -lt "10" ]] ; then
115 min=`echo $min | sed 's/^0//'`
117 if [[ "$min" -lt "60" ]] ; then
118 if [[ "$min" -lt "10" ]] ; then
124 hour=`echo $hour | sed 's/^0//'`
126 if [[ "$hour" -lt "24" ]] ; then
127 if [[ "$hour" -lt "10" ]] ; then
133 days_in_current_month
135 if [[ "$day" -lt "$days_in_month" ]] ; then
136 day=`echo $day | sed 's/^0//'`
138 if [[ "$day" -lt "10" ]] ; then
144 month=`echo $month | sed 's/^0//'`
146 if [[ "$month" -lt "13" ]] ; then
147 if [[ "$month" -lt "10" ]] ; then
157 while [ $# != 0 ] ; do
159 (--commav) comma_v=",v" ;;
160 (--touch) touch=yes ;;
161 (--aclocal) aclocal=yes ;;
162 (--nooptimize) optimize="" ;;
163 (--commit=*) commit="$1" ;;
164 (*) echo "$0: usage [--touch|--commit|]" > /dev/stderr
170 if [ "${aclocal}" != "" ] ; then
171 if [ -f aclocal.m4 ] ; then
172 echo touching aclocal.m4
176 echo aclocal.m4 not found
180 if [ "${comma_v}" != "" -a "${commit}" != "" ] ; then
181 echo "No, you may NOT molest ,v files directly. Go away." > /dev/stderr
194 if [ ! -r "$victim" ] ; then
198 while [ $# != 0 ] ; do
199 if [ "${1}" -nt "${victim}" ] ; then
202 if [ "${1}" -ot "${victim}" ] ; then
205 if [ "${newer}" = "no" -a "${older}" = "no" ] ; then
209 if [ "${newer}" = "yes" ] ; then
210 if [ "${touchmebaby}" = "" ] ; then
214 touchmebaby="${touchmebaby} ${1}"
219 if [ -n "${touchmebaby}" ] ; then
220 echo "*** ${touchmebaby} ${sein} newer than ${victim} "
221 if [ -n "${touch}" ] ; then
223 # This is the old version, in case something backfires...
224 if [ "${optimize}" != "yes" ] ; then
225 echo "Fixing " ;touch -c "$victim" ; sleep 1
228 # echo touch -c -t $year$month$day$hour$min.$sec "$victim"
229 touch -c -t $year$month$day$hour$min.$sec "$victim"
236 makefileins="`/usr/bin/find . -name Attic -prune -o -name Makefile.in${comma_v}`"
238 # aclocal.m4 depends on ***/Makefile.am, configure.ac, acinclude.m4, *.m4 crap
239 touchme aclocal.m4${comma_v} \
240 `/usr/bin/find . -name Attic -prune -o -name Makefile.am${comma_v}` \
241 "configure.in${comma_v}" "configure.ac${comma_v}" \
242 "acinclude.m4${comma_v}"
244 # Makefile.in must be newer than Makefile.am
245 for f in $makefileins ; do
247 touchme "${d}/Makefile.in${comma_v}" "${d}/Makefile.am${comma_v}"
250 # Makefile.in depends on aclocal.m4
251 for f in $makefileins ; do
253 touchme "${d}/Makefile.in${comma_v}" "aclocal.m4${comma_v}"
256 # config.in must be newer than aclocal.m4 and configure.ac
257 if [ -f "config.in${comma_v}" ] ; then
258 touchme "config.in${comma_v}" "aclocal.m4${comma_v}" \
259 "configure.ac${comma_v}" \
260 "configure.in${comma_v}"
263 # config.h.in (or More Thoroughly Modern configh.in)
264 # must be newer than aclocal.m4 and (obsolete) acconfig.h
265 for c_h_in in config.h.in configh.in ; do
266 if [ -f "${c_h_in}${comma_v}" ]; then
267 touchme "${c_h_in}${comma_v}" "aclocal.m4${comma_v}" "acconfig.h${comma_v}"
268 #>>>> WTF? Why? This is nonsensical
269 ## ***/Makefile.in must be newer than config.h.in
270 #for f in $makefileins ; do
271 # touchme "$f" "${c_h_in}${comma_v}"
276 # configure must be newer than everything
277 # touchme configure $makefileins -- why would this be needed?
278 touchme "configure${comma_v}" "aclocal.m4${comma_v}" "acconfig.h${comma_v}" \
279 "config.in${comma_v}" "config.h.in${comma_v}" \
280 "configh.in${comma_v}"
282 if [ -n "${commit}" ] ; then
283 commit="${commit:9}" # strip off "--commit="
284 # First ***/Makefile.am,
285 # configure.in, configure.ac,
288 cvs commit -m "${commit}" \
289 `for f in ${makefileins} ; do \
290 [ -f "$${f%.in}.am" ] && echo "$${f%.in}.am" ; \
292 `[ -f configure.in ] && echo configure.in` \
293 `[ -f configure.ac ] && echo configure.ac` \
294 `[ -f acconfig.h ] && echo acconfig.h` \
295 `/usr/bin/find . -name '*.m4' -mindepth 2`
298 [ -f "aclocal.m4" ] && cvs commit -m "${commit}" aclocal.m4
300 # Next config.in, config.h.in, configh.in
301 [ -f "config.in" ] && cvs commit -m "${commit}" config.in
302 [ -f "config.h.in" ] && cvs commit -m "${commit}" config.h.in
303 [ -f "configh.in" ] && cvs commit -m "${commit}" configh.in
305 # Last ***/Makefile.in, configure
306 cvs commit -m "${commit}" ${makefileins} configure