author | wenzelm |
Tue, 13 Oct 2020 19:29:28 +0200 | |
changeset 72468 | 60471f4bafd2 |
parent 72463 | defbbff7396c |
child 72763 | 3cc73d00553c |
permissions | -rw-r--r-- |
72414 | 1 |
/* Title: Pure/Admin/build_csdp.scala |
2 |
Author: Makarius |
|
3 |
||
72437 | 4 |
Build Isabelle CSDP component from official download. |
72414 | 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 |
||
72438 | 23 |
def print: Option[String] = |
24 |
if (changed.isEmpty) None |
|
25 |
else |
|
26 |
Some(" * " + platform + ":\n" + changed.map(p => " " + p._1 + "=" + p._2) |
|
27 |
.mkString("\n")) |
|
72414 | 28 |
|
29 |
def change(path: Path) |
|
30 |
{ |
|
72417 | 31 |
def change_line(line: String, entry: (String, String)): String = |
32 |
line.replaceAll(entry._1 + "=.*", entry._1 + "=" + entry._2) |
|
72414 | 33 |
File.change(path, s => |
72417 | 34 |
split_lines(s).map(line => (line /: changed)(change_line)).mkString("\n")) |
72414 | 35 |
} |
36 |
} |
|
37 |
||
38 |
val build_flags: List[Flags] = |
|
39 |
List( |
|
40 |
Flags("arm64-linux", |
|
72417 | 41 |
CFLAGS = "-O3 -ansi -Wall -DNOSHORTS -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include", |
72414 | 42 |
LIBS = "-static -L../lib -lsdp -llapack -lblas -lgfortran -lm"), |
72417 | 43 |
Flags("x86_64-linux", |
44 |
CFLAGS = "-O3 -ansi -Wall -DNOSHORTS -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include", |
|
72414 | 45 |
LIBS = "-static -L../lib -lsdp -llapack -lblas -lgfortran -lquadmath -lm"), |
46 |
Flags("x86_64-darwin", |
|
72417 | 47 |
CFLAGS = "-O3 -Wall -DNOSHORTS -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include", |
48 |
LIBS = "-L../lib -lsdp -llapack -lblas -lm"), |
|
49 |
Flags("x86_64-windows")) |
|
50 |
||
51 |
||
52 |
/* build CSDP */ |
|
72414 | 53 |
|
54 |
def build_csdp( |
|
72417 | 55 |
download_url: String = default_download_url, |
72414 | 56 |
verbose: Boolean = false, |
57 |
progress: Progress = new Progress, |
|
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
58 |
target_dir: Path = Path.current, |
72424 | 59 |
mingw: MinGW = MinGW.none) |
72414 | 60 |
{ |
72424 | 61 |
mingw.check |
72423 | 62 |
|
72414 | 63 |
Isabelle_System.with_tmp_dir("build")(tmp_dir => |
64 |
{ |
|
72417 | 65 |
/* component */ |
66 |
||
67 |
val Archive_Name = """^.*?([^/]+)$""".r |
|
68 |
val Version = """^[^0-9]*([0-9].*)\.tar.gz$""".r |
|
69 |
||
70 |
val archive_name = |
|
71 |
download_url match { |
|
72 |
case Archive_Name(name) => name |
|
73 |
case _ => error("Failed to determine source archive name from " + quote(download_url)) |
|
74 |
} |
|
75 |
||
76 |
val version = |
|
77 |
archive_name match { |
|
78 |
case Version(version) => version |
|
79 |
case _ => error("Failed to determine component version from " + quote(archive_name)) |
|
80 |
} |
|
81 |
||
82 |
val component_name = "csdp-" + version |
|
72414 | 83 |
val component_dir = Isabelle_System.new_directory(target_dir + Path.basic(component_name)) |
84 |
progress.echo("Component " + component_dir) |
|
85 |
||
86 |
||
87 |
/* platform */ |
|
88 |
||
72417 | 89 |
val platform_name = |
90 |
proper_string(Isabelle_System.getenv("ISABELLE_WINDOWS_PLATFORM64")) orElse |
|
91 |
proper_string(Isabelle_System.getenv("ISABELLE_PLATFORM64")) getOrElse |
|
92 |
error("No 64bit platform") |
|
72414 | 93 |
|
94 |
val platform_dir = Isabelle_System.make_directory(component_dir + Path.basic(platform_name)) |
|
95 |
||
96 |
||
72417 | 97 |
/* download source */ |
72414 | 98 |
|
72417 | 99 |
val archive_path = tmp_dir + Path.basic(archive_name) |
100 |
Isabelle_System.download(download_url, archive_path, progress = progress) |
|
101 |
||
102 |
Isabelle_System.bash("tar xzf " + File.bash_path(archive_path), cwd = tmp_dir.file).check |
|
72442 | 103 |
val source_name = File.get_dir(tmp_dir) |
72414 | 104 |
|
105 |
Isabelle_System.bash( |
|
106 |
"tar xzf " + archive_path + " && mv " + Bash.string(source_name) + " src", |
|
107 |
cwd = component_dir.file).check |
|
108 |
||
109 |
||
110 |
/* build */ |
|
111 |
||
72440 | 112 |
progress.echo("Building CSDP for " + platform_name + " ...") |
72414 | 113 |
|
72417 | 114 |
val build_dir = tmp_dir + Path.basic(source_name) |
115 |
build_flags.find(flags => flags.platform == platform_name) match { |
|
116 |
case None => error("No build flags for platform " + quote(platform_name)) |
|
117 |
case Some(flags) => |
|
118 |
File.find_files(build_dir.file, pred = file => file.getName == "Makefile"). |
|
119 |
foreach(file => flags.change(File.path(file))) |
|
72414 | 120 |
} |
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
121 |
|
72428 | 122 |
progress.bash(mingw.bash_script("make"), cwd = build_dir.file, echo = verbose).check |
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
123 |
|
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
124 |
|
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
125 |
/* install */ |
72414 | 126 |
|
72417 | 127 |
File.copy(build_dir + Path.explode("LICENSE"), component_dir) |
72463 | 128 |
File.copy(build_dir + Path.explode("solver/csdp").platform_exe, platform_dir) |
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
129 |
|
72463 | 130 |
if (Platform.is_windows) { |
131 |
Executable.libraries_closure(platform_dir + Path.explode("csdp.exe"), mingw = mingw, |
|
132 |
filter = |
|
72468 | 133 |
Set("libblas", "liblapack", "libgfortran", "libgcc_s_seh", |
134 |
"libquadmath", "libwinpthread")) |
|
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
135 |
} |
72414 | 136 |
|
137 |
||
138 |
/* settings */ |
|
139 |
||
140 |
val etc_dir = Isabelle_System.make_directory(component_dir + Path.basic("etc")) |
|
141 |
File.write(etc_dir + Path.basic("settings"), |
|
142 |
"""# -*- shell-script -*- :mode=shellscript: |
|
143 |
||
144 |
ISABELLE_CSDP="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}/csdp" |
|
145 |
""") |
|
146 |
||
147 |
||
148 |
/* README */ |
|
149 |
||
150 |
File.write(component_dir + Path.basic("README"), |
|
72417 | 151 |
"""This is CSDP """ + version + """ from |
152 |
""" + download_url + """ |
|
72414 | 153 |
|
72417 | 154 |
Makefile flags have been changed for various platforms as follows: |
72414 | 155 |
|
72438 | 156 |
""" + build_flags.flatMap(_.print).mkString("\n\n") + """ |
157 |
||
72417 | 158 |
The distribution has been built like this: |
72414 | 159 |
|
72417 | 160 |
cd src && make |
72414 | 161 |
|
72417 | 162 |
Only the bare "solver/csdp" program is used for Isabelle. |
72414 | 163 |
|
164 |
||
72444 | 165 |
Makarius |
166 |
""" + Date.Format.date(Date.now()) + "\n") |
|
72414 | 167 |
}) |
168 |
} |
|
169 |
||
170 |
||
171 |
/* Isabelle tool wrapper */ |
|
172 |
||
173 |
val isabelle_tool = |
|
72437 | 174 |
Isabelle_Tool("build_csdp", "build prover component from official download", |
72414 | 175 |
args => |
176 |
{ |
|
177 |
var target_dir = Path.current |
|
72424 | 178 |
var mingw = MinGW.none |
72417 | 179 |
var download_url = default_download_url |
72414 | 180 |
var verbose = false |
181 |
||
182 |
val getopts = Getopts(""" |
|
183 |
Usage: isabelle build_csdp [OPTIONS] |
|
184 |
||
185 |
Options are: |
|
186 |
-D DIR target directory (default ".") |
|
72425 | 187 |
-M DIR msys/mingw root specification for Windows |
72417 | 188 |
-U URL download URL |
189 |
(default: """" + default_download_url + """") |
|
72414 | 190 |
-v verbose |
191 |
||
72437 | 192 |
Build prover component from official download. |
72414 | 193 |
""", |
194 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
|
72431 | 195 |
"M:" -> (arg => mingw = MinGW(Path.explode(arg))), |
72417 | 196 |
"U:" -> (arg => download_url = arg), |
72414 | 197 |
"v" -> (_ => verbose = true)) |
198 |
||
199 |
val more_args = getopts(args) |
|
200 |
if (more_args.nonEmpty) getopts.usage() |
|
201 |
||
202 |
val progress = new Console_Progress() |
|
203 |
||
72417 | 204 |
build_csdp(download_url = download_url, verbose = verbose, progress = progress, |
72424 | 205 |
target_dir = target_dir, mingw = mingw) |
72414 | 206 |
}) |
207 |
} |