2017-05-05 01:22:20 +08:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# install.py tool to do a generic build of a library
|
|
|
|
# soft linked to by many of the lib/Install.py files
|
|
|
|
# used to automate the steps described in the corresponding lib/README
|
|
|
|
|
2017-07-27 21:25:39 +08:00
|
|
|
from __future__ import print_function
|
|
|
|
import sys,os,subprocess
|
2017-05-05 01:22:20 +08:00
|
|
|
|
|
|
|
# help message
|
|
|
|
|
|
|
|
help = """
|
2017-07-15 06:25:16 +08:00
|
|
|
Syntax from src dir: make lib-libname args="-m machine -e suffix"
|
|
|
|
Syntax from lib dir: python Install.py -m machine -e suffix
|
|
|
|
|
2017-07-27 21:25:39 +08:00
|
|
|
libname = name of lib dir (e.g. atc, h5md, meam, poems, etc)
|
2017-07-15 06:25:16 +08:00
|
|
|
specify -m and optionally -e, order does not matter
|
|
|
|
|
2017-05-05 01:22:20 +08:00
|
|
|
-m = peform a clean followed by "make -f Makefile.machine"
|
|
|
|
machine = suffix of a lib/Makefile.* file
|
|
|
|
-e = set EXTRAMAKE variable in Makefile.machine to Makefile.lammps.suffix
|
|
|
|
does not alter existing Makefile.machine
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-07-27 21:25:39 +08:00
|
|
|
Examples:
|
2017-07-15 06:25:16 +08:00
|
|
|
|
2017-08-09 05:00:09 +08:00
|
|
|
make lib-poems args="-m serial" # build POEMS lib with same settings as in the serial Makefile in src
|
|
|
|
make lib-colvars args="-m mpi" # build USER-COLVARS lib with same settings as in the mpi Makefile in src
|
|
|
|
make lib-meam args="-m ifort" # build MEAM lib with custom Makefile.ifort (using Intel Fortran)
|
2017-05-05 01:22:20 +08:00
|
|
|
"""
|
|
|
|
|
|
|
|
# print error message or help
|
|
|
|
|
|
|
|
def error(str=None):
|
2017-07-27 21:25:39 +08:00
|
|
|
if not str: print(help)
|
|
|
|
else: print("ERROR",str)
|
2017-05-05 01:22:20 +08:00
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
# parse args
|
|
|
|
|
|
|
|
args = sys.argv[1:]
|
|
|
|
nargs = len(args)
|
|
|
|
if nargs == 0: error()
|
|
|
|
|
|
|
|
machine = None
|
|
|
|
extraflag = 0
|
|
|
|
|
|
|
|
iarg = 0
|
|
|
|
while iarg < nargs:
|
|
|
|
if args[iarg] == "-m":
|
|
|
|
if iarg+2 > nargs: error()
|
|
|
|
machine = args[iarg+1]
|
2017-07-27 21:25:39 +08:00
|
|
|
iarg += 2
|
2017-05-05 01:22:20 +08:00
|
|
|
elif args[iarg] == "-e":
|
|
|
|
if iarg+2 > nargs: error()
|
|
|
|
extraflag = 1
|
|
|
|
suffix = args[iarg+1]
|
2017-07-27 21:25:39 +08:00
|
|
|
iarg += 2
|
2017-05-05 01:22:20 +08:00
|
|
|
else: error()
|
|
|
|
|
|
|
|
# set lib from working dir
|
|
|
|
|
|
|
|
cwd = os.getcwd()
|
|
|
|
lib = os.path.basename(cwd)
|
|
|
|
|
|
|
|
# create Makefile.auto as copy of Makefile.machine
|
|
|
|
# reset EXTRAMAKE if requested
|
2017-07-27 21:25:39 +08:00
|
|
|
|
2017-05-05 01:22:20 +08:00
|
|
|
if not os.path.exists("Makefile.%s" % machine):
|
|
|
|
error("lib/%s/Makefile.%s does not exist" % (lib,machine))
|
|
|
|
|
|
|
|
lines = open("Makefile.%s" % machine,'r').readlines()
|
|
|
|
fp = open("Makefile.auto",'w')
|
|
|
|
|
2017-08-08 05:13:01 +08:00
|
|
|
has_extramake = False
|
2017-05-05 01:22:20 +08:00
|
|
|
for line in lines:
|
|
|
|
words = line.split()
|
2017-08-08 05:13:01 +08:00
|
|
|
if len(words) == 3 and words[0] == "EXTRAMAKE" and words[1] == '=':
|
|
|
|
has_extramake = True
|
|
|
|
if extraflag:
|
|
|
|
line = line.replace(words[2],"Makefile.lammps.%s" % suffix)
|
|
|
|
fp.write(line)
|
2017-05-05 01:22:20 +08:00
|
|
|
|
|
|
|
fp.close()
|
|
|
|
|
2017-08-08 05:13:01 +08:00
|
|
|
# make the library via Makefile.auto optionally with parallel make
|
|
|
|
|
|
|
|
try:
|
|
|
|
import multiprocessing
|
|
|
|
n_cpus = multiprocessing.cpu_count()
|
|
|
|
except:
|
|
|
|
n_cpus = 1
|
2017-05-05 01:22:20 +08:00
|
|
|
|
2017-07-27 21:25:39 +08:00
|
|
|
print("Building lib%s.a ..." % lib)
|
2017-08-08 05:13:01 +08:00
|
|
|
cmd = "make -f Makefile.auto clean; make -f Makefile.auto -j%d" % n_cpus
|
2017-07-27 21:25:39 +08:00
|
|
|
txt = subprocess.check_output(cmd,shell=True,stderr=subprocess.STDOUT)
|
2017-08-08 05:13:01 +08:00
|
|
|
print(txt.decode('UTF-8'))
|
2017-05-05 01:22:20 +08:00
|
|
|
|
2017-07-27 21:25:39 +08:00
|
|
|
if os.path.exists("lib%s.a" % lib): print("Build was successful")
|
2017-05-05 01:22:20 +08:00
|
|
|
else: error("Build of lib/%s/lib%s.a was NOT successful" % (lib,lib))
|
2017-08-08 05:13:01 +08:00
|
|
|
if has_extramake and not os.path.exists("Makefile.lammps"):
|
2017-07-27 21:25:39 +08:00
|
|
|
print("lib/%s/Makefile.lammps was NOT created" % lib)
|