comparison src/luan/modules/mmake.luan @ 775:1a68fc55a80c

simplify dir structure
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 26 Aug 2016 14:36:40 -0600
parents core/src/luan/modules/mmake.luan@ca169567ce07
children 4d6c1bb8f975
comparison
equal deleted inserted replaced
774:3e30cf310e56 775:1a68fc55a80c
1 local Luan = require "luan:Luan.luan"
2 local ipairs = Luan.ipairs
3 local Table = require "luan:Table.luan"
4 local Io = require "luan:Io.luan"
5 local print = Io.print
6 local String = require "luan:String.luan"
7 local Time = require "luan:Time.luan"
8
9
10 local compiler = Table.concat( { "javac -g -encoding UTF8", ... }, " " )
11
12
13 local function header()
14 return %>
15 # Makefile created on <%=Time.format(Time.now())%> by Mmake
16
17 .SUFFIXES: .java .class
18
19 .java.class:
20 <%=compiler%> '$<'
21
22 all: <%
23 end
24
25
26 local function mmake(dir)
27 local javas = {}
28 local dirs = {}
29 for _, file in ipairs(dir.children()) do
30 local name = file.name()
31 if String.matches(name,[[\.java$]]) then
32 javas[#javas+1] = String.sub(name,1,-6)
33 end
34 if file.is_directory() and mmake(file) then
35 dirs[#dirs+1] = name
36 end
37 end
38 if #javas == 0 and #dirs == 0 then
39 return false;
40 end
41 local out = dir.child("Makefile").text_writer()
42 out.write( header() )
43 for _, s in ipairs(javas) do
44 s = String.gsub(s,[[\$]],[[\$\$]])
45 out.write( "\\\n\t\t", s , ".class" )
46 end
47 for _, s in ipairs(dirs) do
48 out.write( "\n\tcd ", s, "; make all" )
49 end
50 out.write "\n\nclean:\n\trm -f *.class\n"
51 for _, s in ipairs(dirs) do
52 out.write( "\tcd ", s, "; make clean\n" )
53 end
54 out.close()
55 print(dir.to_string())
56 return true
57 end
58
59 mmake(Io.schemes.file ".")