author | wenzelm |
Fri, 08 Apr 2022 16:42:52 +0200 | |
changeset 75421 | 3c710067b178 |
parent 75394 | 42267c650205 |
child 76518 | b30b8e23383c |
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 |
||
75393 | 10 |
object Build_CSDP { |
72417 | 11 |
// Note: version 6.2.0 does not quite work for the "sos" proof method |
12 |
val default_download_url = "https://github.com/coin-or/Csdp/archive/releases/6.1.1.tar.gz" |
|
72414 | 13 |
|
14 |
||
72417 | 15 |
/* flags */ |
72414 | 16 |
|
75393 | 17 |
sealed case class Flags(platform: String, CFLAGS: String = "", LIBS: String = "") { |
72417 | 18 |
val changed: List[(String, String)] = |
19 |
List("CFLAGS" -> CFLAGS, "LIBS" -> LIBS).filter(p => p._2.nonEmpty) |
|
20 |
||
72438 | 21 |
def print: Option[String] = |
22 |
if (changed.isEmpty) None |
|
23 |
else |
|
73712 | 24 |
Some(" * " + platform + ":\n" + changed.map(p => " " + Properties.Eq(p)) |
72438 | 25 |
.mkString("\n")) |
72414 | 26 |
|
75393 | 27 |
def change(path: Path): Unit = { |
73714 | 28 |
def change_line(line: String, p: (String, String)): String = |
29 |
line.replaceAll(p._1 + "=.*", Properties.Eq(p)) |
|
75205 | 30 |
File.change_lines(path) { _.map(line => changed.foldLeft(line)(change_line)) } |
72414 | 31 |
} |
32 |
} |
|
33 |
||
34 |
val build_flags: List[Flags] = |
|
35 |
List( |
|
36 |
Flags("arm64-linux", |
|
72417 | 37 |
CFLAGS = "-O3 -ansi -Wall -DNOSHORTS -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include", |
72414 | 38 |
LIBS = "-static -L../lib -lsdp -llapack -lblas -lgfortran -lm"), |
72417 | 39 |
Flags("x86_64-linux", |
40 |
CFLAGS = "-O3 -ansi -Wall -DNOSHORTS -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include", |
|
72414 | 41 |
LIBS = "-static -L../lib -lsdp -llapack -lblas -lgfortran -lquadmath -lm"), |
42 |
Flags("x86_64-darwin", |
|
72417 | 43 |
CFLAGS = "-O3 -Wall -DNOSHORTS -DBIT64 -DUSESIGTERM -DUSEGETTIME -I../include", |
44 |
LIBS = "-L../lib -lsdp -llapack -lblas -lm"), |
|
45 |
Flags("x86_64-windows")) |
|
46 |
||
47 |
||
48 |
/* build CSDP */ |
|
72414 | 49 |
|
50 |
def build_csdp( |
|
72417 | 51 |
download_url: String = default_download_url, |
72414 | 52 |
verbose: Boolean = false, |
53 |
progress: Progress = new Progress, |
|
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
54 |
target_dir: Path = Path.current, |
75393 | 55 |
mingw: MinGW = MinGW.none |
56 |
): Unit = { |
|
72424 | 57 |
mingw.check |
72423 | 58 |
|
75394 | 59 |
Isabelle_System.with_tmp_dir("build") { tmp_dir => |
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) |
73566 | 95 |
Isabelle_System.download_file(download_url, archive_path, progress = progress) |
72417 | 96 |
|
97 |
Isabelle_System.bash("tar xzf " + File.bash_path(archive_path), cwd = tmp_dir.file).check |
|
72442 | 98 |
val source_name = File.get_dir(tmp_dir) |
72414 | 99 |
|
100 |
Isabelle_System.bash( |
|
101 |
"tar xzf " + archive_path + " && mv " + Bash.string(source_name) + " src", |
|
102 |
cwd = component_dir.file).check |
|
103 |
||
104 |
||
105 |
/* build */ |
|
106 |
||
72440 | 107 |
progress.echo("Building CSDP for " + platform_name + " ...") |
72414 | 108 |
|
72417 | 109 |
val build_dir = tmp_dir + Path.basic(source_name) |
110 |
build_flags.find(flags => flags.platform == platform_name) match { |
|
111 |
case None => error("No build flags for platform " + quote(platform_name)) |
|
112 |
case Some(flags) => |
|
113 |
File.find_files(build_dir.file, pred = file => file.getName == "Makefile"). |
|
114 |
foreach(file => flags.change(File.path(file))) |
|
72414 | 115 |
} |
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
116 |
|
72428 | 117 |
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
|
118 |
|
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
119 |
|
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
120 |
/* install */ |
72414 | 121 |
|
73317 | 122 |
Isabelle_System.copy_file(build_dir + Path.explode("LICENSE"), component_dir) |
123 |
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
|
124 |
|
72463 | 125 |
if (Platform.is_windows) { |
126 |
Executable.libraries_closure(platform_dir + Path.explode("csdp.exe"), mingw = mingw, |
|
127 |
filter = |
|
72468 | 128 |
Set("libblas", "liblapack", "libgfortran", "libgcc_s_seh", |
129 |
"libquadmath", "libwinpthread")) |
|
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
130 |
} |
72414 | 131 |
|
132 |
||
133 |
/* settings */ |
|
134 |
||
135 |
val etc_dir = Isabelle_System.make_directory(component_dir + Path.basic("etc")) |
|
136 |
File.write(etc_dir + Path.basic("settings"), |
|
137 |
"""# -*- shell-script -*- :mode=shellscript: |
|
138 |
||
139 |
ISABELLE_CSDP="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}/csdp" |
|
140 |
""") |
|
141 |
||
142 |
||
143 |
/* README */ |
|
144 |
||
145 |
File.write(component_dir + Path.basic("README"), |
|
72417 | 146 |
"""This is CSDP """ + version + """ from |
147 |
""" + download_url + """ |
|
72414 | 148 |
|
72417 | 149 |
Makefile flags have been changed for various platforms as follows: |
72414 | 150 |
|
72438 | 151 |
""" + build_flags.flatMap(_.print).mkString("\n\n") + """ |
152 |
||
72417 | 153 |
The distribution has been built like this: |
72414 | 154 |
|
72417 | 155 |
cd src && make |
72414 | 156 |
|
72417 | 157 |
Only the bare "solver/csdp" program is used for Isabelle. |
72414 | 158 |
|
159 |
||
72444 | 160 |
Makarius |
161 |
""" + Date.Format.date(Date.now()) + "\n") |
|
75394 | 162 |
} |
72414 | 163 |
} |
164 |
||
165 |
||
166 |
/* Isabelle tool wrapper */ |
|
167 |
||
168 |
val isabelle_tool = |
|
72763 | 169 |
Isabelle_Tool("build_csdp", "build prover component from official download", Scala_Project.here, |
75394 | 170 |
{ args => |
171 |
var target_dir = Path.current |
|
172 |
var mingw = MinGW.none |
|
173 |
var download_url = default_download_url |
|
174 |
var verbose = false |
|
72414 | 175 |
|
75394 | 176 |
val getopts = Getopts(""" |
72414 | 177 |
Usage: isabelle build_csdp [OPTIONS] |
178 |
||
179 |
Options are: |
|
180 |
-D DIR target directory (default ".") |
|
72425 | 181 |
-M DIR msys/mingw root specification for Windows |
72417 | 182 |
-U URL download URL |
183 |
(default: """" + default_download_url + """") |
|
72414 | 184 |
-v verbose |
185 |
||
72437 | 186 |
Build prover component from official download. |
72414 | 187 |
""", |
75394 | 188 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
189 |
"M:" -> (arg => mingw = MinGW(Path.explode(arg))), |
|
190 |
"U:" -> (arg => download_url = arg), |
|
191 |
"v" -> (_ => verbose = true)) |
|
72414 | 192 |
|
75394 | 193 |
val more_args = getopts(args) |
194 |
if (more_args.nonEmpty) getopts.usage() |
|
72414 | 195 |
|
75394 | 196 |
val progress = new Console_Progress() |
72414 | 197 |
|
75394 | 198 |
build_csdp(download_url = download_url, verbose = verbose, progress = progress, |
199 |
target_dir = target_dir, mingw = mingw) |
|
200 |
}) |
|
72414 | 201 |
} |