import std.cstream, std.file, std.string;

string[] getFileNames()
{
	string[] result;
	foreach (v; listdir("coneneko", "*.d"))
	{
		result ~= v.replace(`coneneko\`, "").replace(".d", "");
	}
	return result;
}

void tab()
{
	dout.writef("\t");
}

void main()
{
	dout.writefln("# このファイルはdoc_mak_generatorで自動生成しました");
	dout.writefln("");
	auto fileNames = getFileNames();
	foreach (v; fileNames)
	{
		dout.writefln(`%s.html : coneneko\%s.d`, v, v);
		tab();
		dout.writefln("dmd -D -o- $**");
		dout.writefln("");
	}
	foreach (v; fileNames)
	{
		dout.writefln(`..\doc\%s.html : %s.html ..\bin\inject_name.exe`, v, v);
		tab();
		dout.writefln(`+..\bin\inject_name < %s.html > $@`, v);
		dout.writefln("");
	}
	dout.writefln(`..\doc\index.html : \`);
	foreach (v; fileNames)
	{
		tab();
		tab();
		dout.writefln(`%s.html \`, v);
	}
	tab();
	tab();
	dout.writefln(`..\bin\extract_href.exe`);
	tab();
	dout.writefln(`+..\bin\extract_href %s.html > $@`, fileNames[0]);
	foreach (v; fileNames[1..$])
	{
		tab();
		dout.writefln(`+..\bin\extract_href %s.html >> $@`, v);
	}
	dout.writefln("");
	dout.writefln(`doc : \`);
	foreach (v; fileNames)
	{
		tab();
		dout.writefln(`..\doc\%s.html \`, v);
	}
	tab();
	dout.writefln(`..\doc\index.html`);
}
