--- configure.bak	2012-05-25 08:05:57.000000000 -0400
+++ configure	2019-09-04 09:45:37.921250000 -0400
@@ -493,7 +493,7 @@
         extralibs="$extralibs -lsocket -lnsl"
         ;;
 
-    FreeBSD)
+    FreeBSD|MidnightBSD)
         make="gmake"
         LDFLAGS="$LDFLAGS -export-dynamic"
         CFLAGS="$CFLAGS -pthread"
@@ -612,7 +612,7 @@
 
 #GCC opt
 if test "$no_gcc_opt" = "no"; then
-    CFLAGS="-O3 $CFLAGS"
+    CFLAGS=" $CFLAGS"
 else
     CFLAGS="-O0 $CFLAGS"
 fi
@@ -2123,9 +2123,9 @@
 echo "#define GPAC_CONFIGURATION \"$GPAC_CONFIGURATION\"" >> $TMPH
 
 version="`grep '#define GPAC_VERSION ' \"$source_path/include/gpac/tools.h\" | cut -d '"' -f 2`"
-version_major=`grep '#define GPAC_VERSION_MAJOR ' $source_path/include/gpac/tools.h | sed -e 's/.*\([0-9]\)\+$/\1/'`
-version_minor=`grep '#define GPAC_VERSION_MINOR ' $source_path/include/gpac/tools.h | sed -e 's/.*\([0-9]\)\+$/\1/'`
-version_micro=`grep '#define GPAC_VERSION_MICRO ' $source_path/include/gpac/tools.h | sed -e 's/.*\([0-9]\)\+$/\1/'`
+version_major=`grep '#define GPAC_VERSION_MAJOR ' $source_path/include/gpac/tools.h | sed -e 's/^[^0-9]*//'`
+version_minor=`grep '#define GPAC_VERSION_MINOR ' $source_path/include/gpac/tools.h | sed -e 's/^[^0-9]*//'`
+version_micro=`grep '#define GPAC_VERSION_MICRO ' $source_path/include/gpac/tools.h | sed -e 's/^[^0-9]*//'`
 soname_version="${version_major}.${version_minor}.${version_micro}"
 
 if [ -d ".svn" ]; then
