From 8a4e28dc8121e50d987e888f9688412e1d3ee663 Mon Sep 17 00:00:00 2001 From: Alexey Sheplyakov Date: Sun, 23 Aug 2020 11:28:07 +0400 Subject: [PATCH] build: accept both python 3 and python 2 This makes building GiNaC a bit easier for users of "old" distributions where python 3 is not installed by default (Ubuntu 16.04), or even not available (CentOS 7). Scripts themselves work just fine with python 2.7 and python 3.x, so only minor changes to CMakeLists.txt are required (autotools scripts already handle python2/3) --- CMakeLists.txt | 8 ++++++++ INSTALL | 3 ++- doc/CMakeLists.txt | 2 +- ginac/CMakeLists.txt | 4 ++-- ginac/function.py | 2 +- ginsh/CMakeLists.txt | 4 ++-- ginsh/ginsh_fcn_help.py | 2 +- ginsh/ginsh_op_help.py | 2 +- scripts/fixupind.py | 4 ++-- scripts/yaptu.py | 2 +- 10 files changed, 21 insertions(+), 12 deletions(-) mode change 100755 => 100644 ginac/function.py mode change 100755 => 100644 ginsh/ginsh_fcn_help.py mode change 100755 => 100644 scripts/fixupind.py diff --git a/CMakeLists.txt b/CMakeLists.txt index cdb18f09..7989df14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -167,6 +167,14 @@ endif() find_program(MAKEINFO makeinfo) find_program(FIG2DEV fig2dev) +find_program(PYTHON python) +if (NOT PYTHON) + find_program(PYTHON python3) +endif() +if (NOT PYTHON) + message(FATAL_ERROR "Python version 3 or 2 is required") +endif() + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/config.h) add_definitions(-DHAVE_CONFIG_H) diff --git a/INSTALL b/INSTALL index 3a0dc2bb..1a0eb81c 100644 --- a/INSTALL +++ b/INSTALL @@ -27,7 +27,8 @@ Known not to work with: - GCC < 4.6.0 due to missing C++-11 support If you install from git, you also need GNU autoconf (>=2.59), automake (>=1.8), -libtool (>= 1.5), python3, bison (>= 2.3), flex (>= 2.5.33) to be installed. +libtool (>= 1.5), python (version 2.7 or 3.x), bison (>= 2.3), flex (>= 2.5.33) +to be installed. INSTALLATION diff --git a/doc/CMakeLists.txt b/doc/CMakeLists.txt index 22e300bd..e42e6bda 100644 --- a/doc/CMakeLists.txt +++ b/doc/CMakeLists.txt @@ -45,7 +45,7 @@ macro(pdflatex_process texfile) add_custom_command( OUTPUT ${_ind} COMMAND ${MAKEINDEX_COMPILER} ${_idx} - COMMAND python3 ${_fixupind} ${_idx} + COMMAND ${PYTHON} ${_fixupind} ${_idx} WORKING_DIRECTORY ${_dirname} DEPENDS ${texfile} ${_idx} COMMENT "MAKEINDEX ${_basename}.idx") diff --git a/ginac/CMakeLists.txt b/ginac/CMakeLists.txt index 1bad4ce7..07d8530e 100644 --- a/ginac/CMakeLists.txt +++ b/ginac/CMakeLists.txt @@ -168,11 +168,11 @@ install(FILES ${ginaclib_public_headers} DESTINATION "${INCLUDE_INSTALL_DIR}/gin add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/function.h - COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/function.py -o ${CMAKE_CURRENT_BINARY_DIR}/function.h ${CMAKE_CURRENT_SOURCE_DIR}/function.hppy + COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/function.py -o ${CMAKE_CURRENT_BINARY_DIR}/function.h ${CMAKE_CURRENT_SOURCE_DIR}/function.hppy DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/function.hppy ${CMAKE_CURRENT_SOURCE_DIR}/function.py) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/function.cpp - COMMAND python3 ${CMAKE_CURRENT_SOURCE_DIR}/function.py -o ${CMAKE_CURRENT_BINARY_DIR}/function.cpp ${CMAKE_CURRENT_SOURCE_DIR}/function.cppy + COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/function.py -o ${CMAKE_CURRENT_BINARY_DIR}/function.cpp ${CMAKE_CURRENT_SOURCE_DIR}/function.cppy DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/function.h ${CMAKE_CURRENT_SOURCE_DIR}/function.cppy ${CMAKE_CURRENT_SOURCE_DIR}/function.py) diff --git a/ginac/function.py b/ginac/function.py old mode 100755 new mode 100644 index 63012a26..f7dc7d46 --- a/ginac/function.py +++ b/ginac/function.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 + # encoding: utf-8 maxargs = 14 diff --git a/ginsh/CMakeLists.txt b/ginsh/CMakeLists.txt index 9f4c0a8f..46de38bf 100644 --- a/ginsh/CMakeLists.txt +++ b/ginsh/CMakeLists.txt @@ -40,13 +40,13 @@ endif() add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ginsh_fcn_help.h - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/ginsh_fcn_help.py -o ginsh_fcn_help.h ${CMAKE_CURRENT_SOURCE_DIR}/ginsh.1.in + COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/ginsh_fcn_help.py -o ginsh_fcn_help.h ${CMAKE_CURRENT_SOURCE_DIR}/ginsh.1.in DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ginsh.1.in ${CMAKE_CURRENT_SOURCE_DIR}/ginsh_fcn_help.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ginsh_op_help.h - COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/ginsh_op_help.py -o ginsh_op_help.h ${CMAKE_CURRENT_SOURCE_DIR}/ginsh.1.in + COMMAND ${PYTHON} ${CMAKE_CURRENT_SOURCE_DIR}/ginsh_op_help.py -o ginsh_op_help.h ${CMAKE_CURRENT_SOURCE_DIR}/ginsh.1.in DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ginsh.1.in ${CMAKE_CURRENT_SOURCE_DIR}/ginsh_op_help.py WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) diff --git a/ginsh/ginsh_fcn_help.py b/ginsh/ginsh_fcn_help.py old mode 100755 new mode 100644 index 1c7ea49a..edc675b4 --- a/ginsh/ginsh_fcn_help.py +++ b/ginsh/ginsh_fcn_help.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 + # encoding: utf-8 # Convert help for ginsh functions from man page to C source import sys, re, optparse diff --git a/ginsh/ginsh_op_help.py b/ginsh/ginsh_op_help.py index f0932572..a38697f1 100755 --- a/ginsh/ginsh_op_help.py +++ b/ginsh/ginsh_op_help.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 + # encoding: utf-8 # Convert help for ginsh operators from man page to C source import sys, re, optparse diff --git a/scripts/fixupind.py b/scripts/fixupind.py old mode 100755 new mode 100644 index ac2c4b97..0e781c09 --- a/scripts/fixupind.py +++ b/scripts/fixupind.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 + # encoding: utf-8 # TeX Live 2012 seems to dislike files produces by doxygen (1.8.x.y) # In particular, makeindex(1) program creates invalid index entries like @@ -11,7 +11,7 @@ import sys, os, re def fixupind(fname): """ Fix \\hyperpage{NNN_} entries in the ind file @var{fname} """ - tmpout = fname + '.tmp' + tmpout = fname + '.tmp' inp = open(fname) out = open(tmpout, 'wt') rx = re.compile('(hyperpage)[{]([0-9]+)[_][}]') diff --git a/scripts/yaptu.py b/scripts/yaptu.py index 734d748a..bc0d4f85 100644 --- a/scripts/yaptu.py +++ b/scripts/yaptu.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 + """ Yet Another Python Templating Utility, Version 1.2, by Alex Martelli. Distributed under PSF license (http://docs.python.org/license.html). -- 2.44.0