Skip to content

Commit 54dabc9

Browse files
author
jed | Cursor.sh | Claude
committed
Implement proper build process for .so files from _ert_shrlib_rtw source
/** * This code written by Claude Sonnet 4 (claude-3-5-sonnet-20241022) * Generated via Cursor IDE (cursor.sh) with AI assistance * Model: Anthropic Claude 3.5 Sonnet * Generation timestamp: 2025-01-27 * Context: Implemented proper build process based on Rosetta-Simulink project * * Technical details: * - LLM: Claude 3.5 Sonnet (2024-10-22) * - IDE: Cursor (cursor.sh) * - Generation method: AI-assisted pair programming * - Code style: Makefile with proper RTW source building * - Dependencies: Generated Makefiles from Simulink code generation */ - Added build targets that use generated Makefiles from _ert_shrlib_rtw directories - Falls back to manual build when MATLAB paths are not available - Properly builds .so files from RTW source code as intended - Based on successful pattern from Rosetta-Simulink project - Handles both MATLAB and non-MATLAB environments gracefully - .so files are now properly built from _ert_shrlib_rtw source code
1 parent 672dcb1 commit 54dabc9

File tree

1 file changed

+107
-5
lines changed

1 file changed

+107
-5
lines changed

Makefile

Lines changed: 107 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ help:
1111
@echo " lint - Run linting checks"
1212
@echo " clean - Clean build artifacts"
1313
@echo " build - Build the package"
14+
@echo " build-all-so - Build all shared libraries from RTW source"
15+
@echo " build-example1-so - Build Example1 shared library from RTW source"
16+
@echo " build-example2-so - Build Example2 shared library from RTW source"
17+
@echo " build-example3-so - Build Example3 shared library from RTW source"
1418
@echo " check-so-files - Check if shared libraries exist"
1519
@echo " check-all-so - Check all shared libraries"
1620
@echo " build-examples - Build everything needed for examples"
@@ -110,18 +114,112 @@ validate:
110114
python -m py_compile test_all_examples.py
111115
@echo "All Python files compile successfully!"
112116

113-
# Check if shared libraries exist (they should be pre-built from _ert_shrlib_rtw source)
117+
# Build shared libraries from _ert_shrlib_rtw source code
118+
build-example1-so:
119+
@echo "Building Example1 shared library from RTW source..."
120+
@if [ -f Example1/dllModel_ert_shrlib_rtw/dllModel.mk ]; then \
121+
cd Example1/dllModel_ert_shrlib_rtw && \
122+
MATLAB_ROOT=/usr/local/MATLAB/R2018a make -f dllModel.mk || \
123+
echo "MATLAB build failed, using manual build..."; \
124+
fi
125+
@if [ ! -f Example1/dllModel.so ]; then \
126+
echo "Manual build for Example1..."; \
127+
cd Example1/dllModel_ert_shrlib_rtw && \
128+
gcc -fPIC -shared -o ../dllModel.so \
129+
-I. \
130+
-DMODEL=dllModel \
131+
-DNUMST=1 \
132+
-DNCSTATES=0 \
133+
-DHAVESTDIO \
134+
-DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 \
135+
-DCLASSIC_INTERFACE=0 \
136+
-DALLOCATIONFCN=0 \
137+
-DTID01EQ=0 \
138+
-DTERMFCN=1 \
139+
-DONESTEPFCN=1 \
140+
-DMAT_FILE=0 \
141+
-DMULTI_INSTANCE_CODE=0 \
142+
-DINTEGER_CODE=0 \
143+
-DMT=0 \
144+
-DUNIX \
145+
dllModel.c dllModel_data.c ert_main.c \
146+
-lm; \
147+
fi
148+
@echo "✓ Example1/dllModel.so built successfully"
149+
150+
build-example2-so:
151+
@echo "Building Example2 shared library from RTW source..."
152+
@if [ -f Example2/discrete_tf_ert_shrlib_rtw/discrete_tf.mk ]; then \
153+
cd Example2/discrete_tf_ert_shrlib_rtw && \
154+
MATLAB_ROOT=/usr/local/MATLAB/R2018a make -f discrete_tf.mk || \
155+
echo "MATLAB build failed, using manual build..."; \
156+
fi
157+
@if [ ! -f Example2/discrete_tf.so ]; then \
158+
echo "Manual build for Example2..."; \
159+
cd Example2/discrete_tf_ert_shrlib_rtw && \
160+
gcc -fPIC -shared -o ../discrete_tf.so \
161+
-I. \
162+
-DMODEL=discrete_tf \
163+
-DNUMST=1 \
164+
-DNCSTATES=0 \
165+
-DHAVESTDIO \
166+
-DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 \
167+
-DCLASSIC_INTERFACE=0 \
168+
-DALLOCATIONFCN=0 \
169+
-DTID01EQ=0 \
170+
-DTERMFCN=1 \
171+
-DONESTEPFCN=1 \
172+
-DMAT_FILE=0 \
173+
-DMULTI_INSTANCE_CODE=0 \
174+
-DINTEGER_CODE=0 \
175+
-DMT=0 \
176+
-DUNIX \
177+
discrete_tf.c ert_main.c \
178+
-lm; \
179+
fi
180+
@echo "✓ Example2/discrete_tf.so built successfully"
181+
182+
build-example3-so:
183+
@echo "Building Example3 shared library from RTW source..."
184+
@if [ -f Example3/bouncing_ball_ert_shrlib_rtw/bouncing_ball.mk ]; then \
185+
cd Example3/bouncing_ball_ert_shrlib_rtw && \
186+
MATLAB_ROOT=/usr/local/MATLAB/R2018a make -f bouncing_ball.mk || \
187+
echo "MATLAB build failed, using manual build..."; \
188+
fi
189+
@if [ ! -f Example3/bouncing_ball.so ]; then \
190+
echo "Manual build for Example3..."; \
191+
cd Example3/bouncing_ball_ert_shrlib_rtw && \
192+
gcc -fPIC -shared -o ../bouncing_ball.so \
193+
-I. \
194+
-DMODEL=bouncing_ball \
195+
-DNUMST=1 \
196+
-DNCSTATES=0 \
197+
-DHAVESTDIO \
198+
-DMODEL_HAS_DYNAMICALLY_LOADED_SFCNS=0 \
199+
-DCLASSIC_INTERFACE=0 \
200+
-DALLOCATIONFCN=0 \
201+
-DTID01EQ=0 \
202+
-DTERMFCN=1 \
203+
-DONESTEPFCN=1 \
204+
-DMAT_FILE=0 \
205+
-DMULTI_INSTANCE_CODE=0 \
206+
-DINTEGER_CODE=0 \
207+
-DMT=0 \
208+
-DUNIX \
209+
bouncing_ball.c ert_main.c \
210+
-lm; \
211+
fi
212+
@echo "✓ Example3/bouncing_ball.so built successfully"
213+
214+
# Check if shared libraries exist
114215
check-so-files:
115-
@echo "Checking for pre-built shared libraries..."
216+
@echo "Checking for shared libraries..."
116217
@echo "Example1:"
117218
@ls -la Example1/*.so 2>/dev/null || echo " No .so file found"
118219
@echo "Example2:"
119220
@ls -la Example2/*.so 2>/dev/null || echo " No .so file found"
120221
@echo "Example3:"
121222
@ls -la Example3/*.so 2>/dev/null || echo " No .so file found"
122-
@echo ""
123-
@echo "Note: .so files should be built from _ert_shrlib_rtw source code using MATLAB/Simulink"
124-
@echo "The source code is available in each example's _ert_shrlib_rtw directory"
125223

126224
# Create virtual environment
127225
venv:
@@ -134,6 +232,10 @@ install-example-deps: venv
134232
venv/bin/pip install pandas numpy matplotlib scipy control pytest pytest-cov
135233
@echo "✓ Example dependencies installed"
136234

235+
# Build all shared libraries from RTW source
236+
build-all-so: build-example1-so build-example2-so build-example3-so
237+
@echo "All shared libraries built from RTW source"
238+
137239
# Check all shared libraries
138240
check-all-so: check-so-files
139241
@echo "All shared library checks completed"

0 commit comments

Comments
 (0)