summaryrefslogtreecommitdiff
path: root/tools/notsd-move
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-09-10 22:13:28 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-09-10 22:13:28 -0400
commit5a889259f2a796052a65e74f75a708e6df62b016 (patch)
treeae4f81ceb25b4322700efcc227a9e1c8babd30a3 /tools/notsd-move
parent151b9b1d3524b565e7d3a7fa43b86e6bf66ac0e9 (diff)
fix
Diffstat (limited to 'tools/notsd-move')
-rwxr-xr-xtools/notsd-move86
1 files changed, 55 insertions, 31 deletions
diff --git a/tools/notsd-move b/tools/notsd-move
index 3a9f4b4a8c..6e7cebe2d0 100755
--- a/tools/notsd-move
+++ b/tools/notsd-move
@@ -1,13 +1,14 @@
#!/usr/bin/env bash
-in_array() {
+in_array() (
+ set +x
local needle=$1; shift
local item
for item in "$@"; do
[[ $item = $needle ]] && return 0 # Found
done
return 1 # Not Found
-}
+)
split_lib() {
local d=$1
@@ -659,25 +660,43 @@ move_files() (
)
breakup_makefile() (
- touch .tmp.move.all
- files=(.tmp.move.all)
- file=/dev/null
- IFS=''
- while read -r line; do
- if [[ $line = '#@'* ]]; then
- file="${line#'#@'}"
- file="${file%% *}"
- elif [[ $file = all ]]; then
- printf '%s\n' "$line" | tee -a "${files[@]}" >/dev/null
- else
+ set -x
+ mkdir -p build-aux/Makefile.{once,each}.{head,tail}
+
+ touch .tmp.move.all
+ files=(.tmp.move.all)
+ file=/dev/null
+ IFS=''
+ declare -i i=0
+ trap 'printf "Makefile.am:%d:%s\n" $i "$line"' EXIT
+ while read -r line; do
+ i+=1
+ if [[ $line = '#@'* ]]; then
+ file="${line#'#@'}"
+ file="${file%% *}"
+ if [[ $file = auto/* ]]; then
+ IFS=/
+ read -r auto dir makefile <<<"$file"
+ IFS=''
+ [[ $auto = auto ]]
+ [[ $makefile = Makefile ]]
+ d="$(find src -type d -name "$dir")"
+ [[ -n "$d" ]]
+ [[ "$(wc -l <<<"$d")" = 1 ]]
+ file="$d/Makefile"
+ fi
+ elif [[ $file = all ]]; then
+ printf '%s\n' "$line" | tee -a "${files[@]}" >/dev/null
+ else
if ! in_array "$file" "${files[@]}"; then
cat .tmp.move.all > "$file"
files+=("$file")
fi
- printf '%s\n' "$line" >> "$file"
- fi
- done < <(fixup_makefile <Makefile.am)
- rm .tmp.move.all
+ printf '%s\n' "$line" >> "$file"
+ fi
+ done < <(fixup_makefile <Makefile.am)
+ trap -- EXIT
+ rm .tmp.move.all
sed -ri \
-e '/^ \$\(AM_V_at\)\$\(MKDIR_P\) \$\(dir \$@\)/d' \
@@ -722,36 +741,41 @@ breakup_zshcompletion() (
)
move() (
- find . \( -name Makefile -o -name '*.mk' \) -delete
+ find . \( -name Makefile -o -name '*.mk' \) -delete
>&2 echo ' => breakup_zshcompletion'
breakup_zshcompletion
>&2 echo ' => move_files'
move_files
>&2 echo ' => breakup_makefile'
- breakup_makefile
+ "$0" breakup_makefile |& tail -n20 > .tmp.log || { r=$?; cat .tmp.log; exit $r; }
>&2 echo ' => ./tools/notsd-fixup'
./tools/notsd-fixup
)
main() {
set -e
+ set -o pipefail
- if [[ -n "$(git status -s)" ]] || [[ -n "$(git clean -xdn)" ]]; then
- echo 'There are changes in the current directory.' >&2
- exit 1
- fi
+ if [[ $# -gt 0 ]]; then
+ "$@"
+ else
+ if [[ -n "$(git status -s)" ]] || [[ -n "$(git clean -xdn)" ]]; then
+ echo 'There are changes in the current directory.' >&2
+ exit 1
+ fi
- git checkout -b tmp/postmove
+ git checkout -b tmp/postmove
- move
+ move
- git add .
- git commit -m './tools/notsd-move'
- git merge -s ours notsystemd/postmove
- git checkout notsystemd/postmove
- git merge tmp/postmove
- git branch -d tmp/postmove
+ git add .
+ git commit -m './tools/notsd-move'
+ git merge -s ours notsystemd/postmove
+ git checkout notsystemd/postmove
+ git merge tmp/postmove
+ git branch -d tmp/postmove
+ fi
}
main "$@"