# BuildFox ninja generator

def gen_make(buildfox_name, cmd_env, ninja_gen_mode, filename = "Makefile"):
	text = """# generated by BuildFox
%s
compile:
	ninja
clean:
	ninja -t clean
"""

	if ninja_gen_mode:
		all = "all: compile"
	else:
		if cmd_env:
			all = "all: set_env configure compile\n"
			all += "set_env:\n"
			all += "\t%s\n" % cmd_env.replace("#", "\\#").replace("$", "$$")
		else:
			all = "all: configure compile\n"
		bf_cmd = "bf -i " + buildfox_name if buildfox_name != "build.fox" else "bf"
		all += "configure:\n"
		all += "\t%s" % bf_cmd

	with open(filename, "w") as f:
		f.write(text % all)
@@ -21,16 +21,32 @@
 erator%0A%0A
+import os, sys%0A%0A
 def gen_
@@ -439,16 +439,17 @@
 pile%5Cn%22%0A
+%0A
 %09%09bf_cmd
@@ -455,74 +455,178 @@
 d = 
-%22bf -i %22 + buildfox_name if buildfox_name != %22build.fox%22 else %22bf%22
+os.path.abspath(sys.argv%5B0%5D)%0A%09%09if bf_cmd.endswith(%22.py%22):%0A%09%09%09bf_cmd = sys.executable + %22 %22 + bf_cmd%0A%09%09if buildfox_name != %22build.fox%22:%0A%09%09%09bf_cmd += %22 -i %22 + buildfox_name
 %0A%09%09a

resolving correct bf name