Skip to content

Commit e85745c

Browse files
authored
Improve robustness of Makefiles at finding some external programs (#996)
This adds a couple of robustness improvements to Makefiles to help portability to different environments: * If `python3-config` is not found, try to look for `python3.XY-config`, where `XY` is the minor version of the Python in the host environment. This is necessary because in at least some OS/Python vesion combos, `python3-config` is not defined by installing the `python3-dev` system package, and is named `python3.XY-config` instead. * `wget` is not a standard utility in many Linux distros, Sometimes `curl` is available. If `wget` is not found, try `curl` before giving up.
1 parent 479aad3 commit e85745c

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

Makefile

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
# If this is changed, updated the value in ./WORKSPACE too.
15+
# If you change the following values, update the values in ./WORKSPACE too.
1616
EIGEN_COMMIT = "b66188b5dfd147265bfa9ec47595ca0db72d21f5"
1717
EIGEN_URL = "https://gitlab.com/libeigen/eigen/-/archive/"
1818

@@ -94,7 +94,7 @@ else
9494
ifneq (,$(strip $(wildcard $(CUDA_PATH)/.)))
9595
# $CUDA_PATH is set, but we know we didn't find nvcc on the user's
9696
# $PATH or as an absolute path (if $NVCC was set to a full path).
97-
# Try the safest choice for finding nvcc & give up if that fails.
97+
# Try the safest choice for finding nvcc & give up if that fails.
9898
NVCC = $(CUDA_PATH)/bin/nvcc
9999
ifneq (,$(strip $(wildcard $(NVCC))))
100100
CXXFLAGS += -I$(CUDA_PATH)/include -L$(CUDA_PATH)/lib64
@@ -120,7 +120,7 @@ ifneq (,$(strip $(CUQUANTUM_ROOT)))
120120
TARGETS += qsim-custatevecex
121121
TESTS += run-custatevec-tests
122122
TESTS += run-custatevecex-tests
123-
TESTS += run-custatevecex-mpi-tests
123+
TESTS += run-custatevecex-mpi-tests
124124
else
125125
$(warning $$CUQUANTUM_ROOT is set, but the path does not seem to exist)
126126
endif
@@ -218,9 +218,18 @@ check-cuquantum-root-set:
218218
exit 1; \
219219
fi
220220

221+
# Check whether wget or curl is available on this system.
222+
ifneq (,$(shell command -v wget))
223+
DOWNLOAD_CMD := wget
224+
else ifneq (,$(shell command -v curl))
225+
DOWNLOAD_CMD := curl --fail -L -O
226+
else
227+
$(error Neither wget nor curl found in PATH. Please install curl or wget.)
228+
endif
229+
221230
eigen:
222231
-rm -rf eigen
223-
wget $(EIGEN_URL)/$(EIGEN_COMMIT)/eigen-$(EIGEN_COMMIT).tar.gz
232+
$(DOWNLOAD_CMD) $(EIGEN_URL)/$(EIGEN_COMMIT)/eigen-$(EIGEN_COMMIT).tar.gz
224233
tar -xzf eigen-$(EIGEN_COMMIT).tar.gz && mv eigen-$(EIGEN_COMMIT) eigen
225234
rm eigen-$(EIGEN_COMMIT).tar.gz
226235

pybind_interface/Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
SUFFIX := $(shell python3-config --extension-suffix)
15+
PYTHON_CONFIG := $(shell command -v python3-config)
16+
ifeq (,$(PYTHON_CONFIG))
17+
PY_VER := $(shell python3 --version 2>&1 | awk -F'[ .]' '{print $$2"."$$3}')
18+
PYTHON_CONFIG := $(shell command -v python$(PY_VER)-config)
19+
ifeq (,$(PYTHON_CONFIG))
20+
$(error Could not find python3-config or python$(PY_VER)-config.)
21+
endif
22+
endif
23+
24+
SUFFIX := $(shell $(PYTHON_CONFIG) --extension-suffix)
1625

1726
# The names of the shared libraries that result after compiling qsim for Pybind11
1827
QSIMLIB_BASIC = ../qsimcirq/qsim_basic$(SUFFIX)

0 commit comments

Comments
 (0)