Commit 3aacea67 authored by Axel Kohlmeyer's avatar Axel Kohlmeyer
Browse files

use argparse in colvars lib build

parent 4e732915
Loading
Loading
Loading
Loading
+26 −25
Original line number Diff line number Diff line
@@ -5,7 +5,12 @@
from __future__ import print_function
import sys,os,subprocess
sys.path.append('..')
from install_helpers import error,get_cpus
from install_helpers import get_cpus

from argparse import ArgumentParser

parser = ArgumentParser(prog='Install.py',
                        description="LAMMPS library build wrapper script")

# help message

@@ -26,37 +31,33 @@ Examples:
make lib-colvars args="-m mpi"     # build COLVARS lib with default mpi compiler wrapper
"""

# parse args
# set lib from working dir

args = sys.argv[1:]
nargs = len(args)
if nargs == 0: error(help=help)
cwd = os.getcwd()
lib = os.path.basename(cwd)

machine = None
extraflag = False
# parse and process arguments

iarg = 0
while iarg < nargs:
  if args[iarg] == "-m":
    if iarg+2 > len(args): error(help=help)
    machine = args[iarg+1]
    iarg += 2
  elif args[iarg] == "-e":
    if iarg+2 > len(args): error(help=help)
    extraflag = True
    suffix = args[iarg+1]
    iarg += 2
  else: error(help=help)
parser.add_argument("-m", "--machine",
                    help="suffix of a <libname>/Makefile.* or of a src/MAKE/MACHINES/Makefile.* file used for compiling this library")
parser.add_argument("-e", "--extramake",
                    help="set EXTRAMAKE variable in <libname>/Makefile.<machine> to Makefile.lammps.<extramake>")

# set lib from working dir
args = parser.parse_args()

cwd = os.getcwd()
lib = os.path.basename(cwd)
# print help message and exit, if neither build nor path options are given
if not args.machine and not args.extramake:
  parser.print_help()
  sys.exit(help)

machine = args.machine
extraflag = args.extramake != None
suffix = args.extramake

def get_lammps_machine_flags(machine):
  """Parse Makefile.machine from LAMMPS, return dictionary of compiler flags"""
  if not os.path.exists("../../src/MAKE/MACHINES/Makefile.%s" % machine):
    error("Cannot locate src/MAKE/MACHINES/Makefile.%s" % machine)
    sys.exit("Cannot locate src/MAKE/MACHINES/Makefile.%s" % machine)
  lines = open("../../src/MAKE/MACHINES/Makefile.%s" % machine,
               'r').readlines()
  machine_flags = {}
@@ -102,7 +103,7 @@ if not os.path.exists("Makefile.%s" % machine):
  machine_flags = get_lammps_machine_flags(machine)
  gen_colvars_makefile_machine(machine, machine_flags)
if not os.path.exists("Makefile.%s" % machine):
  error("lib/%s/Makefile.%s does not exist" % (lib,machine))
  sys.exit("lib/%s/Makefile.%s does not exist" % (lib,machine))

# create Makefile.auto as copy of Makefile.machine
# reset EXTRAMAKE if requested
@@ -131,6 +132,6 @@ except subprocess.CalledProcessError as e:
  sys.exit(1)

if os.path.exists("lib%s.a" % lib): print("Build was successful")
else: error("Build of lib/%s/lib%s.a was NOT successful" % (lib,lib))
else: sys.exit("Build of lib/%s/lib%s.a was NOT successful" % (lib,lib))
if not os.path.exists("Makefile.lammps"):
  print("lib/%s/Makefile.lammps was NOT created" % lib)