Mercurial Hosting > luan
comparison src/luan/modules/mmake.luan @ 1716:b82767112d8e
add String.regex
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 24 Jul 2022 23:43:03 -0600 |
parents | 4d6c1bb8f975 |
children | c637a2a1023d |
comparison
equal
deleted
inserted
replaced
1715:ad44e849c60c | 1716:b82767112d8e |
---|---|
3 local Table = require "luan:Table.luan" | 3 local Table = require "luan:Table.luan" |
4 local Io = require "luan:Io.luan" | 4 local Io = require "luan:Io.luan" |
5 local print = Io.print | 5 local print = Io.print |
6 local output_to = Io.output_to | 6 local output_to = Io.output_to |
7 local String = require "luan:String.luan" | 7 local String = require "luan:String.luan" |
8 local regex = String.regex | |
9 local substring = String.sub | |
10 local ends_with = String.ends_with | |
8 local Time = require "luan:Time.luan" | 11 local Time = require "luan:Time.luan" |
12 local time_now = Time.now | |
13 local time_format = Time.format | |
9 | 14 |
10 | 15 |
11 local compiler = Table.concat( { "javac -g -encoding UTF8", ... }, " " ) | 16 local compiler = Table.concat( { "javac -g -encoding UTF8", ... }, " " ) |
12 | 17 |
13 | 18 |
14 local function header() | 19 local function header() |
15 %> | 20 %> |
16 # Makefile created on <%=Time.format(Time.now())%> by Mmake | 21 # Makefile created on <%=time_format(time_now())%> by Mmake |
17 | 22 |
18 .SUFFIXES: .java .class | 23 .SUFFIXES: .java .class |
19 | 24 |
20 .java.class: | 25 .java.class: |
21 <%=compiler%> '$<' | 26 <%=compiler%> '$<' |
27 local function mmake(dir) | 32 local function mmake(dir) |
28 local javas = {} | 33 local javas = {} |
29 local dirs = {} | 34 local dirs = {} |
30 for _, file in ipairs(dir.children()) do | 35 for _, file in ipairs(dir.children()) do |
31 local name = file.name() | 36 local name = file.name() |
32 if String.matches(name,[[\.java$]]) then | 37 if ends_with(name,".java") then |
33 javas[#javas+1] = String.sub(name,1,-6) | 38 javas[#javas+1] = substring(name,1,-6) |
34 end | 39 end |
35 if file.is_directory() and mmake(file) then | 40 if file.is_directory() and mmake(file) then |
36 dirs[#dirs+1] = name | 41 dirs[#dirs+1] = name |
37 end | 42 end |
38 end | 43 end |
39 if #javas == 0 and #dirs == 0 then | 44 if #javas == 0 and #dirs == 0 then |
40 return false; | 45 return false; |
41 end | 46 end |
42 local out = dir.child("Makefile").text_writer() | 47 local out = dir.child("Makefile").text_writer() |
43 output_to(out,header) | 48 output_to(out,header) |
49 local r = regex([[\$]]) | |
44 for _, s in ipairs(javas) do | 50 for _, s in ipairs(javas) do |
45 s = String.gsub(s,[[\$]],[[\$\$]]) | 51 s = r.gsub(s,[[\$\$]]) |
46 out.write( "\\\n\t\t", s , ".class" ) | 52 out.write( "\\\n\t\t", s , ".class" ) |
47 end | 53 end |
48 for _, s in ipairs(dirs) do | 54 for _, s in ipairs(dirs) do |
49 out.write( "\n\tcd ", s, "; make all" ) | 55 out.write( "\n\tcd ", s, "; make all" ) |
50 end | 56 end |