author | wenzelm |
Sat, 10 Oct 2020 21:12:20 +0200 | |
changeset 72425 | d0937d55eb90 |
parent 72424 | 10c07d224035 |
child 72428 | b7351ffe0dbc |
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, |
72424 | 57 |
mingw: MinGW = MinGW.none) |
72414 | 58 |
{ |
72424 | 59 |
mingw.check |
72423 | 60 |
|
72414 | 61 |
Isabelle_System.with_tmp_dir("build")(tmp_dir => |
62 |
{ |
|
72417 | 63 |
/* component */ |
64 |
||
65 |
val Archive_Name = """^.*?([^/]+)$""".r |
|
66 |
val Version = """^[^0-9]*([0-9].*)\.tar.gz$""".r |
|
67 |
||
68 |
val archive_name = |
|
69 |
download_url match { |
|
70 |
case Archive_Name(name) => name |
|
71 |
case _ => error("Failed to determine source archive name from " + quote(download_url)) |
|
72 |
} |
|
73 |
||
74 |
val version = |
|
75 |
archive_name match { |
|
76 |
case Version(version) => version |
|
77 |
case _ => error("Failed to determine component version from " + quote(archive_name)) |
|
78 |
} |
|
79 |
||
80 |
val component_name = "csdp-" + version |
|
72414 | 81 |
val component_dir = Isabelle_System.new_directory(target_dir + Path.basic(component_name)) |
82 |
progress.echo("Component " + component_dir) |
|
83 |
||
84 |
||
85 |
/* platform */ |
|
86 |
||
72417 | 87 |
val platform_name = |
88 |
proper_string(Isabelle_System.getenv("ISABELLE_WINDOWS_PLATFORM64")) orElse |
|
89 |
proper_string(Isabelle_System.getenv("ISABELLE_PLATFORM64")) getOrElse |
|
90 |
error("No 64bit platform") |
|
72414 | 91 |
|
92 |
val platform_dir = Isabelle_System.make_directory(component_dir + Path.basic(platform_name)) |
|
93 |
||
94 |
||
72417 | 95 |
/* download source */ |
72414 | 96 |
|
72417 | 97 |
val archive_path = tmp_dir + Path.basic(archive_name) |
98 |
Isabelle_System.download(download_url, archive_path, progress = progress) |
|
99 |
||
100 |
Isabelle_System.bash("tar xzf " + File.bash_path(archive_path), cwd = tmp_dir.file).check |
|
72414 | 101 |
|
102 |
val source_name = |
|
72417 | 103 |
File.read_dir(tmp_dir).filter(name => (tmp_dir + Path.basic(name)).is_dir) match { |
104 |
case List(dir) => dir |
|
105 |
case dirs => |
|
106 |
error("Exactly one directory entry expected in archive " + quote(download_url) + |
|
107 |
"\n" + commas_quote(dirs)) |
|
72414 | 108 |
} |
109 |
Isabelle_System.bash( |
|
110 |
"tar xzf " + archive_path + " && mv " + Bash.string(source_name) + " src", |
|
111 |
cwd = component_dir.file).check |
|
112 |
||
113 |
||
114 |
/* build */ |
|
115 |
||
72417 | 116 |
progress.echo("Building CSDP ...") |
72414 | 117 |
|
72417 | 118 |
val build_dir = tmp_dir + Path.basic(source_name) |
119 |
build_flags.find(flags => flags.platform == platform_name) match { |
|
120 |
case None => error("No build flags for platform " + quote(platform_name)) |
|
121 |
case Some(flags) => |
|
122 |
File.find_files(build_dir.file, pred = file => file.getName == "Makefile"). |
|
123 |
foreach(file => flags.change(File.path(file))) |
|
72414 | 124 |
} |
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
125 |
|
72424 | 126 |
progress.bash(mingw.bash_command("make"), cwd = build_dir.file, echo = verbose).check |
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
127 |
|
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
128 |
|
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
129 |
/* install */ |
72414 | 130 |
|
72417 | 131 |
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
|
132 |
|
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
133 |
if (!Platform.is_windows) { |
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
134 |
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
|
135 |
} |
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
136 |
else { |
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
137 |
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
|
138 |
val libs = |
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
139 |
List("libblas", "liblapack", "libgfortran-5", "libgcc_s_seh-1", |
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
140 |
"libquadmath-0", "libwinpthread-1") |
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
141 |
for (name <- libs) { |
72424 | 142 |
File.copy(mingw.get_root + Path.explode("mingw64/bin") + Path.basic(name).ext("dll"), |
72418
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
143 |
platform_dir) |
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
144 |
} |
4ed247fadbc4
proper support for x86_64-windows via msys/mingw64;
wenzelm
parents:
72417
diff
changeset
|
145 |
} |
72414 | 146 |
|
147 |
||
148 |
/* settings */ |
|
149 |
||
150 |
val etc_dir = Isabelle_System.make_directory(component_dir + Path.basic("etc")) |
|
151 |
File.write(etc_dir + Path.basic("settings"), |
|
152 |
"""# -*- shell-script -*- :mode=shellscript: |
|
153 |
||
154 |
ISABELLE_CSDP="$COMPONENT/${ISABELLE_WINDOWS_PLATFORM64:-$ISABELLE_PLATFORM64}/csdp" |
|
155 |
""") |
|
156 |
||
157 |
||
158 |
/* README */ |
|
159 |
||
160 |
File.write(component_dir + Path.basic("README"), |
|
72417 | 161 |
"""This is CSDP """ + version + """ from |
162 |
""" + download_url + """ |
|
72414 | 163 |
|
72417 | 164 |
Makefile flags have been changed for various platforms as follows: |
72414 | 165 |
|
166 |
""" + build_flags.map(_.print).mkString("\n\n") + """ |
|
72417 | 167 |
The distribution has been built like this: |
72414 | 168 |
|
72417 | 169 |
cd src && make |
72414 | 170 |
|
72417 | 171 |
Only the bare "solver/csdp" program is used for Isabelle. |
72414 | 172 |
|
173 |
||
174 |
Makarius |
|
175 |
""" + Date.Format.date(Date.now()) + "\n") |
|
176 |
}) |
|
177 |
} |
|
178 |
||
179 |
||
180 |
/* Isabelle tool wrapper */ |
|
181 |
||
182 |
val isabelle_tool = |
|
183 |
Isabelle_Tool("build_csdp", "build prover component from official downloads", |
|
184 |
args => |
|
185 |
{ |
|
186 |
var target_dir = Path.current |
|
72424 | 187 |
var mingw = MinGW.none |
72417 | 188 |
var download_url = default_download_url |
72414 | 189 |
var verbose = false |
190 |
||
191 |
val getopts = Getopts(""" |
|
192 |
Usage: isabelle build_csdp [OPTIONS] |
|
193 |
||
194 |
Options are: |
|
195 |
-D DIR target directory (default ".") |
|
72425 | 196 |
-M DIR msys/mingw root specification for Windows |
72417 | 197 |
-U URL download URL |
198 |
(default: """" + default_download_url + """") |
|
72414 | 199 |
-v verbose |
200 |
||
201 |
Build prover component from official downloads. |
|
202 |
""", |
|
203 |
"D:" -> (arg => target_dir = Path.explode(arg)), |
|
72424 | 204 |
"M:" -> (arg => mingw = MinGW.root(Path.explode(arg))), |
72417 | 205 |
"U:" -> (arg => download_url = arg), |
72414 | 206 |
"v" -> (_ => verbose = true)) |
207 |
||
208 |
val more_args = getopts(args) |
|
209 |
if (more_args.nonEmpty) getopts.usage() |
|
210 |
||
211 |
val progress = new Console_Progress() |
|
212 |
||
72417 | 213 |
build_csdp(download_url = download_url, verbose = verbose, progress = progress, |
72424 | 214 |
target_dir = target_dir, mingw = mingw) |
72414 | 215 |
}) |
216 |
} |