forked from band-unfolding/bandup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·89 lines (86 loc) · 3.37 KB
/
build
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
#! /usr/bin/env python
# Copyright (C) 2017 Paulo V. C. Medeiros
# This script builds BandUP
# This file is part of BandUP: Band Unfolding code for Plane-wave based calculations.
#
# BandUP is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# BandUP is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with BandUP. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import argparse
import sys
import os
import time
working_dir = os.getcwd()
bandupy_path = os.path.join(working_dir, 'src', 'python_interface', 'bandupy')
sys.path.insert(1, os.path.dirname(bandupy_path))
from bandupy.files import mkdir
from bandupy.build import (
assert_valid_compiler,
compatible_c,
compatible_cpp,
compatible_omp_flags,
qe_interface_available,
castep_interface_available,
)
from bandupy.constants import BANDUP_DIR, BANDUP_CONFIG_DIR, BANDUP_CONFIG_FILE
supported_fortran_compilers = ['ifort', 'gfortran', 'nagfor']
parser = argparse.ArgumentParser()
parser.add_argument(
'-compiler', nargs='?', default=None, choices=supported_fortran_compilers,
help=('If the fortran compiler is not explicitly chosen, the script will attempt '+
'to use one of the allowed choices, in the same order they appear here.'),
)
parser.add_argument(
'--doc', action='store_true',
help='Attempts to generate source code documentation using doxygen.'
)
parser.add_argument('--clean', action='store_true',
help='Removes all files created when building BandUP.')
args = parser.parse_args()
args = assert_valid_compiler(args, supported_fortran_compilers)
omp_fcflag, omp_cflag = compatible_omp_flags(args.compiler)
c_comp = compatible_c(args.compiler)
cpp = compatible_cpp(args.compiler)
# Building (or cleaning, if "--clean" was passed)
clean = ''
if(args.clean):
clean = 'veryclean'
os.chdir(os.path.join(working_dir, 'src', 'external'))
# Compiling code from external sources
if(args.compiler=="nagfor"):
# Not using openmp to compile spglib if NAG Fortran is used
os.system('make FC=%s CC=%s %s'%(args.compiler, c_comp, clean))
else:
os.system(
'make FC=%s CC=%s OMP_FCFLAG=%s OMP_CFLAG=%s %s'%(
args.compiler, c_comp, omp_fcflag, omp_cflag, clean
)
)
os.chdir(os.path.join(working_dir, 'src'))
if(args.doc and not args.clean):
# Making source code documentation
os.system('make sourcedoc')
else:
# Making BandUP
os.system('make FC=%s CC=%s %s'%(args.compiler, c_comp, clean))
os.chdir(working_dir)
# Creating config dir and file
mkdir(BANDUP_CONFIG_DIR, ignore_existing=True)
now = time.strftime('%-H:%M UTC%z on %b %d, %Y')
with open(BANDUP_CONFIG_FILE, 'w') as f:
f.write('# Created by BandUP on %s\n'%(now))
f.write('BANDUPDIR=%s\n'%(BANDUP_DIR))
if(qe_interface_available(calling_from_build_script=True)):
f.write('QE_SUPPORT=True\n')
if(castep_interface_available(calling_from_build_script=True)):
f.write('CASTEP_SUPPORT=True\n')