작성 배경: 여러 개의 Makefile을 한꺼번에 다루기 위해서
42서울에서 진행하는 과제에서는 Makefile을 사용한다. 하나의 과제 속에는 여러 개의 작은 문제이 존재하고 make 명령어를 여러 번 작성하는 것을 번거롭다고 느꼈다.
(+제출할 Git Repository에 '.o' 와 같은 목적 파일과 실행 파일도 올라가면 안 된다)

./buildTest.sh [-f | --fclean] [TargetDirectory]make (fclean) 한다.3N -> 2 로 단축cd ex00
make
make fclean
cd ../ex01
make
make fclean
cd ../ex02
make
make fclean
...
cd ../ex0N
make
make fclean
(make -C 를 사용하여도 N개의 명령어)
buildTest 00
buildTest -f 00
#!/bin/bash
# Function to recursively find and run make in directories containing Makefiles
run_make() {
local dir="$1"
local fclean="$2"
cd "$dir" || exit
# Find directories containing a Makefile and run make on them
find . -type f -name 'Makefile' | while read -r makefile; do
subdir=$(dirname "$makefile")
echo "Running make in $subdir..."
if [[ "$fclean" == "true" ]]; then
make -C "$subdir" fclean
else
make -C "$subdir"
fi
done
}
# Parse arguments
DIRECTORY=""
FCLEAN="false"
while [[ "$#" -gt 0 ]]; do
case "$1" in
-f|--fclean) FCLEAN="true"; shift ;;
*) DIRECTORY="$1"; shift ;;
esac
done
# Check if directory is specified
if [[ -z "$DIRECTORY" ]]; then
echo "Please specify a directory."
exit 1
fi
echo "alias buildTest='sh ~/buildTest.sh'" >> ~/.zshrc
source ~/.zshrc
MacOS에서는
c++명령어의-std=c++98옵션이 유효하지 않다.
(Mac OS의 Clang 컴파일러가 이를 무시한다.) 따라서 42 과제의 요구사항인your code will comply with the C++98 standard.을 지켰는지 확인하기 번거롭다.
GitHub Codespace에서 위 스크립트를 사용하면 편하게 98standard 를 지켰는지 확인할 수 있다.