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