Allow CC, CXX, and CFLAGS to be specified.

Add linking with boost_system and fix linking with boost_date_time.
https://savannah.nongnu.org/bugs/?39593

Look for dependencies in PATH.

Do not add Fink library and include paths.

Fix finding fribidi.

Do not remove duplicate flags when calling env.ParseConfig, as that turns the
"-arch x86_64 -arch i386" we pass when building universal into
"x86_64 -arch i386" resulting in "error: no such file or directory: 'x86_64'".

Exit after building the bundle, before building the dmg and rebuilding sources.
--- SConstruct.orig	2009-08-30 14:23:30.000000000 -0500
+++ SConstruct	2018-10-18 00:39:21.000000000 -0500
@@ -14,6 +14,9 @@
 
 def establish_options(env):
     opts = Options('options_cache.py')
+    opts.Add("CC", "Manually set the C compiler", "cc")
+    opts.Add("CXX", "Manually set the C++ compiler", "c++")
+    opts.Add("CFLAGS", "Manually add to the CFLAGS", "-g")
     opts.Add("CXXFLAGS", "Manually add to the CXXFLAGS", "-g")
     opts.Add("LINKFLAGS", "Manually add to the LINKFLAGS", "-g")
     if isDarwinPlatform:
@@ -120,13 +123,23 @@
         missing.append("libboost_thread")
     env.Append(LIBS=[boost_thread])
 
+    boost_system = ''
+    if conf.CheckLib("boost_system"):
+        boost_system="boost_system"
+    elif conf.CheckLib("boost_system-mt"):
+        boost_system="boost_system-mt"
+    else:
+        print "Could not find libboost_system or libboost_system-mt"
+        missing.append("libboost_system")
+    env.Append(LIBS=[boost_system])
+
     boost_date_time = ''
     if conf.CheckLib("boost_date_time") and conf.CheckCXXHeader("boost/date_time/posix_time/posix_time.hpp"):
-        boost_thread="boost_thread"
+        boost_date_time="boost_date_time"
     elif conf.CheckLib("boost_date_time-mt") and conf.CheckCXXHeader("boost/date_time/posix_time/posix_time.hpp"):
-        boost_thread="boost_thread-mt"
+        boost_date_time="boost_date_time-mt"
     else:
-        print "Could not find libboost_date_time or libboost_date_time-mt or boost/thread/thread.hpp"
+        print "Could not find libboost_date_time or libboost_date_time-mt or boost/date_time/posix_time/posix_time.hpp"
         missing.append("libboost_date_time")
     env.Append(LIBS=[boost_date_time])
 
@@ -225,7 +238,7 @@
               action='store',
               metavar='portaudio',
               help='should portaudio be used')
-    env = Environment()
+    env = Environment(ENV = {'PATH' : os.environ['PATH']})
     try:
         env.Clone()
     except AttributeError:
@@ -241,11 +254,10 @@
     if env['mingw'] or isWindowsPlatform:
         env.Append(LIBPATH=["C:/msys/1.0/local/lib", "C:/msys/1.0/lib"])
         env.Append(CPPPATH=["C:/msys/1.0/local/include/SDL", "C:/msys/1.0/local/include", "C:/msys/1.0/include/SDL", "C:/msys/1.0/include"])
-    if isDarwinPlatform:
-        env.Append(LIBPATH=["/sw/lib"])
-        env.Append(CPPPATH=["/sw/include"])
-    configure(env)
     env.Append(CPPPATH=['#libgag/include', '#'])
+    env.ParseConfig("pkg-config fribidi --cflags", None, False)
+    env.ParseConfig("pkg-config fribidi --libs", None, False)
+    configure(env)
     if env['release']:
         env.Append(CXXFLAGS=' -O2')
         env.Append(LINKFLAGS=' -O2')
@@ -261,8 +273,8 @@
         env.Append(CPPPATH=['/usr/local/include/SDL'])
         env.Append(CPPDEFINES=['-D_GNU_SOURCE=1', '-Dmain=SDL_main'])
     else:
-        env.ParseConfig("sdl-config --cflags")
-        env.ParseConfig("sdl-config --libs")
+        env.ParseConfig("sdl-config --cflags", None, False)
+        env.ParseConfig("sdl-config --libs", None, False)
     env.Append(LIBS=['vorbisfile', 'SDL_ttf', 'SDL_image', 'SDL_net', 'speex'])
 
     env["TARFILE"] = env.Dir("#").abspath + "/glob2-" + env["VERSION"] + ".tar.gz"
@@ -296,6 +307,7 @@
             BUNDLE_PLIST="darwin/Info.plist",
             BUNDLE_ICON="darwin/Glob2.icns" )
         bundle.createBundle(os.getcwd(), os.getcwd(), env)
+        Exit(0)
         dmg.create_dmg("Glob2-%s"%env["VERSION"],"%s.app"%env["BUNDLE_NAME"],env)
 
         #TODO mac_bundle should be dependency of Dmg:
