Skip to content

Instantly share code, notes, and snippets.

@RandyMcMillan
Forked from mnoumanshahzad/make-to-just.sh
Created March 6, 2025 17:39
Show Gist options
  • Save RandyMcMillan/f643a7019d5f722769e1d1a7900935c8 to your computer and use it in GitHub Desktop.
Save RandyMcMillan/f643a7019d5f722769e1d1a7900935c8 to your computer and use it in GitHub Desktop.
Port Makefile targets to Justfile recipes to enable incremental deprecation of Makefile usage
#!/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