From f504e95c0338865afcbf389940a6c67009805060 Mon Sep 17 00:00:00 2001
From: Diane Bruce <db@db.net>
Date: Tue, 10 Jan 2006 02:43:23 +0000
Subject: [PATCH] - ok, this should enable Bobs portaudio fixes and ALSA
 depending on   --enable options.

This will have to be cleaned up a lot more to minimise #ifdef's
a2d_() is needed for portaudio which is needed by both windows and *nix
but only a small piece of start_threads.c is needed for portaudio
the ALSA part is #ifdef'd out when USE_PORTAUDIO is enabled.
audio_init.f90 and a2d.f90 now have #ifdef's on USE_PORTAUDIO
instead of Win32.

Lots to do still.



git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/trunk@73 ab8295b8-cf94-4d9e-aec4-7959e3be5d79
---
 Makefile.in     | 14 ++++++++++----
 a2d.f90         |  3 ++-
 audio_init.f90  |  4 +++-
 configure       | 27 ++++++++++++++-------------
 configure.ac    | 23 +++++++++++++----------
 start_threads.c | 23 ++++++++++-------------
 6 files changed, 52 insertions(+), 42 deletions(-)

diff --git a/Makefile.in b/Makefile.in
index a4e405a52..d20f43885 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -3,6 +3,7 @@ FC ?= @F77@
 FFLAGS	= @FFLAGS@
 LDFLAGS	= @LDFLAGS@
 CPPFLAGS = @CPPFLAGS@
+CFLAGS	= @CFLAGS@
 #
 # WSJT specific Fortran flags
 FFLAGS += -Wall -fbounds-check
@@ -12,7 +13,7 @@ G95=@G95@
 COMPILER=@G95_LIB_PATH@
 
 LDFLAGS	+= -L${COMPILER}
-LDFLAGS	+= -lpthread -lg2c
+LDFLAGS	+= -lg2c
 
 PYTHON	?= @PYTHON@
 RM	?= @RM@
@@ -35,14 +36,19 @@ SRCS2F90 = a2d.f90 abc441.f90 astro0.f90 audio_init.f90 azdist0.f90 \
 	wsjtgen.f90 runqqq.f90 fivehz.f90
 SRCS2F77	= wsjt1.f fsubs1.f fsubs.f astro.f astropak.f
 #
-# ok, so far for Windows @AUDIO@ will be jtaudio.c since it uses portaudio
-#            for *nix @AUDIO@ will also be jtaudio.c for portaudio
+# ok, so far for now
+# Windows @AUDIO@ will be jtaudio.c since it uses portaudio
+#            for *nix @AUDIO@ will also be jtaudio.c and start_threads.c 
+#		for portaudio
 #            for *nix @AUDIO@ will be start_threads.c for alsa
 #            for *nix @AUDIO@ will be ?? for oss
 #
 # ptt_unix.c vs. ptt.c I'll sort out later. 
 # ditto for cutil.c (only used on *nix)
 # --db
+# jtaudio.c/start_threads.c mess will have to be sorted out later
+# to minimise #ifdef's 
+# --db
 #
 SRCS2C	= ptt_unix.c igray.c wrapkarn.c cutil.c
 SRCS2C	+=  @AUDIO@
@@ -56,7 +62,7 @@ wsjt6:	Audio.so #wsjt.spec
 #	${RM} wsjt6
 
 Audio.so: $(OBJS2C)
-	 ${PYTHON} ${F2PY_PY} -c --verbose --opt="-O -cpp -D${OS} \
+	 ${PYTHON} ${F2PY_PY} -c --verbose --opt="-O -cpp -D${CFLAGS} \
 	-fno-second-underscore"	$(OBJS2C) -m Audio \
 	--f77exec=${G95} --f90exec=${G95} ${CPPFLAGS} ${LDFLAGS} \
 	only: $(F2PYONLY) \
diff --git a/a2d.f90 b/a2d.f90
index 8ee572251..71809c42e 100644
--- a/a2d.f90
+++ b/a2d.f90
@@ -1,7 +1,8 @@
 !---------------------------------------------------- a2d
 subroutine a2d(iarg)
 
-#ifdef Win32
+#if 1
+!--- # ifdef USE_PORTAUDIO
 ! Start the PortAudio streams for audio input and output.
   integer nchin(0:20),nchout(0:20)
   include 'gcom1.f90'
diff --git a/audio_init.f90 b/audio_init.f90
index 2b1915481..1cbe3207c 100644
--- a/audio_init.f90
+++ b/audio_init.f90
@@ -5,8 +5,10 @@ subroutine audio_init(ndin,ndout)
 #ifdef Win32
   use dfmt
   integer Thread1,Thread2
-  external a2d,decode1
 #endif
+#ifdef USE_PORTAUDIO
+  external a2d,decode1
+#endif
 
   integer*2 a(225000)           !Pixel values for 750 x 300 array
   integer brightness,contrast
diff --git a/configure b/configure
index e6392354d..8e24295c4 100755
--- a/configure
+++ b/configure
@@ -2,7 +2,7 @@
 # Guess values for system-dependent variables and create Makefiles.
 # Generated by GNU Autoconf 2.53 for wsjt 0.9.
 #
-# $Id: configure.ac 70 2006-01-09 21:30:35Z va3db $
+# $Id: configure.ac 71 2006-01-09 21:35:25Z va3db $
 #
 # Copyright 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002
 # Free Software Foundation, Inc.
@@ -924,7 +924,7 @@ Free Software Foundation, Inc.
 This configure script is free software; the Free Software Foundation
 gives unlimited permission to copy, distribute and modify it.
 
-$Id: configure.ac 70 2006-01-09 21:30:35Z va3db $
+$Id: configure.ac 71 2006-01-09 21:35:25Z va3db $
 _ACEOF
   exit 0
 fi
@@ -2198,7 +2198,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu
 CFLAGS="$OLD_CFLAGS"
 
 CPPFLAGS="-I/usr/local/include -I/usr/include/alsa ${CPPFLAGS}"
-LDFLAGS="-L/usr/local/lib ${LDFLAGS}"
+LDFLAGS="-L/usr/local/lib -lpthread ${LDFLAGS}"
 
 echo "$as_me:$LINENO: checking uname -s for Cygwin, Solaris or HPUX" >&5
 echo $ECHO_N "checking uname -s for Cygwin, Solaris or HPUX... $ECHO_C" >&6
@@ -2236,15 +2236,15 @@ echo $ECHO_N "checking if $CC is Apple GCC... $ECHO_C" >&6
 	echo "$as_me:$LINENO: result: $AppleGCC" >&5
 echo "${ECHO_T}$AppleGCC" >&6
 
-	WSJT_CFLAGS="$WSJT_CFLAGS -Wall -O0"
+	CFLAGS="$CFLAGS -Wall -O0"
 fi
 
 if test "$ac_cv_prog_cc_g" = yes; then
-		WSJT_CFLAGS="$WSJT_CFLAGS -g"
+		CFLAGS="$CFLAGS -g"
 fi
 
 if test ! -z "$CFLAGS"; then
-	WSJT_CFLAGS="$WSJT_CFLAGS $CFLAGS"
+	CFLAGS="$CFLAGS $CFLAGS"
 fi
 
 
@@ -5556,11 +5556,10 @@ _ACEOF
 fi
 
 
-
 if test "$prefix" = "NONE"; then
 
 cat >>confdefs.h <<_ACEOF
-#define WSJT_PREFIX "$ac_default_prefix"
+#define PREFIX "$ac_default_prefix"
 _ACEOF
 
 
@@ -5570,7 +5569,7 @@ else
 	prefix=`echo $prefix | sed 's/\/$//'`
 
 cat >>confdefs.h <<_ACEOF
-#define WSJT_PREFIX "$prefix"
+#define PREFIX "$prefix"
 _ACEOF
 
 
@@ -5614,7 +5613,7 @@ _ACEOF
 
 	AUDIO="start_threads.c"
 
-	LDFLAGS="${LDFLAGS} -lpthreads -lasound"
+	LDFLAGS="${LDFLAGS} -lpthread -lasound"
 fi
 
 if test "$oss" = yes; then
@@ -5633,9 +5632,11 @@ cat >>confdefs.h <<\_ACEOF
 #define USE_PORTAUDIO 1
 _ACEOF
 
-	AUDIO="jtaudio.c"
+	AUDIO="jtaudio.c start_threads.c"
 
-	LDFLAGS="${LDFLAGS} -lpthreads -lportaudio"
+	LDFLAGS="${LDFLAGS} -lportaudio"
+	CFLAGS="${CFLAGS} -DUSE_PORTAUDIO"
+	CPPFLAGS="${CPPFLAGS} -DUSE_PORTAUDIO"
 fi
 
 
@@ -5689,6 +5690,7 @@ CPPFLAGS="${CPPFLAGS}"
 LDFLAGS="${LDFLAGS}"
 
 
+
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
 # tests run on this system so they can be shared between configure
@@ -6272,7 +6274,6 @@ s,@G95@,$G95,;t t
 s,@G95_LIB_PATH@,$G95_LIB_PATH,;t t
 s,@OS@,$OS,;t t
 s,@CLOBBER@,$CLOBBER,;t t
-s,@WSJT_CFLAGS@,$WSJT_CFLAGS,;t t
 s,@AUDIO@,$AUDIO,;t t
 CEOF
 
diff --git a/configure.ac b/configure.ac
index e513ce912..568570029 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,7 +24,7 @@ CFLAGS="$OLD_CFLAGS"
 
 dnl Lets guess at some likely places for extra libs/includes XXX -db
 CPPFLAGS="-I/usr/local/include -I/usr/include/alsa ${CPPFLAGS}"
-LDFLAGS="-L/usr/local/lib ${LDFLAGS}"
+LDFLAGS="-L/usr/local/lib -lpthread ${LDFLAGS}"
 
 AC_MSG_CHECKING([uname -s for Cygwin, Solaris or HPUX])
 case `uname -s` in
@@ -52,19 +52,19 @@ if test "$ac_cv_c_compiler_gnu" = yes; then
 
 	AC_MSG_RESULT($AppleGCC)
 
-	WSJT_CFLAGS="$WSJT_CFLAGS -Wall -O0"
+	CFLAGS="$CFLAGS -Wall -O0"
 fi
 
 dnl If we support -g, use it!
 if test "$ac_cv_prog_cc_g" = yes; then
-		WSJT_CFLAGS="$WSJT_CFLAGS -g"
+		CFLAGS="$CFLAGS -g"
 fi
 
 dnl jdc -- If CFLAGS is defined, best use it everywhere...
 dnl NOTE: jv says it must be added to the *END*, because things like
 dnl "gcc -O9 -O2" will result in -O2 getting preference.  How stupid.
 if test ! -z "$CFLAGS"; then
-	WSJT_CFLAGS="$WSJT_CFLAGS $CFLAGS"
+	CFLAGS="$CFLAGS $CFLAGS"
 fi
 
 
@@ -177,10 +177,9 @@ if test "$assert" = no; then
 	AC_DEFINE(NDEBUG, 1, [Define this to disable debugging support.])
 fi
 
-AC_SUBST(WSJT_CFLAGS)
 
 if test "$prefix" = "NONE"; then 
-	AC_DEFINE_UNQUOTED(WSJT_PREFIX, "$ac_default_prefix", [Prefix where wsjt is installed.])
+	AC_DEFINE_UNQUOTED(PREFIX, "$ac_default_prefix", [Prefix where wsjt is installed.])
 
 else
 
@@ -188,7 +187,7 @@ dnl Don't get bitten by Cygwin's stupidity if the user specified
 dnl a custom prefix with a trailing slash
 
 	prefix=`echo $prefix | sed 's/\/$//'`
-	AC_DEFINE_UNQUOTED(WSJT_PREFIX, "$prefix", [Prefix where wsjt is installed.])
+	AC_DEFINE_UNQUOTED(PREFIX, "$prefix", [Prefix where wsjt is installed.])
 	
 fi
 
@@ -220,7 +219,7 @@ AC_HELP_STRING([--enable-portaudio],[Force PORTAUDIO SOUND usage.]),
 if test "$alsa" = yes; then
 	AC_DEFINE(USE_ALSA, 1, [Define if you want ALSA used.])
 	AC_SUBST(AUDIO, "start_threads.c")
-	LDFLAGS="${LDFLAGS} -lpthreads -lasound"
+	LDFLAGS="${LDFLAGS} -lpthread -lasound"
 fi
 
 if test "$oss" = yes; then
@@ -228,10 +227,13 @@ if test "$oss" = yes; then
 	AC_SUBST(AUDIO, "jtaudio.c")
 fi
 
+dnl XXX
 if test "$portaudio" = yes; then
 	AC_DEFINE(USE_PORTAUDIO, 1, [Define if you want PORTAUDIO used.])
-	AC_SUBST(AUDIO, "jtaudio.c")
-	LDFLAGS="${LDFLAGS} -lpthreads -lportaudio"
+	AC_SUBST(AUDIO, "jtaudio.c start_threads.c")
+	LDFLAGS="${LDFLAGS} -lportaudio"
+	CFLAGS="${CFLAGS} -DUSE_PORTAUDIO"
+	CPPFLAGS="${CPPFLAGS} -DUSE_PORTAUDIO"
 fi
 
 dnl set conf flags
@@ -270,6 +272,7 @@ fi
 dnl 
 AC_SUBST(CPPFLAGS, "${CPPFLAGS}")
 AC_SUBST(LDFLAGS, "${LDFLAGS}")
+AC_SUBST(CFLAGS)
 
 AC_OUTPUT
 
diff --git a/start_threads.c b/start_threads.c
index 7fb488e69..85d2d1cd3 100644
--- a/start_threads.c
+++ b/start_threads.c
@@ -3,21 +3,18 @@
 #include <pthread.h>
 #include "conf.h"
 
-/* 
- * XXX This should have been caught in the sanity tests in configure --db
- */
-#if defined(USE_ALSA) && !defined(HAS_ASOUNDLIB_H)
-#error "You must have alsa support to use alsa"
-#endif
-
-#if defined(USE_ALSA) && defined(HAS_ASOUNDLIB_H)
+#ifdef USE_ALSA
 #include <alsa/asoundlib.h>
 #endif
 
 #include <inttypes.h>
 #include <time.h>
 
-#if defined(USE_ALSA) && defined(HAS_ASOUNDLIB_H)
+#ifdef USE_PORTAUDIO
+extern a2d_();
+#endif
+
+#ifdef USE_ALSA
 
 #if 1
 #define ALSA_LOG
@@ -519,7 +516,7 @@ int start_threads_(int *ndevin, int *ndevout, short y1[], short y2[],
   int iarg1 = 1,iarg2 = 2;
   //int32_t rate=11025;
   int32_t rate=*nfsample;
-#if defined(USE_ALSA) && defined(HAS_ASOUNDLIB_H)
+#ifdef USE_ALSA
   alsa_driver_capture.app_buffer_y1 = y1;
   alsa_driver_capture.app_buffer_y2 = y2;
   alsa_driver_capture.app_buffer_offset = iwrite;
@@ -539,7 +536,7 @@ int start_threads_(int *ndevin, int *ndevout, short y1[], short y2[],
 #endif
   printf("start threads called\n");
   iret1 = pthread_create(&thread1,NULL,decode1_,&iarg1);
-#if defined(USE_ALSA) && defined(HAS_ASOUNDLIB_H)
+#ifdef USE_ALSA
 /* Open audio card. */
   ao_alsa_open(&alsa_driver_playback, &rate, SND_PCM_STREAM_PLAYBACK);
   ao_alsa_open(&alsa_driver_capture, &rate, SND_PCM_STREAM_CAPTURE);
@@ -552,8 +549,8 @@ int start_threads_(int *ndevin, int *ndevout, short y1[], short y2[],
   snd_pcm_start(alsa_driver_capture.audio_fd);
   snd_pcm_prepare(alsa_driver_playback.audio_fd);
   //snd_pcm_start(alsa_driver_playback.audio_fd);
-
+#else
  /* snd_pcm_start */
-  //iret2 = pthread_create(&thread2,NULL,a2d_,&iarg2);
+  iret2 = pthread_create(&thread2,NULL,a2d_,&iarg2);
 #endif
 }