--- SConstruct.orig	2011-05-17 20:59:50.000000000 -0700
+++ SConstruct	2011-05-17 23:54:27.000000000 -0700
@@ -123,9 +123,9 @@
 # sources = [s for s in sources if not "/fst" in s]
 
 ### SDL (include if it's there in case iulib needs it)
-
-if conf.CheckLibWithHeader('SDL', 'SDL/SDL.h', 'C'):
-    if conf.CheckLibWithHeader('SDL_gfx', 'SDL/SDL_gfxPrimitives.h', 'C'):
+#Jason C. avoid SDL_main problem
+if conf.CheckCXXHeader("SDL/SDL.h"):
+    if conf.CheckCXXHeader('SDL/SDL_gfxPrimitives.h'):
         env.Append(LIBS=["SDL","SDL_gfx"])
 
 ### Leptonica
@@ -175,6 +175,7 @@
 
 env.Prepend(CPPPATH=glob("ocr-*"))
 env.Prepend(LIBPATH=['.'])
+env.Append(SHLINKFLAGS = '-dynamiclib -install_name "@@PREFIX@@/lib/libocropus.dylib"')
 # libocropus = env.StaticLibrary('libocropus.a',sources)
 libocropus = env.SharedLibrary('libocropus',sources)
 # env.Prepend(LIBS=[File("libocropus.so")])
@@ -204,12 +205,10 @@
 ################################################################
 
 penv = env.Clone()
-penv.Append(LIBS=[File("libocropus.so")])
-penv.Append(CCFLAGS=["-Xlinker","-rpath=${iulib}/lib"])
-penv.Append(LINKFLAGS=["-Xlinker","-rpath=${iulib}/lib"])
+penv.Append(LIBS=[File(libocropus)])
 
 for cmd in glob("commands/*.cc"): 
-    penv.Program(cmd,LIBS=File("libocropus.so"))
+    penv.Program(cmd,LIBS=File(libocropus))
     penv.Install(destdir+bindir,re.sub('.cc$','',cmd))
 
 ################################################################
@@ -221,7 +220,7 @@
     test_builder = Builder(action='$SOURCE && touch $TARGET',
         suffix = '.passed',
         src_suffix = '')
-    env.Append(BUILDERS={'Test':test_builder})
+    penv.Append(BUILDERS={'Test':test_builder})
     for cmd in Glob("*/test-*.cc")+Glob("*/test*/test-*.cc"):
         cmd = str(cmd)
         penv.Program(cmd)
