-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_wrapper.sh
More file actions
executable file
·92 lines (76 loc) · 2.78 KB
/
build_wrapper.sh
File metadata and controls
executable file
·92 lines (76 loc) · 2.78 KB
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
91
92
#!/bin/bash
# build_wrapper.sh
# Automates the generation of the C# wrapper for Baumer neoAPI on Linux.
set -e # Exit immediately if a command exits with a non-zero status.
ROOT_DIR=$(pwd)
WRAPPER_DIR="$ROOT_DIR/wrapper"
OUTPUT_FILE="$WRAPPER_DIR/neoAPI_linux.cs"
INTERFACE_FILE="$ROOT_DIR/neoapi.i"
if [ "$#" -eq 0 ]; then
if [ -d "$WRAPPER_DIR/include/neoapi" ] && [ -d "$WRAPPER_DIR/lib" ]; then
echo "Using localized headers and libraries in $WRAPPER_DIR"
INC_PATH="$WRAPPER_DIR/include"
LIB_PATH="$WRAPPER_DIR/lib"
else
echo "Usage: $0 <path_to_baumer_sdk>"
echo "Alternatively, provide include/neoapi and lib in the wrapper directory."
exit 1
fi
else
SDK_PATH=$(realpath "$1")
echo "Using SDK at: $SDK_PATH"
# 1. Validation
if [ ! -d "$SDK_PATH/include/neoapi" ] || [ ! -d "$SDK_PATH/lib" ]; then
echo "Error: SDK path does not contain include/neoapi or lib directory."
exit 1
fi
# Update localized assets
echo "Updating localized headers and libraries from SDK..."
mkdir -p "$WRAPPER_DIR/include/neoapi" "$WRAPPER_DIR/lib"
cp -r "$SDK_PATH"/include/neoapi/* "$WRAPPER_DIR/include/neoapi/"
cp -r "$SDK_PATH"/lib/* "$WRAPPER_DIR/lib/"
INC_PATH="$WRAPPER_DIR/include"
LIB_PATH="$WRAPPER_DIR/lib"
fi
if [ ! -f "$INTERFACE_FILE" ]; then
echo "Error: SWIG interface file $INTERFACE_FILE not found."
exit 1
fi
# 2. Check for dependencies
if ! command -v swig &> /dev/null; then
echo "Error: swig is not installed. Please run 'sudo apt install swig'."
exit 1
fi
if ! command -v g++ &> /dev/null; then
echo "Error: g++ is not installed."
exit 1
fi
# 3. Preparation
echo "Cleaning up generated files..."
rm -f "$WRAPPER_DIR"/*.cs "$WRAPPER_DIR"/*.cxx "$WRAPPER_DIR"/*.so
rm -f "$OUTPUT_FILE"
# 4. SWIG Generation
echo "Running SWIG with namespace NeoAPI_Linux..."
swig -c++ -csharp -namespace NeoAPI_Linux -I"$INC_PATH" -outdir "$WRAPPER_DIR" -o "$WRAPPER_DIR/neoapi_wrap.cxx" "$INTERFACE_FILE"
# 5. Compilation
echo "Compiling native library..."
g++ -shared -fPIC "$WRAPPER_DIR/neoapi_wrap.cxx" \
-I"$INC_PATH" \
-L"$LIB_PATH" \
-Wl,--no-as-needed -lneoapi_cpp \
-Wl,-rpath,'$ORIGIN/lib' -Wl,-rpath,'$ORIGIN' \
-o "$WRAPPER_DIR/libneoapi_csharp.so"
# 6. Consolidation
echo "Consolidating C# files into $OUTPUT_FILE..."
if [ -f "$ROOT_DIR/extra_handlers.cs" ]; then
cat "$WRAPPER_DIR"/*.cs "$ROOT_DIR/extra_handlers.cs" > "$OUTPUT_FILE"
else
cat "$WRAPPER_DIR"/*.cs > "$OUTPUT_FILE"
fi
# 7. Cleanup
echo "Cleaning intermediate files..."
find "$WRAPPER_DIR" -maxdepth 1 -name "*.cs" ! -name "neoAPI_linux.cs" -delete
find "$WRAPPER_DIR" -name "*.cxx" -delete
echo "Done! Generated files:"
echo " - $OUTPUT_FILE"
echo " - $WRAPPER_DIR/libneoapi_csharp.so"