#!/bin/bash

# Get the target from the first argument or use "all" as default
TARGET=${1:-all}

find .. -mindepth 2 -maxdepth 2 -name 'Makefile' | while read -r makefile; do
    dir=$(dirname "$makefile")
    echo "Running 'make $TARGET' in $dir"
    (
        cd "$dir" && make "$TARGET"
    )
    if [ $? -ne 0 ]; then
        echo "Error: make $TARGET failed in $dir"
        exit 1 
    fi
done

echo "All make processes completed successfully."
