Last active
May 11, 2025 05:36
-
-
Save Justintime50/fd65dcd5d3c19808f0cb0e431a07fa6c to your computer and use it in GitHub Desktop.
Make Justfiles out of Makefiles
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
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