#mkdir '-p', 'build/classes'
SOURCES = wildcard 'src/**.java'
CLASSES = patsubst SOURCES, 'src/%.java', 'build/classes/%.class'
DATA = wildcard 'data/*'

MAIN_CLASS = 'totallynotmalware.TotallyNotMalware'
NAME = 'TotallyNotMalware'

public default target 'jar', from: "build/#{NAME}.jar"
public target 'java', from: CLASSES
public target 'data', from: patsubst DATA, 'data/%', 'build/classes/%'

public target 'clean', fn: =>
	-rm '-rf', 'build/classes', 'Manifest.mf'

public target 'mrproper', deps: 'clean', fn: =>
	-rm '-rf', 'build/TotallyNotMalware.jar'

target "build/#{NAME}.jar", deps: {'java', 'data'}, out: "build/#{NAME}.jar", fn: =>
	fd = io.open 'Manifest.mf', 'w'
	fd\write "Manifest-Version: 1.0\n"
	fd\write "Main-Class: #{MAIN_CLASS}\n"
	fd\close!
	-jar 'cvfm', @outfile, 'Manifest.mf', '-C', 'build/classes', '.'
	#rm 'Manifest.mf'

target 'build/classes/%.class', in: 'src/%.java', out: 'build/classes/%.class', fn: =>
	-javac '-cp', 'src:build/classes', '-d', 'build/classes', @infile

foreach DATA, =>
	out = patsubst @, 'data/%', 'build/classes/%'
	target out, in: @, out: out, fn: =>
		-cp '-a', @infile, @outfile
