-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_8.5.1
executable file
·533 lines (473 loc) · 22.4 KB
/
install_8.5.1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
#!/usr/bin/sbcl --script
#|-*- mode:lisp -*-|#
;;;; atus-pro-install.lisp
(require "asdf")
(require "sb-posix")
(defparameter *argv* (uiop:command-line-arguments))
(defparameter *CC* (unless (string= (uiop:getenv "CC") "")
(uiop:getenv "CC")))
(defparameter *CXX* (unless (string= (uiop:getenv "CXX") "")
(uiop:getenv "CXX")))
(defvar *packages*
'((:name openmpi :version "3.0.0"
:url "https://www.open-mpi.org/software/ompi/v3.0/downloads/openmpi-3.0.0.tar.gz")
(:name lapack :version "3.8.0"
:url "http://www.netlib.org/lapack/lapack-3.8.0.tar.gz")
(:name gsl :version "2.4"
:url "ftp://ftp.gnu.org/gnu/gsl/gsl-2.4.tar.gz")
(:name nlopt :version "2.4.2"
:url "https://github.com/stevengj/nlopt/releases/download/nlopt-2.4.2/nlopt-2.4.2.tar.gz")
(:name muparser :version "2.2.5"
:url "https://codeload.github.com/beltoforion/muparser/tar.gz/v2.2.5"
:path "muparser-2.2.5")
(:name p4est :version "2.0"
:url "https://p4est.github.io/release/p4est-2.0.tar.gz")
(:name petsc :version "3.8.2"
:url "http://ftp.mcs.anl.gov/pub/petsc/release-snapshots/petsc-lite-3.8.2.tar.gz"
:path "petsc-3.8.2")
(:name deal.ii :version "8.5.1"
:url "https://github.com/dealii/dealii/releases/download/v8.5.1/dealii-8.5.1.tar.gz")
(:name atus-pro :version "git"))
"List of installable packages")
(defun package-match (key value)
"Returns first plist in *packages* with <key> corresponds to <value>.
Otherwise returns nil. Test is done via equal."
(find-if (lambda (x) (equal (getf x key) value)) *packages*))
(defun get-arg (arg)
"Get next command line argument after arg"
(let ((pos (position arg *argv* :test #'equalp)))
(when pos
(elt *argv* (1+ pos)))))
(defun arg-exist-p (arg)
"Checks if arg is supplied as command line argument"
(find arg *argv* :test #'string=))
(defparameter *debug-mode* (or (arg-exist-p "--debug") (arg-exist-p "-d")))
(defun create-directory (path)
(when path
(ensure-directories-exist (uiop:ensure-directory-pathname
(uiop:truenamize path)))))
(defparameter *root-p*
(string= "0" (string-trim '(#\Space #\Tab #\Newline #\Return #\Linefeed)
(uiop:run-program "id -u" :output 'string))))
(defparameter *atus-dir* (uiop:getcwd))
(defvar *default-system-build-dir* (pathname "/tmp/"))
(defvar *default-user-build-dir* (merge-pathnames "local/src/" (user-homedir-pathname)))
(defparameter *build-dir*
(or (create-directory (get-arg "--build-dir"))
(if *root-p*
*default-system-build-dir*
*default-user-build-dir*)))
(defvar *default-system-install-dir* (pathname "/opt/"))
(defvar *default-user-install-dir* (merge-pathnames "local/opt/" (user-homedir-pathname)))
(defparameter *install-dir*
(or (create-directory (get-arg "--install-dir"))
(if *root-p*
*default-system-install-dir*
*default-user-install-dir*)))
(defvar *default-system-module-dir* (pathname "/usr/local/share/modules/modulefiles/"))
(defvar *default-user-module-dir* (merge-pathnames "local/modules/modulefiles/"
(user-homedir-pathname)))
(defparameter *module-dir*
(or (create-directory (get-arg "--module-dir"))
(if *root-p*
*default-system-module-dir*
*default-user-module-dir*)))
(defparameter *make-threads* (or (get-arg "-j") 1))
(defun run (cmd)
(format t "~a ~~~a ~a~%" (uiop:getcwd) (if *root-p* "#" "$") cmd)
(uiop:run-program (format nil "~a" cmd)
:output :interactive
:error-output :interactive))
(defun export-variables (full-name)
(sb-posix:setenv "PATH"
(format nil "~a~a/bin/:~a" *install-dir* full-name
(sb-posix:getenv "PATH"))
1)
(sb-posix:setenv "LD_LIBRARY_PATH" (format nil "~a~a/lib/:~:*~:*~a~a/lib64/:~a"
*install-dir* full-name
(sb-posix:getenv "LD_LIBRARY_PATH"))
1))
(defun check-binary-exist (binary &optional optional-p)
(let ((exit-code
(nth-value 2 (uiop:run-program (concatenate 'string "which " binary)
:ignore-error-status t))))
(if (= exit-code 0)
t
(format t "~@[Optional ~*~]Dependency missing: ~a ~%" optional-p binary))))
(defun lib-exist-p (library directory)
(cond ((listp directory)
(some (lambda (dir) (lib-exist-p library dir))
directory))
((pathnamep (pathname directory))
(when (< 0
(length (uiop:run-program (format nil "find ~a -name ~a\\*"
directory library)
:output 'string
:ignore-error-status t)))
t))
(t (error "Unknown type of directory: ~a ~%~a" (type-of directory) directory))))
(defun check-library-exist (library &optional optional-p)
(let* ((lib (some (lambda (dir)
(lib-exist-p library dir))
(append (uiop:split-string (uiop:getenv "LD_LIBRARY_PATH")
:separator (list #\:))
(list "/lib/" "/lib64/" "/usr/lib/"
"/usr/lib64/" "/usr/local/lib/"
"/usr/local/lib64/")))))
(if lib
t
(format t "~@[Optional ~*~]Dependency missing: ~a ~%" optional-p library))))
;; openmpi
(defmethod install ((sw-name (eql 'openmpi)) version)
"Install method for openmpi"
(let* ((name (string-downcase (symbol-name sw-name)))
(full-name (format nil "~a-~a" name version)))
(run (format nil
"./configure --prefix=~a~a --enable-mpi-fortran"
*install-dir* full-name))
(run "make clean")
(run (format nil "make ~@[-j ~a~]" *make-threads*))
(run "make install")
(install-module name *install-dir* version *module-dir* '("CC" "mpicc"
"CXX" "mpic++"
"FC" "mpif90"))
(export-variables full-name)
(sb-posix:setenv "CC" "mpicc" 1)
(sb-posix:setenv "CXX" "mpic++" 1)
(sb-posix:setenv "FC" "mpif90" 1)))
;; lapack
(defmethod install ((sw-name (eql 'lapack)) version)
"Install method for lapack"
(let* ((name (string-downcase (symbol-name sw-name)))
(full-name (format nil "~a-~a" name version)))
(uiop:chdir (uiop:ensure-pathname (format nil "~abuild/" (uiop:getcwd))
:ensure-directory t :ensure-directories-exist t))
(run (format nil "cmake -DCMAKE_BUILD_TYPE=Release \\
~@[-DCMAKE_C_COMPILER=~a~] ~@[-DCMAKE_CXX_COMPILER=~a~] \\
-DCMAKE_FORTRAN_FLAGS_RELEASE=\"-march=native -fpic -O3\" \\
-DCMAKE_INSTALL_PREFIX=~a~a -DBUILD_SHARED_LIBS=ON .." *CC* *CXX* *install-dir* full-name))
(run "make clean")
(run (format nil "make ~@[-j ~a~]" *make-threads*))
(run "make install")
(install-module name *install-dir* version *module-dir*)
(export-variables full-name)))
;; gsl
(defmethod install ((sw-name (eql 'gsl)) version)
"Install method for gsl"
(let* ((name (string-downcase (symbol-name sw-name)))
(full-name (format nil "~a-~a" name version)))
(run (format nil "./configure --prefix=~a~a" *install-dir* full-name))
(run "make clean")
(run (format nil "make ~@[-j ~a~] CFLAGS=\"-march=native -O3\"" *make-threads*))
(run "make install")
(install-module name *install-dir* version *module-dir*)
(export-variables full-name)))
;; nlopt
(defmethod install ((sw-name (eql 'nlopt)) version)
"Install method for nlopt"
(let* ((name (string-downcase (symbol-name sw-name)))
(full-name (format nil "~a-~a" name version)))
(run (format nil "./configure --prefix=~a~a" *install-dir* full-name))
(run "make clean")
(run (format nil "make ~@[-j ~a~] CFLAGS=\"-march=native -O3\"" *make-threads*))
(run "make install")
(install-module name *install-dir* version *module-dir*)
(export-variables full-name)))
;; muparser
(defmethod install ((sw-name (eql 'muparser)) version)
"Install method for muparser"
(let* ((name (string-downcase (symbol-name sw-name)))
(full-name (format nil "~a-~a" name version)))
(run (format nil "./configure --prefix=~a~a" *install-dir* full-name))
(run "make clean")
(run "make CFLAGS=\"-march=native -O3\"")
(run "make install")
(install-module name *install-dir* version *module-dir*)
(export-variables full-name)))
;; p4est
(defmethod install ((sw-name (eql 'p4est)) version)
"Install method for p4est"
(unless (every #'check-binary-exist
(list "mpicc"))
(error "Dependencies missing"))
(let* ((name (string-downcase (symbol-name sw-name)))
(full-name (format nil "~a-~a" name version)))
(run (format nil "./configure --prefix=~a~a --enable-mpi --enable-shared --disable-vtk-binary --without-blas" *install-dir* full-name))
(run "make clean")
(run (format nil "make ~@[-j ~a~] CFLAGS=\"-march=native -O3\"" *make-threads*))
(run "make install")
(install-module name *install-dir* version *module-dir*)
(export-variables full-name)))
;; petsc
(defmethod install ((sw-name (eql 'petsc)) version)
"Install method for petsc"
(unless (every #'check-binary-exist
(list "mpicc")))
(let* ((name (string-downcase (symbol-name sw-name)))
(full-name (format nil "~a-~a" name version)))
(run (format nil "python2 ./configure --prefix=~a~a --with-shared-libraries --with-x=0 --with-debugging=0 --with-mpi=1 --download-hypre=yes --download-fblaslapack=1 --download-scalapack --download-mumps --download-ptscotch" *install-dir* full-name))
(run "make clean")
(run (format nil "make all")) ;; No make -j support
(run (format nil "make install"))
(install-module name *install-dir* version *module-dir*)
(export-variables full-name)))
;; deal.II
(defmethod install ((sw-name (eql 'deal.ii)) version)
"Install method for deal.ii"
(unless (and (every #'check-binary-exist
(list "mpicc")))
(error "Dependencies missing"))
(let* ((name (string-downcase (symbol-name sw-name)))
(full-name (format nil "~a-~a" name version)))
(uiop:chdir (uiop:ensure-pathname (format nil "~abuild/" (uiop:getcwd)) :ensure-directory t :ensure-directories-exist t))
(run (format nil "cmake ~@[-DCMAKE_C_COMPILER=~a~] ~@[-DCMAKE_CXX_COMPILER=~a~] -DCMAKE_BUILD_TYPE=\"Release\" \\
-DDEAL_II_WITH_UMFPACK=ON -DDEAL_II_WITH_LAPACK=ON -DLAPACK_DIR=~a~a -DDEAL_II_WITH_PETSC=ON -DPETSC_DIR=~a~a -DDEAL_II_WITH_P4EST=ON -DP4EST_DIR=~a~a -DGSL_DIR=~a~a -DMUPARSER_DIR=~a~a -DDEAL_II_WITH_THREADS=OFF -DDEAL_II_WITH_MPI=ON -DDEAL_II_WITH_HDF5=OFF -DCMAKE_INSTALL_PREFIX=~a~a .."
*CC*
*CXX*
*install-dir*
(format nil "lapack-~a" (getf (package-match :name 'lapack) :version))
*install-dir*
(format nil "petsc-~a" (getf (package-match :name 'petsc) :version))
*install-dir*
(format nil "p4est-~a" (getf (package-match :name 'p4est) :version))
*install-dir*
(format nil "gsl-~a" (getf (package-match :name 'gsl) :version))
*install-dir*
(format nil "muparser-~a" (getf (package-match :name 'muparser) :version))
*install-dir* full-name))
(run "make clean")
(run (format nil "make ~@[-j ~a~]" *make-threads*))
(run "make install")
(install-module name *install-dir* version *module-dir*)
(export-variables full-name)))
;; atus-pro
(defmethod install ((sw-name (eql 'atus-pro)) version)
"Install method for atus-pro"
(unless (and (every #'check-binary-exist
(list "mpicc")))
(error "Dependencies missing"))
(let* ((name (string-downcase (symbol-name sw-name)))
(full-name (format nil "~a-~a" name version)))
(uiop:chdir (uiop:ensure-pathname (format nil "~abuild/" (uiop:getcwd))
:ensure-directory t
:ensure-directories-exist t))
(run (format nil "cmake ~@[-DCMAKE_C_COMPILER=~a~] ~@[-DCMAKE_CXX_COMPILER=~a~] .."
*CC*
*CXX*))
(run "make clean")
(run (format nil "make ~@[-j ~a~]" *make-threads*))
(let ((exit-code
(nth-value 2 (uiop:run-program "which doxygen"
:ignore-error-status t))))
(if (= exit-code 0)
(run "make doc")
(format t "Install doxygen to generate documentation.~%")))
(install-module name *install-dir* version *module-dir*)
(install-meta-module name *install-dir* version *module-dir*)))
(defun install-module (tool path version install-path &optional extra-variables)
(let* ((full-name (concatenate 'string tool "-" version))
(tool-path (merge-pathnames full-name path)))
(with-open-file (out (merge-pathnames full-name
(ensure-directories-exist install-path))
:direction :output :if-exists :supersede
:if-does-not-exist :create)
(format t "Install modulefiles for ~a in ~a~%" full-name install-path)
(format out "#%Module1.0#####################################################################
################################################################################
set path ~a
set tool ~a
set version ~a
proc ModulesHelp { } {
puts stderr \"\t $tool $version \"
}
module-whatis \"sets the environment for $tool $version.\"
################################################################################
#
set mode [ module-info mode ]
if { $mode eq \"load\" || $mode eq \"switch2\" } {
puts stderr \"Module for $tool $version loaded.\"
} elseif { $mode eq \"remove\" || $mode eq \"switch3\" } {
puts stderr \"Module for $tool $version unloaded.\"
}
################################################################################
#
prepend-path PATH $path/bin
prepend-path MANPATH $path/share/man
prepend-path LD_LIBRARY_PATH $path/lib
prepend-path LD_LIBRARY_PATH $path/lib64
prepend-path LD_RUN_PATH $path/lib
prepend-path LD_RUN_PATH $path/lib64
~{~&setenv ~a ~a~}~&"
tool-path
tool
version
extra-variables))))
(defun install-meta-module (tool path version install-path )
(let ((name (concatenate 'string tool "-" version "-meta")))
(format t "Install modulefiles for ~a in ~a~%" name install-path)
(with-open-file (out (merge-pathnames name install-path)
:direction :output
:if-exists :supersede
:if-does-not-exist :create)
(format out "#%Module1.0#####################################################################
################################################################################
set path ~a
set tool ~a
set version ~a
proc ModulesHelp { } {
puts stderr \"\t meta $tool $version \"
}
module-whatis \"sets the environment for $tool $version meta.\"
################################################################################
#
set mode [ module-info mode ]
if { $mode eq \"load\" || $mode eq \"switch2\" } {
puts stderr \"Module for $tool $version loaded.\"
} elseif { $mode eq \"remove\" || $mode eq \"switch3\" } {
puts stderr \"Module for $tool $version unloaded.\"
}
################################################################################
#
~{~&module load ~a~}~&"
path
tool
version
(loop :for package :in *packages*
:collect (format nil "~a-~a" (string-downcase (getf package :name))
(getf package :version)))))))
(defun remove-tgz-filetype (file)
(merge-pathnames (subseq file 0 (or (search ".tar.gz" file)
(search ".tgz" file)))
(uiop:getcwd)))
(defun main ()
;; Banner3
(format t "~a~%" "
## ##### # # #### ##### ##### ####
# # # # # # # # # # # #
# # # # # #### # # # # # #
###### # # # # ##### ##### # #
# # # # # # # # # # # #
# # # #### #### # # # #### ")
(format t "~%ATUS-PRO: A FEM-based solver for the time-dependent and stationary Gross-Pitaevskii equation.~%~%")
(when (or (arg-exist-p "-h") (arg-exist-p "--help"))
(format t "-h Print this help text
--help Print this help text
--no-fetch Skip Download
-j THREADS Number of make threads
--build-dir DIR Build directory
System Default: ~a
User Default: ~a
--install-dir DIR Installation directory
System Default: ~a
User Default: ~a
--module-dir DIR Module directory
System Default: ~a
User Default: ~a~%~%"
*default-system-build-dir* *default-user-build-dir*
*default-system-install-dir* *default-user-install-dir*
*default-system-module-dir* *default-user-module-dir*)
(uiop:quit))
;; boost missing (fedora: dnf install boost boost-devel)
(format t "Check Dependencies.~%")
(unless (and (every #'check-binary-exist
(list "gcc"
"g++"
"gfortran"
"bison"
"flex"
"make"
"cmake"
"python2"
"doxygen"))
(every #'check-library-exist
(list "libboost")))
(error "Error: Dependency missing.~%" )
(uiop:quit))
(when *debug-mode*
(mapcar (lambda (x) (check-binary-exist x t))
(list "mpicc" "mpic++" "mpif90" "doxygen" "make" "cmake"))
(mapcar (lambda (x) (check-library-exist x t))
(list "libmpi" "liblapack" "libgsl" "libmuparser" "libnlopt" "libp4est" "libpetsc" "libdeal_II")))
(format t "Current Configuration (see ./install -h):~%")
(format t " Current Working Directory: ~a~%" (uiop:getcwd))
(format t " Software will be build in: ~a~%" *build-dir*)
(format t " Software will be installed in: ~a~%" *install-dir*)
(format t " Modulefiles will be installed in: ~a~%" *module-dir*)
(format t " Make Threads: ~a~%" *make-threads*)
(format t " CC=~a, CXX=~a~%" *CC* *CXX*)
(when *debug-mode*
(format t " Debug Mode: ON~%" ))
(unless (uiop:file-exists-p "install_8.5.1")
(error "Wrong working directory: Please restart script inside atus-pro directory."))
(handler-case
(mapcar #'ensure-directories-exist (list *build-dir* *install-dir* *module-dir*))
(error ()
(format t "~%Error: Cannot create directories: ~%~{ ~a~%~}~%"
(list *build-dir* *install-dir* *module-dir*))
(uiop:quit)))
(format t "~%What do you want to install?
Press number of each package to be installed and then press ENTER:
~{~&~a - ~a~}
a - all
q - Abort Installation.
>> " (loop :for package :in *packages*
:for index :below (length *packages*)
:append (list index (string-downcase (getf package :name)))))
(let ((selection (read-line t nil)))
(unless selection
(fresh-line)
(uiop:quit))
;;;; Test for Quit condition
(when (or (null selection) (find #\q selection))
(uiop:quit))
(loop :for package :in *packages*
:for index :below (length *packages*)
:when (or (find #\a selection) (find (digit-char index) selection))
:do
(let* ((name (getf package :name))
(version (getf package :version))
(url (getf package :url))
(src-dir (when url
(uiop:with-current-directory (*build-dir*)
(let* ((tarball (subseq url
(1+ (position #\/ url :from-end t))))
(src-dir (merge-pathnames
(or (getf package :path)
(remove-tgz-filetype tarball))
(uiop:getcwd))))
(progn (unless (arg-exist-p "--no-fetch")
(run (format nil "curl -LO ~a" url)))
(run (format nil "tar xfz ~a" tarball))
(format t "src-dir ~a~%" src-dir)
(uiop:ensure-directory-pathname src-dir)))))))
(uiop:with-current-directory (src-dir)
(install name version))))
(format t "~%Installation finished.~%")
(when *debug-mode*
(mapcar (lambda (x) (check-binary-exist x t))
(list "mpicc" "mpic++" "mpif90" "doxygen" "make" "cmake"))
(mapcar (lambda (x) (check-library-exist x t))
(list "libmpi" "liblapack" "libgsl" "libp4est" "libpetsc" "libdeal_II"))
(format t "PATH=~a~%LD_LIBRARY_PATH=~a~%" (sb-posix:getenv "PATH") (sb-posix:getenv "LD_LIBRARY_PATH"))
(uiop:run-program "echo $PATH" :output :interactive :ignore-error-status t)
(uiop:run-program "echo $LD_LIBRARY_PATH" :output :interactive :ignore-error-status t))
(let ((module-path (format nil "export MODULEPATH=~a:$MODULEPATH" *module-dir*))
(shell-config-file (if (string= (pathname-name (uiop:getenv "SHELL")) "zsh")
".zshrc"
".bashrc")))
(when (yes-or-no-p "Should I append the following text to your ~a?~%~a~%"
shell-config-file module-path)
(with-open-file (out (merge-pathnames shell-config-file
(user-homedir-pathname))
:direction :output
:if-exists :append
:if-does-not-exist :create)
(format out "~&~a~%" module-path))))
(uiop:quit)))
(if *debug-mode*
(main)
(handler-case
(main)
(error (con)
(format t "~%Error: ~a~%" con)
(uiop:quit))))