From 86ceab39f4ce8507a4b73e34d5bbba2d6bce7468 Mon Sep 17 00:00:00 2001
From: Landon Curt Noll
Date: Sun, 21 Jul 2024 23:42:16 -0700
Subject: [PATCH] improve bin/new-year.sh and Makefile sub-dir processing
The `bin/new-year.sh` now uses make rules to perform some
if its actions. It modifies the `Makefile` to add the
new year to the `${YEARS}` make variable.
Changed `bin/new-year.sh` VERSION from "1.0 2024-07-21"
to "1.1 2024-07-21".
The top level `Makefile` will test of a Makefile for
a given year exits before calling a make rule for the year.
If there is no `YYYY/Makefile` a warning message is issued
Updated `bin/README.md` to reflect these changes.
Performed `make www` to accomplish the above and to test under macOS.
---
Makefile | 227 ++++++++++++++++++++++++++++++++++++------------
bin/README.md | 4 +-
bin/index.html | 4 +-
bin/new-year.sh | 150 ++++++++++++++++++++++----------
4 files changed, 279 insertions(+), 106 deletions(-)
diff --git a/Makefile b/Makefile
index ab815887d..8941094c1 100644
--- a/Makefile
+++ b/Makefile
@@ -75,10 +75,11 @@ ENTRY2CSV= bin/entry2csv.sh
# IOCCC years
#############
#
-YEARS= 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 \
- 1994 1995 1996 1998 2000 2001 2004 2005 2006 2011 \
- 2012 2013 2014 2015 2018 2019 2020
-
+# BEGIN - DO NOT REMOVE THIS LINE - make new_year uses this line #
+YEARS= 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 \
+ 1996 1998 2000 2001 2004 2005 2006 2011 2012 2013 2014 2015 2018 \
+ 2019 2020
+# END - DO NOT REMOVE THIS LINE - make new_year also uses this #
###################
# build all entries
@@ -87,14 +88,18 @@ YEARS= 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 \
all:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
.PHONY: all alt data everything diff_orig_prog diff_prog_orig \
diff_alt_prog diff_prog_alt diff_orig_alt diff_alt_orig \
- clean clobber install genpath love haste waste maker \
+ clean clobber install genpath new_year love haste waste maker \
easter_egg sandwich supernova deep_magic magic charon pluto
# alternative executable
@@ -102,8 +107,12 @@ all:
alt:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
@@ -112,8 +121,12 @@ alt:
data:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
@@ -122,8 +135,12 @@ data:
everything:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
@@ -137,8 +154,12 @@ everything:
diff_orig_prog:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
@@ -147,8 +168,12 @@ diff_orig_prog:
diff_prog_orig:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
@@ -157,8 +182,12 @@ diff_prog_orig:
diff_alt_prog:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
@@ -167,8 +196,12 @@ diff_alt_prog:
diff_prog_alt:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
@@ -177,16 +210,25 @@ diff_prog_alt:
diff_orig_alt:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
(cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
diff_alt_orig:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
@@ -198,32 +240,48 @@ diff_alt_orig:
clean:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
clobber:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
install:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
indent.c:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
@@ -330,6 +388,7 @@ help:
######################################################
# verify that there are no leading ASCII tabs in leading whitespace in markdown files
+#
tab_check:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@TAB_LIST="$$(${FIND} * \( -name NOTES -o -name tmp -o -name markdown.md \) -prune -o \
@@ -353,9 +412,14 @@ genpath:
@${RM} -f .tmp.genpath
@-for i in ${YEARS}; do \
echo "$$i" >> .tmp.genpath; \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
+ ${SORT} -n -u .tmp.genpath -o .tmp.genpath;
@-if ${CMP} -s .tmp.genpath .top; then \
${RM} -f .tmp.genpath; \
else \
@@ -712,6 +776,13 @@ update:
# NOTE: 'Don't Panic' if you don't understand the stuff below
#############################################################
+# add ${NEW_YEAR} to the list of ${YEARS} and output Makefile lines to set updated ${YEARS} value
+#
+new_year:
+ @(echo 'YEARS= '; \
+ (echo ${YEARS} ${NEW_YEAR}) | ${TR} ' ' '\012' | ${SORT} -n) | \
+ ${FMT} -p | ${SED} -e '2,$$s/^/\t/' -e 's/$$/ \\/' -e '$$s/ \\//'
+
##################
# 133t hacker rulz
@@ -720,48 +791,72 @@ update:
love:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
haste:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
waste:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
maker:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
easter_egg:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
sandwich:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
@@ -771,39 +866,59 @@ sandwich:
supernova:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
deep_magic:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
magic:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
charon:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
pluto:
@echo '=-=-=-=-= IOCCC begin make $@ =-=-=-=-='
@-for i in ${YEARS}; do \
- echo "cd $$i; make $@"; \
- (cd $$i; make $@); \
+ if [[ -f $$i/Makefile ]]; then \
+ echo "cd $$i; make $@"; \
+ (cd $$i; make $@); \
+ else \
+ echo "Warning: $$i/Makefile not found, skipping $$i for $@ processing" 1>&2 ; \
+ fi; \
done
@echo '=-=-=-=-= IOCCC complete make $@ =-=-=-=-='
diff --git a/bin/README.md b/bin/README.md
index fce8e6f00..4b7223d9c 100644
--- a/bin/README.md
+++ b/bin/README.md
@@ -583,9 +583,7 @@ For example:
```
mkdir -p YYYY
- chmod +w .top
- bin/new-year.sh YYYY
- chmod -w .top
+ bin/new-year.sh -v 1 YYYY
```
Here, `YYYY` must be a new 4-digit IOCCC year.
diff --git a/bin/index.html b/bin/index.html
index 07f311c41..1f25a5926 100644
--- a/bin/index.html
+++ b/bin/index.html
@@ -720,9 +720,7 @@ the md2html tool.
steps to announce a new set of winning IOCCC entries.
For example:
mkdir -p YYYY
- chmod +w .top
- bin/new-year.sh YYYY
- chmod -w .top
+ bin/new-year.sh -v 1 YYYY
Here, YYYY must be a new 4-digit IOCCC year.
diff --git a/bin/new-year.sh b/bin/new-year.sh
index d98713e4a..0840e474f 100755
--- a/bin/new-year.sh
+++ b/bin/new-year.sh
@@ -88,7 +88,7 @@ shopt -s globstar # enable ** to match all files and zero or more directories an
# set variables referenced in the usage message
#
-export VERSION="1.0 2024-07-21"
+export VERSION="1.1 2024-07-21"
NAME=$(basename "$0")
export NAME
export V_FLAG=0
@@ -201,6 +201,7 @@ else
exit 1
fi
+
# verify that we have a topdir directory
#
REPO_NAME=$(basename "$REPO_URL")
@@ -221,6 +222,7 @@ if [[ ! -d $TOPDIR ]]; then
exit 6
fi
+
# cd to topdir
#
if [[ ! -e $TOPDIR ]]; then
@@ -244,7 +246,8 @@ if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: now in directory: $(/bin/pwd)" 1>&2
fi
-# verify we have a non-empty writable .top file
+
+# verify we have a non-empty readable .top file
#
export TOP_FILE=".top"
if [[ ! -e $TOP_FILE ]]; then
@@ -255,15 +258,37 @@ if [[ ! -f $TOP_FILE ]]; then
echo "$0: ERROR: .top is not a regular file: $TOP_FILE" 1>&2
exit 6
fi
-if [[ ! -w $TOP_FILE ]]; then
- echo "$0: ERROR: .top is not an writable file: $TOP_FILE" 1>&2
+if [[ ! -r $TOP_FILE ]]; then
+ echo "$0: ERROR: .top is not an readable file: $TOP_FILE" 1>&2
exit 6
fi
if [[ ! -s $TOP_FILE ]]; then
- echo "$0: ERROR: .top is not a non-empty writable file: $TOP_FILE" 1>&2
+ echo "$0: ERROR: .top is not a non-empty readable file: $TOP_FILE" 1>&2
exit 6
fi
+
+# verify we have a non-empty readable Makefile
+
+export MAKE_FILE="Makefile"
+if [[ ! -e $MAKE_FILE ]]; then
+ echo "$0: ERROR: .top does not exist: $MAKE_FILE" 1>&2
+ exit 6
+fi
+if [[ ! -f $MAKE_FILE ]]; then
+ echo "$0: ERROR: .top is not a regular file: $MAKE_FILE" 1>&2
+ exit 6
+fi
+if [[ ! -r $MAKE_FILE ]]; then
+ echo "$0: ERROR: .top is not an readable file: $MAKE_FILE" 1>&2
+ exit 6
+fi
+if [[ ! -s $MAKE_FILE ]]; then
+ echo "$0: ERROR: .top is not a non-empty readable file: $MAKE_FILE" 1>&2
+ exit 6
+fi
+
+
# print running info if verbose
#
# If -v 3 or higher, print exported variables in order that they were exported.
@@ -281,6 +306,7 @@ if [[ $V_FLAG -ge 3 ]]; then
echo "$0: debug[3]: REPO_NAME=$REPO_NAME" 1>&2
echo "$0: debug[3]: CD_FAILED=$CD_FAILED" 1>&2
echo "$0: debug[3]: TOP_FILE=$TOP_FILE" 1>&2
+ echo "$0: debug[3]: MAKE_FILE=$MAKE_FILE" 1>&2
fi
# -N stops early before any processing is performed
@@ -293,64 +319,100 @@ if [[ -n $DO_NOT_PROCESS ]]; then
fi
-# verify that YEAR is not already in .top
+# create a temporary Makefile
#
-if grep -E -q "^$YEAR$" "$TOP_FILE"; then
- echo "$0: notice: YEAR: $YEAR already found in: $TOP_FILE" 1>&2
+export TMP_MAKEFILE=".tmp.$NAME.MAKEFILE.$$.tmp"
+if [[ $V_FLAG -ge 3 ]]; then
+ echo "$0: debug[3]: temporary Makefile: $TMP_MAKEFILE" 1>&2
+fi
+trap 'rm -f $TMP_MAKEFILE; exit' 0 1 2 3 15
+rm -f "$TMP_MAKEFILE"
+if [[ -e $TMP_MAKEFILE ]]; then
+ echo "$0: ERROR: cannot remove temporary Makefile: $TMP_MAKEFILE" 1>&2
+ exit 10
+fi
+echo '# author_handle,entry_id,entry_id,entry_id,…,,,,,,,,,,,,,,,' > \
+ "$TMP_MAKEFILE"
+if [[ ! -e $TMP_MAKEFILE ]]; then
+ echo "$0: ERROR: cannot create temporary Makefile: $TMP_MAKEFILE" 1>&2
+ exit 11
fi
-# year directory must exist
+
+# form the temporary Makefile with the added year
#
-if [[ ! -e $YEAR ]]; then
- echo "$0: ERROR: year directory does not exist: $YEAR" 1>&2
- exit 1
+if [[ $V_FLAG -ge 3 ]]; then
+ echo "$0: debug[3]: forming temporary Makefile: $TMP_MAKEFILE" 1>&2
fi
-if [[ ! -d $YEAR ]]; then
- echo "$0: ERROR: year is not a directory: $YEAR" 1>&2
- exit 1
+sed -n -e '1,/^# BEGIN - DO NOT REMOVE THIS LINE - make new_year uses this line #/p' "$MAKE_FILE" > "$TMP_MAKEFILE"
+make new_year NEW_YEAR="$YEAR" >> "$TMP_MAKEFILE"
+status="$?"
+if [[ $status -ne 0 ]]; then
+ echo "$0: ERROR: make new_year NEW_YEAR=\"$YEAR\" >> \"$TMP_MAKEFILE\" failed," \
+ "error code: $status" 1>&2
+ exit 12
fi
+sed -n -e '/^# END - DO NOT REMOVE THIS LINE - make new_year also uses this #/,$p' "$MAKE_FILE" >> "$TMP_MAKEFILE"
-# case: without -n
+# Update Makefile if different and not -n
#
if [[ -z $NOOP ]]; then
- # append year to .top
- #
- if [[ $V_FLAG -ge 3 ]]; then
- echo "$0: debug[3]: appending YEAR: $YEAR to: $TOP_FILE" 1>&2
- fi
- echo "$YEAR" >> "$TOP_FILE"
+ if cmp -s "$TMP_MAKEFILE" "$MAKE_FILE"; then
- # sort .top numerically
- #
- if [[ $V_FLAG -ge 3 ]]; then
- echo "$0: debug[3]: about to: sort -n -u $TOP_FILE -o $TOP_FILE" 1>&2
- fi
- sort -n -u "$TOP_FILE" -o "$TOP_FILE"
- status="$?"
- if [[ $status -ne 0 ]]; then
- echo "$0: ERROR: sort -n -u $TOP_FILE -o $TOP_FILE failed," \
- "error code: $status" 1>&2
- exit 10
- fi
+ # case: author_wins.csv did not change
+ #
+ if [[ $V_FLAG -ge 5 ]]; then
+ echo "$0: debug[5]: Makefile file did not change: $MAKE_FILE" 1>&2
+ fi
- # firewall
- #
- if grep -E -q "^$YEAR$" "$TOP_FILE"; then
- if [[ $V_FLAG -ge 1 ]]; then
- echo "$0: debug[1]: YEAR: $YEAR is in: $TOP_FILE" 1>&2
- echo "$0: debug[1]: Happy New IOCCC Year!!!" 1>&2
- fi
else
- echo "$0: ERROR: failed to add YEAR: $YEAR to: $TOP_FILE" 1>&2
- exit 11
+
+ # case: Makefile file changed, update the file
+ #
+ if [[ $V_FLAG -ge 5 ]]; then
+ echo "$0: debug[5]: about to: mv -f -- $TMP_MAKEFILE $MAKE_FILE" 1>&2
+ fi
+ if [[ $V_FLAG -ge 3 ]]; then
+ mv -f -v -- "$TMP_MAKEFILE" "$MAKE_FILE"
+ status="$?"
+ else
+ mv -f -- "$TMP_MAKEFILE" "$MAKE_FILE"
+ status="$?"
+ fi
+ if [[ status -ne 0 ]]; then
+ echo "$0: ERROR: mv -f -- $TMP_MAKEFILE $MAKE_FILE filed," \
+ "error code: $status" 1>&2
+ exit 13
+ elif [[ $V_FLAG -ge 1 ]]; then
+ echo "$0: debug[1]: updated Makefile: $MAKE_FILE" 1>&2
+ fi
+ if [[ ! -s $MAKE_FILE ]]; then
+ echo "$0: ERROR: not a non-empty Makefile: $MAKE_FILE" 1>&2
+ exit 14
+ fi
+
+ # update .top and friends
+ #
+ if [[ $V_FLAG -ge 3 ]]; then
+ echo "$0: debug[3]: about to run: make genpath >/dev/null" 1>&2
+ fi
+ make genpath >/dev/null
+ status="$?"
+ if [[ status -ne 0 ]]; then
+ echo "$0: ERROR: make genpath >/dev/null failed," \
+ "error code: $status" 1>&2
+ exit 15
+ elif [[ $V_FLAG -ge 1 ]]; then
+ echo "$0: debug[1]: updated .top and friends" 1>&2
+ fi
fi
# case: with -n
#
elif [[ $V_FLAG -ge 3 ]]; then
- echo "$0: debug[3]: -n disabled adding YEAR: $YEAR to $TOP_FILE" 1>&2
+ echo "$0: debug[3]: -n disabled updating: $MAKE_FILE" 1>&2
fi