diff --git a/Makefile b/Makefile
index b2c4cb1ba3256f491bb439ada7c9932923deb24f..35b84e463a87c6150da2d4c575a089706fd7b725 100644
--- a/Makefile
+++ b/Makefile
@@ -259,9 +259,11 @@ endif
 ##### gcc version #####
 
 ifneq ($(findstring gnu,$(COMPILER)),)
-GCC_MAJOR    := $(shell $(CXX) -dumpversion 2>&1 | cut -d'.' -f1)
-GCC_MINOR    := $(shell $(CXX) -dumpversion 2>&1 | cut -d'.' -f2)
-GCC_VERS     := gcc-$(GCC_MAJOR).$(GCC_MINOR)
+GCC_MAJOR     := $(shell $(CXX) -dumpversion 2>&1 | cut -d'.' -f1)
+GCC_MINOR     := $(shell $(CXX) -dumpversion 2>&1 | cut -d'.' -f2)
+GCC_PATCH     := $(shell $(CXX) -dumpversion 2>&1 | cut -d'.' -f3)
+GCC_VERS      := gcc-$(GCC_MAJOR).$(GCC_MINOR)
+GCC_VERS_FULL := gcc-$(GCC_MAJOR).$(GCC_MINOR).$(GCC_PATCH)
 endif
 
 ##### f77 options #####
diff --git a/treeplayer/Module.mk b/treeplayer/Module.mk
index 5fa3593c9080ec51f94d377d7b6bcc8673615a78..e82377088535a8f81c05fc3245402dc791b6d6a7 100644
--- a/treeplayer/Module.mk
+++ b/treeplayer/Module.mk
@@ -68,3 +68,11 @@ distclean-treeplayer: clean-treeplayer
 		   $(TREEPLAYERLIB)
 
 distclean::     distclean-treeplayer
+
+##### extra rules ######
+ifeq ($(ARCH),macosx)
+ifeq ($(GCC_VERS_FULL),gcc-4.0.1)
+$(TREEPLAYERDIRS)/TTreeFormula.o: $(TREEPLAYERDIRS)/TTreeFormula.cxx
+	$(CXX) $(NOOPT) $(CXXFLAGS) -o $@ -c $<
+endif
+endif