1
0
mirror of https://github.com/TREX-CoE/trexio.git synced 2024-07-22 18:57:39 +02:00
trexio/tools/prepare_python.sh

47 lines
1.5 KiB
Bash
Raw Normal View History

2021-08-05 16:55:34 +02:00
#!/bin/bash
# Check that script is executed from tools directory
if [[ $(basename $PWD) != "tools" ]] ; then
echo "This script should run in the tools directory"
exit -1
fi
TREXIO_ROOT=$(dirname "${PWD}../")
# First define readonly global variables.
readonly SRC=${TREXIO_ROOT}/src
readonly INCLUDIR=${TREXIO_ROOT}/include
readonly TOOLS=${TREXIO_ROOT}/tools
readonly PYDIR=${TREXIO_ROOT}/python
readonly PYTREXIODIR=${PYDIR}/pytrexio
2021-08-05 16:55:34 +02:00
# We want the script to crash on the 1st error:
set -e
2021-08-18 12:30:03 +02:00
# Create src and trexio directories in the python folder if not yet done
2021-08-05 16:55:34 +02:00
mkdir -p ${PYDIR}/src
2021-08-18 12:30:03 +02:00
mkdir -p ${PYTREXIODIR}
2021-08-05 16:55:34 +02:00
# Copy all the source code and header files in the corresponding python directory
2021-08-24 10:51:29 +02:00
cp ${SRC}/pytrexio.py ${PYTREXIODIR}/pytrexio.py
cp ${SRC}/trexio.py ${PYDIR}/trexio.py
2021-08-05 16:55:34 +02:00
cp ${SRC}/*.c ${PYDIR}/src
cp ${SRC}/*.h ${PYDIR}/src
cp ${INCLUDIR}/trexio.h ${PYDIR}/src
# fix needed to define HAVE_HDF5 symbol so that Python extension is always compiled with HDF5 (without including config.h)
# add "#define HAVE_HDF5 1" line after "#include stdint.h" using awk and sed
export LINE_NO=$(($(awk '/stdint.h/{print NR}' ${PYDIR}/src/trexio.h) + 1))
# sed on MacOS is different from GNU sed on Linux and requires special treatment
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' -e "$LINE_NO"'i \
#define HAVE_HDF5 1' "${PYDIR}/src/trexio.h"
else
sed -i -e "$LINE_NO"'i \
#define HAVE_HDF5 1' "${PYDIR}/src/trexio.h"
fi
2021-08-05 16:55:34 +02:00
# Copy additional info
2021-09-08 19:34:16 +02:00
cp ${TREXIO_ROOT}/AUTHORS ${TREXIO_ROOT}/LICENSE ${PYDIR}
2021-08-05 16:55:34 +02:00