$NetBSD: patch-configure,v 1.5 2022/12/14 13:54:19 tsutsui Exp $

o Handle properly sh3, evbarm, arm64, and m68k ports on NetBSD.
o Fix CPU family detection on NetBSD with /proc mounted with "-o linux"
  (please see also kern/25076).
o Delete not needed -Iffmpeg from the CFLAGS.
o Fix a bug which broke the detection of a lot of X11 libraries.
o Add necessary libs for aalib support even if the aa option is turned on with
  --enable-aa.
o Add support for dvb capture on NetBSD.
o Explicitly enable PIE to avoid text relocations on NetBSD/i386 8.x
o use /dev/audio instead of /dev/sound for OSS audio device for NetBSD
  (see PR/54229) and OpenBSD (no /dev/sound since 6.1)

--- configure.orig	2022-02-27 09:09:00.000000000 +0000
+++ configure
@@ -1768,7 +1768,7 @@ else
       cc_name=$cc_name_tmp
       echocheck "$_cc version"
       cc_vendor=gnu
-      cc_version=$($_cc -dumpversion 2>&1)
+      cc_version=$( ( $_cc -dumpversion | sed -e 's/-nb[0-9]//' ) 2>&1 )
       case $cc_version in
         2.96*)
           cc_fail=yes
@@ -1845,13 +1845,19 @@ if test -z "$_target" ; then
       sun4*|sparc*) host_arch=sparc ;;
       parisc*|hppa*|9000*) host_arch=hppa ;;
       aarch64*|ARM64) host_arch=aarch64 ;;
-      arm*|zaurus|cats) host_arch=arm ;;
-      sh3|sh4|sh4a) host_arch=sh ;;
+      arm*|zaurus|cats|evbarm)
+        case "$(uname -p 2>&1)" in
+          aarch64*) host_arch=aarch64 ;;
+          *) host_arch=arm ;;
+        esac ;;
+      sh3*) host_arch=sh ;;
+      sh4|sh4a) host_arch=sh4 ;;
       s390) host_arch=s390 ;;
       s390x) host_arch=s390x ;;
       *mips*) host_arch=mips ;;
       nios2) host_arch=nios2 ;;
       vax) host_arch=vax ;;
+      m68k) host_arch=m68k ;;
       xtensa*) host_arch=xtensa ;;
       *) host_arch=UNKNOWN ;;
   esac
@@ -2068,7 +2074,7 @@ if x86 ; then
   # gather more CPU information
   pname=$($_cpuinfo | grep 'model name' | cut -d ':' -f 2 | head -n 1)
   pvendor=$($_cpuinfo | grep 'vendor_id' | cut -d ':' -f 2  | cut -d ' ' -f 2 | head -n 1)
-  pfamily=$($_cpuinfo | grep 'cpu family' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -n 1)
+  pfamily=$($_cpuinfo | grep -i 'cpu family' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -n 1)
   pmodel=$($_cpuinfo | grep -v 'model name' | grep 'model' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -n 1)
   pstepping=$($_cpuinfo | grep 'stepping' | cut -d ':' -f 2 | cut -d ' ' -f 2 | head -n 1)
 
@@ -2585,7 +2591,12 @@ case "$host_arch" in
     test $_fast_clz = "auto" && _fast_clz=yes
     ;;
 
-  sh|sh4)
+  sh)
+    arch='sh'
+    iproc='sh'
+    ;;
+
+  sh4)
     arch='sh4'
     iproc='sh4'
     ;;
@@ -2823,6 +2834,11 @@ EOF
     iproc='vax'
     ;;
 
+  m68k)
+    arch='m68k'
+    iproc='m68k'
+    ;;
+
   xtensa)
     arch='xtensa'
     iproc='xtensa'
@@ -2949,23 +2965,23 @@ else
 fi
 if test -z "$CFLAGS" || test "$_profile" != "" || test "$_debug" != ""; then
   if test "$cc_vendor" = "intel" ; then
-    CFLAGS="-O2 $_march $_mcpu $_pipe -fomit-frame-pointer"
+    CFLAGS="$CFLAGS $_march $_mcpu $_pipe -fomit-frame-pointer"
     WARNFLAGS="-wd167 -wd556 -wd144"
   elif test "$cc_vendor" = "sun" ; then
-    CFLAGS="-O2 $_march $_mcpu $_pipe -xc99 -xregs=frameptr"
+    CFLAGS="$CFLAGS $_march $_mcpu $_pipe -xc99 -xregs=frameptr"
   elif test "$cc_vendor" = "clang"; then
-    CFLAGS="-O2 $_march $_pipe"
+    CFLAGS="$CFLAGS $_march $_pipe"
   elif test "$cc_vendor" != "gnu" ; then
-    CFLAGS="-O2 $_march $_mcpu $_pipe"
+    CFLAGS="$CFLAGS $_march $_mcpu $_pipe"
   else
-    CFLAGS="-O4 $_march $_mcpu $_pipe -ffast-math -fomit-frame-pointer"
+    CFLAGS="$CFLAGS $_march $_mcpu $_pipe -ffast-math -fomit-frame-pointer"
     WARNFLAGS="-Wall -Wno-switch -Wno-parentheses -Wpointer-arith -Wredundant-decls -Werror=format-security"
     WARN_CFLAGS="-Werror-implicit-function-declaration"
     extra_ldflags="$extra_ldflags -ffast-math"
   fi
 
   if test "$_profile" != "" || test "$_debug" != ""; then
-    CFLAGS="-O2 $_march $_mcpu $_pipe $_debug $_profile"
+    CFLAGS="$CFLAGS $_march $_mcpu $_pipe $_debug $_profile"
     WARNFLAGS="-W -Wall $WARNFLAGS"
     _install_strip=
   fi
@@ -2973,8 +2989,8 @@ else
   warn_cflags=yes
 fi
 
-CFLAGS="-D_ISOC99_SOURCE -I. -Iffmpeg $CFLAGS"
-HOSTCFLAGS="-D_ISOC99_SOURCE -I. -Iffmpeg -O3"
+CFLAGS="-D_ISOC99_SOURCE -I. $CFLAGS"
+HOSTCFLAGS="-D_ISOC99_SOURCE -I. -O3"
 
 # On glibc, add some more CPPFLAGS for enabling required functionality.
 cpp_condition_check features.h "defined __GLIBC__" &&
@@ -3030,10 +3046,11 @@ if test $relocatable = "auto" ; then
   elif win32 && ! wine ; then
     relocatable=no
     res_comment="unnecessary and broken on win32"
-  elif x86_32 && cflag_check -pie ; then
+  elif x86_32 && cflag_check -fpie -pie ; then
     extra_ldflags="$extra_ldflags -pie"
+    extra_cflags="$extra_cflags -fpic -fpie"
     relocatable=yes
-    res_comment="non-PIC"
+    res_comment="fast PIC"
   elif x86_64 && cflag_check -fpie -pie ; then
     extra_ldflags="$extra_ldflags -fpie -pie"
     extra_cflags="$extra_cflags -fpie"
@@ -4951,7 +4968,11 @@ if test "$_x11" = auto && test "$_x11_he
            -L/usr/X11/lib -L/usr/lib32 -L/usr/openwin/lib -L/usr/local/lib64 -L/usr/X11R6/lib64 \
            -L/usr/lib ; do
     if netbsd; then
-      ld_tmp="$I -lXext -lX11 $ld_pthread -Wl,-R$(echo $I | sed s/^-L//)"
+	  if test -n "$I" ; then
+        ld_tmp="$I -lXext -lX11 $ld_pthread -Wl,-R$(echo $I | sed s/^-L//)"
+	  else
+        ld_tmp="-lXext -lX11 $ld_pthread"
+	  fi
     else
       ld_tmp="$I -lXext -lX11 $ld_pthread"
     fi
@@ -5354,6 +5375,8 @@ if test "$_aa" = yes ; then
   def_aa='#define CONFIG_AA 1'
   if cygwin ; then
     libs_mplayer="$libs_mplayer $(aalib-config --libs | cut -d " " -f 2,5,6)"
+  else
+    libs_mplayer="$libs_mplayer $(aalib-config --libs)"
   fi
   vomodules="aa $vomodules"
 else
@@ -5441,7 +5464,6 @@ EOF
       extra_cflags="$extra_cflags $inc_tmp" && break
   done
 fi
-echores "$_dvb"
 if test "$_dvb" = yes ; then
   _dvbin=yes
   inputmodules="dvb $inputmodules"
@@ -5450,14 +5472,29 @@ if test "$_dvb" = yes ; then
   aomodules="mpegpes(dvb) $aomodules"
   vomodules="mpegpes(dvb) $vomodules"
 else
-  _dvbin=no
-  noinputmodules="dvb $noinputmodules"
-  def_dvb='#undef CONFIG_DVB'
-  def_dvbin='#undef CONFIG_DVBIN '
-  aomodules="mpegpes(file) $aomodules"
-  vomodules="mpegpes(file) $vomodules"
+  cat >$TMPC <<EOF
+#include <dev/dtv/dtvio.h>
+int main(void) {return 0;}
+EOF
+  cc_check && _dvb=yes
+  if test "$_dvb" = yes ; then
+    _dvbin=yes
+    inputmodules="dvb $inputmodules"
+    def_dvb='#undef CONFIG_DVB'
+    def_dvbin='#define CONFIG_DVBIN 1'
+    aomodules="mpegpes(file) $aomodules"
+    vomodules="mpegpes(file) $vomodules"
+  else
+    _dvbin=no
+    noinputmodules="dvb $noinputmodules"
+    def_dvb='#undef CONFIG_DVB'
+    def_dvbin='#undef CONFIG_DVBIN '
+    aomodules="mpegpes(file) $aomodules"
+    vomodules="mpegpes(file) $vomodules"
+  fi
 fi
 
+echores "$_dvb"
 
 if darwin; then
 
@@ -6117,7 +6154,7 @@ if test "$_ossaudio" = yes ; then
   if test "$_real_ossaudio" = yes; then
       def_ossaudio_devdsp='#define PATH_DEV_DSP "/dev/dsp"'
   elif netbsd ; then
-      def_ossaudio_devdsp='#define PATH_DEV_DSP "/dev/sound"'
+      def_ossaudio_devdsp='#define PATH_DEV_DSP "/dev/audio"'
       extra_ldflags="$extra_ldflags -lossaudio"
   else
       def_ossaudio_devdsp='#define PATH_DEV_DSP "/dev/dsp"'
