Index: trunk/indra/SConstruct
===================================================================
--- trunk.orig/indra/SConstruct	2008-01-23 12:00:25.000000000 +0000
+++ trunk/indra/SConstruct	2008-01-23 12:00:29.000000000 +0000
@@ -96,7 +96,8 @@
         allowed_values=('Release', 'Release Candidate', 'WindLight')),
     BoolOption('ELFIO', 'Enabled enhanced backtraces with libELFIO symbol extraction support', True),
     BoolOption('STANDALONE', 'Build using system packages (implies OPENSOURCE)', False),
-    BoolOption('OPENSOURCE', 'Build using only non-proprietary dependencies', True) # OPENSOURCE: do not edit this line
+    BoolOption('OPENSOURCE', 'Build using only non-proprietary dependencies', True), # OPENSOURCE: do not edit this line
+    BoolOption('OPENAL', 'Build using OpenAL Audio support', True)
 )
 optenv = Environment(options = opts)
 Help(opts.GenerateHelpText(optenv))
@@ -114,6 +115,7 @@
 opensource = standalone or optenv['OPENSOURCE']
 enable_fmod = not opensource and optenv['FMOD']
 elfio = optenv['ELFIO']
+enable_openal = opensource or optenv['OPENAL']
 
 targets = [ target_param ]
 
@@ -153,6 +155,13 @@
 if enable_gstreamer:
     standalone_pkgs.append( 'gstreamer-0.10' )
 
+if enable_gstreamer:
+    standalone_pkgs.append( 'gstreamer-0.10' )
+
+if enable_openal:
+    standalone_pkgs.append( 'openal' )
+    standalone_pkgs.append( 'freealut' )
+
 def pkgconfig(opt, pkgs=None):
     if pkgs is None:
         pkgs = standalone_pkgs + standalone_net_pkgs
@@ -251,6 +260,10 @@
     if standalone:
         cppflags += '-DLL_STANDALONE '
 
+    if enable_openal:
+    	cppflags += ' -DLL_OPENAL '
+
+
     if build_target == 'server':
         # Server flags
         cppflags += '-D_GNU_SOURCE -DLL_MESA_HEADLESS=1 -DLL_MESA=1 '
Index: trunk/indra/newview/llstartup.cpp
===================================================================
--- trunk.orig/indra/newview/llstartup.cpp	2008-01-23 12:00:25.000000000 +0000
+++ trunk/indra/newview/llstartup.cpp	2008-01-23 12:00:29.000000000 +0000
@@ -41,7 +41,15 @@
 
 #include "audioengine.h"
 
+ 
+#if LL_FMOD
+#include "audioengine_fmod.h"
+#endif
+ 
+#if LL_OPENAL
 #include "audioengine_openal.h"
+#endif
+
 
 #include "audiosettings.h"
 #include "llares.h"
@@ -599,9 +607,24 @@
 		// or audio cues in connection UI.
 		//-------------------------------------------------
 
-		if (gUseAudio)
-		{
-			gAudiop = (LLAudioEngine *) new LLAudioEngine_OpenAL();
+		// Audio engines FMOD and OpenAL are selectable at build time. If both are enabled then if FMOD fails OpenAL
+		// will be attempted next. FMOD can be disabled by setting the LL_BAD_ALSA/OSS/ESD environmental variables.
+		// OpenAL can be prevented from loading with LL_BAD_OPENAL.
+
+ 		if (gUseAudio)
+ 		{
+			gAudiop = NULL;
+#if LL_FMOD
+ 			gAudiop = (LLAudioEngine *) new LLAudioEngine_FMOD();
+ #endif
+ 
+#if LL_OPENAL
+			// FMOD not compiled or run time detected, try OpenAL
+			if(gAudiop==NULL)
+			{
+				gAudiop = (LLAudioEngine *) new LLAudioEngine_OpenAL();
+			}
+#endif	
 
 			if (gAudiop)
 			{
Index: trunk/indra/llaudio/listener_openal.cpp
===================================================================
--- trunk.orig/indra/llaudio/listener_openal.cpp	2008-01-23 12:00:25.000000000 +0000
+++ trunk/indra/llaudio/listener_openal.cpp	2008-01-23 12:00:29.000000000 +0000
@@ -1,6 +1,8 @@
 #include "linden_common.h"
 #include "audioengine.h"
 
+#if LL_OPENAL
+
 #include "listener_openal.h"
 
 LLListener_OpenAL::LLListener_OpenAL(){
@@ -63,3 +65,5 @@
 	llinfos << "LLListener_OpenAL::getDopplerFactor() : " << factor << llendl;
 	return factor;
 }
+
+#endif #LL_OPENAL
Index: trunk/indra/llaudio/audioengine_openal.h
===================================================================
--- trunk.orig/indra/llaudio/audioengine_openal.h	2008-01-23 12:00:25.000000000 +0000
+++ trunk/indra/llaudio/audioengine_openal.h	2008-01-23 12:00:29.000000000 +0000
@@ -1,6 +1,8 @@
 #ifndef LL_AUDIOENGINE_OpenAL_H
 #define LL_AUDIOENGINE_OpenAL_H
 
+#ifdef LL_OPENAL
+
 #include <string>
 
 #include "audioengine.h"
@@ -80,3 +82,7 @@
 
 #endif
 
+#endif
+
+
+
Index: trunk/indra/llaudio/audioengine_openal.cpp
===================================================================
--- trunk.orig/indra/llaudio/audioengine_openal.cpp	2008-01-23 12:13:43.000000000 +0000
+++ trunk/indra/llaudio/audioengine_openal.cpp	2008-01-23 13:30:47.000000000 +0000
@@ -1,5 +1,7 @@
 #include "linden_common.h"
 
+#if LL_OPENAL
+
 #include "audioengine_openal.h"
 #include "listener_openal.h"
 
@@ -24,6 +26,12 @@
 BOOL LLAudioEngine_OpenAL::init(const S32 num_channels, void* userdata){
 	LLAudioEngine::init(num_channels, userdata);
 
+	if (NULL != getenv("LL_BAD_OPENAL")) /*Flawfinder: ignore*/
+	{
+		llwarns << "LLAudioEngine_OpenAL::init() Not stating openAL due to LL_BAD_OPENAL environmental variable set. "<< llendl;
+		return FALSE;
+	}
+
 	if(!alutInit(NULL, NULL)){
 		llwarns << "LLAudioEngine_OpenAL::init() ALUT initialization failed: " << alutGetErrorString (alutGetError ()) << llendl;
 		return FALSE;
@@ -276,4 +284,4 @@
 	return mInternetStreamURL.c_str();
 }
 
-
+#endif // #LL_OPENAL
