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