11#! /bin/bash
2+ set -euo pipefail
23C_MODULES=(uinput hiddrv sc_by_bt remotepad cemuhook)
34C_VERSION_uinput=9
45C_VERSION_hiddrv=5
@@ -7,27 +8,29 @@ C_VERSION_remotepad=1
78C_VERSION_cemuhook=1
89
910function rebuild_c_modules() {
10- echo " lib$1 .so is outdated or missing, building one"
11+ echo " lib${1} .so is outdated or missing, building one"
1112 echo " Please wait, this should be done only once."
1213 echo " "
13-
14- # Next line generates string like 'lib.linux-x86_64-2.7', directory where libuinput.so was just generated
15- LIB=$( python3 -c ' import platform ; print("lib.linux-%s-%s.%s" % ((platform.machine(),) + platform.python_version_tuple()[0:2]))' )
14+ # cpython-312-x86_64-linux-gnu
15+ # SOABI=$(python3 -c 'import sysconfig; print(sysconfig.get_config_var("SOABI").split("-")[0:2])');
16+
17+ # lib.linux-x86_64-cpython-312 - directory where libuinput.so was just generated
18+ LIB=$( python3 -c ' import platform; import sysconfig; soabi = sysconfig.get_config_var("SOABI").split("-")[0:2]; print(f"lib.linux-{platform.machine()}-{soabi[0]}-{soabi[1]}")' )
19+ # .cpython-312-x86_64-linux-gnu.so
1620 EXT_SUFFIX=$( python3 -c ' import sysconfig ; print(sysconfig.get_config_var("EXT_SUFFIX"))' )
17-
1821 for cmod in ${C_MODULES[@]} ; do
19- if [ -e build/$LIB /lib${cmod}${EXT_SUFFIX} ] ; then
20- rm build/$LIB /lib${cmod}${EXT_SUFFIX} || exit 1
22+ if [[ -e build/${ LIB} /lib${cmod}${EXT_SUFFIX} ]] ; then
23+ rm " build/${ LIB} /lib${cmod}${EXT_SUFFIX} "
2124 fi
2225 done
23-
24- python3 setup.py build || exit 1
26+
27+ python3 setup.py build
2528 echo " "
26-
29+
2730 for cmod in ${C_MODULES[@]} ; do
28- if [ ! -e lib${cmod} .so ] ; then
29- ln -s build/$LIB /lib${cmod}${EXT_SUFFIX} ./lib${cmod} .so || exit 1
30- echo Symlinked ./lib${cmod}${EXT_SUFFIX} ' ->' build/$LIB /lib${cmod} .so
31+ if [[ ! -e lib${cmod} .so ] ] ; then
32+ ln -s " build/${ LIB} /lib${cmod}${EXT_SUFFIX} " " ./lib${cmod} .so"
33+ echo " Symlinked ./lib${cmod} .so '->' build/${ LIB} /lib${cmod}${EXT_SUFFIX} "
3134 fi
3235 done
3336 echo " "
@@ -39,17 +42,19 @@ cd "$(dirname "$0")"
3942
4043# Check if c modules are compiled and actual
4144for cmod in ${C_MODULES[@]} ; do
42- eval expected_version=\$ C_VERSION_${cmod}
43- reported_version=$( PYTHONPATH=" ." python3 -c ' import os, ctypes; lib=ctypes.CDLL("./' lib${cmod} ' .so"); print(lib.' ${cmod} ' _module_version())' )
44- if [ x" $reported_version " != x" $expected_version " ] ; then
45- rebuild_c_modules ${cmod}
45+ expected_version=\$ C_VERSION_${cmod}
46+ if ! reported_version=$( PYTHONPATH=" ." python3 -c ' import os, ctypes; lib=ctypes.CDLL("./' lib${cmod} ' .so"); print(lib.' ${cmod} ' _module_version())' ) ; then
47+ echo " Failed to check module version for ${cmod} , this is normal"
48+ fi
49+ if [[ " $reported_version " != " ${expected_version} " ]] ; then
50+ rebuild_c_modules " ${cmod} "
4651 fi
4752done
4853
4954# Set PATH
5055SCRIPTS=" $( pwd) /scripts"
5156export PATH=" $SCRIPTS " :" $PATH "
52- export PYTHONPATH=" ." :" $PYTHONPATH "
57+ export PYTHONPATH=" ." :" ${ PYTHONPATH-} "
5358export SCC_SHARED=" $( pwd) "
5459
5560# Execute
0 commit comments