From 56086a9c421547825d8254c03bdbe86fa14913a8 Mon Sep 17 00:00:00 2001
From: Jonathan Wilkes <jon.w.wilkes@gmail.com>
Date: Sun, 28 Aug 2022 21:03:15 -0400
Subject: [PATCH] fixes to get Purr building on catalina

---
 externals/apple/Makefile               |  6 +++++-
 externals/ext13/openpatch.c            |  6 ++++++
 externals/footils/knob/knob.c          |  4 ++++
 externals/iem/iemgui/src/room_sim_2d.c |  8 ++++----
 externals/iem/iemgui/src/room_sim_3d.c |  8 ++++----
 externals/iem16/src/tab16write.c       | 13 +++++++++++++
 externals/iemlib/iemlib2/src/dollarg.c |  2 ++
 externals/moonlib/mknob.c              |  1 +
 externals/unauthorized/grid.c          |  2 ++
 9 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/externals/apple/Makefile b/externals/apple/Makefile
index b8e367473..bed1837ec 100644
--- a/externals/apple/Makefile
+++ b/externals/apple/Makefile
@@ -10,7 +10,11 @@ SOURCES =
 
 # For objects that only build on certain platforms, add those to the SOURCES
 # line for the right platforms.
-SOURCES_macosx = ambient_light_sensor.c iodisplay.c keyboard_light.c sudden_motion_sensor.c smc.c keyboard_layout.c
+#
+# For some reason keyboard_layout.c doesn't work anymore. Even searching for
+# some of the system function calls used returns zero results. So we disable
+# building it below.
+SOURCES_macosx = ambient_light_sensor.c iodisplay.c keyboard_light.c sudden_motion_sensor.c smc.c #keyboard_layout.c
 SOURCES_iphoneos = multitouch.c
 
 # list all pd objects (i.e. myobject.pd) files here, and their helpfiles will
diff --git a/externals/ext13/openpatch.c b/externals/ext13/openpatch.c
index 915a37987..6928b2662 100644
--- a/externals/ext13/openpatch.c
+++ b/externals/ext13/openpatch.c
@@ -1,5 +1,11 @@
 #include "ext13.h"
 #include "m_pd.h"
+
+/* Just go ahead and include the private header since the author wants it.
+   Anyway, I think this can be handled natively now so it should only be here
+   for compatibility purposes anyway. */
+#include "m_imp.h"
+
 /*
 #ifndef PD_MAJOR_VERSION
 #include "s_stuff.h"
diff --git a/externals/footils/knob/knob.c b/externals/footils/knob/knob.c
index 78b8ce140..13ad25b2c 100644
--- a/externals/footils/knob/knob.c
+++ b/externals/footils/knob/knob.c
@@ -27,8 +27,12 @@
 #include "g_canvas.h"
 
 #include "g_all_guis.h"
+/* This really should be part of g_all_guis.h... */
+EXTERN int gfxstub_haveproperties(void *key);
+
 #include <math.h>
 
+
 #ifdef WIN32
 #include <io.h>
 #else
diff --git a/externals/iem/iemgui/src/room_sim_2d.c b/externals/iem/iemgui/src/room_sim_2d.c
index 4dc9535b3..cfb46ec41 100644
--- a/externals/iem/iemgui/src/room_sim_2d.c
+++ b/externals/iem/iemgui/src/room_sim_2d.c
@@ -874,13 +874,13 @@ static void room_sim_2d__motionhook(t_scalehandle *sh,
             scalehandle_unclick_scale(sh);
         }
 
-        int properties = gfxstub_haveproperties((void *)x);
-        if (properties)
-        {
+        //int properties = gfxstub_haveproperties((void *)x);
+        //if (properties)
+        //{
             /* No properties for room_sim externals atm */
             //properties_set_field_int(properties,"width",new_w);
             //properties_set_field_int(properties,"height",new_h);
-        }
+        //}
     }
     scalehandle_dragon_label(sh,mouse_x, mouse_y);
 }
diff --git a/externals/iem/iemgui/src/room_sim_3d.c b/externals/iem/iemgui/src/room_sim_3d.c
index 11d9dad53..d6382ebc2 100644
--- a/externals/iem/iemgui/src/room_sim_3d.c
+++ b/externals/iem/iemgui/src/room_sim_3d.c
@@ -1008,13 +1008,13 @@ static void room_sim_3d__motionhook(t_scalehandle *sh,
             scalehandle_unclick_scale(sh);
         }
 
-        int properties = gfxstub_haveproperties((void *)x);
-        if (properties)
-        {
+        //int properties = gfxstub_haveproperties((void *)x);
+        //if (properties)
+        //{
             /* No properties for room_sim externals atm */
             //properties_set_field_int(properties,"width",new_w);
             //properties_set_field_int(properties,"height",new_h);
-        }
+        //}
     }
     scalehandle_dragon_label(sh,mouse_x, mouse_y);
 }
diff --git a/externals/iem16/src/tab16write.c b/externals/iem16/src/tab16write.c
index 2c0e6ef1d..d082da4bc 100644
--- a/externals/iem16/src/tab16write.c
+++ b/externals/iem16/src/tab16write.c
@@ -8,6 +8,19 @@
 
 #include "iem16_table.h"
 
+/* the following two functions are copied from table16.c so that each class can
+   be instantiated without a dependency on table16 already existing */
+static int table16_getarray16(t_table16*x, int*size,t_iem16_16bit**vec){
+  *size=x->x_size;
+  *vec =x->x_table;
+  return 1;
+}
+
+static void table16_usedindsp(t_table16*x){
+  x->x_usedindsp=1;
+}
+
+
 /* ------------------ tab16write: control ------------------------ */
 
 static t_class *tab16write_class;
diff --git a/externals/iemlib/iemlib2/src/dollarg.c b/externals/iemlib/iemlib2/src/dollarg.c
index 946108115..c05d0edb5 100644
--- a/externals/iemlib/iemlib2/src/dollarg.c
+++ b/externals/iemlib/iemlib2/src/dollarg.c
@@ -8,6 +8,8 @@ iemlib2 written by Thomas Musil, Copyright (c) IEM KUG Graz Austria 2000 - 2006
 # include "g_canvas.h"
 #else
 EXTERN t_canvas *glist_getcanvas(t_glist *x);
+EXTERN void canvas_unsetcurrent(t_canvas *x);
+EXTERN void canvas_setcurrent(t_canvas *x);
 #endif
 #include "iemlib.h"
 
diff --git a/externals/moonlib/mknob.c b/externals/moonlib/mknob.c
index d8430ffd9..1b2f9cc01 100644
--- a/externals/moonlib/mknob.c
+++ b/externals/moonlib/mknob.c
@@ -23,6 +23,7 @@
 #include <unistd.h>
 #endif
 
+EXTERN int gfxstub_haveproperties(void *key);
 
 #define MKNOB_TANGLE 100
 #define MKNOB_DEFAULTH 100
diff --git a/externals/unauthorized/grid.c b/externals/unauthorized/grid.c
index 9a423dbe0..c5b7b4f0e 100644
--- a/externals/unauthorized/grid.c
+++ b/externals/unauthorized/grid.c
@@ -25,6 +25,8 @@
 #include <unistd.h>
 #endif
 
+EXTERN int gfxstub_haveproperties(void *key);
+
 #define DEFAULT_GRID_WIDTH 200
 #define DEFAULT_GRID_HEIGHT 200
 #define DEFAULT_GRID_NBLINES 10
-- 
GitLab