Index: trunk/config/sys/Darwin-g++.gmk
===================================================================
--- trunk/config/sys/Darwin-g++.gmk	(revision 874)
+++ trunk/config/sys/Darwin-g++.gmk	(revision 875)
@@ -3,8 +3,10 @@
 #                                 MacOS 10.3 gcc-3.3
 #                                 MacOS 10.4 gcc-4.0
+#                                 MacOS 10.5 gcc-4.0
 #
 # Original author: Helmut Burkhardt - CERN
 #       Revisions: Guy Barrand - LAL
 #                  Gabriele Cosmo - CERN
+#                  Laurent Garnier - LAL
 #
 ifeq ($(G4SYSTEM),Darwin-g++)
@@ -64,5 +66,5 @@
     OGLLIBS   := -L$(OGLHOME)/lib -lGLU -lGL
     ifeq ($(G4SYSTEM),Darwin-g++)
-          # It may be required to uncomment the following lines for building on MacOSX 10.5 "Leopard"
+          # the following lines are for building on MacOSX 10.5 "Leopard"
       OGLLIBS   := $(shell test -f /System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib && echo " -Wl,-dylib_file,/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib:/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries/libGL.dylib")
       endif
@@ -72,9 +74,13 @@
   endif
 
-  ifeq ($(QTHOME),/Library/Frameworks)
-    QT_VERSION := $(shell grep "QT_VERSION_STR" $(QTHOME)/QtCore.framework/Headers/qglobal.h | sed 's/.* \"\([0-9]\)\..*\"/\1/')
-  else
-    QT_VERSION := $(shell grep "QT_VERSION_STR" $(QTHOME)/include/qt/qglobal.h | sed 's/.* \"\([0-9]\)\..*\"/\1/')
+  ifndef QTMOC
+   ifeq ($(QTHOME),/Library/Frameworks)
+     QTMOC      := /usr/bin/moc
+   else
+     QTMOC      := $(QTHOME)/bin/moc
+   endif
   endif
+
+  QT_VERSION := $(shell $(QTMOC) 2>&1 -v | sed 's/.* .Qt \([0-9]\)\..*/\1/' )
 
   ifndef QTFLAGS
@@ -85,11 +91,4 @@
     else
       QTFLAGS   := -I $(QTHOME)/include/Qt -I$(QTHOME)/include
-    endif
-  endif
-  ifndef QTMOC
-    ifeq ($(QT_VERSION),4)
-      QTMOC      := /usr/bin/moc
-    else
-      QTMOC      := $(QTHOME)/bin/moc
     endif
   endif
Index: trunk/config/sys/Linux-g++.gmk
===================================================================
--- trunk/config/sys/Linux-g++.gmk	(revision 874)
+++ trunk/config/sys/Linux-g++.gmk	(revision 875)
@@ -63,33 +63,58 @@
     QTHOME     := /usr
   endif
-  QT_VERSION   := $(shell test -f $(QTHOME)/lib/libQt3Support.so && echo QT4 || echo QT3)
 
-  ifndef QTFLAGS
-    ifeq ($(QT_VERSION),QT4)
-      QTFLAGS    := -I$(QTHOME)/include/qt4/Qt
-      QTFLAGS    += -I$(QTHOME)/include/qt4
-    else
-      QTFLAGS    := -I$(QTHOME)/include/qt
-    endif
-  endif
   ifndef QTMOC
     QTMOC      := $(QTHOME)/bin/moc
   endif
 
+  QT_VERSION := $(shell $(QTMOC) 2>&1 -v | sed 's/.* .Qt \([0-9]\)\..*/\1/' )
+
+  ifndef QTFLAGS
+    ifeq ($(QT_VERSION),4)
+      QTFLAGS   := -I $(QTHOME)/include/qt$(QT_VERSION)/QtCore 
+      QTFLAGS   += -I $(QTHOME)/include/qt$(QT_VERSION)/QtGui 
+      QTFLAGS   += -I $(QTHOME)/include/qt$(QT_VERSION)/QtOpenGL 
+    else
+      QTFLAGS    := -I$(QTHOME)/include/qt$(QT_VERSION)/Qt
+      QTFLAGS    += -I$(QTHOME)/include/qt$(QT_VERSION)
+    endif
+  endif
+
+
+  ifndef QTLIBPATH
+    QT_SEARCH_LIB1 := $(shell ls  $(QTHOME)/lib/qt$(QT_VERSION)/libq* 2>/dev/null | wc -l )
+    QT_SEARCH_LIB2 := $(shell ls  $(QTHOME)/lib/libq*  2>/dev/null | wc -l )
+    ifneq ($(QT_SEARCH_LIB1),0)
+      QTLIBPATH   := /lib/qt$(QT_VERSION)
+    endif
+    ifneq ($(QT_SEARCH_LIB2),0)
+      QTLIBPATH   := /lib
+    endif
+  endif
+
+  ifndef QTLIBS
+    QTLIBS   := -L$(QTHOME)$(QTLIBPATH)
+    ifeq ($(QT_VERSION),3)
+      QT3_MT  := $(shell ls  $(QTHOME)$(QTLIBPATH)/libqt-mt.* | wc -l )
+      ifneq ($(QT3_MT),0)
+        QTLIBS  += -lqt-mt
+      else
+        QTLIBS  += -lqt
+      endif
+      QTLIBS   += -lqui
+    else
+      QTLIBS    += -lQtCore -lQtGui
+    endif
+  endif
 
   ifndef GLQTLIBS
-    ifeq ($(QT_VERSION),QT3)
-      GLQTLIBS    := -L$(QTHOME)/lib -lqt-mt
+    ifeq ($(QT_VERSION),3)
+        # already done in QTLIBS
+        #      GLQTLIBS    := $(QTLIBS)
     else
-      GLQTLIBS    := -L$(QTHOME)/lib/qt4 -lQtCore -lQtGui -lQtOpenGL
+      GLQTLIBS    := -L$(QTHOME)$(QTLIBPATH) -lQtCore -lQtGui -lQtOpenGL
     endif
   endif
-  ifndef QTLIBS
-    ifeq ($(QT_VERSION),QT3)
-      QTLIBS    := -L$(QTHOME)/lib -lqt-mt
-    else
-      QTLIBS    := -L$(QTHOME)/lib/qt4 -lQtCore -lQtGui
-    endif
-  endif
+
   ifndef XAWFLAGS
     XAWFLAGS   := -I/usr/X11R6/include
