view src/luan/modules/mmake.luan @ 1802:ca98dee04e08 default tip

add Parsers.json_null
author Franklin Schmidt <fschmidt@gmail.com>
date Sun, 21 Apr 2024 21:25:15 -0600
parents c637a2a1023d
children
line wrap: on
line source

local Luan = require "luan:Luan.luan"
local ipairs = Luan.ipairs
local Table = require "luan:Table.luan"
local Io = require "luan:Io.luan"
local print = Io.print
local output_to = Io.output_to
local String = require "luan:String.luan"
local replace = String.replace
local substring = String.sub
local ends_with = String.ends_with
local Time = require "luan:Time.luan"
local time_now = Time.now
local time_format = Time.format


local compiler = Table.concat( { "javac -g -encoding UTF8", ... }, " " )


local function header()
%>
# Makefile created on <%=time_format(time_now())%> by Mmake

.SUFFIXES: .java .class

.java.class:
	<%=compiler%> '$<'

all: <%
end


local function mmake(dir)
	local javas = {}
	local dirs = {}
	for _, file in ipairs(dir.children()) do
		local name = file.name()
		if ends_with(name,".java") then
			javas[#javas+1] = substring(name,1,-6)
		end
		if file.is_directory() and mmake(file) then
			dirs[#dirs+1] = name
		end
	end
	if #javas == 0 and #dirs == 0 then
		return false;
	end
	local out = dir.child("Makefile").text_writer()
	output_to(out,header)
	for _, s in ipairs(javas) do
		s = replace(s,"$","$$")
		out.write( "\\\n\t\t",  s , ".class" )
	end
	for _, s in ipairs(dirs) do
		out.write( "\n\tcd ", s, ";  make all" )
	end
	out.write "\n\nclean:\n\trm -f *.class\n"
	for _, s in ipairs(dirs) do
		out.write( "\tcd ", s, ";  make clean\n" )
	end
	out.close()
	print(dir.to_string())
	return true
end

mmake(Io.schemes.file ".")