Created
July 9, 2021 15:35
-
-
Save taskie/047849e7964c3758e876af6bc2844c64 to your computer and use it in GitHub Desktop.
サブディレクトリにいたまま make(1) したいという気持ち
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -eu | |
die () { | |
printf "$(basename "$0"): %s\n" "$*" >&2 | |
exit 1 | |
} | |
get_device () { | |
stat -c '%d' "$1" | |
} | |
if [ $# -eq 0 ]; then | |
die 'base path must be specified' | |
fi | |
dir="$1" | |
shift | |
if [ $# -eq 0 ]; then | |
die 'options for `find` must be specified' | |
fi | |
cur="$(realpath "$dir")" | |
current_device="$(get_device "$cur")" | |
while true; do | |
found="$(find "$cur" -mindepth 1 -maxdepth 1 "$@")" | |
if [ -n "$found" ]; then | |
printf "%s\n" "$found" | |
exit 0 | |
fi | |
if [ "$cur" = / ]; then | |
break | |
fi | |
cur="$(dirname "$cur")" | |
next_device="$(get_device "$cur")" | |
if [ "$current_device" != "$next_device" ]; then | |
die 'stopping at filesystem boundary' | |
fi | |
done | |
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -eu | |
found="$(findup . -name Makefile -o -name GNUmakefile | head -n 1)" | |
if [ -n "$found" ]; then | |
make -C "$(dirname "$found")" "$@" | |
else | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment