1 Project
:= Object clone do(
2 cc
:= method(System
getenv("CC") ifNilEval(return "cc"))
3 cxx
:= method(System
getenv("CXX") ifNilEval(return "g++"))
4 platform
:= System platform split
at(0) asLowercase
6 systemCall
:= method(s
,
8 if(r
== 256, System
exit(1))
12 trySystemCall
:= method(s
,
13 result
:= System
system("sh -c '" .. s
.. "'")
17 modulesInFolder
:= method(name
,
18 folder
:= Directory clone setPath(name
)
19 if(folder exists not
, return List clone)
20 subfolders
:= folder folders
21 subfolders
selectInPlace(fileNamedOrNil("build.io"))
23 module
:= Lobby doString(f
fileNamedOrNil("build.io") contents
)
24 module folder
setPath(f path
)
30 self addons
:= modulesInFolder("addons") sortInPlaceBy(block(x
, y
, x name
< y name
))
33 buildAddon
:= method(name
,
34 addons
detect(addon
, addon name
== name
) build
37 availableAddon
:= method(addon
,
38 if(addon
hasSlot("isAvailable"), return addon isAvailable
)
39 if(addon
supportedOnPlatform(platform
) not
,
40 error
:= (addon name
.. " is not supported on " .. platform
.. "\n") print
41 File clone openForAppending("errors") write(error
) close
42 addon isAvailable
:= false
45 if(addon hasDepends not
, return false
)
46 addon depends addons
foreach(addonName
,
47 dependancy
:= addons
detect(name
== addonName
)
49 error
:= (addon name
.. " is missing " .. addonName
.. " addon\n") print
50 File clone openForAppending("errors") write(error
) close
51 addon isAvailable
:= false
54 if(availableAddon(dependancy
) not
,
55 error
:= (addon name
.. " is missing " .. addonName
.. " addon\n") print
56 File clone openForAppending("errors") write(error
) close
57 addon isAvailable
:= false
61 addon isAvailable
:= true
65 availableAddons
:= method(
66 addons
selectInPlace(addon
, availableAddon(addon
))
70 if (platform
== "windows",
71 "-MDd -DWIN32 -D_DEBUG -DIOBINDINGS"
73 "-Os -g -Wall -DSANE_POPEN -DIOBINDINGS"
78 File clone with("errors") remove close
80 writeln("\n--- build complete ---\n")
83 orderedAddons
:= method(
85 dependencies
:= availableAddons
clone
86 while(0 < dependencies size
,
87 ordered
= dependencies
clone appendSeq(ordered
) unique
88 dependencies
= dependencies
map(depends addons
map(a
, addons
detect(name
== a
))) flatten unique
93 buildAddons
:= method(
94 writeln("\n--- building addons ---\n")
96 orderedAddons
foreach(build(options
))
100 libPaths
:= Directory with("libs") folders
map(path
)
102 otherLibPaths
:= method(libtype
,
103 if(libtype
== nil
, libtype
= "_build/dll")
104 addons
:= availableAddons
106 l
appendSeq(addons
map(a
, "-Laddons/" .. a name
.. "/" .. libtype
))
111 libPaths
map(s
, "-I" .. s
.. "/_build/headers")
114 cleanAddons
:= method(
115 writeln("--- Project cleanAddons ---")
116 addons
foreach(clean
)
120 writeln("--- Project clean ---")
122 trySystemCall("rm -rf projects/*/build")
123 trySystemCall("rm -f IoAddonsInit.*")
127 writeln("--- Project generate embedded docs ---")
128 systemCall("cd libs/iovm; ../../_build/binaries/io ../../tools/io/DocsExtractor.io .")
129 addons
foreach(generateDocs
)
133 writeln("--- Project clean embedded docs ---")
134 systemCall("cd vm; make cleanDocs")
135 addons
foreach(cleanDocs
)
138 runUnitTests
:= method(
141 availableAddons
foreach(addon
,
142 path
:= Path
with(addon folder path
, "tests/run.io")
143 if(File clone setPath(path
) exists
,
144 write(addon name
alignLeft(10), " - ")
145 File standardOutput flush
146 r
:= System
system("./_build/binaries/io " .. path
)
147 if(r
== 0, writeln("PASSED"), writeln("FAILED ", r
, " TESTS"))
148 failures
= failures
+ r
152 if(failures
== 0, writeln("ALL TESTS PASSED"), writeln("FAILED ", failures
, " tests"))
156 installDependenciesFor
:= method(name
,
157 addons
map(installCommands
) map(at(name
)) select(!=nil
) foreach(c
,
163 aptget
:= method(installDependenciesFor("aptget"))
164 emerge
:= method(installDependenciesFor("emerge"))
165 port
:= method(installDependenciesFor("port"))
166 urpmi
:= method(installDependenciesFor("urpmi"))