From 88021b5767656900896752ed30ae4e559dcf4656 Mon Sep 17 00:00:00 2001 From: Christian Tabedzki <35670232+tabedzki@users.noreply.github.com> Date: Thu, 18 Jun 2026 15:44:57 -0400 Subject: [PATCH] fix(build): make install/compile scripts run on non-Windows The install and compile scripts assumed a Windows + MSVC environment and the Java/Swing MATLAB runtime, so they failed on macOS/Linux. Make them portable without changing Windows behaviour: - compile_transformations: on macOS, link the optional C++ MEX export symbols with the classic linker (-ld_classic); newer Xcode linkers treat MATLAB's as hard errors otherwise. - install_virmen: only copy git-hooks when the directory exists, write version.txt relative to the repo (the old $GIT_DIR path is unset when run interactively), guard the Windows-only winmerge call behind ispc, and report errors via getReport (displayException did not exist). - compile_serialcomm: skip on non-Windows -- Serial.cpp uses the Win32 COM-port API and cannot build elsewhere. - calibrateBallMEX, calibrateBallMEX_2sensors: replace the Java java.lang.Thread.sleep(8) with pause(0.008), which does not depend on the removed MATLAB Java runtime. Assisted-by: ClaudeCode:claude-opus-4.8 --- compile_transformations.m | 8 +++++++- install_virmen.m | 14 +++++++++----- sensors/calibrateBallMEX.m | 2 +- sensors/calibrateBallMEX_2sensors.m | 2 +- sensors/serialCommunications/compile_serialcomm.m | 6 ++++++ 5 files changed, 24 insertions(+), 8 deletions(-) diff --git a/compile_transformations.m b/compile_transformations.m index ee44512..68344ec 100644 --- a/compile_transformations.m +++ b/compile_transformations.m @@ -19,7 +19,13 @@ function compile_transformations() if isfile('miniVR_projection_wparameters.cpp') fprintf('================== Compiling miniVR_projection_wparameters ============\n'); - mex miniVR_projection_wparameters.cpp -R2018a + if ismac + % Newer Xcode linkers error on MATLAB's optional C++ MEX export + % symbols; the classic linker treats them as optional + mex('miniVR_projection_wparameters.cpp', '-R2018a', 'LDFLAGS=$LDFLAGS -Wl,-ld_classic'); + else + mex miniVR_projection_wparameters.cpp -R2018a + end end diff --git a/install_virmen.m b/install_virmen.m index fdacb2e..5120430 100644 --- a/install_virmen.m +++ b/install_virmen.m @@ -3,11 +3,13 @@ function install_virmen() [scriptDir,scriptName] = fileparts(mfilename('fullpath')); origLoc = cd(scriptDir); -fprintf(':: Copying git hooks...\n'); -copyfile('git-hooks/*', '.git/hooks'); +if exist('git-hooks', 'dir') + fprintf(':: Copying git hooks...\n'); + copyfile('git-hooks/*', '.git/hooks'); +end fprintf(':: Logging git status to version.txt...\n'); -system('git log -1 --pretty=oneline HEAD > $GIT_DIR/../version.txt'); +system('git log -1 --pretty=oneline HEAD > version.txt'); try @@ -35,14 +37,16 @@ function install_virmen() ' is properly configured, and then re-run ' scriptName '.\n' ... '\n\n' ... ]); - displayException(err); + disp(getReport(err)); end cd(scriptDir); if exist('extras/RigParameters.m', 'file') - system('start winmerge extras/RigParameters.m extras/RigParameters.m.example'); + if ispc + system('start winmerge extras/RigParameters.m extras/RigParameters.m.example'); + end fprintf(':: Please edit your existing RigParameters.m to match RigParameters.m.example.\n'); else copyfile('extras/RigParameters.m.example', 'extras/RigParameters.m'); diff --git a/sensors/calibrateBallMEX.m b/sensors/calibrateBallMEX.m index 39c8bf5..cb0651d 100644 --- a/sensors/calibrateBallMEX.m +++ b/sensors/calibrateBallMEX.m @@ -17,7 +17,7 @@ while true [dy1,dx1,dY,dX,dT] = arduinoReader('get'); arduinoReader('poll'); - java.lang.Thread.sleep(8); + pause(0.008); dx = dx + dX; dy = dy + dY; diff --git a/sensors/calibrateBallMEX_2sensors.m b/sensors/calibrateBallMEX_2sensors.m index db1f85e..1ec3b21 100644 --- a/sensors/calibrateBallMEX_2sensors.m +++ b/sensors/calibrateBallMEX_2sensors.m @@ -19,7 +19,7 @@ while true [dy1,dx1,dY,dX,dT] = arduinoReader('get'); arduinoReader('poll'); - java.lang.Thread.sleep(8); + pause(0.008); dx_bottom = dx_bottom + dX; dy_bottom = dy_bottom + dY; diff --git a/sensors/serialCommunications/compile_serialcomm.m b/sensors/serialCommunications/compile_serialcomm.m index 30a6bc9..bcc6c38 100644 --- a/sensors/serialCommunications/compile_serialcomm.m +++ b/sensors/serialCommunications/compile_serialcomm.m @@ -1,5 +1,11 @@ function compile_serialcomm() + % Serial.cpp uses the Windows COM-port API + if ~ispc + fprintf('!! WARNING: Serial communications MEX is only supported on Windows. Doing nothing.\n'); + return; + end + % Compilation options mexOpts = {'-O'};