diff --git a/lib/python/Makefile.lammps b/lib/python/Makefile.lammps index 8538994694..4289674e99 100644 --- a/lib/python/Makefile.lammps +++ b/lib/python/Makefile.lammps @@ -1,6 +1,7 @@ # Settings that the LAMMPS build will import when this package library is used # See the README file for more explanation -python_SYSINC = $(shell which python2-config > /dev/null 2>&1 && python2-config --includes || python-config --includes ) -python_SYSLIB = $(shell which python2-config > /dev/null 2>&1 && python2-config --ldflags || python-config --ldflags) +python_SYSINC = $(shell which python-config > /dev/null 2>&1 && python-config --includes || :) +python_SYSLIB = $(shell which python-config > /dev/null 2>&1 && python-config --ldflags || :) python_SYSPATH = +PYTHON=python diff --git a/lib/python/Makefile.lammps.python2 b/lib/python/Makefile.lammps.python2 index 8538994694..266a91251e 100644 --- a/lib/python/Makefile.lammps.python2 +++ b/lib/python/Makefile.lammps.python2 @@ -1,6 +1,7 @@ # Settings that the LAMMPS build will import when this package library is used # See the README file for more explanation -python_SYSINC = $(shell which python2-config > /dev/null 2>&1 && python2-config --includes || python-config --includes ) -python_SYSLIB = $(shell which python2-config > /dev/null 2>&1 && python2-config --ldflags || python-config --ldflags) +python_SYSINC = $(shell which python2-config > /dev/null 2>&1 && python2-config --includes || which python-config > /dev/null 2>&1 && python-config --includes || :) +python_SYSLIB = $(shell which python2-config > /dev/null 2>&1 && python2-config --ldflags || which python-config > /dev/null 2>&1 && python-config --ldflags || :) python_SYSPATH = +PYTHON=$(shell which python2 > /dev/null 2>&1 && echo python2 || echo python) diff --git a/lib/python/Makefile.lammps.python2.7 b/lib/python/Makefile.lammps.python2.7 index b5807086f2..07c6a94b21 100644 --- a/lib/python/Makefile.lammps.python2.7 +++ b/lib/python/Makefile.lammps.python2.7 @@ -4,3 +4,4 @@ python_SYSINC = -I/usr/local/include/python2.7 python_SYSLIB = -lpython2.7 -lnsl -ldl -lreadline -ltermcap -lpthread -lutil -lm -Xlinker -export-dynamic python_SYSPATH = +PYTHON=python2.7 diff --git a/lib/python/Makefile.lammps.python3 b/lib/python/Makefile.lammps.python3 index 1d5d5f2d81..2aa160e923 100644 --- a/lib/python/Makefile.lammps.python3 +++ b/lib/python/Makefile.lammps.python3 @@ -1,6 +1,7 @@ # Settings that the LAMMPS build will import when this package library is used # See the README file for more explanation -python_SYSINC = $(shell which python3-config > /dev/null 2>&1 && python3-config --includes || python-config --includes ) -python_SYSLIB = $(shell which python3-config > /dev/null 2>&1 && python3-config --ldflags || python-config --ldflags) +python_SYSINC = $(shell which python3-config > /dev/null 2>&1 && python3-config --includes || which python-config > /dev/null 2>&1 && python-config --includes || :) +python_SYSLIB = $(shell which python3-config > /dev/null 2>&1 && python3-config --ldflags || which python-config > /dev/null 2>&1 && python-config --ldflags || : ) python_SYSPATH = +PYTHON=$(shell which python3 > /dev/null 2>&1 && echo python3 || echo python) diff --git a/lib/python/README b/lib/python/README index 077c2547d2..8de2bc4bd7 100644 --- a/lib/python/README +++ b/lib/python/README @@ -1,22 +1,26 @@ The Makefile.lammps file in this directory is used when building LAMMPS with its PYTHON package installed. The file has several settings needed to compile and link LAMMPS with the Python library. -You should choose a Makefile.lammps.* file compatible with your system -and your version of Python, and copy it to Makefile.lammps before -building LAMMPS itself. You may need to edit one of the provided -files to match your system. -If you create a new Makefile.lammps file suitable for some version of -Python on some system, that is not a match to one of the provided -Makefile.lammps.* files, you can send it to the developers, and we can -include it in the distribution for others to use. +The default Makefile.lammps will automatically choose the default +python interpreter of your system and will infer the flags from +the python-config utility, that is usually bundled with the python +installation. If needed, you can copy one of the other provided +Makefile.lammps.* files to to Makefile.lammps before building +LAMMPS itself. -To illustrate, these are example settings from the -Makefile.lammps.python2.7 file: +The files Makefile.lammps.python2 and Makefile.lammps.python3 are +similar to the default file, but meant for the case that both, +python 2 and python 3, are installed simultaneously and you want +to prefer one over the other. If neither of these files work, you +may have to create a custom Makefile.lammps file suitable for +the version of Python on your system. To illustrate, these are +example settings from the Makefile.lammps.python2.7 file: python_SYSINC = -I/usr/local/include/python2.7 python_SYSLIB = -lpython2.7 -lnsl -ldl -lreadline -ltermcap -lpthread -lutil -lm -python_SYSPATH = +python_SYSPATH = +PYTHON=python2.7 python_SYSINC refers to the directory where Python's Python.h file is found. LAMMPS includes this file. @@ -26,10 +30,13 @@ application (LAMMPS in this case) to "embed" Python in the application. The Python library itself is listed (-lpython2.7) are are several system libraries needed by Python. -python_SYSPATH = refers to the path (e.g. -L/usr/local/lib) where the +python_SYSPATH refers to the path (e.g. -L/usr/local/lib) where the Python library can be found. You may not need this setting if the path is already included in your LD_LIBRARY_PATH environment variable. +PYTHON is the name of the python interpreter. It is used for +installing the LAMMPS python module with "make install-python" + ------------------------- Note that the trickiest issue to figure out for inclusion in diff --git a/src/Makefile b/src/Makefile index e6821646d1..59f9540148 100644 --- a/src/Makefile +++ b/src/Makefile @@ -224,7 +224,8 @@ mpi-stubs: @cd STUBS; $(MAKE) clean; $(MAKE) # install LAMMPS shared lib and Python wrapper for Python usage - +# include python package settings to automatically adapt name of python interpreter +sinclude ../lib/python/Makefile.lammps install-python: @$(PYTHON) ../python/install.py