Skip to content

Instantly share code, notes, and snippets.

@Justintime50
Last active March 4, 2024 22:46
Show Gist options
  • Save Justintime50/fd65dcd5d3c19808f0cb0e431a07fa6c to your computer and use it in GitHub Desktop.
Save Justintime50/fd65dcd5d3c19808f0cb0e431a07fa6c to your computer and use it in GitHub Desktop.
Make Justfiles out of Makefiles
import os
def main():
makefile_path = os.path.join(os.getcwd(), "Makefile")
with open(makefile_path, "r") as makefile:
content = makefile.readlines()
new_content = ""
for line in content:
# 1. Remove PHONY lines
if line.startswith(".PHONY"):
pass
else:
# 2. Swap variable syntax
# 3. Remove the piped dependencies
# 4. Swap make for just
var_replacement = (
line.replace("$(", "{{").replace(")", "}}").replace(": | ", ": ").replace("make", "just")
)
if len(var_replacement.split(" - ")) > 1:
# 5. Remove the double-verbose comment headers
new_content += "# " + var_replacement.split(" - ")[1]
else:
new_content += var_replacement
# 6. Replace Makefile tabs with 4 spaces
new_content = new_content.expandtabs(4)
with open("justfile", "w") as justfile:
justfile.write(new_content)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment