Skip to content

Commit

Permalink
Use pkg-config instead of own script
Browse files Browse the repository at this point in the history
Switch to `pkg-config` to get the required CFLAGS and LDFLAGS.
  • Loading branch information
HeavyWombat committed Sep 9, 2018
1 parent bd325ab commit 166ae68
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 54 deletions.
4 changes: 2 additions & 2 deletions internal/pycgo/updateYAML.go.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
package pycgo

/*
#cgo CFLAGS: -I<path-to-dir-that-has-python-header-file>
#cgo LDFLAGS: -L<path-to-dir-that-has-python-lib> -l<name-of-python-lib>
#cgo CFLAGS: <cflags>
#cgo LDFLAGS: <ldflags>

#include <stdlib.h>

Expand Down
54 changes: 2 additions & 52 deletions scripts/createGoSourceFileFromTemplate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,7 @@ set -euo pipefail

BASEDIR="$(cd "$(dirname "$0")/.." && pwd)"

FIND_PYTHON_H="$( (find /usr -type f -name Python.h 2>/dev/null || true) | grep python3)"
if [[ "$(wc -l <<<"${FIND_PYTHON_H}")" -eq 0 ]]; then
echo "Unable to find Python header file in /usr"
exit 1
fi

if [[ "$(wc -l <<<"${FIND_PYTHON_H}")" -gt 1 ]]; then
echo "Found more than one Python header file, not sure what to do ..."
exit 1
fi

case "$(uname)" in
Linux)
FIND_PYTHON_LIB="$( (find /usr -name "libpython3*.so" -exec readlink -f {} \; 2>/dev/null || true) | uniq)"
if [[ "$(wc -l <<<"${FIND_PYTHON_LIB}")" -eq 0 ]]; then
echo "Unable to find Python library in /usr"
exit 1
fi

if [[ "$(wc -l <<<"${FIND_PYTHON_LIB}")" -gt 1 ]]; then
echo "Found more than one Python library, not sure what to do ..."
exit 1
fi
;;

\
Darwin)
FIND_PYTHON_LIB="$( (find /usr -name "libpython3.?.dylib" 2>/dev/null || true) | grep "lib/lib")"
if [[ "$(wc -l <<<"${FIND_PYTHON_LIB}")" -eq 0 ]]; then
echo "Unable to find Python library in /usr"
exit 1
fi

if [[ "$(wc -l <<<"${FIND_PYTHON_LIB}")" -gt 1 ]]; then
echo "Found more than one Python library, not sure what to do ..."
exit 1
fi
;;

esac

PATH_TO_PYTHON_H_DIR="$(dirname "${FIND_PYTHON_H}")"
PATH_TO_PYTHON_LIB="$(dirname "${FIND_PYTHON_LIB}")"
PYTHON_LIB_NAME="$(basename "${FIND_PYTHON_LIB}" | sed -e 's/^lib//' -e 's/.so.*//' -e 's/.dylib//')"

echo "Path to Python.h: ${PATH_TO_PYTHON_H_DIR}"
echo "Path to Python library: ${PATH_TO_PYTHON_LIB}"
echo "Name of Python library used: ${PYTHON_LIB_NAME}"

sed \
-e "s:<path-to-dir-that-has-python-header-file>:${PATH_TO_PYTHON_H_DIR}:" \
-e "s:<path-to-dir-that-has-python-lib>:${PATH_TO_PYTHON_LIB}:" \
-e "s:<name-of-python-lib>:${PYTHON_LIB_NAME}:" \
-e "s:<cflags>:$(pkg-config --cflags python3):" \
-e "s:<ldflags>:$(pkg-config --static --libs python3):" \
"${BASEDIR}/internal/pycgo/updateYAML.go.template" >"${BASEDIR}/internal/pycgo/updateYAML.go"

0 comments on commit 166ae68

Please sign in to comment.