author | wenzelm |
Sat, 04 Nov 2023 16:31:02 +0100 | |
changeset 78896 | 3523df57df51 |
parent 77566 | 2a99fcb283ee |
child 80004 | 31ebb6be32b0 |
permissions | -rw-r--r-- |
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77510
diff
changeset
|
1 |
/* Title: Pure/Admin/component_csdp.scala |
72414 | 2 |
Author: Makarius |
3 |
||
72437 | 4 |
Build Isabelle CSDP component from official download. |
72414 | 5 |
*/ |
6 |
||
7 |
package isabelle |
|
8 |
||
9 |
||
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77510
diff
changeset
|
10 |
object Component_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 |
progress: Progress = new Progress, |
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
53 |
target_dir: Path = Path.current, |
75393 | 54 |
mingw: MinGW = MinGW.none |
55 |
): Unit = { |
|
72424 | 56 |
mingw.check |
72423 | 57 |
|
75394 | 58 |
Isabelle_System.with_tmp_dir("build") { tmp_dir => |
72417 | 59 |
/* component */ |
60 |
||
61 |
val Archive_Name = """^.*?([^/]+)$""".r |
|
62 |
val Version = """^[^0-9]*([0-9].*)\.tar.gz$""".r |
|
63 |
||
64 |
val archive_name = |
|
65 |
download_url match { |
|
66 |
case Archive_Name(name) => name |
|
67 |
case _ => error("Failed to determine source archive name from " + quote(download_url)) |
|
68 |
} |
|
69 |
||
70 |
val version = |
|
71 |
archive_name match { |
|
72 |
case Version(version) => version |
|
73 |
case _ => error("Failed to determine component version from " + quote(archive_name)) |
|
74 |
} |
|
75 |
||
76 |
val component_name = "csdp-" + version |
|
76518 | 77 |
val component_dir = |
76547 | 78 |
Components.Directory(target_dir + Path.basic(component_name)).create(progress = progress) |
72414 | 79 |
|
80 |
||
81 |
/* platform */ |
|
82 |
||
72417 | 83 |
val platform_name = |
84 |
proper_string(Isabelle_System.getenv("ISABELLE_WINDOWS_PLATFORM64")) orElse |
|
85 |
proper_string(Isabelle_System.getenv("ISABELLE_PLATFORM64")) getOrElse |
|
86 |
error("No 64bit platform") |
|
72414 | 87 |
|
76518 | 88 |
val platform_dir = |
89 |
Isabelle_System.make_directory(component_dir.path + Path.basic(platform_name)) |
|
72414 | 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 |
|
76540
83de6e9ae983
clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents:
76529
diff
changeset
|
97 |
Isabelle_System.extract(archive_path, tmp_dir) |
83de6e9ae983
clarified signature: prefer Scala functions instead of shell scripts;
wenzelm
parents:
76529
diff
changeset
|
98 |
val source_dir = File.get_dir(tmp_dir, title = download_url) |
72414 | 99 |
|
76541 | 100 |
Isabelle_System.extract(archive_path, component_dir.src, strip = true) |
72414 | 101 |
|
102 |
||
103 |
/* build */ |
|
104 |
||
72440 | 105 |
progress.echo("Building CSDP for " + platform_name + " ...") |
72414 | 106 |
|
72417 | 107 |
build_flags.find(flags => flags.platform == platform_name) match { |
108 |
case None => error("No build flags for platform " + quote(platform_name)) |
|
109 |
case Some(flags) => |
|
76529 | 110 |
File.find_files(source_dir.file, pred = file => file.getName == "Makefile"). |
72417 | 111 |
foreach(file => flags.change(File.path(file))) |
72414 | 112 |
} |
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
113 |
|
77510
f5d6cd98b16a
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
76548
diff
changeset
|
114 |
progress.bash(mingw.bash_script("make"), |
f5d6cd98b16a
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
76548
diff
changeset
|
115 |
cwd = source_dir.file, |
f5d6cd98b16a
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
76548
diff
changeset
|
116 |
echo = progress.verbose).check |
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
117 |
|
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 |
/* install */ |
72414 | 120 |
|
76529 | 121 |
Isabelle_System.copy_file(source_dir + Path.explode("LICENSE"), component_dir.path) |
122 |
Isabelle_System.copy_file(source_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
|
123 |
|
72463 | 124 |
if (Platform.is_windows) { |
125 |
Executable.libraries_closure(platform_dir + Path.explode("csdp.exe"), mingw = mingw, |
|
126 |
filter = |
|
72468 | 127 |
Set("libblas", "liblapack", "libgfortran", "libgcc_s_seh", |
128 |
"libquadmath", "libwinpthread")) |
|
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
129 |
} |
72414 | 130 |
|
131 |
||
132 |
/* settings */ |
|
133 |
||
76548 | 134 |
component_dir.write_settings(""" |
72414 | 135 |
ISABELLE_CSDP="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}/csdp" |
136 |
""") |
|
137 |
||
138 |
||
139 |
/* README */ |
|
140 |
||
76518 | 141 |
File.write(component_dir.README, |
72417 | 142 |
"""This is CSDP """ + version + """ from |
143 |
""" + download_url + """ |
|
72414 | 144 |
|
72417 | 145 |
Makefile flags have been changed for various platforms as follows: |
72414 | 146 |
|
72438 | 147 |
""" + build_flags.flatMap(_.print).mkString("\n\n") + """ |
148 |
||
72417 | 149 |
The distribution has been built like this: |
72414 | 150 |
|
72417 | 151 |
cd src && make |
72414 | 152 |
|
72417 | 153 |
Only the bare "solver/csdp" program is used for Isabelle. |
72414 | 154 |
|
155 |
||
72444 | 156 |
Makarius |
157 |
""" + Date.Format.date(Date.now()) + "\n") |
|
75394 | 158 |
} |
72414 | 159 |
} |
160 |
||
161 |
||
162 |
/* Isabelle tool wrapper */ |
|
163 |
||
164 |
val isabelle_tool = |
|
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77510
diff
changeset
|
165 |
Isabelle_Tool("component_csdp", "build prover component from official download", Scala_Project.here, |
75394 | 166 |
{ args => |
167 |
var target_dir = Path.current |
|
168 |
var mingw = MinGW.none |
|
169 |
var download_url = default_download_url |
|
170 |
var verbose = false |
|
72414 | 171 |
|
75394 | 172 |
val getopts = Getopts(""" |
77566
2a99fcb283ee
renamed administrative tools to build Isabelle components (unrelated to "isabelle build");
wenzelm
parents:
77510
diff
changeset
|
173 |
Usage: isabelle component_csdp [OPTIONS] |
72414 | 174 |
|
175 |
Options are: |
|
176 |
-D DIR target directory (default ".") |
|
72425 | 177 |
-M DIR msys/mingw root specification for Windows |
72417 | 178 |
-U URL download URL |
179 |
(default: """" + default_download_url + """") |
|
72414 | 180 |
-v verbose |
181 |
||
72437 | 182 |
Build prover component from official download. |
72414 | 183 |
""", |
75394 | 184 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
185 |
"M:" -> (arg => mingw = MinGW(Path.explode(arg))), |
|
186 |
"U:" -> (arg => download_url = arg), |
|
187 |
"v" -> (_ => verbose = true)) |
|
72414 | 188 |
|
75394 | 189 |
val more_args = getopts(args) |
190 |
if (more_args.nonEmpty) getopts.usage() |
|
72414 | 191 |
|
77510
f5d6cd98b16a
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
76548
diff
changeset
|
192 |
val progress = new Console_Progress(verbose = verbose) |
72414 | 193 |
|
77510
f5d6cd98b16a
clarified signature: manage "verbose" flag via "progress";
wenzelm
parents:
76548
diff
changeset
|
194 |
build_csdp(download_url = download_url, progress = progress, |
75394 | 195 |
target_dir = target_dir, mingw = mingw) |
196 |
}) |
|
72414 | 197 |
} |