72414
|
1 |
/* Title: Pure/Admin/build_csdp.scala
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Build Isabelle CSDP component from official downloads.
|
|
5 |
*/
|
|
6 |
|
|
7 |
package isabelle
|
|
8 |
|
|
9 |
|
|
10 |
object Build_CSDP
|
|
11 |
{
|
72417
|
12 |
// Note: version 6.2.0 does not quite work for the "sos" proof method
|
|
13 |
val default_download_url = "https://github.com/coin-or/Csdp/archive/releases/6.1.1.tar.gz"
|
72414
|
14 |
|
|
15 |
|
72417
|
16 |
/* flags */
|
72414
|
17 |
|
|
18 |
sealed case class Flags(platform: String, CFLAGS: String = "", LIBS: String = "")
|
|
19 |
{
|
72417
|
20 |
val changed: List[(String, String)] =
|
|
21 |
List("CFLAGS" -> CFLAGS, "LIBS" -> LIBS).filter(p => p._2.nonEmpty)
|
|
22 |
|
72414
|
23 |
def print: String =
|
72417
|
24 |
if (changed.isEmpty) ""
|
|
25 |
else " * " + platform + ":\n" + changed.map(p => " " + p._1 + "=" + p._2).mkString("\n")
|
72414
|
26 |
|
|
27 |
def change(path: Path)
|
|
28 |
{
|
72417
|
29 |
def change_line(line: String, entry: (String, String)): String =
|
|
30 |
line.replaceAll(entry._1 + "=.*", entry._1 + "=" + entry._2)
|
72414
|
31 |
File.change(path, s =>
|
72417
|
32 |
split_lines(s).map(line => (line /: changed)(change_line)).mkString("\n"))
|
72414
|
33 |
}
|
|
34 |
}
|
|
35 |
|
|
36 |
val build_flags: List[Flags] =
|
|
37 |
List(
|
|
38 |
Flags("arm64-linux",
|
72417
|
39 |
CFLAGS = "-O3 -ansi -Wall -DNOSHORTS -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include",
|
72414
|
40 |
LIBS = "-static -L../lib -lsdp -llapack -lblas -lgfortran -lm"),
|
72417
|
41 |
Flags("x86_64-linux",
|
|
42 |
CFLAGS = "-O3 -ansi -Wall -DNOSHORTS -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include",
|
72414
|
43 |
LIBS = "-static -L../lib -lsdp -llapack -lblas -lgfortran -lquadmath -lm"),
|
|
44 |
Flags("x86_64-darwin",
|
72417
|
45 |
CFLAGS = "-O3 -Wall -DNOSHORTS -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include",
|
|
46 |
LIBS = "-L../lib -lsdp -llapack -lblas -lm"),
|
|
47 |
Flags("x86_64-windows"))
|
|
48 |
|
|
49 |
|
|
50 |
/* build CSDP */
|
72414
|
51 |
|
|
52 |
def build_csdp(
|
72417
|
53 |
download_url: String = default_download_url,
|
72414
|
54 |
verbose: Boolean = false,
|
|
55 |
progress: Progress = new Progress,
|
|
56 |
target_dir: Path = Path.current)
|
|
57 |
{
|
|
58 |
Isabelle_System.with_tmp_dir("build")(tmp_dir =>
|
|
59 |
{
|
72417
|
60 |
/* component */
|
|
61 |
|
|
62 |
val Archive_Name = """^.*?([^/]+)$""".r
|
|
63 |
val Version = """^[^0-9]*([0-9].*)\.tar.gz$""".r
|
|
64 |
|
|
65 |
val archive_name =
|
|
66 |
download_url match {
|
|
67 |
case Archive_Name(name) => name
|
|
68 |
case _ => error("Failed to determine source archive name from " + quote(download_url))
|
|
69 |
}
|
|
70 |
|
|
71 |
val version =
|
|
72 |
archive_name match {
|
|
73 |
case Version(version) => version
|
|
74 |
case _ => error("Failed to determine component version from " + quote(archive_name))
|
|
75 |
}
|
|
76 |
|
|
77 |
val component_name = "csdp-" + version
|
72414
|
78 |
val component_dir = Isabelle_System.new_directory(target_dir + Path.basic(component_name))
|
|
79 |
progress.echo("Component " + component_dir)
|
|
80 |
|
|
81 |
|
|
82 |
/* platform */
|
|
83 |
|
72417
|
84 |
val platform_name =
|
|
85 |
proper_string(Isabelle_System.getenv("ISABELLE_WINDOWS_PLATFORM64")) orElse
|
|
86 |
proper_string(Isabelle_System.getenv("ISABELLE_PLATFORM64")) getOrElse
|
|
87 |
error("No 64bit platform")
|
72414
|
88 |
|
|
89 |
val platform_dir = Isabelle_System.make_directory(component_dir + Path.basic(platform_name))
|
|
90 |
|
|
91 |
|
72417
|
92 |
/* download source */
|
72414
|
93 |
|
72417
|
94 |
val archive_path = tmp_dir + Path.basic(archive_name)
|
|
95 |
Isabelle_System.download(download_url, archive_path, progress = progress)
|
|
96 |
|
|
97 |
Isabelle_System.bash("tar xzf " + File.bash_path(archive_path), cwd = tmp_dir.file).check
|
72414
|
98 |
|
|
99 |
val source_name =
|
72417
|
100 |
File.read_dir(tmp_dir).filter(name => (tmp_dir + Path.basic(name)).is_dir) match {
|
|
101 |
case List(dir) => dir
|
|
102 |
case dirs =>
|
|
103 |
error("Exactly one directory entry expected in archive " + quote(download_url) +
|
|
104 |
"\n" + commas_quote(dirs))
|
72414
|
105 |
}
|
|
106 |
Isabelle_System.bash(
|
|
107 |
"tar xzf " + archive_path + " && mv " + Bash.string(source_name) + " src",
|
|
108 |
cwd = component_dir.file).check
|
|
109 |
|
|
110 |
|
|
111 |
/* build */
|
|
112 |
|
72417
|
113 |
progress.echo("Building CSDP ...")
|
72414
|
114 |
|
72417
|
115 |
val build_dir = tmp_dir + Path.basic(source_name)
|
|
116 |
build_flags.find(flags => flags.platform == platform_name) match {
|
|
117 |
case None => error("No build flags for platform " + quote(platform_name))
|
|
118 |
case Some(flags) =>
|
|
119 |
File.find_files(build_dir.file, pred = file => file.getName == "Makefile").
|
|
120 |
foreach(file => flags.change(File.path(file)))
|
72414
|
121 |
}
|
72417
|
122 |
Isabelle_System.bash("make",
|
|
123 |
cwd = build_dir.file,
|
|
124 |
progress_stdout = progress.echo_if(verbose, _),
|
|
125 |
progress_stderr = progress.echo_if(verbose, _)).check
|
72414
|
126 |
|
72417
|
127 |
File.copy(build_dir + Path.explode("LICENSE"), component_dir)
|
|
128 |
File.copy(build_dir + Path.explode("solver/csdp"), platform_dir)
|
72414
|
129 |
|
|
130 |
|
|
131 |
/* settings */
|
|
132 |
|
|
133 |
val etc_dir = Isabelle_System.make_directory(component_dir + Path.basic("etc"))
|
|
134 |
File.write(etc_dir + Path.basic("settings"),
|
|
135 |
"""# -*- shell-script -*- :mode=shellscript:
|
|
136 |
|
|
137 |
ISABELLE_CSDP="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}/csdp"
|
|
138 |
""")
|
|
139 |
|
|
140 |
|
|
141 |
/* README */
|
|
142 |
|
|
143 |
File.write(component_dir + Path.basic("README"),
|
72417
|
144 |
"""This is CSDP """ + version + """ from
|
|
145 |
""" + download_url + """
|
72414
|
146 |
|
72417
|
147 |
Makefile flags have been changed for various platforms as follows:
|
72414
|
148 |
|
|
149 |
""" + build_flags.map(_.print).mkString("\n\n") + """
|
72417
|
150 |
The distribution has been built like this:
|
72414
|
151 |
|
72417
|
152 |
cd src && make
|
72414
|
153 |
|
72417
|
154 |
Only the bare "solver/csdp" program is used for Isabelle.
|
72414
|
155 |
|
|
156 |
|
|
157 |
Makarius
|
|
158 |
""" + Date.Format.date(Date.now()) + "\n")
|
|
159 |
})
|
|
160 |
}
|
|
161 |
|
|
162 |
|
|
163 |
/* Isabelle tool wrapper */
|
|
164 |
|
|
165 |
val isabelle_tool =
|
|
166 |
Isabelle_Tool("build_csdp", "build prover component from official downloads",
|
|
167 |
args =>
|
|
168 |
{
|
|
169 |
var target_dir = Path.current
|
72417
|
170 |
var download_url = default_download_url
|
72414
|
171 |
var verbose = false
|
|
172 |
|
|
173 |
val getopts = Getopts("""
|
|
174 |
Usage: isabelle build_csdp [OPTIONS]
|
|
175 |
|
|
176 |
Options are:
|
|
177 |
-D DIR target directory (default ".")
|
72417
|
178 |
-U URL download URL
|
|
179 |
(default: """" + default_download_url + """")
|
72414
|
180 |
-v verbose
|
|
181 |
|
|
182 |
Build prover component from official downloads.
|
|
183 |
""",
|
|
184 |
"D:" -> (arg => target_dir = Path.explode(arg)),
|
72417
|
185 |
"U:" -> (arg => download_url = arg),
|
72414
|
186 |
"v" -> (_ => verbose = true))
|
|
187 |
|
|
188 |
val more_args = getopts(args)
|
|
189 |
if (more_args.nonEmpty) getopts.usage()
|
|
190 |
|
|
191 |
val progress = new Console_Progress()
|
|
192 |
|
72417
|
193 |
build_csdp(download_url = download_url, verbose = verbose, progress = progress,
|
72414
|
194 |
target_dir = target_dir)
|
|
195 |
})
|
|
196 |
}
|