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