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