Created
January 11, 2024 12:21
-
-
Save mnoumanshahzad/92e88b96e2c5c97f6e94ab1465cadd54 to your computer and use it in GitHub Desktop.
Port Makefile targets to Justfile recipes to enable incremental deprecation of Makefile usage
This file contains hidden or 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/bash | |
# Name of the Makefile to be converted | |
MAKEFILE="Makefile" | |
# Name of the output Justfile | |
JUSTFILE="Justfile" | |
# Check if the Makefile exists | |
if [ ! -f "$MAKEFILE" ]; then | |
echo "Makefile not found" | |
exit 1 | |
fi | |
# Clear the Justfile content | |
> "$JUSTFILE" | |
# Add in the default recipe to Justfile | |
echo "default:" >> "$JUSTFILE" | |
echo -e " just --list\n" >> "$JUSTFILE" | |
# Read each line in the Makefile | |
while IFS= read -r line | |
do | |
# Extract target names (lines ending with ':') | |
if [[ "$line" =~ ^[a-zA-Z0-9_-]+: ]]; then | |
# Extract the target name | |
target_name=$(echo "$line" | cut -d':' -f1) | |
# Write the corresponding recipe to Justfile | |
echo "$target_name:" >> "$JUSTFILE" | |
echo -e " make $target_name\n" >> "$JUSTFILE" | |
fi | |
done < "$MAKEFILE" | |
echo "Successfully ported the Makefile to Justfile." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment