1#!/usr/bin/env python
2
3"""
4Install.py tool to build the CSlib library
5used to automate the steps described in the README file in this dir
6"""
7
8from __future__ import print_function
9import sys, os, subprocess, shutil
10from argparse import ArgumentParser
11
12sys.path.append('..')
13from install_helpers import fullpath
14
15parser = ArgumentParser(prog='Install.py',
16                        description="LAMMPS library build wrapper script")
17
18# help message
19
20HELP = """
21Syntax from src dir: make lib-message args="-m"
22                 or: make lib-message args="-s -z"
23Syntax from lib dir: python Install.py -m
24                 or: python Install.py -s -z
25
26Example:
27
28make lib-message args="-m -z"   # build parallel CSlib with ZMQ support
29make lib-message args="-s"   # build serial CSlib with no ZMQ support
30"""
31
32pgroup = parser.add_mutually_exclusive_group()
33pgroup.add_argument("-m", "--mpi", action="store_true",
34                    help="parallel build of CSlib with MPI")
35pgroup.add_argument("-s", "--serial", action="store_true",
36                    help="serial build of CSlib")
37parser.add_argument("-z", "--zmq", default=False, action="store_true",
38                    help="build CSlib with ZMQ socket support, default ()")
39
40args = parser.parse_args()
41
42# print help message and exit, if neither build nor path options are given
43if not args.mpi and not args.serial:
44  parser.print_help()
45  sys.exit(HELP)
46
47mpiflag = args.mpi
48serialflag = args.serial
49zmqflag = args.zmq
50
51# build CSlib
52# copy resulting lib to cslib/src/libmessage.a
53# copy appropriate Makefile.lammps.* to Makefile.lammps
54
55print("Building CSlib ...")
56srcdir = fullpath(os.path.join("cslib", "src"))
57
58if mpiflag and zmqflag:
59  cmd = "make -C %s lib_parallel" % srcdir
60elif mpiflag and not zmqflag:
61  cmd = "make -C %s lib_parallel zmq=no" % srcdir
62elif not mpiflag and zmqflag:
63  cmd = "make -C %s lib_serial" % srcdir
64elif not mpiflag and not zmqflag:
65  cmd = "make -C %s lib_serial zmq=no" % srcdir
66
67print(cmd)
68try:
69  txt = subprocess.check_output(cmd, stderr=subprocess.STDOUT, shell=True)
70  print(txt.decode('UTF-8'))
71except subprocess.CalledProcessError as e:
72    print("Make failed with:\n %s" % e.output.decode('UTF-8'))
73    sys.exit(1)
74
75slb = os.path.join(srcdir, "libcsnompi.a")
76if mpiflag:
77  slb = os.path.join(srcdir, "libcsmpi.a")
78shutil.copyfile(slb, os.path.join(srcdir, "libmessage.a"))
79
80smk = "Makefile.lammps.nozmq"
81if zmqflag:
82  smk = "Makefile.lammps.zmq"
83shutil.copyfile(smk, "Makefile.lammps")
84print("Using %s for Makefile.lammps" % smk)
85