-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathswig_compile_pbs.sh
executable file
·91 lines (73 loc) · 2.62 KB
/
swig_compile_pbs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/bin/bash
# This script uses the PBS supplied include file pbs_ifl.h and pbs.i
# to create pbs.py, pbs_wrap.c and _pbs.so.
# This script must be run as a normal user and not run as root.
#
# Usage:
#
# $ ./swig_compile_pbs.sh
#
# Notes:
# 1. The package "openssl-devel" provides the libs to link with,
# i.e. "... -lcrypto -lssl".
# $ rpmquery -ql openssl-devel | grep lib
# /usr/lib64/libcrypto.so
# /usr/lib64/libssl.so
#############################
# Set your configuration here
#############################
# Location of your PBS configuration file
conf="/etc/pbs.conf"
# Specify here where the include files are for the version of Python that you are using.
# If you are using a Python in a virtual environment then use the include location that
# the virtual env was derived from.
PYTHON_INCL="/usr/include/python3.8"
# Location of the swig exectable.
SWIG_EXEC="/usr/bin/swig"
# You should not need to change anything below here.
#################
# Start the Build
#################
# Make sure the user is not running this script as root.
if [[ $EUID -eq 0 ]]; then
echo "You should NOT be root to run this script."
echo "You should run it as an unprivileged user."
echo "Exiting"
echo ""
exit 0
fi
# Make sure we have a PBS config file.
if [ ! -f $conf ]; then
echo "Error: missing PBS configuration file $conf"
exit 0
fi
# The PBS config file must be sourced to provide $PBS_EXEC.
. $conf
# Set LD_RUN_PATH here so users should not need to export LD_LIBRARY_PATH at run time.
# If you link with libpbs.so below you will need to export LD_RUN_PATH.
# If you link with libpbs.a then LD_RUN_PATH will not be needed.
export LD_RUN_PATH=$PBS_EXEC/lib
# Running swig creates pbs.py and pbs_wrap.c under the src/ directory.
$SWIG_EXEC -I$PBS_EXEC/include -python src/pbs.i
if [ $? -ne 0 ]; then
echo 'Error: You are probably missing the file: /opt/pbs/include/pbs_ifl.h'
exit 0
fi
# Running gcc creates _pbs.so
# Note: This is what I had before, compile and link in one step.
# But I have commented out this and separated the compile and link
# as its then easier to debug errors during build.
#gcc -shared -fPIC -I$PYTHON_INCL -I$PBS_EXEC/include pbs_wrap.c \
# $PBS_EXEC/lib/libpbs.a \
# -L/lib -lpthread -lcrypto -lssl \
# -o _pbs.so
# Compiling
gcc -c -shared -fpic -I$PYTHON_INCL -I$PBS_EXEC/include src/pbs_wrap.c -o src/pbs_wrap.o
# Linking
# Not sure if we need to also add -L/lib
gcc -shared -fpic -L/opt/pbs/lib \
$PBS_EXEC/lib/libpbs.so src/pbs_wrap.o \
-lpthread -lcrypto -lssl -lsec \
-o src/_pbs.so
# It does not need to be executable.
chmod ugo-x src/_pbs.so