forked from lijiext/lammps
Merge pull request #11 from akohlmey/python3-for-make-py
Python 3 support for Make.py with Python 2.7 compatibility
This commit is contained in:
commit
ef69bf8695
|
@ -1,6 +1,7 @@
|
|||
/Makefile.package
|
||||
/Makefile.package.settings
|
||||
/MAKE/MINE
|
||||
/Make.py.last
|
||||
/lmp_*
|
||||
|
||||
/style_*.h
|
||||
|
|
365
src/Make.py
365
src/Make.py
|
@ -3,9 +3,10 @@
|
|||
# Make.py tool for managing packages and their auxiliary libs,
|
||||
# auto-editing machine Makefiles, and building LAMMPS
|
||||
# Syntax: Make.py -h (for help)
|
||||
# Notes: needs python 2.7 (not Python 3)
|
||||
# Notes: should be compatible with python 2.7 and 3.x thanks to 'futurize'
|
||||
|
||||
import sys,os,commands,re,copy,subprocess,platform
|
||||
from __future__ import print_function
|
||||
import sys,os,re,copy,subprocess,platform
|
||||
|
||||
# switch abbrevs
|
||||
# switch classes = created class for each switch
|
||||
|
@ -34,15 +35,15 @@ gpubuildflag = 0
|
|||
# functions
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# if flag = 1, print str and exit
|
||||
# if flag = 0, print str as warning and do not exit
|
||||
# if flag = 1, print txt and exit
|
||||
# if flag = 0, print txt as warning and do not exit
|
||||
|
||||
def error(str,flag=1):
|
||||
def error(txt,flag=1):
|
||||
if flag:
|
||||
print "ERROR:",str
|
||||
print("ERROR:",txt)
|
||||
sys.exit()
|
||||
else:
|
||||
print "WARNING:",str
|
||||
print("WARNING:",txt)
|
||||
|
||||
# store command-line args as sw = dict of key/value
|
||||
# key = switch word, value = list of following args
|
||||
|
@ -83,15 +84,15 @@ def switch2str(switches,switch_order):
|
|||
|
||||
def compile_check(compiler,ccflags,warn):
|
||||
open("tmpauto.cpp",'w').write("int main(int, char **) {}\n")
|
||||
str = "%s %s -c tmpauto.cpp" % (compiler,ccflags)
|
||||
txt = commands.getoutput(str)
|
||||
tmp = "%s %s -c tmpauto.cpp" % (compiler,ccflags)
|
||||
txt = subprocess.check_output(tmp,stderr=subprocess.STDOUT,shell=True).decode()
|
||||
flag = 1
|
||||
if txt or not os.path.isfile("tmpauto.o"):
|
||||
flag = 0
|
||||
if warn:
|
||||
print str
|
||||
if txt: print txt
|
||||
else: print "compile produced no output"
|
||||
print(tmp)
|
||||
if txt: print(txt)
|
||||
else: print("compile produced no output")
|
||||
os.remove("tmpauto.cpp")
|
||||
if os.path.isfile("tmpauto.o"): os.remove("tmpauto.o")
|
||||
return flag
|
||||
|
@ -102,15 +103,15 @@ def compile_check(compiler,ccflags,warn):
|
|||
|
||||
def link_check(linker,linkflags,libs,warn):
|
||||
open("tmpauto.cpp",'w').write("int main(int, char **) {}\n")
|
||||
str = "%s %s -o tmpauto tmpauto.cpp %s" % (linker,linkflags,libs)
|
||||
txt = commands.getoutput(str)
|
||||
tmp = "%s %s -o tmpauto tmpauto.cpp %s" % (linker,linkflags,libs)
|
||||
txt = subprocess.check_output(tmp,stderr=subprocess.STDOUT,shell=True).decode()
|
||||
flag = 1
|
||||
if txt or not os.path.isfile("tmpauto"):
|
||||
flag = 0
|
||||
if warn:
|
||||
print str
|
||||
if txt: print txt
|
||||
else: print "link produced no output"
|
||||
print(tmp)
|
||||
if txt: print(txt)
|
||||
else: print("link produced no output")
|
||||
os.remove("tmpauto.cpp")
|
||||
if os.path.isfile("tmpauto"): os.remove("tmpauto")
|
||||
return flag
|
||||
|
@ -121,7 +122,7 @@ def link_check(linker,linkflags,libs,warn):
|
|||
|
||||
# actions
|
||||
|
||||
class Actions:
|
||||
class Actions(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
|
||||
|
@ -229,18 +230,18 @@ class Actions:
|
|||
|
||||
def lib(self,suffix):
|
||||
if suffix != "all":
|
||||
print "building",suffix,"library ..."
|
||||
str = "%s.build()" % suffix
|
||||
exec(str)
|
||||
print("building",suffix,"library ...")
|
||||
txt = "%s.build()" % suffix
|
||||
exec(txt)
|
||||
else:
|
||||
final = packages.final
|
||||
for one in packages.lib:
|
||||
if final[one]:
|
||||
if "user" in one: pkg = one[5:]
|
||||
else: pkg = one
|
||||
print "building",pkg,"library ..."
|
||||
str = "%s.build()" % pkg
|
||||
exec(str)
|
||||
print("building",pkg,"library ...")
|
||||
txt = "%s.build()" % pkg
|
||||
exec(txt)
|
||||
|
||||
# read Makefile.machine
|
||||
# if caller = "file", edit via switches
|
||||
|
@ -526,8 +527,10 @@ class Actions:
|
|||
# unless caller = "exe" and "file" action already invoked
|
||||
|
||||
if caller == "file" or "file" not in self.alist:
|
||||
# make certain that 'MAKE/MINE' folder exists.
|
||||
subprocess.check_output("mkdir -p %s/MAKE/MINE" % dir.src,stderr=subprocess.STDOUT,shell=True)
|
||||
make.write("%s/MAKE/MINE/Makefile.auto" % dir.src,1)
|
||||
print "Created src/MAKE/MINE/Makefile.auto"
|
||||
print("Created src/MAKE/MINE/Makefile.auto")
|
||||
|
||||
# test full compile and link
|
||||
# unless caller = "file" and "exe" action will be invoked later
|
||||
|
@ -545,9 +548,9 @@ class Actions:
|
|||
# invoke "make clean-auto" to force clean before build
|
||||
|
||||
def clean(self):
|
||||
str = "cd %s; make clean-auto" % dir.src
|
||||
commands.getoutput(str)
|
||||
print "Performed make clean-auto"
|
||||
txt = "cd %s; make clean-auto" % dir.src
|
||||
subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
print("Performed make clean-auto")
|
||||
|
||||
# build LAMMPS using Makefile.auto and -j setting
|
||||
# invoke self.file() first, to test makefile compile/link
|
||||
|
@ -556,15 +559,15 @@ class Actions:
|
|||
|
||||
def exe(self):
|
||||
self.file("exe")
|
||||
commands.getoutput("cd %s; rm -f lmp_auto" % dir.src)
|
||||
subprocess.check_output("cd %s; rm -f lmp_auto" % dir.src,stderr=subprocess.STDOUT,shell=True)
|
||||
if self.stubs and not os.path.isfile("%s/STUBS/libmpi_stubs.a" % dir.src):
|
||||
print "building serial STUBS library ..."
|
||||
str = "cd %s/STUBS; make clean; make" % dir.src
|
||||
txt = commands.getoutput(str)
|
||||
print("building serial STUBS library ...")
|
||||
tmp = "cd %s/STUBS; make clean; make" % dir.src
|
||||
txt = subprocess.check_output(tmp,stderr=subprocess.STDOUT,shell=True).decode()
|
||||
if not os.path.isfile("%s/STUBS/libmpi_stubs.a" % dir.src):
|
||||
print txt
|
||||
print(txt)
|
||||
error('Unsuccessful "make stubs"')
|
||||
print "Created src/STUBS/libmpi_stubs.a"
|
||||
print("Created src/STUBS/libmpi_stubs.a")
|
||||
|
||||
# special hack for shannon GPU cluster
|
||||
# must use "srun make" if on it and building w/ GPU package, else just make
|
||||
|
@ -574,24 +577,24 @@ class Actions:
|
|||
if "shannon" == platform.node() and packages.final["gpu"]:
|
||||
make = "srun make"
|
||||
|
||||
if jmake: str = "cd %s; %s -j %d auto" % (dir.src,make,jmake.n)
|
||||
else: str = "cd %s; %s auto" % (dir.src,make)
|
||||
if jmake: tmp = "cd %s; %s -j %d auto" % (dir.src,make,jmake.n)
|
||||
else: tmp = "cd %s; %s auto" % (dir.src,make)
|
||||
|
||||
# if verbose, print output as build proceeds, else only print if fails
|
||||
|
||||
if verbose: subprocess.call(str,shell=True)
|
||||
if verbose: subprocess.call(tmp,shell=True)
|
||||
else:
|
||||
print str
|
||||
try: subprocess.check_output(str,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print e.output
|
||||
print(tmp)
|
||||
try: subprocess.check_output(tmp,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print(e.output)
|
||||
|
||||
if not os.path.isfile("%s/lmp_auto" % dir.src):
|
||||
error('Unsuccessful "make auto"')
|
||||
elif not output: print "Created src/lmp_auto"
|
||||
elif not output: print("Created src/lmp_auto")
|
||||
|
||||
# dir switch
|
||||
|
||||
class Dir:
|
||||
class Dir(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
|
||||
|
@ -625,7 +628,7 @@ class Dir:
|
|||
|
||||
# help switch
|
||||
|
||||
class Help:
|
||||
class Help(object):
|
||||
def __init__(self,list): pass
|
||||
|
||||
def help(self):
|
||||
|
@ -650,7 +653,7 @@ Syntax: Make.py switch args ...
|
|||
|
||||
# jmake switch
|
||||
|
||||
class Jmake:
|
||||
class Jmake(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
|
||||
|
@ -671,7 +674,7 @@ class Jmake:
|
|||
|
||||
# makefile switch
|
||||
|
||||
class Makefile:
|
||||
class Makefile(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
|
||||
|
@ -690,7 +693,7 @@ class Makefile:
|
|||
|
||||
# output switch
|
||||
|
||||
class Output:
|
||||
class Output(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
|
||||
|
@ -707,7 +710,7 @@ class Output:
|
|||
|
||||
# packages switch
|
||||
|
||||
class Packages:
|
||||
class Packages(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
|
||||
|
@ -805,14 +808,14 @@ class Packages:
|
|||
# key = package name, value = 1 if currently installed, else 0
|
||||
|
||||
original = {}
|
||||
str = "cd %s; make ps" % dir.src
|
||||
output = commands.getoutput(str).split('\n')
|
||||
tmp = "cd %s; make ps" % dir.src
|
||||
output = subprocess.check_output(tmp,stderr=subprocess.STDOUT,shell=True).decode()
|
||||
pattern = "Installed\s+(\w+): package (\S+)"
|
||||
for line in output:
|
||||
m = re.search(pattern,line)
|
||||
if not m: continue
|
||||
pkg = m.group(2).lower()
|
||||
if pkg not in all: error('Package list does not math "make ps" results')
|
||||
if pkg not in all: error('Package list does not match "make ps" results')
|
||||
if m.group(1) == "NO": original[pkg] = 0
|
||||
elif m.group(1) == "YES": original[pkg] = 1
|
||||
|
||||
|
@ -849,33 +852,33 @@ class Packages:
|
|||
# install packages in plist
|
||||
|
||||
def install(self):
|
||||
if self.plist: print "Installing packages ..."
|
||||
if self.plist: print("Installing packages ...")
|
||||
for one in self.plist:
|
||||
if one == "orig": continue
|
||||
commands.getoutput("cd %s; make %s" % (dir.src,one))
|
||||
subprocess.check_output("cd %s; make %s" % (dir.src,one),stderr=subprocess.STDOUT,shell=True)
|
||||
if self.plist and verbose:
|
||||
txt = commands.getoutput("cd %s; make ps" % dir.src)
|
||||
print "Package status after installation:"
|
||||
print txt
|
||||
txt = subprocess.check_output("cd %s; make ps" % dir.src,stderr=subprocess.STDOUT,shell=True).decode()
|
||||
print("Package status after installation:")
|
||||
print(txt)
|
||||
|
||||
# restore packages to original list if requested
|
||||
# order of re-install should not matter matter b/c of Depend.sh
|
||||
|
||||
def uninstall(self):
|
||||
if not self.plist or self.plist[-1] != "orig": return
|
||||
print "Restoring packages to original state ..."
|
||||
commands.getoutput("cd %s; make no-all" % dir.src)
|
||||
print("Restoring packages to original state ...")
|
||||
subprocess.check_output("cd %s; make no-all" % dir.src,stderr=subprocess.STDOUT,shell=True)
|
||||
for one in self.all:
|
||||
if self.original[one]:
|
||||
commands.getoutput("cd %s; make yes-%s" % (dir.src,one))
|
||||
subprocess.check_output("cd %s; make yes-%s" % (dir.src,one),stderr=subprocess.STDOUT,shell=True)
|
||||
if verbose:
|
||||
txt = commands.getoutput("cd %s; make ps" % dir.src)
|
||||
print "Restored package status:"
|
||||
print txt
|
||||
txt = subprocess.check_output("cd %s; make ps" % dir.src,stderr=subprocess.STDOUT,shell=True).decode()
|
||||
print("Restored package status:")
|
||||
print(txt)
|
||||
|
||||
# redo switch
|
||||
|
||||
class Redo:
|
||||
class Redo(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
|
||||
|
@ -940,8 +943,8 @@ class Redo:
|
|||
if words[0][-1] == ':': label = words[0][:-1]
|
||||
else: label = None
|
||||
if not self.labels:
|
||||
if label: commands.append(' '.join(words[1:]))
|
||||
else: commands.append(line)
|
||||
if label: subprocess.append(' '.join(words[1:]))
|
||||
else: subprocess.append(line)
|
||||
else:
|
||||
if not label: continue
|
||||
dict[label] = ' '.join(words[1:])
|
||||
|
@ -950,13 +953,13 @@ class Redo:
|
|||
|
||||
for label in self.labels:
|
||||
if label not in dict: error("Redo label not in redo file")
|
||||
commands.append(dict[label])
|
||||
subprocess.append(dict[label])
|
||||
|
||||
self.commands = commands
|
||||
|
||||
# settings switch
|
||||
|
||||
class Settings:
|
||||
class Settings(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
|
||||
|
@ -979,7 +982,7 @@ class Settings:
|
|||
|
||||
# verbose switch
|
||||
|
||||
class Verbose:
|
||||
class Verbose(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
|
||||
|
@ -995,7 +998,7 @@ class Verbose:
|
|||
|
||||
# zoutput switch for making copy of final Makefile.auto
|
||||
|
||||
class Zoutput:
|
||||
class Zoutput(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
|
||||
|
@ -1018,7 +1021,7 @@ class Zoutput:
|
|||
|
||||
# ATC lib
|
||||
|
||||
class ATC:
|
||||
class ATC(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.make = "g++"
|
||||
|
@ -1051,25 +1054,25 @@ class ATC:
|
|||
make.setvar("EXTRAMAKE","Makefile.lammps.%s" % self.lammps)
|
||||
make.write("%s/Makefile.auto" % libdir)
|
||||
|
||||
commands.getoutput("cd %s; make -f Makefile.auto clean" % libdir)
|
||||
if jmake: str = "cd %s; make -j %d -f Makefile.auto" % (libdir,jmake.n)
|
||||
else: str = "cd %s; make -f Makefile.auto" % libdir
|
||||
subprocess.check_output("cd %s; make -f Makefile.auto clean" % libdir,stderr=subprocess.STDOUT,shell=True)
|
||||
if jmake: txt = "cd %s; make -j %d -f Makefile.auto" % (libdir,jmake.n)
|
||||
else: txt = "cd %s; make -f Makefile.auto" % libdir
|
||||
|
||||
# if verbose, print output as build proceeds, else only print if fails
|
||||
|
||||
if verbose: subprocess.call(str,shell=True)
|
||||
if verbose: subprocess.call(txt,shell=True)
|
||||
else:
|
||||
try: subprocess.check_output(str,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print e.output
|
||||
try: subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print(e.output)
|
||||
|
||||
if not os.path.isfile("%s/libatc.a" % libdir) or \
|
||||
not os.path.isfile("%s/Makefile.lammps" % libdir):
|
||||
error("Unsuccessful build of lib/atc library")
|
||||
else: print "Created lib/atc library"
|
||||
else: print("Created lib/atc library")
|
||||
|
||||
# AWPMD lib
|
||||
|
||||
class AWPMD:
|
||||
class AWPMD(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.make = "mpicc"
|
||||
|
@ -1102,25 +1105,25 @@ class AWPMD:
|
|||
make.setvar("EXTRAMAKE","Makefile.lammps.%s" % self.lammps)
|
||||
make.write("%s/Makefile.auto" % libdir)
|
||||
|
||||
commands.getoutput("cd %s; make -f Makefile.auto clean" % libdir)
|
||||
if jmake: str = "cd %s; make -j %d -f Makefile.auto" % (libdir,jmake.n)
|
||||
else: str = "cd %s; make -f Makefile.auto" % libdir
|
||||
subprocess.check_output("cd %s; make -f Makefile.auto clean" % libdir,stderr=subprocess.STDOUT,shell=True)
|
||||
if jmake: txt = "cd %s; make -j %d -f Makefile.auto" % (libdir,jmake.n)
|
||||
else: txt = "cd %s; make -f Makefile.auto" % libdir
|
||||
|
||||
# if verbose, print output as build proceeds, else only print if fails
|
||||
|
||||
if verbose: subprocess.call(str,shell=True)
|
||||
if verbose: subprocess.call(txt,shell=True)
|
||||
else:
|
||||
try: subprocess.check_output(str,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print e.output
|
||||
try: subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print(e.output)
|
||||
|
||||
if not os.path.isfile("%s/libawpmd.a" % libdir) or \
|
||||
not os.path.isfile("%s/Makefile.lammps" % libdir):
|
||||
error("Unsuccessful build of lib/awpmd library")
|
||||
else: print "Created lib/awpmd library"
|
||||
else: print("Created lib/awpmd library")
|
||||
|
||||
# COLVARS lib
|
||||
|
||||
class COLVARS:
|
||||
class COLVARS(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.make = "g++"
|
||||
|
@ -1153,25 +1156,25 @@ class COLVARS:
|
|||
make.setvar("EXTRAMAKE","Makefile.lammps.%s" % self.lammps)
|
||||
make.write("%s/Makefile.auto" % libdir)
|
||||
|
||||
commands.getoutput("cd %s; make -f Makefile.auto clean" % libdir)
|
||||
if jmake: str = "cd %s; make -j %d -f Makefile.auto" % (libdir,jmake.n)
|
||||
else: str = "cd %s; make -f Makefile.auto" % libdir
|
||||
subprocess.check_output("cd %s; make -f Makefile.auto clean" % libdir,stderr=subprocess.STDOUT,shell=True)
|
||||
if jmake: txt = "cd %s; make -j %d -f Makefile.auto" % (libdir,jmake.n)
|
||||
else: txt = "cd %s; make -f Makefile.auto" % libdir
|
||||
|
||||
# if verbose, print output as build proceeds, else only print if fails
|
||||
|
||||
if verbose: subprocess.call(str,shell=True)
|
||||
if verbose: subprocess.call(txt,shell=True)
|
||||
else:
|
||||
try: subprocess.check_output(str,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print e.output
|
||||
try: subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print(e.output)
|
||||
|
||||
if not os.path.isfile("%s/libcolvars.a" % libdir) or \
|
||||
not os.path.isfile("%s/Makefile.lammps" % libdir):
|
||||
error("Unsuccessful build of lib/colvars library")
|
||||
else: print "Created lib/colvars library"
|
||||
else: print("Created lib/colvars library")
|
||||
|
||||
# CUDA lib
|
||||
|
||||
class CUDA:
|
||||
class CUDA(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.mode = "double"
|
||||
|
@ -1205,30 +1208,30 @@ class CUDA:
|
|||
|
||||
def build(self):
|
||||
libdir = dir.lib + "/cuda"
|
||||
commands.getoutput("cd %s; make clean" % libdir)
|
||||
subprocess.check_output("cd %s; make clean" % libdir,stderr=subprocess.STDOUT,shell=True)
|
||||
if self.mode == "double": n = 2
|
||||
elif self.mode == "mixed": n = 3
|
||||
elif self.mode == "single": n = 1
|
||||
if jmake: str = "cd %s; make -j %d precision=%d arch=%s" % \
|
||||
if jmake: txt = "cd %s; make -j %d precision=%d arch=%s" % \
|
||||
(libdir,jmake.n,n,self.arch)
|
||||
else: str = str = "cd %s; make precision=%d arch=%s" % \
|
||||
else: txt = "cd %s; make precision=%d arch=%s" % \
|
||||
(libdir,n,self.arch)
|
||||
|
||||
# if verbose, print output as build proceeds, else only print if fails
|
||||
|
||||
if verbose: subprocess.call(str,shell=True)
|
||||
if verbose: subprocess.call(txt,shell=True)
|
||||
else:
|
||||
try: subprocess.check_output(str,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print e.output
|
||||
try: subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print(e.output)
|
||||
|
||||
if not os.path.isfile("%s/liblammpscuda.a" % libdir) or \
|
||||
not os.path.isfile("%s/Makefile.lammps" % libdir):
|
||||
error("Unsuccessful build of lib/cuda library")
|
||||
else: print "Created lib/cuda library"
|
||||
else: print("Created lib/cuda library")
|
||||
|
||||
# GPU lib
|
||||
|
||||
class GPU:
|
||||
class GPU(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.make = "linux.double"
|
||||
|
@ -1300,25 +1303,25 @@ class GPU:
|
|||
make = "make"
|
||||
if "shannon" == platform.node(): make = "srun make"
|
||||
|
||||
commands.getoutput("cd %s; %s -f Makefile.auto clean" % (libdir,make))
|
||||
if jmake: str = "cd %s; %s -j %d -f Makefile.auto" % (libdir,make,jmake.n)
|
||||
else: str = "cd %s; %s -f Makefile.auto" % (libdir,make)
|
||||
subprocess.check_output("cd %s; %s -f Makefile.auto clean" % (libdir,make),stderr=subprocess.STDOUT,shell=True)
|
||||
if jmake: txt = "cd %s; %s -j %d -f Makefile.auto" % (libdir,make,jmake.n)
|
||||
else: txt = "cd %s; %s -f Makefile.auto" % (libdir,make)
|
||||
|
||||
# if verbose, print output as build proceeds, else only print if fails
|
||||
|
||||
if verbose: subprocess.call(str,shell=True)
|
||||
if verbose: subprocess.call(txt,shell=True)
|
||||
else:
|
||||
try: subprocess.check_output(str,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print e.output
|
||||
try: subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print(e.output)
|
||||
|
||||
if not os.path.isfile("%s/libgpu.a" % libdir) or \
|
||||
not os.path.isfile("%s/Makefile.lammps" % libdir):
|
||||
error("Unsuccessful build of lib/gpu library")
|
||||
else: print "Created lib/gpu library"
|
||||
else: print("Created lib/gpu library")
|
||||
|
||||
# H5MD lib
|
||||
|
||||
class H5MD:
|
||||
class H5MD(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.make = "h5cc"
|
||||
|
@ -1351,24 +1354,24 @@ class H5MD:
|
|||
make.setvar("EXTRAMAKE","Makefile.lammps.%s" % self.lammps)
|
||||
make.write("%s/Makefile.auto" % libdir)
|
||||
|
||||
commands.getoutput("cd %s; make clean" % libdir)
|
||||
str = "cd %s; make" % libdir
|
||||
subprocess.check_output("cd %s; make clean" % libdir,stderr=subprocess.STDOUT,shell=True)
|
||||
txt = "cd %s; make" % libdir
|
||||
|
||||
# if verbose, print output as build proceeds, else only print if fails
|
||||
|
||||
if verbose: subprocess.call(str,shell=True)
|
||||
if verbose: subprocess.call(txt,shell=True)
|
||||
else:
|
||||
try: subprocess.check_output(str,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print e.output
|
||||
try: subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print(e.output)
|
||||
|
||||
if not os.path.isfile("%s/libch5md.a" % libdir) or \
|
||||
not os.path.isfile("%s/Makefile.lammps" % libdir):
|
||||
error("Unsuccessful build of lib/h5md library")
|
||||
else: print "Created lib/h5md library"
|
||||
else: print("Created lib/h5md library")
|
||||
|
||||
# MEAM lib
|
||||
|
||||
class MEAM:
|
||||
class MEAM(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.make = "gfortran"
|
||||
|
@ -1401,25 +1404,25 @@ class MEAM:
|
|||
make.setvar("EXTRAMAKE","Makefile.lammps.%s" % self.lammps)
|
||||
make.write("%s/Makefile.auto" % libdir)
|
||||
|
||||
commands.getoutput("cd %s; make -f Makefile.auto clean" % libdir)
|
||||
subprocess.check_output("cd %s; make -f Makefile.auto clean" % libdir,stderr=subprocess.STDOUT,shell=True)
|
||||
# do not use -j for MEAM build, parallel build does not work
|
||||
str = "cd %s; make -f Makefile.auto" % libdir
|
||||
txt = "cd %s; make -f Makefile.auto" % libdir
|
||||
|
||||
# if verbose, print output as build proceeds, else only print if fails
|
||||
|
||||
if verbose: subprocess.call(str,shell=True)
|
||||
if verbose: subprocess.call(txt,shell=True)
|
||||
else:
|
||||
try: subprocess.check_output(str,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print e.output
|
||||
try: subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print(e.output)
|
||||
|
||||
if not os.path.isfile("%s/libmeam.a" % libdir) or \
|
||||
not os.path.isfile("%s/Makefile.lammps" % libdir):
|
||||
error("Unsuccessful build of lib/meam library")
|
||||
else: print "Created lib/meam library"
|
||||
else: print("Created lib/meam library")
|
||||
|
||||
# POEMS lib
|
||||
|
||||
class POEMS:
|
||||
class POEMS(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.make = "g++"
|
||||
|
@ -1452,25 +1455,25 @@ class POEMS:
|
|||
make.setvar("EXTRAMAKE","Makefile.lammps.%s" % self.lammps)
|
||||
make.write("%s/Makefile.auto" % libdir)
|
||||
|
||||
commands.getoutput("cd %s; make -f Makefile.auto clean" % libdir)
|
||||
if jmake: str = "cd %s; make -j %d -f Makefile.auto" % (libdir,jmake.n)
|
||||
else: str = "cd %s; make -f Makefile.auto" % libdir
|
||||
subprocess.check_output("cd %s; make -f Makefile.auto clean" % libdir,stderr=subprocess.STDOUT,shell=True)
|
||||
if jmake: txt = "cd %s; make -j %d -f Makefile.auto" % (libdir,jmake.n)
|
||||
else: txt = "cd %s; make -f Makefile.auto" % libdir
|
||||
|
||||
# if verbose, print output as build proceeds, else only print if fails
|
||||
|
||||
if verbose: subprocess.call(str,shell=True)
|
||||
if verbose: subprocess.call(txt,shell=True)
|
||||
else:
|
||||
try: subprocess.check_output(str,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print e.output
|
||||
try: subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print(e.output)
|
||||
|
||||
if not os.path.isfile("%s/libpoems.a" % libdir) or \
|
||||
not os.path.isfile("%s/Makefile.lammps" % libdir):
|
||||
error("Unsuccessful build of lib/poems library")
|
||||
else: print "Created lib/poems library"
|
||||
else: print("Created lib/poems library")
|
||||
|
||||
# PYTHON lib
|
||||
|
||||
class PYTHON:
|
||||
class PYTHON(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.make = "g++"
|
||||
|
@ -1497,15 +1500,15 @@ class PYTHON:
|
|||
def build(self):
|
||||
libdir = dir.lib + "/python"
|
||||
if self.lammpsflag:
|
||||
commands.getoutput("cd %s; cp Makefile.lammps.%s Makefile.lammps" %
|
||||
subprocess.check_output("cd %s; cp Makefile.lammps.%s Makefile.lammps" %
|
||||
(libdir,self.lammps))
|
||||
if not os.path.isfile("%s/Makefile.lammps.%s" % (libdir,self.lammps)):
|
||||
error("Unsuccessful creation of lib/python/Makefile.lammps.%s file" % self.lammps)
|
||||
else: print "Created lib/python/Makefile.lammps file"
|
||||
else: print("Created lib/python/Makefile.lammps file")
|
||||
|
||||
# QMMM lib
|
||||
|
||||
class QMMM:
|
||||
class QMMM(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.make = "gfortran"
|
||||
|
@ -1538,25 +1541,25 @@ class QMMM:
|
|||
make.setvar("EXTRAMAKE","Makefile.lammps.%s" % self.lammps)
|
||||
make.write("%s/Makefile.auto" % libdir)
|
||||
|
||||
commands.getoutput("cd %s; make -f Makefile.auto clean" % libdir)
|
||||
if jmake: str = "cd %s; make -j %d -f Makefile.auto" % (libdir,jmake.n)
|
||||
else: str = "cd %s; make -f Makefile.auto" % libdir
|
||||
subprocess.check_output("cd %s; make -f Makefile.auto clean" % libdir,stderr=subprocess.STDOUT,shell=True)
|
||||
if jmake: txt = "cd %s; make -j %d -f Makefile.auto" % (libdir,jmake.n)
|
||||
else: txt = "cd %s; make -f Makefile.auto" % libdir
|
||||
|
||||
# if verbose, print output as build proceeds, else only print if fails
|
||||
|
||||
if verbose: subprocess.call(str,shell=True)
|
||||
if verbose: subprocess.call(txt,shell=True)
|
||||
else:
|
||||
try: subprocess.check_output(str,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print e.output
|
||||
try: subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print(e.output)
|
||||
|
||||
if not os.path.isfile("%s/libqmmm.a" % libdir) or \
|
||||
not os.path.isfile("%s/Makefile.lammps" % libdir):
|
||||
error("Unsuccessful build of lib/qmmm library")
|
||||
else: print "Created lib/qmmm library"
|
||||
else: print("Created lib/qmmm library")
|
||||
|
||||
# REAX lib
|
||||
|
||||
class REAX:
|
||||
class REAX(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.make = "gfortran"
|
||||
|
@ -1590,24 +1593,24 @@ class REAX:
|
|||
make.write("%s/Makefile.auto" % libdir)
|
||||
|
||||
commands.getoutput("cd %s; make -f Makefile.auto clean" % libdir)
|
||||
if jmake: str = "cd %s; make -j %d -f Makefile.auto" % (libdir,jmake.n)
|
||||
else: str = "cd %s; make -f Makefile.auto" % libdir
|
||||
if jmake: txt = "cd %s; make -j %d -f Makefile.auto" % (libdir,jmake.n)
|
||||
else: txt = "cd %s; make -f Makefile.auto" % libdir
|
||||
|
||||
# if verbose, print output as build proceeds, else only print if fails
|
||||
|
||||
if verbose: subprocess.call(str,shell=True)
|
||||
if verbose: subprocess.call(txt,shell=True)
|
||||
else:
|
||||
try: subprocess.check_output(str,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print e.output
|
||||
try: subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
except Exception as e: print(e.output)
|
||||
|
||||
if not os.path.isfile("%s/libreax.a" % libdir) or \
|
||||
not os.path.isfile("%s/Makefile.lammps" % libdir):
|
||||
error("Unsuccessful build of lib/reax library")
|
||||
else: print "Created lib/reax library"
|
||||
else: print("Created lib/reax library")
|
||||
|
||||
# VORONOI lib
|
||||
|
||||
class VORONOI:
|
||||
class VORONOI(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.install = ""
|
||||
|
@ -1635,9 +1638,9 @@ class VORONOI:
|
|||
if not self.install: return
|
||||
libdir = dir.lib + "/voronoi"
|
||||
cmd = "cd %s; python install.py %s" % (libdir,self.install)
|
||||
txt = commands.getoutput(cmd)
|
||||
if verbose: print txt
|
||||
print "Created lib/voronoi library"
|
||||
txt = subprocess.check_output(cmd,stderr=subprocess.STDOUT,shell=True).decode()
|
||||
if verbose: print(txt)
|
||||
print("Created lib/voronoi library")
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# build classes for intel, kokkos build options
|
||||
|
@ -1645,7 +1648,7 @@ class VORONOI:
|
|||
|
||||
# Intel class
|
||||
|
||||
class Intel:
|
||||
class Intel(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.mode = "cpu"
|
||||
|
@ -1666,7 +1669,7 @@ class Intel:
|
|||
|
||||
# Kokkos class
|
||||
|
||||
class Kokkos:
|
||||
class Kokkos(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.mode = ""
|
||||
|
@ -1688,7 +1691,7 @@ class Kokkos:
|
|||
"""
|
||||
|
||||
def check(self):
|
||||
print self.inlist
|
||||
print(self.inlist)
|
||||
if self.inlist != None and len(self.inlist) == 0:
|
||||
error("-kokkos args are invalid")
|
||||
|
||||
|
@ -1710,7 +1713,7 @@ class Kokkos:
|
|||
|
||||
# Cc class
|
||||
|
||||
class Cc:
|
||||
class Cc(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.compiler = self.abbrev = ""
|
||||
|
@ -1762,7 +1765,7 @@ class Cc:
|
|||
|
||||
# Flags class
|
||||
|
||||
class Flags:
|
||||
class Flags(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.flags = []
|
||||
|
@ -1803,7 +1806,7 @@ class Flags:
|
|||
|
||||
# Mpi class
|
||||
|
||||
class Mpi:
|
||||
class Mpi(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.style = self.dir = ""
|
||||
|
@ -1837,7 +1840,7 @@ class Mpi:
|
|||
|
||||
# Fft class
|
||||
|
||||
class Fft:
|
||||
class Fft(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.dir = self.incdir = self.libdir = ""
|
||||
|
@ -1877,7 +1880,7 @@ class Fft:
|
|||
|
||||
# Jpg class
|
||||
|
||||
class Jpg:
|
||||
class Jpg(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.on = 1
|
||||
|
@ -1916,7 +1919,7 @@ class Jpg:
|
|||
|
||||
# Png class
|
||||
|
||||
class Png:
|
||||
class Png(object):
|
||||
def __init__(self,list):
|
||||
self.inlist = copy.copy(list)
|
||||
self.on = 1
|
||||
|
@ -1958,7 +1961,7 @@ class Png:
|
|||
|
||||
# read, tweak, and write a Makefile
|
||||
|
||||
class MakeReader:
|
||||
class MakeReader(object):
|
||||
|
||||
# read a makefile
|
||||
# flag = 0 if file is full path name
|
||||
|
@ -2127,14 +2130,14 @@ class MakeReader:
|
|||
if not line.isdigit():
|
||||
if flag and i == 0:
|
||||
line = "# auto = makefile auto-generated by Make.py"
|
||||
print >>fp,line
|
||||
print(line, file=fp)
|
||||
else:
|
||||
index = int(line)
|
||||
name = self.varinfo[index][0]
|
||||
txt = self.varinfo[index][1]
|
||||
if name not in self.var: continue
|
||||
values = self.var[name]
|
||||
print >>fp,"%s%s" % (txt,' '.join(values))
|
||||
print("%s%s" % (txt,' '.join(values)), file=fp)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# main program
|
||||
|
@ -2203,7 +2206,7 @@ while 1:
|
|||
switches[switch] = cmd_switches[switch]
|
||||
|
||||
argstr = switch2str(switches,switch_order)
|
||||
print "Redo command: Make.py",argstr
|
||||
print("Redo command: Make.py",argstr)
|
||||
else:
|
||||
switches = cmd_switches
|
||||
switch_order = cmd_switch_order
|
||||
|
@ -2246,10 +2249,10 @@ while 1:
|
|||
|
||||
if help or (actions and "-h" in actions.inlist) or not switches:
|
||||
if not help: help = Help(None)
|
||||
print help.help()
|
||||
print(help.help())
|
||||
for switch in switch_order:
|
||||
if switch == "h": continue
|
||||
print classes[switch].help()[1:]
|
||||
print(classes[switch].help()[1:])
|
||||
sys.exit()
|
||||
|
||||
# create needed default classes if not specified with switch
|
||||
|
@ -2298,7 +2301,7 @@ while 1:
|
|||
|
||||
if actions:
|
||||
for action in actions.alist:
|
||||
print "Action %s ..." % action
|
||||
print("Action %s ..." % action)
|
||||
if action.startswith("lib-"): actions.lib(action[4:])
|
||||
elif action == "file": actions.file("file")
|
||||
elif action == "clean": actions.clean()
|
||||
|
@ -2310,35 +2313,35 @@ while 1:
|
|||
|
||||
if output and actions and "exe" in actions.alist:
|
||||
txt = "cp %s/lmp_auto %s/lmp_%s" % (dir.src,dir.cwd,output.machine)
|
||||
commands.getoutput(txt)
|
||||
print "Created lmp_%s in %s" % (output.machine,dir.cwd)
|
||||
subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
print("Created lmp_%s in %s" % (output.machine,dir.cwd))
|
||||
|
||||
# create copy of Makefile.auto if requested, and file or exe action performed
|
||||
# ditto for library Makefile.auto and Makefile.lammps files
|
||||
|
||||
|
||||
if zoutput and actions and \
|
||||
("file" in actions.alist or "exe" in actions.alist):
|
||||
txt = "cp %s/MAKE/MINE/Makefile.auto %s/MAKE/MINE/Makefile.%s" % \
|
||||
(dir.src,dir.src,zoutput.machine)
|
||||
commands.getoutput(txt)
|
||||
print "Created Makefile.%s in %s/MAKE/MINE" % (zoutput.machine,dir.src)
|
||||
subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
print("Created Makefile.%s in %s/MAKE/MINE" % (zoutput.machine,dir.src))
|
||||
if gpubuildflag:
|
||||
txt = "cp %s/gpu/Makefile.auto %s/MAKE/MINE/Makefile_gpu.%s" % \
|
||||
(dir.lib,dir.src,zoutput.machine)
|
||||
commands.getoutput(txt)
|
||||
print "Created Makefile_gpu.%s in %s/MAKE/MINE" % \
|
||||
(zoutput.machine,dir.src)
|
||||
subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
print("Created Makefile_gpu.%s in %s/MAKE/MINE" % \
|
||||
(zoutput.machine,dir.src))
|
||||
txt = "cp %s/gpu/Makefile.lammps %s/MAKE/MINE/Makefile_gpu_lammps.%s" % \
|
||||
(dir.lib,dir.src,zoutput.machine)
|
||||
commands.getoutput(txt)
|
||||
print "Created Makefile_gpu_lammps.%s in %s/MAKE/MINE" % \
|
||||
(zoutput.machine,dir.src)
|
||||
subprocess.check_output(txt,stderr=subprocess.STDOUT,shell=True)
|
||||
print("Created Makefile_gpu_lammps.%s in %s/MAKE/MINE" % \
|
||||
(zoutput.machine,dir.src))
|
||||
|
||||
# write current Make.py command to src/Make.py.last
|
||||
|
||||
fp = open("%s/Make.py.last" % dir.src,'w')
|
||||
print >>fp,"# last invoked Make.py command"
|
||||
print >>fp,switch2str(switches,switch_order)
|
||||
print("# last invoked Make.py command", file=fp)
|
||||
print(switch2str(switches,switch_order), file=fp)
|
||||
fp.close()
|
||||
|
||||
# if not redoflag, done
|
||||
|
|
Loading…
Reference in New Issue