diff --git a/lib/colvars/Install.py b/lib/colvars/Install.py index 60cee31393..e481536768 100644 --- a/lib/colvars/Install.py +++ b/lib/colvars/Install.py @@ -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 - -args = sys.argv[1:] -nargs = len(args) -if nargs == 0: error(help=help) - -machine = None -extraflag = False - -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) - # set lib from working dir cwd = os.getcwd() lib = os.path.basename(cwd) +# parse and process arguments + +parser.add_argument("-m", "--machine", + help="suffix of a /Makefile.* or of a src/MAKE/MACHINES/Makefile.* file used for compiling this library") +parser.add_argument("-e", "--extramake", + help="set EXTRAMAKE variable in /Makefile. to Makefile.lammps.") + +args = parser.parse_args() + +# 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)