--- configure.in.orig	Thu Jun  1 11:29:43 2006
+++ configure.in	Thu Jun  1 12:39:18 2006
@@ -81,6 +81,15 @@
 
 dnl look for tcl 8.x... do I really have to go through all this!?
 
+dnl need to modify CFLAGS and LDFLAGS on FreeBSD in order to search
+dnl /usr/local/*
+
+if test `uname -s` = FreeBSD;
+then
+  CPPFLAGS="$CPPFLAGS -I/usr/local/include"
+  LDFLAGS="$LDFLAGS -L/usr/local/lib"
+fi
+
 foundit=no
 if test $foundit == "no";
 then
@@ -122,22 +131,39 @@
     exit -1
 fi
 
+dnl FreeBSD has libtcl8X.so, not libtcl8.X.so
+
 AC_CHECK_LIB(tcl8.7, main,,
+AC_CHECK_LIB(tcl87, main,,
     AC_CHECK_LIB(tcl8.6, main,,
+  AC_CHECK_LIB(tcl86, main,,
 	AC_CHECK_LIB(tcl8.5, main,,
+    AC_CHECK_LIB(tcl85, main,,
 	    AC_CHECK_LIB(tcl8.4, main,,
+      AC_CHECK_LIB(tcl84, main,,
 		AC_CHECK_LIB(tcl8.3, main,,
+        AC_CHECK_LIB(tcl83, main,,
 		    AC_CHECK_LIB(tcl8.2, main,,
-        		AC_CHECK_LIB(tcl8.0, main,,echo no tcl library found || exit 1)))))))
+          AC_CHECK_LIB(tcl82, main,,
+            AC_CHECK_LIB(tcl8.0, main,,
+            AC_CHECK_LIB(tcl80, main,,echo no tcl library found || exit 1))))))))))))))
+
+dnl FreeBSD has libtk8X.so, not libtk8.X.so
 
 AC_CHECK_LIB(tk8.7, main,,
+AC_CHECK_LIB(tk87, main,,
     AC_CHECK_LIB(tk8.6, main,,
+  AC_CHECK_LIB(tk86, main,,
 	AC_CHECK_LIB(tk8.5, main,,
+    AC_CHECK_LIB(tk85, main,,
 	    AC_CHECK_LIB(tk8.4, main,,
+      AC_CHECK_LIB(tk84, main,,
 		AC_CHECK_LIB(tk8.3, main,,
+        AC_CHECK_LIB(tk83, main,,
 		    AC_CHECK_LIB(tk8.2, main,,
-        		AC_CHECK_LIB(tk8.0, main,,echo no tk library found || exit 1)))))))
-
+          AC_CHECK_LIB(tk82, main,,
+            AC_CHECK_LIB(tk8.0, main,,
+            AC_CHECK_LIB(tk80, main,, echo no tk library found || exit 1))))))))))))))
 
 if test `uname -s` = Linux;
 then
@@ -322,6 +348,38 @@
     then
         LDFLAGS=$LDFLAGS" -weak_framework Jack"
     fi
+fi
+
+if test `uname -s` = FreeBSD;
+then
+    EXT=pd_freebsd
+    MORECFLAGS="-DPA_USE_OSS -DPA_LITTLE_ENDIAN -DUNIX -DUNISTD\
+      -DUSEAPI_OSS \
+        -I../portaudio/pa_common \
+        -I../portaudio/pablio -I../portaudio/portmidi-macosx \
+        -Werror -fno-strict-aliasing"
+    SYSSRC="s_audio_oss.c"
+    if test x$portaudio == "xyes";
+    then
+     MORECFLAGS="-DUSEAPI_PORTAUDIO "$MORECFLAGS
+ SYSSRC="s_audio_pa.c \
+ ../portaudio/pa_common/pa_allocation.c  \
+ ../portaudio/pa_common/pa_converters.c  \
+ ../portaudio/pa_common/pa_cpuload.c     \
+ ../portaudio/pa_common/pa_dither.c      \
+ ../portaudio/pa_common/pa_front.c       \
+ ../portaudio/pa_common/pa_process.c     \
+ ../portaudio/pa_common/pa_skeleton.c    \
+ ../portaudio/pa_common/pa_stream.c      \
+ ../portaudio/pa_common/pa_trace.c       \
+ ../portaudio/pablio/pablio_pd.c         \
+ ../portaudio/pablio/ringbuffer_pd.c     \
+ ../portaudio/pa_unix/pa_unix_hostapis.c \
+ ../portaudio/pa_unix/pa_unix_util.c     \
+ ../portaudio/pa_unix_oss/pa_unix_oss.c "$SYSSRC
+    fi
+    GUINAME="pd-gui"
+    OSNUMBER=0
 fi
 
 # support for jack, on either linux or darwin:
--- d_osc.c.orig	Thu Jun  1 12:42:15 2006
+++ d_osc.c	Thu Jun  1 12:48:12 2006
@@ -30,6 +30,11 @@
 #include <machine/endian.h>
 #endif
 
+#if defined(__FreeBSD__)
+#define __BYTE_ORDER _BYTE_ORDER
+#define __LITTLE_ENDIAN _LITTLE_ENDIAN
+#endif
+
 #ifdef __APPLE__
 #define __BYTE_ORDER BYTE_ORDER
 #define __LITTLE_ENDIAN LITTLE_ENDIAN
--- s_audio_oss.c.orig	Thu Jun  1 12:22:20 2006
+++ s_audio_oss.c	Thu Jun  1 12:49:23 2006
@@ -5,7 +5,12 @@
 
 /* this file inputs and outputs audio using the OSS API available on linux. */
 
+/* OSS != Linux */
+#if defined(__FreeBSD__)
+#include <sys/soundcard.h>
+#else
 #include <linux/soundcard.h>
+#endif
 
 #include "m_pd.h"
 #include "s_stuff.h"
--- s_stuff.h.orig	Thu Jun  1 12:26:28 2006
+++ s_stuff.h	Thu Jun  1 12:49:56 2006
@@ -174,6 +174,10 @@
 #define API_DEFAULT API_OSS
 #define API_DEFSTRING "OSS"
 #endif
+#ifdef __FreeBSD__
+#define API_DEFAULT API_OSS
+#define API_DEFSTRING "OSS"
+#endif
 #ifdef MSW
 #define API_DEFAULT API_MMIO
 #define API_DEFSTRING "MMIO"
--- x_list.c.orig	Thu Jun  1 12:40:36 2006
+++ x_list.c	Thu Jun  1 12:51:26 2006
@@ -4,10 +4,16 @@
 
 #include "m_pd.h"
 /* #include <string.h> */
+
 #ifdef MSW
 #include <malloc.h>
 #else
+/* stuff in malloc.h and alloca.h is in stdlib.h on FreeBSD */
+#if defined(__FreeBSD__)
+#include <stdlib.h>
+#else
 #include <alloca.h>
+#endif
 #endif
 
 extern t_pd *newest;
