From 5c076c6ce8d26a70b44fd6bfddda7723de16fcff Mon Sep 17 00:00:00 2001
From: Vassil Vassilev <vvasilev@cern.ch>
Date: Thu, 26 Jan 2017 17:12:51 +0100
Subject: [PATCH] Revert "Merge branch '130'". This broke the cmake build
 system.

This reverts commit b406328d0c306c66a49733f23365396050c73084, reversing
changes made to 318c7a47744c5b83a344e062ae004f79ff4d7b87.
---
 CMakeLists.txt                                |  47 +--
 Makefile                                      |   9 +-
 bindings/pyroot/CMakeLists.txt                |  12 +-
 bindings/pyroot/ROOT.py                       |   2 +-
 cmake/modules/RootBuildOptions.cmake          |   2 +-
 cmake/modules/RootConfiguration.cmake         |  15 +-
 cmake/modules/RootNewMacros.cmake             |  24 +-
 cmake/scripts/local_install.cmake             |  20 ++
 config/RConfigure.in                          |   3 +-
 config/rootrc.in                              |  17 +-
 configure                                     |   1 -
 core/CMakeLists.txt                           |   4 +-
 core/base/inc/TROOT.h                         |  15 -
 core/base/src/TApplication.cxx                |  28 +-
 core/base/src/TEnv.cxx                        |  28 +-
 core/base/src/TPluginManager.cxx              |   4 -
 core/base/src/TROOT.cxx                       | 319 +++---------------
 core/base/src/TSystem.cxx                     |  68 +++-
 core/clingutils/res/TClingUtils.h             |  16 +
 core/clingutils/src/TClingUtils.cxx           |  57 ++++
 core/dictgen/res/rootcling_impl.h             |   3 +-
 core/dictgen/src/rootcling_impl.cxx           |  46 ++-
 core/meta/src/TClass.cxx                      |  12 +-
 core/metacling/res/rootclingTCling.h          |   2 -
 core/metacling/src/TCling.cxx                 |  35 +-
 core/metacling/src/rootclingTCling.cxx        |  12 -
 core/rint/src/TRint.cxx                       |  12 +-
 core/rint/src/TTabCom.cxx                     |   3 +-
 core/rootcling_stage1/CMakeLists.txt          |  14 +-
 core/rootcling_stage1/ModuleVars.mk           |   4 +-
 .../rootcling_stage1/src/rootcling_stage1.cxx |  20 +-
 core/unix/src/TUnixSystem.cxx                 |  51 ++-
 core/winnt/src/TWinNTSystem.cxx               |  61 ++--
 core/zip/CMakeLists.txt                       |   1 -
 documentation/doxygen/converttonotebook.py    |   2 +-
 geom/geom/src/TGeoElement.cxx                 |   9 +-
 graf2d/asimage/src/TASImage.cxx               |  61 ++--
 graf2d/cocoa/src/QuartzWindow.mm              |  13 +-
 graf2d/gpad/src/TClassTree.cxx                |  12 +-
 graf2d/graf/src/TTF.cxx                       |  19 +-
 graf2d/postscript/src/TPostScript.cxx         |   7 +-
 graf2d/qt/src/TGQt.cxx                        |  32 +-
 graf3d/gl/src/TGLFontManager.cxx              |   7 +-
 graf3d/gl/src/TGLSAViewer.cxx                 |   9 +-
 graf3d/gl/src/TGLText.cxx                     |   8 +-
 gui/gui/src/TGApplication.cxx                 |   7 +-
 gui/gui/src/TGResourcePool.cxx                |  51 ++-
 gui/gui/src/TGSpeedo.cxx                      |   9 +-
 gui/gui/src/TGTextEditor.cxx                  |   9 +-
 gui/gui/src/TRootBrowser.cxx                  |   9 +-
 gui/gui/src/TRootBrowserLite.cxx              |   9 +-
 gui/gui/src/TRootCanvas.cxx                   |   9 +-
 gui/guihtml/src/TGHtmlBrowser.cxx             |   9 +-
 gui/sessionviewer/src/TSessionViewer.cxx      |   9 +-
 html/src/THtml.cxx                            |  20 +-
 io/io/src/TFile.cxx                           |   6 +-
 main/CMakeLists.txt                           |   6 +-
 main/ModuleVars.mk                            |   2 +-
 main/src/nbmain.cxx                           |  12 +-
 main/src/rootcling.cxx                        |   5 +-
 math/mathcore/src/Integrator.cxx              |   3 +
 montecarlo/eg/src/TDatabasePDG.cxx            |   7 +-
 net/auth/CMakeLists.txt                       |   1 +
 net/auth/src/DaemonUtils.cxx                  |  20 +-
 net/auth/src/TAuthenticate.cxx                |  14 +-
 net/http/src/THttpServer.cxx                  |  19 +-
 net/net/src/TApplicationServer.cxx            |  12 +-
 net/net/src/TServerSocket.cxx                 |  17 +-
 net/rootd/src/rootd.cxx                       |  36 +-
 net/rpdutils/CMakeLists.txt                   |   1 +
 proof/proof/src/TProofLite.cxx                |  24 +-
 proof/proof/src/TProofServ.cxx                |   8 +-
 proof/proof/src/TSlaveLite.cxx                |   7 +-
 proof/proofbench/CMakeLists.txt               |   2 +-
 proof/proofbench/src/TProofBench.cxx          |   6 +-
 proof/proofbench/src/TProofBenchDataSet.cxx   |   7 +-
 proof/proofbench/src/TProofBenchRunCPU.cxx    |   6 +-
 .../proofbench/src/TProofBenchRunDataRead.cxx |   6 +-
 proof/proofd/src/XrdROOT.cxx                  |  16 +-
 proof/proofd/src/proofd.cxx                   |  55 +--
 roofit/histfactory/CMakeLists.txt             |   8 +-
 roofit/histfactory/config/prepareHistFactory  |  12 +-
 roofit/roostats/CMakeLists.txt                |   7 +-
 rootx/src/rootx.cxx                           |  54 +--
 test/RootIDE/TGRootIDE.cxx                    |   9 +-
 test/rhtml/rhtml.cxx                          |   9 +-
 tmva/tmva/CMakeLists.txt                      |   3 +
 tmva/tmva/Module.mk                           |   4 +-
 tmva/tmvagui/CMakeLists.txt                   |   6 +-
 tree/treeviewer/src/TTreeViewer.cxx           |   9 +-
 tutorials/eve/SplitGLView.C                   |  12 +-
 tutorials/fit/fit1.C                          |   2 +-
 tutorials/fit/fitslicesy.C                    |   2 +-
 tutorials/fit/myfit.C                         |   2 +-
 tutorials/foam/foam_demopers.C                |   2 +-
 tutorials/geom/runplugin.C                    |   2 +-
 tutorials/graphics/earth.C                    |   2 +-
 tutorials/graphics/psview.C                   |   2 +-
 tutorials/graphs/motorcycle.C                 |   2 +-
 tutorials/hist/FirstContour.C                 |   2 +-
 tutorials/hist/h1draw.C                       |   2 +-
 tutorials/hist/hbars.C                        |   2 +-
 tutorials/hsimple.C                           |   2 +-
 tutorials/image/rose_image.C                  |   7 +-
 tutorials/io/importCode.C                     |   2 +-
 tutorials/io/mergeSelective.C                 |   2 +-
 tutorials/io/testMergeCont.C                  |   2 +-
 tutorials/multicore/mp103_processSelector.C   |   2 +-
 tutorials/pyroot/benchmarks.py                |   2 +-
 tutorials/pyroot/fit1.py                      |   2 +-
 tutorials/pyroot/geometry.py                  |   2 +-
 tutorials/pyroot/rootmarks.py                 |   2 +-
 tutorials/pyroot/staff.py                     |   2 +-
 tutorials/roofit/rf505_asciicfg.C             |   4 +-
 tutorials/spectrum/Background_compton.C       |   2 +-
 tutorials/spectrum/Background_decr.C          |   2 +-
 tutorials/spectrum/Background_incr.C          |   2 +-
 tutorials/spectrum/Background_order.C         |   2 +-
 tutorials/spectrum/Background_smooth.C        |   2 +-
 tutorials/spectrum/Background_width.C         |   2 +-
 tutorials/spectrum/Background_width2.C        |   2 +-
 tutorials/spectrum/Deconvolution.C            |   2 +-
 tutorials/spectrum/DeconvolutionRL_wide.C     |   2 +-
 .../spectrum/DeconvolutionRL_wide_boost.C     |   2 +-
 tutorials/spectrum/Deconvolution_wide.C       |   2 +-
 tutorials/spectrum/Deconvolution_wide_boost.C |   2 +-
 tutorials/spectrum/SearchHR1.C                |   2 +-
 tutorials/spectrum/SearchHR3.C                |   2 +-
 tutorials/spectrum/Smoothing.C                |   2 +-
 tutorials/tmva/TMVAClassificationCategory.C   |   2 +-
 .../TMVAClassificationCategoryApplication.C   |   2 +-
 tutorials/tmva/TMVAMulticlass.C               |   2 +-
 .../tmva/TMVAMultipleBackgroundExample.C      |   2 +-
 tutorials/tmva/keras/MulticlassKeras.py       |   2 +-
 tutorials/tree/basic.C                        |   2 +-
 tutorials/tree/basic2.C                       |   2 +-
 tutorials/tree/cernbuild.C                    |   2 +-
 tutorials/tree/cernstaff.C                    |   2 +-
 tutorials/tree/jets.C                         |   2 +-
 tutorials/tree/ntuple1.C                      |   2 +-
 tutorials/xml/DOMParsePerson.C                |   2 +-
 tutorials/xml/DOMRecursive.C                  |   2 +-
 tutorials/xml/SAXHandler.C                    |   2 +-
 143 files changed, 1082 insertions(+), 747 deletions(-)
 create mode 100644 cmake/scripts/local_install.cmake

diff --git a/CMakeLists.txt b/CMakeLists.txt
index e2ab356c84d..39c904dfdb6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -91,7 +91,7 @@ foreach(var ${variables})
   endif()
 endforeach()
 
-#---Move (copy) directories to binary tree------------------------------------------------------
+#---Move (copy) the headers and other directories to binary tree---------------------------------
 set(stamp_file ${CMAKE_CURRENT_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/move_artifacts.stamp)
 add_custom_command(OUTPUT ${stamp_file}
                    COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_SOURCE_DIR}/etc ${CMAKE_BINARY_DIR}/etc
@@ -119,7 +119,11 @@ foreach(tutorial_file ${tutorial_files})
   endif()
 endforeach()
 
-add_custom_target(move_artifacts DEPENDS ${stamp_file} ${tutorial_files_builddir})
+add_custom_target(move_headers DEPENDS ${stamp_file} ${tutorial_files_builddir}
+                               COMMAND ${CMAKE_COMMAND} -DPREFIX=${CMAKE_BINARY_DIR}
+                                                        -DCOMPONENTS="headers"
+                                                        -P ${CMAKE_SOURCE_DIR}/cmake/scripts/local_install.cmake)
+include_directories(${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR})
 
 
 #---Recurse into the given subdirectories.  This does not actually cause another cmake executable
@@ -178,7 +182,7 @@ add_custom_command(OUTPUT etc/dictpch/allLinkDefs.h
                    DEPENDS ${CMAKE_SOURCE_DIR}/build/unix/makepchinput.py ${__allFiles})
 
 add_custom_command(OUTPUT etc/allDict.cxx.pch
-                   COMMAND ${CMAKE_COMMAND} -E env ROOTIGNOREPREFIX=1 ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/etc/dictpch/makepch.py etc/allDict.cxx.pch -I${CMAKE_BINARY_DIR}/include
+                   COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_SOURCE_DIR}/etc/dictpch/makepch.py etc/allDict.cxx.pch -I${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_INCLUDEDIR}
                    DEPENDS ${CMAKE_SOURCE_DIR}/etc/dictpch/makepch.py
                            etc/dictpch/allLinkDefs.h
                            etc/dictpch/allHeaders.h
@@ -205,28 +209,26 @@ if(cxxmodules)
                      COMMAND echo ${__echo_args} ${__modulemap_extra_content} >> ${CMAKE_BINARY_DIR}/include/module.modulemap
                      VERBATIM
                     )
-  add_dependencies(move_artifacts copymodulemap)
+  add_dependencies(move_headers copymodulemap)
 endif(cxxmodules)
 
 #---hsimple.root---------(use the executable for clearer dependencies and proper return code)---
-add_custom_target(hsimple ALL DEPENDS tutorials/hsimple.root)
-add_dependencies(hsimple onepcm)
-if(WIN32)
-  add_custom_command(OUTPUT tutorials/hsimple.root
-                     COMMAND set PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} &&
-                             set ROOTIGNOREPREFIX=1 &&
-                             $<TARGET_FILE:root.exe> -l -q -b -n -x hsimple.C -e return
-                     WORKING_DIRECTORY tutorials
-                     DEPENDS $<TARGET_FILE:root.exe> Cling Hist Tree Gpad Graf HistPainter move_artifacts)
-else()
-  add_custom_command(OUTPUT tutorials/hsimple.root
-                     COMMAND ${ld_library_path}=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}:$ENV{${ld_library_path}}
-                             ROOTIGNOREPREFIX=1
-                             $<TARGET_FILE:root.exe> -l -q -b -n -x hsimple.C -e return
-                     WORKING_DIRECTORY tutorials
-                     DEPENDS $<TARGET_FILE:root.exe> Cling Hist Tree Gpad Graf HistPainter move_artifacts)
+if(NOT gnuinstall)   # TODO hsimple.root for gnuinstall
+  add_custom_target(hsimple ALL DEPENDS tutorials/hsimple.root)
+  add_dependencies(hsimple onepcm)
+  if(WIN32)
+    add_custom_command(OUTPUT tutorials/hsimple.root
+                       COMMAND set PATH=${CMAKE_RUNTIME_OUTPUT_DIRECTORY} && 
+                               $<TARGET_FILE:root.exe> -l -q -b -n -x hsimple.C -e return
+                       WORKING_DIRECTORY tutorials DEPENDS root.exe Cling Hist Tree Gpad Graf HistPainter)
+  else()
+    add_custom_command(OUTPUT tutorials/hsimple.root
+                       COMMAND ${ld_library_path}=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}:$ENV{${ld_library_path}} 
+                               $<TARGET_FILE:root.exe> -l -q -b -n -x hsimple.C -e return
+                       WORKING_DIRECTORY tutorials DEPENDS  $<TARGET_FILE:root.exe> Cling Hist Tree Gpad Graf HistPainter)
+  endif()
+  install(FILES ${CMAKE_BINARY_DIR}/tutorials/hsimple.root DESTINATION ${CMAKE_INSTALL_TUTDIR} COMPONENT tests)
 endif()
-install(FILES ${CMAKE_BINARY_DIR}/tutorials/hsimple.root DESTINATION ${CMAKE_INSTALL_TUTDIR} COMPONENT tests)
 
 #---version--------------------------------------------------------------------------------------
 add_custom_target(version COMMAND ${CMAKE_SOURCE_DIR}/build/unix/makeversion.sh ${CMAKE_BINARY_DIR}
@@ -272,6 +274,9 @@ endif()
 #---Configure Testing using CTest----------------------------------------------------------------
 configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/CTestCustom.cmake ${CMAKE_BINARY_DIR} COPYONLY)
 if(testing)
+  if(gnuinstall)
+    message(FATAL_ERROR "You cannot enable to run the tests in the build directory (testing=ON) and at the same time select a GNU style installation (gnuinstall=ON). This is because the code is built with the final installation location (CMAKE_INSTALL_PREFIX) for many ancillary files (tutorials, etc, icons, macros, etc.) and these are not available before installation. Tests can be run against the installation once is completed. See the instructions in the web")
+  endif()
   include(RootCTest)
   if(roottest)
     find_package(Git REQUIRED)
diff --git a/Makefile b/Makefile
index b59ee952282..3e3edb383dd 100644
--- a/Makefile
+++ b/Makefile
@@ -758,9 +758,11 @@ ifneq ($(findstring map, $(MAKECMDGOALS)),)
 .NOTPARALLEL:
 endif
 
+ifeq ($(USECONFIG),FALSE)
 all: tutorials/hsimple.root
 tutorials/hsimple.root: rootexecs postbin
-	@(cd tutorials; ! ROOTIGNOREPREFIX=1 ../bin/root -l -q -b -n -x hsimple.C)
+	@(cd tutorials; ! ../bin/root -l -q -b -n -x hsimple.C)
+endif
 
 all:            rootexecs postbin
 	@echo " "
@@ -1234,7 +1236,7 @@ endif
 
 $(ROOTPCH): $(MAKEPCH) $(ROOTCLINGSTAGE1DEP) $(ALLHDRS) $(CLINGETCPCH) $(ORDER_) $(ALLLIBS)
 	@$(MAKEPCHINPUT) $(ROOT_SRCDIR) "$(MODULES)" $(CLINGETCPCH) -- $(ROOTPCHCXXFLAGS) $(SYSTEMDEF)
-	@ROOTIGNOREPREFIX=1 $(MAKEPCH) $@
+	@$(MAKEPCH) $@
 
 $(MAKEPCH): $(ROOT_SRCDIR)/$(MAKEPCH)
 	@mkdir -p $(dir $@)
@@ -1339,6 +1341,8 @@ install: all
 	   $(INSTALLDATA) build/misc/root-help.el $(DESTDIR)$(ELISPDIR); \
 	   echo "Installing GDML conversion scripts in $(DESTDIR)$(LIBDIR)"; \
 	   $(INSTALLDATA) $(ROOT_SRCDIR)/geom/gdml/*.py $(DESTDIR)$(LIBDIR); \
+	   (cd $(DESTDIR)$(TUTDIR); \
+	      ! LD_LIBRARY_PATH=$(DESTDIR)$(LIBDIR):$$LD_LIBRARY_PATH $(DESTDIR)$(BINDIR)/root -l -b -q -n -x hsimple.C); \
 	fi
 
 uninstall:
@@ -1465,6 +1469,7 @@ runtimedirs:
 		--exclude proofd.xinetd \
 		--exclude rootd.rc.d \
 		--exclude rootd.xinetd \
+		--exclude gitinfo.txt \
 		$(ROOT_SRCDIR)/etc . ; \
 	echo "Rsync'ing $(ROOT_SRCDIR)/macros..."; \
 	$(RSYNC) \
diff --git a/bindings/pyroot/CMakeLists.txt b/bindings/pyroot/CMakeLists.txt
index c537baed6ae..ba30ce20a8c 100644
--- a/bindings/pyroot/CMakeLists.txt
+++ b/bindings/pyroot/CMakeLists.txt
@@ -36,18 +36,18 @@ endif()
 file(GLOB pyfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.py)
 foreach(pyfile ${pyfiles})
   install(FILES ${pyfile} DESTINATION ${runtimedir})
-  install(CODE "execute_process(COMMAND python -m py_compile \$ENV{DESTDIR}${runtimedir}/${pyfile})")
-  install(CODE "execute_process(COMMAND python -O -m py_compile \$ENV{DESTDIR}${runtimedir}/${pyfile})")
-  file(COPY ${pyfile} DESTINATION ${localruntimedir})
+  install(CODE "execute_process(COMMAND python -m py_compile \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${runtimedir}/${pyfile} )")
+  install(CODE "execute_process(COMMAND python -O -m py_compile \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${runtimedir}/${pyfile} )")
+  file(COPY ${pyfile} DESTINATION ${CMAKE_BINARY_DIR}/${runtimedir})
 endforeach()
 
-set(JupyROOTDirName "JupyROOT")
+set( JupyROOTDirName "JupyROOT")
 install (DIRECTORY ${JupyROOTDirName} DESTINATION ${runtimedir})
-file(COPY ${JupyROOTDirName} DESTINATION ${localruntimedir})
+file(COPY ${JupyROOTDirName} DESTINATION ${CMAKE_BINARY_DIR}/${runtimedir})
 
 set( JsMVADirName "JsMVA")
 install (DIRECTORY ${JsMVADirName} DESTINATION ${runtimedir})
-file(COPY ${JsMVADirName} DESTINATION ${localruntimedir})
+file(COPY ${JsMVADirName} DESTINATION ${CMAKE_BINARY_DIR}/${runtimedir})
 
 #---Install headers----------------------------------------------------------
 ROOT_INSTALL_HEADERS()
diff --git a/bindings/pyroot/ROOT.py b/bindings/pyroot/ROOT.py
index 53e64da69b4..ec385e2e84b 100644
--- a/bindings/pyroot/ROOT.py
+++ b/bindings/pyroot/ROOT.py
@@ -540,7 +540,7 @@ class ModuleFacade( types.ModuleType ):
 
           # system logon, user logon, and local logon (skip Rint.Logon)
             name = '.rootlogon.C'
-            logons = [ os.path.join( str(self.TROOT.GetEtcDir()), 'system' + name ),
+            logons = [ os.path.join( str(gRootDir), 'etc', 'system' + name ),
                        os.path.expanduser( os.path.join( '~', name ) ) ]
             if logons[-1] != os.path.join( os.getcwd(), name ):
                logons.append( name )
diff --git a/cmake/modules/RootBuildOptions.cmake b/cmake/modules/RootBuildOptions.cmake
index a8eab8a9385..42a056c26d7 100644
--- a/cmake/modules/RootBuildOptions.cmake
+++ b/cmake/modules/RootBuildOptions.cmake
@@ -258,7 +258,7 @@ set(CMAKE_MACOSX_RPATH TRUE)              # use RPATH for MacOSX
 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) # point to directories outside the build tree to the install RPATH
 
 # Check whether to add RPATH to the installation (the build tree always has the RPATH enabled)
-if(rpath)
+if(rpath OR gnuinstall)
   set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR}) # install LIBDIR
   set(CMAKE_SKIP_INSTALL_RPATH FALSE)          # don't skip the full RPATH for the install tree
 elseif(APPLE)
diff --git a/cmake/modules/RootConfiguration.cmake b/cmake/modules/RootConfiguration.cmake
index acc86db36ff..b72a9af6bc1 100644
--- a/cmake/modules/RootConfiguration.cmake
+++ b/cmake/modules/RootConfiguration.cmake
@@ -670,8 +670,8 @@ endif()
 
 #---Get the value of CMAKE_CXX_FLAGS provided by the user in the command line
 set(usercflags ${CMAKE_CXX_FLAGS-CACHED})
-file(REMOVE ${CMAKE_BINARY_DIR}/installtree/root-config)
-configure_file(${CMAKE_SOURCE_DIR}/config/root-config.in ${CMAKE_BINARY_DIR}/installtree/root-config @ONLY NEWLINE_STYLE UNIX)
+file(REMOVE ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/root-config)
+configure_file(${CMAKE_SOURCE_DIR}/config/root-config.in ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/root-config @ONLY NEWLINE_STYLE UNIX)
 configure_file(${CMAKE_SOURCE_DIR}/config/memprobe.in ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/memprobe @ONLY NEWLINE_STYLE UNIX)
 configure_file(${CMAKE_SOURCE_DIR}/config/thisroot.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/thisroot.sh @ONLY NEWLINE_STYLE UNIX)
 configure_file(${CMAKE_SOURCE_DIR}/config/thisroot.csh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/thisroot.csh @ONLY NEWLINE_STYLE UNIX)
@@ -688,15 +688,6 @@ if(WIN32)
   configure_file(${CMAKE_SOURCE_DIR}/config/thisroot.bat ${thisrootbat} @ONLY)
 endif()
 
-#--Local root-configure
-set(prefix $ROOTSYS)
-set(bindir $ROOTSYS/bin)
-set(libdir $ROOTSYS/lib)
-set(incdir $ROOTSYS/include)
-set(etcdir $ROOTSYS/etc)
-set(mandir $ROOTSYS/man)
-configure_file(${CMAKE_SOURCE_DIR}/config/root-config.in ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/root-config @ONLY NEWLINE_STYLE UNIX)
-
 install(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/thisroot.sh
               ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/thisroot.csh
               ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/setxrd.csh
@@ -708,7 +699,7 @@ install(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/thisroot.sh
               DESTINATION ${CMAKE_INSTALL_BINDIR})
               
 install(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/memprobe
-              ${CMAKE_BINARY_DIR}/installtree/root-config
+              ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/root-config
               ${CMAKE_SOURCE_DIR}/cmake/scripts/setenvwrap.csh
               ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/roots
               ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/proofserv
diff --git a/cmake/modules/RootNewMacros.cmake b/cmake/modules/RootNewMacros.cmake
index 4b2c4d7d563..6d128b6659b 100644
--- a/cmake/modules/RootNewMacros.cmake
+++ b/cmake/modules/RootNewMacros.cmake
@@ -19,7 +19,6 @@ if(WIN32)
   set(libprefix lib)
   set(ld_library_path PATH)
   set(libsuffix .dll)
-  set(localruntimedir ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
   set(runtimedir ${CMAKE_INSTALL_BINDIR})
 elseif(APPLE)
   set(ld_library_path DYLD_LIBRARY_PATH)
@@ -27,7 +26,6 @@ elseif(APPLE)
   set(scomment \#)
   set(libprefix lib)
   set(libsuffix .so)
-  set(localruntimedir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
   set(runtimedir ${CMAKE_INSTALL_LIBDIR})
 else()
   set(ld_library_path LD_LIBRARY_PATH)
@@ -35,7 +33,6 @@ else()
   set(scomment \#)
   set(libprefix lib)
   set(libsuffix .so)
-  set(localruntimedir ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
   set(runtimedir ${CMAKE_INSTALL_LIBDIR})
 endif()
 
@@ -340,7 +337,7 @@ function(ROOT_GENERATE_DICTIONARY dictionary)
     set(pcm_name)
   else()
     if(CMAKE_PROJECT_NAME STREQUAL ROOT)
-      set(command ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib:$ENV{LD_LIBRARY_PATH}" "ROOTIGNOREPREFIX=1" $<TARGET_FILE:rootcling> -rootbuild)
+      set(command ${CMAKE_COMMAND} -E env "LD_LIBRARY_PATH=${CMAKE_BINARY_DIR}/lib:$ENV{LD_LIBRARY_PATH}" ${CMAKE_BINARY_DIR}/bin/rootcling -rootbuild)
       set(ROOTCINTDEP rootcling)
     else()
       set(command rootcling)
@@ -531,6 +528,9 @@ function(ROOT_LINKER_LIBRARY library)
   if(TARGET G__${library})
     add_dependencies(${library} G__${library})
   endif()
+  if(TARGET move_headers)
+    add_dependencies(${library} move_headers)
+  endif()
   set_property(GLOBAL APPEND PROPERTY ROOT_EXPORTED_TARGETS ${library})
   set_target_properties(${library} PROPERTIES OUTPUT_NAME ${library_name})
   set_target_properties(${library} PROPERTIES LINK_INTERFACE_LIBRARIES "${ARG_DEPENDENCIES}")
@@ -579,6 +579,9 @@ function(ROOT_OBJECT_LIBRARY library)
   if(lib_srcs MATCHES "(^|/)(G__[^.]*)[.]cxx.*")
      add_dependencies(${library} ${CMAKE_MATCH_2})
   endif()
+  if(TARGET move_headers)
+    add_dependencies(${library} move_headers)
+  endif()
 
   #--- Only for building shared libraries
   set_property(TARGET ${library} PROPERTY POSITION_INDEPENDENT_CODE 1)
@@ -632,6 +635,9 @@ function(ROOT_MODULE_LIBRARY library)
   ROOT_GET_SOURCES(lib_srcs src ${ARG_UNPARSED_ARGUMENTS})
   include_directories(${CMAKE_BINARY_DIR}/include)
   add_library( ${library} SHARED ${lib_srcs})
+  if(TARGET move_headers)
+    add_dependencies(${library} move_headers)
+  endif()
   set_target_properties(${library}  PROPERTIES ${ROOT_LIBRARY_PROPERTIES})
   # Do not add -Dname_EXPORTS to the command-line when building files in this
   # target. Doing so is actively harmful for the modules build because it
@@ -722,10 +728,6 @@ function(ROOT_INSTALL_HEADERS)
                            PATTERN ".svn" EXCLUDE
                            REGEX "LinkDef" EXCLUDE
                            ${ARG_OPTIONS})
-    file(COPY ${d} DESTINATION ${CMAKE_BINARY_DIR}/include
-                   PATTERN ".svn" EXCLUDE
-                   REGEX "LinkDef" EXCLUDE
-                   ${ARG_OPTIONS})
     set_property(GLOBAL APPEND PROPERTY ROOT_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/${d})
   endforeach()
 endfunction()
@@ -765,6 +767,9 @@ function(ROOT_EXECUTABLE executable)
   if (ARG_ADDITIONAL_COMPILE_FLAGS)
     set_target_properties(${executable} PROPERTIES COMPILE_FLAGS ${ARG_ADDITIONAL_COMPILE_FLAGS})
   endif()
+  if(TARGET move_headers)
+    add_dependencies(${executable} move_headers)
+  endif()
   if(ARG_BUILTINS)
     foreach(arg1 ${ARG_BUILTINS})
       if(${arg1}_TARGET)
@@ -991,9 +996,6 @@ function(ROOT_ADD_TEST test)
     set_property(TEST ${test} PROPERTY ENVIRONMENT ROOT_DIR=${CMAKE_BINARY_DIR})
   else()
     add_test(NAME ${test} COMMAND ${_command})
-    if (gnuinstall)
-      set_property(TEST ${test} PROPERTY ENVIRONMENT ROOTIGNOREPREFIX=1)
-    endif()
   endif()
 
   #- Handle TIMOUT and DEPENDS arguments
diff --git a/cmake/scripts/local_install.cmake b/cmake/scripts/local_install.cmake
new file mode 100644
index 00000000000..a75841ac505
--- /dev/null
+++ b/cmake/scripts/local_install.cmake
@@ -0,0 +1,20 @@
+# Arguments:
+#  PREFIX    - Installation prefix
+#  COMPONENTS - Installation component
+
+set(COMPONENTS ${COMPONENTS})
+set(ENV{DESTDIR} "")
+foreach(component ${COMPONENTS})
+  execute_process(
+    COMMAND ${CMAKE_COMMAND} -DCMAKE_INSTALL_PREFIX=${PREFIX}
+                             -DCMAKE_INSTALL_COMPONENT=${component}
+                             -P cmake_install.cmake
+    RESULT_VARIABLE result
+    OUTPUT_QUIET
+  )
+
+  if(result)
+    set(msg "Local installation of ${component} failed: ${result}\n")
+    message(FATAL_ERROR "${msg}")
+  endif()
+endforeach()
diff --git a/config/RConfigure.in b/config/RConfigure.in
index c0601629cac..5140669fee8 100644
--- a/config/RConfigure.in
+++ b/config/RConfigure.in
@@ -14,11 +14,10 @@
 #define ROOTTUTDIR    "@tutdir@"
 #define ROOTSRCDIR    "@srcdir@"
 #define ROOTICONPATH  "@iconpath@"
+#define EXTRAICONPATH "@extraiconpath@"
 #define TTFFONTDIR    "@ttffontdir@"
 #endif
 
-#define EXTRAICONPATH "@extraiconpath@"
-
 #@setresuid@ R__HAS_SETRESUID   /**/
 #@hasmathmore@ R__HAS_MATHMORE   /**/
 #@haspthread@ R__HAS_PTHREAD    /**/
diff --git a/config/rootrc.in b/config/rootrc.in
index 2c747e79a44..8fe8ed44ce3 100644
--- a/config/rootrc.in
+++ b/config/rootrc.in
@@ -9,24 +9,24 @@
 # and to PATH on Windows.
 # Paths are different for Unix and Windows. The example shows the defaults
 # for all ROOT applications for either Unix or Windows.
-#Unix.*.Root.DynamicPath:    .:@libdir@
-#WinNT.*.Root.DynamicPath:   .;@bindir@
+Unix.*.Root.DynamicPath:    .:@libdir@:
+WinNT.*.Root.DynamicPath:   .;@bindir@;
 
 # Path used to find macros.
 # Paths are different for Unix and Windows. The example shows the defaults
 # for all ROOT applications for either Unix or Windows.
-#Unix.*.Root.MacroPath:      .:@macrodir@
-#WinNT.*.Root.MacroPath:     .;@macrodir@
+Unix.*.Root.MacroPath:      .:@macrodir@:
+WinNT.*.Root.MacroPath:     .;@macrodir@;
 
 # Path used to find plugin macros.
 # Paths are different for Unix and Windows. The example shows the defaults
 # for all ROOT applications for either Unix or Windows.
-#Unix.*.Root.PluginPath:     @plugindir@
-#WinNT.*.Root.PluginPath:    @plugindir@
+Unix.*.Root.PluginPath:      :@plugindir@:
+WinNT.*.Root.PluginPath:     ;@plugindir@;
 
 # Path where to look for TrueType fonts.
 Unix.*.Root.UseTTFonts:     true
-#*.*.Root.TTFontPath:        @ttffontdir@
+*.*.Root.TTFontPath:        @ttffontdir@
 
 # Use Net* API functions.
 WinNT.UseNetAPI:         true
@@ -225,8 +225,7 @@ Gui.DocumentBackgroundColor: white
 Gui.DocumentForegroundColor: black
 Gui.TooltipBackgroundColor:  LightYellow
 Gui.TooltipForegroundColor:  black
-#Unix.*.Gui.IconPath:         .:$(HOME)/icons:@iconpath@:@extraiconpath@
-#WinNT.*.Gui.IconPath:        .;$(HOME)/icons;@iconpath@;@extraiconpath@
+Gui.IconPath:                $(HOME)/icons:@iconpath@:.
 Gui.MimeTypeFile:            $(HOME)/.root.mimes
 # If above does not exists defaults to this:
 #Gui.MimeTypeFile:            @etcdir@/root.mimes
diff --git a/configure b/configure
index 42cab175568..3acf81ebdd8 100755
--- a/configure
+++ b/configure
@@ -8235,7 +8235,6 @@ sed -e "s|@libdir@|$libdir|"               \
     -e "s|@bindir@|$bindir|"               \
     -e "s|@etcdir@|$etcdir|"               \
     -e "s|@ttffontdir@|$fontdir|"          \
-    -e "s|@extraiconpath@|$extraiconpath|" \
     -e "s|@iconpath@|$iconpath|"           \
     -e "s|@hasxrd@|$hasxrd|"               \
     -e "s|@hasnotxrd@|$hasnotxrd|"         \
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt
index 504be6c8bed..d33950fdee8 100644
--- a/core/CMakeLists.txt
+++ b/core/CMakeLists.txt
@@ -71,14 +71,14 @@ if(WIN32)
                      COMMAND ${CMAKE_SOURCE_DIR}/build/win/gitinfo.bat ${CMAKE_SOURCE_DIR}
                      COMMAND ${CMAKE_SOURCE_DIR}/build/win/githeader.bat RGitCommit.h.tmp
                      COMMENT "Recording the git revision now"
-                     DEPENDS ${dep_objects} move_artifacts
+                     DEPENDS ${dep_objects}
                      WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
 else()
   add_custom_command(OUTPUT  ${CMAKE_BINARY_DIR}/RGitCommit.h.tmp
                      COMMAND ${CMAKE_SOURCE_DIR}/build/unix/gitinfo.sh ${CMAKE_SOURCE_DIR}
                      COMMAND ${CMAKE_SOURCE_DIR}/build/unix/githeader.sh RGitCommit.h.tmp
                      COMMENT "Recording the git revision now"
-                     DEPENDS ${dep_objects} move_artifacts
+                     DEPENDS ${dep_objects}
                      WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
 endif()
 add_custom_target(gitcommit ALL DEPENDS ${CMAKE_BINARY_DIR}/RGitCommit.h.tmp)
diff --git a/core/base/inc/TROOT.h b/core/base/inc/TROOT.h
index c1e6b4d14a0..73cf65142d3 100644
--- a/core/base/inc/TROOT.h
+++ b/core/base/inc/TROOT.h
@@ -350,21 +350,6 @@ public:
    static Int_t       ConvertVersionInt2Code(Int_t v);
    static Int_t       RootVersionCode();
    static const char**&GetExtraInterpreterArgs();
-
-   static const TString& GetRootSys();
-   static const TString& GetBinDir();
-   static const TString& GetLibDir();
-   static const TString& GetIncludeDir();
-   static const TString& GetEtcDir();
-   static const TString& GetDataDir();
-   static const TString& GetDocDir();
-   static const TString& GetMacroDir();
-   static const TString& GetTutorialDir();
-   static const TString& GetSourceDir();
-   static const TString& GetIconPath();
-   static const TString& GetTTFFontDir();
-
-   // Backward compatibility function - do not use for new code
    static const char *GetTutorialsDir();
 
    ClassDef(TROOT,0)  //Top level (or root) structure for all classes
diff --git a/core/base/src/TApplication.cxx b/core/base/src/TApplication.cxx
index fba6e6b0296..98bb2fbbe9c 100644
--- a/core/base/src/TApplication.cxx
+++ b/core/base/src/TApplication.cxx
@@ -276,7 +276,11 @@ void TApplication::InitializeGraphics()
    // mode and Root.UseTTFonts is true and Root.TTFontPath exists. Abort silently
    // if libttf or libGX11TTF are not found in $ROOTSYS/lib or $ROOTSYS/ttf/lib.
    const char *ttpath = gEnv->GetValue("Root.TTFontPath",
-                                       TROOT::GetTTFFontDir());
+#ifdef TTFFONTDIR
+                                       TTFFONTDIR);
+#else
+                                       "$(ROOTSYS)/fonts");
+#endif
    char *ttfont = gSystem->Which(ttpath, "arialbd.ttf", kReadPermission);
    // Check for use of DFSG - fonts
    if (!ttfont)
@@ -884,19 +888,29 @@ Long_t TApplication::ProcessLine(const char *line, Bool_t sync, Int_t *err)
          Error("ProcessLine", "Cannot show demos in batch mode!");
          return 1;
       }
-      ProcessLine(".x " + TROOT::GetTutorialDir() + "/demos.C");
+#ifdef ROOTTUTDIR
+      ProcessLine(".x " ROOTTUTDIR "/demos.C");
+#else
+      ProcessLine(".x $(ROOTSYS)/tutorials/demos.C");
+#endif
       return 0;
    }
 
    if (!strncmp(line, ".license", 8)) {
-      return PrintFile(TROOT::GetDocDir() + "/LICENSE");
+#ifdef ROOTDOCDIR
+      return PrintFile(ROOTDOCDIR "/LICENSE");
+#else
+      return PrintFile("$(ROOTSYS)/LICENSE");
+#endif
    }
 
    if (!strncmp(line, ".credits", 8)) {
-      TString credits = TROOT::GetDocDir() + "/CREDITS";
-      if (gSystem->AccessPathName(credits, kReadPermission))
-         credits = TROOT::GetDocDir() + "/README/CREDITS";
-      return PrintFile(credits);
+#ifdef ROOTDOCDIR
+      return PrintFile(ROOTDOCDIR "/CREDITS");
+#else
+      return PrintFile("$(ROOTSYS)/README/CREDITS");
+#endif
+
    }
 
    if (!strncmp(line, ".pwd", 4)) {
diff --git a/core/base/src/TEnv.cxx b/core/base/src/TEnv.cxx
index 2f698bbf30a..cf7057236f6 100644
--- a/core/base/src/TEnv.cxx
+++ b/core/base/src/TEnv.cxx
@@ -401,7 +401,21 @@ TEnv::TEnv(const char *name)
 
       TString sname = "system";
       sname += name;
-      char *s = gSystem->ConcatFileName(TROOT::GetEtcDir(), sname);
+#ifdef ROOTETCDIR
+      char *s = gSystem->ConcatFileName(ROOTETCDIR, sname);
+#else
+      TString etc = gRootDir;
+#ifdef WIN32
+      etc += "\\etc";
+#else
+      etc += "/etc";
+#endif
+#if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
+      // on iOS etc does not exist and system<name> resides in $ROOTSYS
+      etc = gRootDir;
+#endif
+      char *s = gSystem->ConcatFileName(etc, sname);
+#endif
       ReadFile(s, kEnvGlobal);
       delete [] s;
       if (!gSystem->Getenv("ROOTENV_NO_HOME")) {
@@ -671,7 +685,17 @@ void TEnv::SaveLevel(EEnvLevel level)
 
       TString sname = "system";
       sname += fRcName;
-      char *s = gSystem->ConcatFileName(TROOT::GetEtcDir(), sname);
+#ifdef ROOTETCDIR
+      char *s = gSystem->ConcatFileName(ROOTETCDIR, sname);
+#else
+      TString etc = gRootDir;
+#ifdef WIN32
+      etc += "\\etc";
+#else
+      etc += "/etc";
+#endif
+      char *s = gSystem->ConcatFileName(etc, sname);
+#endif
       rootrcdir = s;
       delete [] s;
    } else if (level == kEnvUser) {
diff --git a/core/base/src/TPluginManager.cxx b/core/base/src/TPluginManager.cxx
index d811a338538..0a0883e8b1a 100644
--- a/core/base/src/TPluginManager.cxx
+++ b/core/base/src/TPluginManager.cxx
@@ -470,10 +470,6 @@ void TPluginManager::LoadHandlersFromPluginDirs(const char *base)
       TPH__IsReadingDirs() = kTRUE;
 
       TString plugindirs = gEnv->GetValue("Root.PluginPath", (char*)0);
-      if (plugindirs.Length() == 0) {
-         plugindirs = "plugins";
-         gSystem->PrependPathName(TROOT::GetEtcDir(), plugindirs);
-      }
 #ifdef WIN32
       dirs = plugindirs.Tokenize(";");
 #else
diff --git a/core/base/src/TROOT.cxx b/core/base/src/TROOT.cxx
index d4624273e46..461fb20a80e 100644
--- a/core/base/src/TROOT.cxx
+++ b/core/base/src/TROOT.cxx
@@ -658,22 +658,6 @@ TROOT::TROOT(const char *name, const char *title, VoidFuncPtr_t *initfunc)
    // Initialize Operating System interface
    InitSystem();
 
-   // Initialize static directory functions
-   GetRootSys();
-   GetBinDir();
-   GetLibDir();
-   GetIncludeDir();
-   GetEtcDir();
-   GetDataDir();
-   GetDocDir();
-   GetMacroDir();
-   GetTutorialDir();
-   GetSourceDir();
-   GetIconPath();
-   GetTTFFontDir();
-
-   gRootDir = GetRootSys().Data();
-
    TDirectory::Build();
 
    // Initialize interface to CINT C++ interpreter
@@ -1909,9 +1893,21 @@ void TROOT::InitInterpreter()
                "after the call to TROOT::InitInterpreter()!");
       }
 
-      char *libcling = gSystem->DynamicPathName("libCling");
+      const char *libcling = 0;
+      char *libclingStorage = 0;
+#ifdef ROOTLIBDIR
+      libcling = ROOTLIBDIR "/libCling."
+# ifdef R__WIN32
+      "dll";
+# else
+      "so";
+# endif
+#else
+      libclingStorage = gSystem->DynamicPathName("libCling");
+      libcling = libclingStorage;
+#endif
       gInterpreterLib = dlopen(libcling, RTLD_LAZY|RTLD_LOCAL);
-      delete [] libcling;
+      delete [] libclingStorage;
 
       if (!gInterpreterLib) {
          TString err = dlerror();
@@ -2258,7 +2254,22 @@ void TROOT::ReadGitInfo()
 #endif
 
    TString gitinfo = "gitinfo.txt";
-   char *filename = gSystem->ConcatFileName(TROOT::GetEtcDir(), gitinfo);
+   char *filename = 0;
+#ifdef ROOTETCDIR
+   filename = gSystem->ConcatFileName(ROOTETCDIR, gitinfo);
+#else
+   TString etc = gRootDir;
+#ifdef WIN32
+   etc += "\\etc";
+#else
+   etc += "/etc";
+#endif
+#if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
+   // on iOS etc does not exist and gitinfo resides in $ROOTSYS
+   etc = gRootDir;
+#endif
+   filename = gSystem->ConcatFileName(etc, gitinfo);
+#endif
 
    FILE *fp = fopen(filename, "r");
    if (fp) {
@@ -2576,9 +2587,17 @@ const char *TROOT::GetMacroPath()
 #endif
       if (macroPath.Length() == 0)
 #if !defined(R__WIN32)
-         macroPath = ".:" + TROOT::GetMacroDir();
+   #ifdef ROOTMACRODIR
+         macroPath = ".:" ROOTMACRODIR;
+   #else
+         macroPath = TString(".:") + gRootDir + "/macros";
+   #endif
 #else
-         macroPath = ".;" + TROOT::GetMacroDir();
+   #ifdef ROOTMACRODIR
+         macroPath = ".;" ROOTMACRODIR;
+   #else
+         macroPath = TString(".;") + gRootDir + "/macros";
+   #endif
 #endif
    }
 
@@ -2673,261 +2692,15 @@ const char**& TROOT::GetExtraInterpreterArgs() {
    return extraInterpArgs;
 }
 
-////////////////////////////////////////////////////////////////////////////////
-
-#ifdef ROOTPREFIX
-static Bool_t IgnorePrefix() {
-   static Bool_t ignorePrefix = gSystem->Getenv("ROOTIGNOREPREFIX");
-   return ignorePrefix;
-}
-#endif
-
-////////////////////////////////////////////////////////////////////////////////
-/// Get the rootsys directory in the installation. Static utility function.
-
-const TString& TROOT::GetRootSys() {
-#ifdef ROOTPREFIX
-   if (IgnorePrefix()) {
-#endif
-      static TString rootsys;
-      if (rootsys.IsNull())
-         rootsys = gSystem->Getenv("ROOTSYS");
-      if (rootsys.IsNull())
-         rootsys = gRootDir;
-      return rootsys;
-#ifdef ROOTPREFIX
-   } else {
-      const static TString rootsys = ROOTPREFIX;
-      return rootsys;
-   }
-#endif
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Get the binary directory in the installation. Static utility function.
-
-const TString& TROOT::GetBinDir() {
-#ifdef ROOTBINDIR
-   if (IgnorePrefix()) {
-#endif
-      static TString rootbindir;
-      if (rootbindir.IsNull()) {
-         rootbindir = "bin";
-         gSystem->PrependPathName(GetRootSys(), rootbindir);
-      }
-      return rootbindir;
-#ifdef ROOTBINDIR
-   } else {
-      const static TString rootbindir = ROOTBINDIR;
-      return rootbindir;
-   }
-#endif
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Get the library directory in the installation. Static utility function.
-
-const TString& TROOT::GetLibDir() {
-#ifdef ROOTLIBDIR
-   if (IgnorePrefix()) {
-#endif
-      static TString rootlibdir;
-      if (rootlibdir.IsNull()) {
-         rootlibdir = "lib";
-         gSystem->PrependPathName(GetRootSys(), rootlibdir);
-      }
-      return rootlibdir;
-#ifdef ROOTLIBDIR
-   } else {
-      const static TString rootlibdir = ROOTLIBDIR;
-      return rootlibdir;
-   }
-#endif
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Get the include directory in the installation. Static utility function.
-
-const TString& TROOT::GetIncludeDir() {
-#ifdef ROOTINCDIR
-   if (IgnorePrefix()) {
-#endif
-      static TString rootincdir;
-      if (rootincdir.IsNull()) {
-         rootincdir = "include";
-         gSystem->PrependPathName(GetRootSys(), rootincdir);
-      }
-      return rootincdir;
-#ifdef ROOTINCDIR
-   } else {
-      const static TString rootincdir = ROOTINCDIR;
-      return rootincdir;
-   }
-#endif
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Get the sysconfig directory in the installation. Static utility function.
-
-const TString& TROOT::GetEtcDir() {
-#ifdef ROOTETCDIR
-   if (IgnorePrefix()) {
-#endif
-      static TString rootetcdir;
-      if (rootetcdir.IsNull()) {
-         rootetcdir = "etc";
-         gSystem->PrependPathName(GetRootSys(), rootetcdir);
-      }
-      return rootetcdir;
-#ifdef ROOTETCDIR
-   } else {
-      const static TString rootetcdir = ROOTETCDIR;
-      return rootetcdir;
-   }
-#endif
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Get the data directory in the installation. Static utility function.
-
-const TString& TROOT::GetDataDir() {
-#ifdef ROOTDATADIR
-   if (IgnorePrefix()) {
-#endif
-      return GetRootSys();
-#ifdef ROOTDATADIR
-   } else {
-      const static TString rootdatadir = ROOTDATADIR;
-      return rootdatadir;
-   }
-#endif
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Get the documentation directory in the installation. Static utility function.
-
-const TString& TROOT::GetDocDir() {
-#ifdef ROOTDOCDIR
-   if (IgnorePrefix()) {
-#endif
-      return GetRootSys();
-#ifdef ROOTDOCDIR
-   } else {
-      const static TString rootdocdir = ROOTDOCDIR;
-      return rootdocdir;
-   }
-#endif
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Get the macro directory in the installation. Static utility function.
-
-const TString& TROOT::GetMacroDir() {
-#ifdef ROOTMACRODIR
-   if (IgnorePrefix()) {
-#endif
-      static TString rootmacrodir;
-      if (rootmacrodir.IsNull()) {
-         rootmacrodir = "macros";
-         gSystem->PrependPathName(GetRootSys(), rootmacrodir);
-      }
-      return rootmacrodir;
-#ifdef ROOTMACRODIR
-   } else {
-      const static TString rootmacrodir = ROOTMACRODIR;
-      return rootmacrodir;
-   }
-#endif
-}
-
 ////////////////////////////////////////////////////////////////////////////////
 /// Get the tutorials directory in the installation. Static utility function.
 
-const TString& TROOT::GetTutorialDir() {
-#ifdef ROOTTUTDIR
-   if (IgnorePrefix()) {
-#endif
-      static TString roottutdir;
-      if (roottutdir.IsNull()) {
-         roottutdir = "tutorials";
-         gSystem->PrependPathName(GetRootSys(), roottutdir);
-      }
-      return roottutdir;
+const char *TROOT::GetTutorialsDir()
+{
 #ifdef ROOTTUTDIR
-   } else {
-      const static TString roottutdir = ROOTTUTDIR;
-      return roottutdir;
-   }
-#endif
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Get the source directory in the installation. Static utility function.
-
-const TString& TROOT::GetSourceDir() {
-#ifdef ROOTSRCDIR
-   if (IgnorePrefix()) {
-#endif
-      static TString rootsrcdir;
-      if (rootsrcdir.IsNull()) {
-         rootsrcdir = "src";
-         gSystem->PrependPathName(GetRootSys(), rootsrcdir);
-      }
-      return rootsrcdir;
-#ifdef ROOTSRCDIR
-   } else {
-      const static TString rootsrcdir = ROOTSRCDIR;
-      return rootsrcdir;
-   }
-#endif
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Get the icon path in the installation. Static utility function.
-
-const TString& TROOT::GetIconPath() {
-#ifdef ROOTICONPATH
-   if (IgnorePrefix()) {
-#endif
-      static TString rooticonpath;
-      if (rooticonpath.IsNull()) {
-         rooticonpath = "icons";
-         gSystem->PrependPathName(GetRootSys(), rooticonpath);
-      }
-      return rooticonpath;
-#ifdef ROOTICONPATH
-   } else {
-      const static TString rooticonpath = ROOTICONPATH;
-      return rooticonpath;
-   }
-#endif
-}
-
-////////////////////////////////////////////////////////////////////////////////
-/// Get the fonts directory in the installation. Static utility function.
-
-const TString& TROOT::GetTTFFontDir() {
-#ifdef TTFFONTDIR
-   if (IgnorePrefix()) {
-#endif
-      static TString ttffontdir;
-      if (ttffontdir.IsNull()) {
-         ttffontdir = "fonts";
-         gSystem->PrependPathName(GetRootSys(), ttffontdir);
-      }
-      return ttffontdir;
-#ifdef TTFFONTDIR
-   } else {
-      const static TString ttffontdir = TTFFONTDIR;
-      return ttffontdir;
-   }
+   return ROOTTUTDIR;
+#else
+   static TString tutdir = TString(gRootDir) + "/tutorials";
+   return tutdir;
 #endif
 }
-
-////////////////////////////////////////////////////////////////////////////////
-/// Get the tutorials directory in the installation. Static utility function.
-/// Backward compatibility function - do not use for new code
-
-const char *TROOT::GetTutorialsDir() {
-   return GetTutorialDir();
-}
diff --git a/core/base/src/TSystem.cxx b/core/base/src/TSystem.cxx
index f5d2e850325..8538e44a77d 100644
--- a/core/base/src/TSystem.cxx
+++ b/core/base/src/TSystem.cxx
@@ -1911,10 +1911,22 @@ int TSystem::Load(const char *module, const char *entry, Bool_t system)
       if (!system) {
          // Mark the library in $ROOTSYS/lib as system.
          const char *dirname = DirName(path);
-         system = R__MatchFilename(TROOT::GetLibDir(), dirname);
+#ifdef ROOTLIBDIR
+         TString rootlibdir = ROOTLIBDIR;
+#else
+         TString rootlibdir = "lib";
+         PrependPathName(gRootDir, rootlibdir);
+#endif
+         system = R__MatchFilename(rootlibdir,dirname);
 
          if (!system) {
-            system = R__MatchFilename(TROOT::GetBinDir(), dirname);
+#ifdef ROOTBINDIR
+            TString rootbindir = ROOTBINDIR;
+#else
+            TString rootbindir = "bin";
+            PrependPathName(gRootDir, rootbindir);
+#endif
+            system = R__MatchFilename(rootbindir,dirname);
          }
       }
 
@@ -2566,9 +2578,12 @@ static void R__WriteDependencyFile(const TString &build_loc, const TString &depf
 #else
    TString touch = "echo > "; touch += "\"" + depfilename + "\"";
 #endif
-   TString builddep = "rmkdepend";
-   gSystem->PrependPathName(TROOT::GetBinDir(), builddep);
-   builddep += " \"-f";
+#ifdef ROOTBINDIR
+   TString builddep = ROOTBINDIR;
+#else
+   TString builddep = TString(gRootDir) + "/bin";
+#endif
+   builddep += "/rmkdepend \"-f";
    builddep += depfilename;
    builddep += "\" -o_" + extension + "." + gSystem->GetSoExt() + " ";
    if (build_loc.BeginsWith(gSystem->WorkingDirectory())) {
@@ -2590,7 +2605,12 @@ static void R__WriteDependencyFile(const TString &build_loc, const TString &depf
       builddep += "/\" ";
    }
    builddep += " -Y -- ";
-   TString rootsysInclude = TROOT::GetIncludeDir();
+#ifndef ROOTINCDIR
+   TString rootsysInclude = gSystem->Getenv("ROOTSYS");
+   rootsysInclude += "/include";
+#else
+   TString rootsysInclude = ROOTINCDIR;
+#endif
    builddep += " \"-I"+rootsysInclude+"\" "; // cflags
    builddep += includes;
    builddep += defines;
@@ -3421,17 +3441,27 @@ int TSystem::CompileMacro(const char *filename, Option_t *opt,
       TString name = ".rootmap";
       TString sname = "system.rootmap";
       TString file;
-      AssignAndDelete(file, ConcatFileName(TROOT::GetEtcDir(), sname) );
+#ifdef ROOTETCDIR
+      AssignAndDelete(file, ConcatFileName(ROOTETCDIR, sname) );
+#else
+      TString etc = gRootDir;
+#ifdef WIN32
+      etc += "\\etc";
+#else
+      etc += "/etc";
+#endif
+      AssignAndDelete(file, ConcatFileName(etc, sname));
       if (gSystem->AccessPathName(file)) {
          // for backward compatibility check also $ROOTSYS/system<name> if
          // $ROOTSYS/etc/system<name> does not exist
-         AssignAndDelete(file, ConcatFileName(TROOT::GetRootSys(), sname));
+         AssignAndDelete(file, ConcatFileName(gRootDir, sname));
          if (gSystem->AccessPathName(file)) {
             // for backward compatibility check also $ROOTSYS/<name> if
             // $ROOTSYS/system<name> does not exist
-            AssignAndDelete(file, ConcatFileName(TROOT::GetRootSys(), name));
+            AssignAndDelete(file, ConcatFileName(gRootDir, name));
          }
       }
+#endif
       mapfileStream << file << std::endl;
       AssignAndDelete(file, ConcatFileName(gSystem->HomeDirectory(), name) );
       mapfileStream << file << std::endl;
@@ -3445,9 +3475,23 @@ int TSystem::CompileMacro(const char *filename, Option_t *opt,
    mapfileStream.close();
 
    // ======= Generate the rootcling command line
-   TString rcling = "rootcling";
-   PrependPathName(TROOT::GetBinDir(), rcling);
-   rcling += " -v0 \"--lib-list-prefix=";
+   TString rcling;
+#ifndef ROOTBINDIR
+   rcling = gSystem->Getenv("ROOTSYS");
+#ifndef R__WIN32
+   rcling += "/bin/";
+#else
+   rcling += "\\bin\\";
+#endif
+#else
+   rcling = ROOTBINDIR;
+#ifndef R__WIN32
+   rcling += "/";
+#else
+   rcling += "\\";
+#endif
+#endif
+   rcling += "rootcling -v0 \"--lib-list-prefix=";
    rcling += mapfile;
    rcling += "\" -f \"";
    rcling.Append(dict).Append("\" -c -p ");
diff --git a/core/clingutils/res/TClingUtils.h b/core/clingutils/res/TClingUtils.h
index 1207dfb793f..f583b4978d9 100644
--- a/core/clingutils/res/TClingUtils.h
+++ b/core/clingutils/res/TClingUtils.h
@@ -334,6 +334,10 @@ clang::QualType AddDefaultParameters(clang::QualType instanceType,
 //______________________________________________________________________________
 llvm::StringRef DataMemberInfo__ValidArrayIndex(const clang::DeclaratorDecl &m, int *errnum = 0, llvm::StringRef  *errstr = 0);
 
+//______________________________________________________________________________
+// Return the ROOT include directory
+std::string GetROOTIncludeDir(bool rootbuild);
+
 enum class EIOCtorCategory : short {kAbsent, kDefault, kIOPtrType, kIORefType};
 
 //______________________________________________________________________________
@@ -539,6 +543,18 @@ clang::Module* declareModuleMap(clang::CompilerInstance* CI,
                                  const char* moduleFileName,
                                  const char* headers[]);
 
+//______________________________________________________________________________
+// Return the -I needed to find RuntimeUniverse.h
+std::string GetInterpreterExtraIncludePath(bool rootbuild);
+
+//______________________________________________________________________________
+// Return the LLVM / clang resource directory
+std::string GetLLVMResourceDir(bool rootbuild);
+
+//______________________________________________________________________________
+// Return the ROOT include directory
+std::string GetROOTIncludeDir(bool rootbuild);
+
 //______________________________________________________________________________
 // Return (in the argument 'output') a mangled version of the C++ symbol/type (pass as 'input')
 // that can be used in C++ as a variable name.
diff --git a/core/clingutils/src/TClingUtils.cxx b/core/clingutils/src/TClingUtils.cxx
index a86a66b0c83..24c1bb3ee05 100644
--- a/core/clingutils/src/TClingUtils.cxx
+++ b/core/clingutils/src/TClingUtils.cxx
@@ -3306,6 +3306,40 @@ void ROOT::TMetaUtils::GetFullyQualifiedTypeName(std::string &typenamestr,
                              interpreter.getCI()->getASTContext());
 }
 
+////////////////////////////////////////////////////////////////////////////////
+/// Return the -I needed to find RuntimeUniverse.h
+
+std::string ROOT::TMetaUtils::GetInterpreterExtraIncludePath(bool rootbuild)
+{
+#ifdef ROOTETCDIR
+   if (rootbuild) {
+      // Building ROOT, ignore ROOTETCDIR!
+#endif
+      const char* rootsys = getenv("ROOTSYS");
+      if (!rootsys) {
+         Error(0, "Environment variable ROOTSYS not set!\n");
+         return "-Ietc";
+      }
+      return std::string("-I") + rootsys + "/etc";
+#ifdef ROOTETCDIR
+   }
+   return std::string("-I") + ROOTETCDIR;
+#endif
+}
+
+////////////////////////////////////////////////////////////////////////////////
+/// Return the LLVM / clang resource directory
+
+std::string ROOT::TMetaUtils::GetLLVMResourceDir(bool rootbuild)
+{
+#ifdef R__EXTERN_LLVMDIR
+   return R__EXTERN_LLVMDIR;
+#else
+   return GetInterpreterExtraIncludePath(rootbuild)
+      .substr(2, std::string::npos) + "/cling";
+#endif
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 /// Get the template specialisation decl and template decl behind the qualtype
 /// Returns true if successfully found, false otherwise
@@ -3936,6 +3970,29 @@ clang::QualType ROOT::TMetaUtils::GetTypeForIO(const clang::QualType& thisType,
    return GetNameTypeForIO(thisType, interpreter, normCtxt, mode).second;
 }
 
+////////////////////////////////////////////////////////////////////////////////
+
+std::string ROOT::TMetaUtils::GetROOTIncludeDir(bool rootbuild)
+{
+   const std::string defaultInclude ("include");
+   if (!rootbuild) {
+#ifndef ROOTINCDIR
+      const char* rootSysContent = getenv("ROOTSYS");
+      if (rootSysContent) {
+         std::string incl_rootsys (rootSysContent);
+         return incl_rootsys + "/" + defaultInclude;
+      } else {
+         Error(0,"Environment variable ROOTSYS not set\n");
+         return defaultInclude;
+      }
+#else
+      return ROOTINCDIR;
+#endif
+   }
+
+   return defaultInclude;
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 /// Return the dictionary file name for a module
 
diff --git a/core/dictgen/res/rootcling_impl.h b/core/dictgen/res/rootcling_impl.h
index 19b2adc9b54..cbd1133cf92 100644
--- a/core/dictgen/res/rootcling_impl.h
+++ b/core/dictgen/res/rootcling_impl.h
@@ -19,12 +19,11 @@ namespace Internal {
 namespace RootCling {
    struct DriverConfig {
       bool fBuildingROOTStage1 = false;
+      std::string fLLVMResourceDir;
       const char** fPRootDir = nullptr;
 
       // Function that might (rootcling) or might not (rootcling_stage1) be there.
       const char ** * (*fTROOT__GetExtraInterpreterArgs)() = nullptr;
-      const char *(*fTROOT__GetIncludeDir)() = nullptr;
-      const char *(*fTROOT__GetEtcDir)() = nullptr;
       cling::Interpreter *(*fTCling__GetInterpreter)() = nullptr;
       void (*fInitializeStreamerInfoROOTFile)(const char *filename) = nullptr;
       void (*fAddStreamerInfoToROOTFile)(const char *normName) = nullptr;
diff --git a/core/dictgen/src/rootcling_impl.cxx b/core/dictgen/src/rootcling_impl.cxx
index cb010fe00f7..d54dd12dc77 100644
--- a/core/dictgen/src/rootcling_impl.cxx
+++ b/core/dictgen/src/rootcling_impl.cxx
@@ -270,6 +270,12 @@ const std::string gPathSeparator(ROOT::TMetaUtils::GetPathSeparator());
 bool gBuildingROOT = false;
 const ROOT::Internal::RootCling::DriverConfig* gDriverConfig = nullptr;
 
+#ifdef R__EXTERN_LLVMDIR
+# define R__LLVMDIR R__EXTERN_LLVMDIR
+#else
+# define R__LLVMDIR "./interpreter/llvm/inst" // only works for rootbuild for now!
+#endif
+
 namespace {
    // Copy-pasted from TClass.h We cannot #include TClass.h because we are compiling in -fno-rtti mode
    template <typename T> struct IsPointerTClassCopy {
@@ -699,7 +705,7 @@ void SetRootSys()
       if ((s = strrchr(ep, '/'))) {
          // $ROOTSYS/bin/rootcling
          int removesubdirs = 2;
-         if (!strncmp(s + 1, "rootcling_stage1", 16)) {
+         if (!strncmp(s + 1, "rootcling_stage1", 13)) {
             // $ROOTSYS/core/rootcling_stage1/src/rootcling_stage1
             removesubdirs = 4;
             gBuildingROOT = true;
@@ -3928,6 +3934,14 @@ int RootClingMain(int argc,
       clingArgs.push_back("-DG__VECTOR_HAS_CLASS_ITERATOR");
    }
 
+#if !defined(ROOTINCDIR)
+   if (!gBuildingROOT)
+      SetRootSys();
+#else
+   if (gBuildingROOT)
+      SetRootSys(); // Ignore install prefix
+#endif
+
    if (ic < argc && !strcmp(argv[ic], "-c")) {
       // Simply ignore the -c options.
       ic++;
@@ -4083,7 +4097,7 @@ int RootClingMain(int argc,
    }
 
    ic = nextStart;
-   clingArgs.push_back(std::string("-I") + gDriverConfig->fTROOT__GetIncludeDir());
+   clingArgs.push_back(std::string("-I") + TMetaUtils::GetROOTIncludeDir(gBuildingROOT));
 
    std::vector<std::string> pcmArgs;
    for (size_t parg = 0, n = clingArgs.size(); parg < n; ++parg) {
@@ -4107,7 +4121,7 @@ int RootClingMain(int argc,
    }
 
    // cling-only arguments
-   clingArgs.push_back(std::string("-I") + gDriverConfig->fTROOT__GetEtcDir());
+   clingArgs.push_back(TMetaUtils::GetInterpreterExtraIncludePath(gBuildingROOT));
    // We do not want __ROOTCLING__ in the pch!
    if (!onepcm) {
       clingArgs.push_back("-D__ROOTCLING__");
@@ -4132,9 +4146,11 @@ int RootClingMain(int argc,
    }
 
 #ifdef R__EXTERN_LLVMDIR
-   std::string resourceDir = R__EXTERN_LLVMDIR;
+   std::string resourceDir = R__EXTERN_LLVMDIR ;
 #else
-   std::string resourceDir = std::string(gDriverConfig->fTROOT__GetEtcDir()) + "/cling";
+   std::string resourceDir = gDriverConfig->fLLVMResourceDir;
+   if (resourceDir.empty())
+      resourceDir = TMetaUtils::GetLLVMResourceDir(gBuildingROOT);
 #endif
 
    std::unique_ptr<cling::Interpreter> owningInterpPtr;
@@ -4185,6 +4201,11 @@ int RootClingMain(int argc,
 
    interp.getOptions().ErrorOut = true;
    interp.enableRawInput(true);
+#ifdef ROOTINCDIR
+   const bool useROOTINCDIR = !gBuildingROOT;
+#else
+   const bool useROOTINCDIR = false;
+#endif
    if (isGenreflex) {
       if (interp.declare("namespace std {} using namespace std;") != cling::Interpreter::kSuccess) {
          // There was an error.
@@ -4200,10 +4221,17 @@ int RootClingMain(int argc,
                               "#include <stddef.h>\n"
                               "#include <string.h>\n"
                              ) != cling::Interpreter::kSuccess
-            || interp.declare("#include \"Rtypes.h\"\n"
-                              "#include \"TClingRuntime.h\"\n"
-                              "#include \"TObject.h\""
-                             ) != cling::Interpreter::kSuccess
+            || (!useROOTINCDIR
+                && interp.declare("#include \"Rtypes.h\"\n"
+                                  "#include \"TClingRuntime.h\"\n"
+                                  "#include \"TObject.h\"") != cling::Interpreter::kSuccess)
+#ifdef ROOTINCDIR
+            || (useROOTINCDIR
+                && interp.declare("#include \"" ROOTINCDIR "/Rtypes.h\"\n"
+                                  "#include \"" ROOTINCDIR "/TClingRuntime.h\"\n"
+                                  "#include \"" ROOTINCDIR "/TObject.h\"") != cling::Interpreter::kSuccess
+               )
+#endif
          ) {
          // There was an error.
          ROOT::TMetaUtils::Error(0, "Error loading the default header files.\n");
diff --git a/core/meta/src/TClass.cxx b/core/meta/src/TClass.cxx
index 709e8139f14..6bc024cb52b 100644
--- a/core/meta/src/TClass.cxx
+++ b/core/meta/src/TClass.cxx
@@ -1722,7 +1722,17 @@ Int_t TClass::ReadRules()
 {
    static const char *suffix = "class.rules";
    TString sname = suffix;
-   gSystem->PrependPathName(TROOT::GetEtcDir(), sname);
+#ifdef ROOTETCDIR
+   gSystem->PrependPathName(ROOTETCDIR, sname);
+#else
+   TString etc = gRootDir;
+#ifdef WIN32
+   etc += "\\etc";
+#else
+   etc += "/etc";
+#endif
+   gSystem->PrependPathName(etc, sname);
+#endif
 
    Int_t res = -1;
 
diff --git a/core/metacling/res/rootclingTCling.h b/core/metacling/res/rootclingTCling.h
index 0623bea5e0c..80b3b731c22 100644
--- a/core/metacling/res/rootclingTCling.h
+++ b/core/metacling/res/rootclingTCling.h
@@ -27,7 +27,5 @@ namespace cling {
 
 extern "C" {
    R__DLLEXPORT const char ** *TROOT__GetExtraInterpreterArgs();
-   R__DLLEXPORT const char *TROOT__GetIncludeDir();
-   R__DLLEXPORT const char *TROOT__GetEtcDir();
    R__DLLEXPORT cling::Interpreter *TCling__GetInterpreter();
 }
diff --git a/core/metacling/src/TCling.cxx b/core/metacling/src/TCling.cxx
index 5d7a1a15aba..363ed7ab259 100644
--- a/core/metacling/src/TCling.cxx
+++ b/core/metacling/src/TCling.cxx
@@ -1057,26 +1057,27 @@ TCling::TCling(const char *name, const char *title)
    std::vector<std::string> clingArgsStorage;
    clingArgsStorage.push_back("cling4root");
 
+   std::string interpInclude;
    // rootcling sets its arguments through TROOT::GetExtraInterpreterArgs().
    if (!fromRootCling) {
       ROOT::TMetaUtils::SetPathsForRelocatability(clingArgsStorage);
 
       // Add -I early so ASTReader can find the headers.
-      std::string interpInclude(TROOT::GetEtcDir());
-      clingArgsStorage.push_back("-I" + interpInclude);
+      std::string interpInclude = ROOT::TMetaUtils::GetInterpreterExtraIncludePath(false);
+      clingArgsStorage.push_back(interpInclude);
 
       // Add include path to etc/cling. FIXME: This is a short term solution. The
       // llvm/clang header files shouldn't be there at all. We have to get rid of
       // that dependency and avoid copying the header files.
-      clingArgsStorage.push_back("-I" + interpInclude + "/cling");
+      clingArgsStorage.push_back(interpInclude + "/cling");
 
       // Add the root include directory and etc/ to list searched by default.
-      clingArgsStorage.push_back(std::string("-I" + TROOT::GetIncludeDir()));
+      clingArgsStorage.push_back(std::string("-I") + ROOT::TMetaUtils::GetROOTIncludeDir(false));
 
       // Add the current path to the include path
       // TCling::AddIncludePath(".");
 
-      std::string pchFilename = interpInclude + "/allDict.cxx.pch";
+      std::string pchFilename = interpInclude.substr(2) + "/allDict.cxx.pch";
       if (gSystem->Getenv("ROOT_PCH")) {
          pchFilename = gSystem->Getenv("ROOT_PCH");
       }
@@ -1095,11 +1096,7 @@ TCling::TCling(const char *name, const char *title)
            eArg = clingArgsStorage.end(); iArg != eArg; ++iArg)
       interpArgs.push_back(iArg->c_str());
 
-#ifdef R__EXTERN_LLVMDIR
-   TString llvmResourceDir = R__EXTERN_LLVMDIR;
-#else
-   TString llvmResourceDir = TROOT::GetEtcDir() + "/cling";
-#endif
+   std::string llvmResourceDir = ROOT::TMetaUtils::GetLLVMResourceDir(false);
    // Add statically injected extra arguments, usually coming from rootcling.
    for (const char** extraArgs = TROOT::GetExtraInterpreterArgs();
         extraArgs && *extraArgs; ++extraArgs) {
@@ -1113,7 +1110,7 @@ TCling::TCling(const char *name, const char *title)
 
    fInterpreter = new cling::Interpreter(interpArgs.size(),
                                          &(interpArgs[0]),
-                                         llvmResourceDir);
+                                         llvmResourceDir.c_str());
 
    if (!fromRootCling) {
       fInterpreter->installLazyFunctionCreator(llvmLazyFunctionCreator);
@@ -4723,7 +4720,21 @@ void TCling::InitRootmapFile(const char *name)
 
    TString sname = "system";
    sname += name;
-   char *s = gSystem->ConcatFileName(TROOT::GetEtcDir(), sname);
+#ifdef ROOTETCDIR
+   char *s = gSystem->ConcatFileName(ROOTETCDIR, sname);
+#else
+   TString etc = gRootDir;
+#ifdef WIN32
+   etc += "\\etc";
+#else
+   etc += "/etc";
+#endif
+#if defined(R__MACOSX) && (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
+   // on iOS etc does not exist and system<name> resides in $ROOTSYS
+   etc = gRootDir;
+#endif
+   char *s = gSystem->ConcatFileName(etc, sname);
+#endif
 
    Int_t ret = ReadRootmapFile(s);
    if (ret == -3) // old format
diff --git a/core/metacling/src/rootclingTCling.cxx b/core/metacling/src/rootclingTCling.cxx
index c75912fe174..a534005be48 100644
--- a/core/metacling/src/rootclingTCling.cxx
+++ b/core/metacling/src/rootclingTCling.cxx
@@ -29,18 +29,6 @@ const char ** *TROOT__GetExtraInterpreterArgs()
   return &TROOT::GetExtraInterpreterArgs();
 }
 
-extern "C"
-const char *TROOT__GetIncludeDir()
-{
-   return TROOT::GetIncludeDir();
-}
-
-extern "C"
-const char *TROOT__GetEtcDir()
-{
-   return TROOT::GetEtcDir();
-}
-
 extern "C"
 cling::Interpreter *TCling__GetInterpreter()
 {
diff --git a/core/rint/src/TRint.cxx b/core/rint/src/TRint.cxx
index a7c653bbf7f..a6cfa6824da 100644
--- a/core/rint/src/TRint.cxx
+++ b/core/rint/src/TRint.cxx
@@ -304,7 +304,17 @@ void TRint::ExecLogon()
    TString name = ".rootlogon.C";
    TString sname = "system";
    sname += name;
-   char *s = gSystem->ConcatFileName(TROOT::GetEtcDir(), sname);
+#ifdef ROOTETCDIR
+   char *s = gSystem->ConcatFileName(ROOTETCDIR, sname);
+#else
+   TString etc = gRootDir;
+#ifdef WIN32
+   etc += "\\etc";
+#else
+   etc += "/etc";
+#endif
+   char *s = gSystem->ConcatFileName(etc, sname);
+#endif
    if (!gSystem->AccessPathName(s, kReadPermission)) {
       ProcessFile(s);
    }
diff --git a/core/rint/src/TTabCom.cxx b/core/rint/src/TTabCom.cxx
index 7c57bb10ce5..fb4751bd643 100644
--- a/core/rint/src/TTabCom.cxx
+++ b/core/rint/src/TTabCom.cxx
@@ -1671,7 +1671,8 @@ Int_t TTabCom::Hook(char *buf, int *pLoc, std::ostream& out)
    case kROOT_Load:
       {
          const TString fileName = s3("[^\"]*$");
-         const TString dynamicPath = DeterminePath(fileName, gSystem->GetDynamicPath());
+//             const TString  dynamicPath  = DeterminePath( fileName, TROOT::GetDynamicPath() ); /* should use this one */
+         const TString dynamicPath = DeterminePath(fileName,gEnv->GetValue("Root.DynamicPath",(char *) 0));
          const TSeqCollection *pListOfFiles = GetListOfFilesInPath(dynamicPath);
 
 //             pos = Complete( "[^\"/]*$", pListOfFiles, "\");", out);
diff --git a/core/rootcling_stage1/CMakeLists.txt b/core/rootcling_stage1/CMakeLists.txt
index eefb2a4a35b..c5e32b4370c 100644
--- a/core/rootcling_stage1/CMakeLists.txt
+++ b/core/rootcling_stage1/CMakeLists.txt
@@ -4,20 +4,26 @@
 
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../dictgen/res)
 
+set(ROOTCLING1TMPSRC ${CMAKE_CURRENT_BINARY_DIR}/rootcling_stage1_out.cxx)
+
+set(R__LLVMRESOURCEDIR ${CMAKE_BINARY_DIR}/etc/cling)
+configure_file(src/rootcling_stage1.cxx ${ROOTCLING1TMPSRC} @ONLY)
+
 if(WIN32)
-  set_source_files_properties(src/rootcling_stage1.cxx PROPERTIES COMPILE_FLAGS "-D_WIN32 -DNOMINMAX")
+  set_source_files_properties(${ROOTCLING1TMPSRC} PROPERTIES COMPILE_FLAGS "-D_WIN32 -DNOMINMAX -DR__HAVE_LLVMRESOURCEDIR")
 else()
   if(CXX_HAS_fno_rtti)
-    set_source_files_properties(src/rootcling_stage1.cxx PROPERTIES COMPILE_FLAGS "-fno-rtti")
+    set_source_files_properties(${ROOTCLING1TMPSRC} PROPERTIES COMPILE_FLAGS "-DR__HAVE_LLVMRESOURCEDIR -fno-rtti")
+  else()
+    set_source_files_properties(${ROOTCLING1TMPSRC} PROPERTIES COMPILE_FLAGS "-DR__HAVE_LLVMRESOURCEDIR")
   endif()
 endif()
 
-ROOT_EXECUTABLE(rootcling_stage1 src/rootcling_stage1.cxx
+ROOT_EXECUTABLE(rootcling_stage1 ${ROOTCLING1TMPSRC}
                               $<TARGET_OBJECTS:Clib>
                               $<TARGET_OBJECTS:ClingUtils>
                               $<TARGET_OBJECTS:Dictgen>
                               $<TARGET_OBJECTS:Foundation_Stage1>
                               LIBRARIES ${CLING_LIBRARIES}  ${CMAKE_DL_LIBS} ${CMAKE_THREAD_LIBS_INIT}
                               NOINSTALL)
-set_target_properties(rootcling_stage1 PROPERTIES RUNTIME_OUTPUT_DIRECTORY src)
 add_dependencies(rootcling_stage1 CLING LLVMRES)
diff --git a/core/rootcling_stage1/ModuleVars.mk b/core/rootcling_stage1/ModuleVars.mk
index 86dbaaf18e4..5ae9a98a641 100644
--- a/core/rootcling_stage1/ModuleVars.mk
+++ b/core/rootcling_stage1/ModuleVars.mk
@@ -8,8 +8,8 @@ ifneq ($(HOST),)
 ROOTCLING1DIRS  := $(BUILDTOOLSDIR)/core/rootcling_stage1/src
 
 ROOTCLING1S     := $(ROOTCLING1DIRS)/rootcling_stage1.cxx
-ROOTCLING1O     := $(ROOTCLING1S:.cxx=.o)
-ROOTCLING1EXE   := $(UTILSDIRS)/rootcling_stage1$(EXEEXT)
+ROOTCLING1O     := $(call stripsrc,$(ROOTCLING1S:.cxx=.o))
+ROOTCLING1EXE   := $(call stripsrc,$(UTILSDIRS)/rootcling_stage1$(EXEEXT))
 ROOTCLINGSTAGE1 := $(ROOTCLING1EXE)
 
 ##### Dependencies for all dictionaries
diff --git a/core/rootcling_stage1/src/rootcling_stage1.cxx b/core/rootcling_stage1/src/rootcling_stage1.cxx
index 44f83c0d315..cae40d990c3 100644
--- a/core/rootcling_stage1/src/rootcling_stage1.cxx
+++ b/core/rootcling_stage1/src/rootcling_stage1.cxx
@@ -11,7 +11,6 @@
 #include "rootcling_impl.h"
 #include "RConfigure.h"
 #include "RConfig.h"
-#include <stdlib.h>
 
 extern "C" {
    R__DLLEXPORT void usedToIdentifyRootClingByDlSym() {}
@@ -20,16 +19,6 @@ extern "C" {
 
 ROOT::Internal::RootCling::TROOTSYSSetter gROOTSYSSetter;
 
-static const char *GetIncludeDir() {
-   static std::string incdir = std::string(getenv("ROOTSYS")) + "/include";
-   return incdir.c_str();
-}
-
-static const char *GetEtcDir() {
-   static std::string etcdir = std::string(getenv("ROOTSYS")) + "/etc";
-   return etcdir.c_str();
-}
-
 int main(int argc, char **argv)
 {
    // Force the emission of the symbol - the compiler cannot know that argv
@@ -40,10 +29,15 @@ int main(int argc, char **argv)
    }
 
    ROOT::Internal::RootCling::DriverConfig config{};
+#ifdef R__HAVE_LLVMRESOURCEDIR
+   // This is ignored (in rootcling_impl.cxx) if R__EXTERN_LLVMDIR is defined.
+   // This is not configured (i.e. R__HAVE_LLVMRESOURCEDIR is undefined) for
+   // configure / make; the resource directory is instead determined by
+   // TMetaUtils::GetLLVMResourceDir() in rootcling_impl.cxx.
+   config.fLLVMResourceDir= "@R__LLVMRESOURCEDIR@";
+#endif
 
    config.fBuildingROOTStage1 = true;
-   config.fTROOT__GetIncludeDir = &GetIncludeDir;
-   config.fTROOT__GetEtcDir = &GetEtcDir;
 
    return ROOT_rootcling_Driver(argc, argv, config);
 }
diff --git a/core/unix/src/TUnixSystem.cxx b/core/unix/src/TUnixSystem.cxx
index ec21121ca98..d6d7a7668f9 100644
--- a/core/unix/src/TUnixSystem.cxx
+++ b/core/unix/src/TUnixSystem.cxx
@@ -458,9 +458,7 @@ static const char *GetExePath()
 
 static void SetRootSys()
 {
-#ifdef ROOTPREFIX
-   if (gSystem->Getenv("ROOTIGNOREPREFIX")) {
-#endif
+#ifndef ROOTPREFIX
    void *addr = (void *)SetRootSys;
    Dl_info info;
    if (dladdr(addr, &info) && info.dli_fname && info.dli_fname[0]) {
@@ -473,8 +471,8 @@ static void SetRootSys()
          gSystem->Setenv("ROOTSYS", gSystem->DirName(rs));
       }
    }
-#ifdef ROOTPREFIX
-   }
+#else
+   return;
 #endif
 }
 #endif
@@ -502,9 +500,7 @@ static void DylibAdded(const struct mach_header *mh, intptr_t /* vmaddr_slide */
    TRegexp sovers = "libCore\\.[0-9]+\\.*[0-9]*\\.so";
    TRegexp dyvers = "libCore\\.[0-9]+\\.*[0-9]*\\.dylib";
 
-#ifdef ROOTPREFIX
-   if (gSystem->Getenv("ROOTIGNOREPREFIX")) {
-#endif
+#ifndef ROOTPREFIX
 #if TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR
    // first loaded is the app so set ROOTSYS to app bundle
    if (i == 1) {
@@ -530,8 +526,6 @@ static void DylibAdded(const struct mach_header *mh, intptr_t /* vmaddr_slide */
       }
    }
 #endif
-#ifdef ROOTPREFIX
-   }
 #endif
 
    // when libSystem.B.dylib is loaded we have finished loading all dylibs
@@ -619,8 +613,13 @@ Bool_t TUnixSystem::Init()
    SetRootSys();
 #endif
 
-   // This is a fallback in case TROOT::GetRootSys() can't determine ROOTSYS
-   gRootDir = "/usr/local/root";
+#ifndef ROOTPREFIX
+   gRootDir = Getenv("ROOTSYS");
+   if (gRootDir == 0)
+      gRootDir= "/usr/local/root";
+#else
+   gRootDir = ROOTPREFIX;
+#endif
 
    return kFALSE;
 }
@@ -2255,17 +2254,22 @@ void TUnixSystem::StackTrace()
       if (AccessPathName(gdbscript, kReadPermission)) {
          fprintf(stderr, "Root.StacktraceScript %s does not exist\n", gdbscript.Data());
          gdbscript = "";
+      } else {
+         gdbscript += " ";
       }
    }
    if (gdbscript == "") {
-      gdbscript = "gdb-backtrace.sh";
-      gSystem->PrependPathName(TROOT::GetEtcDir(), gdbscript);
+#ifdef ROOTETCDIR
+      gdbscript.Form("%s/gdb-backtrace.sh", ROOTETCDIR);
+#else
+      gdbscript.Form("%s/etc/gdb-backtrace.sh", Getenv("ROOTSYS"));
+#endif
       if (AccessPathName(gdbscript, kReadPermission)) {
          fprintf(stderr, "Error in <TUnixSystem::StackTrace> script %s is missing\n", gdbscript.Data());
          return;
       }
+      gdbscript += " ";
    }
-   gdbscript += " ";
 
    TString gdbmess = gEnv->GetValue("Root.StacktraceMessage", "");
    gdbmess = gdbmess.Strip();
@@ -4612,7 +4616,11 @@ static const char *DynamicPath(const char *newpath = 0, Bool_t reset = kFALSE)
       TString rdynpath = gEnv->GetValue("Root.DynamicPath", (char*)0);
       rdynpath.ReplaceAll(": ", ":");  // in case DynamicPath was extended
       if (rdynpath.IsNull()) {
-         rdynpath = ".:"; rdynpath += TROOT::GetLibDir();
+#ifdef ROOTLIBDIR
+         rdynpath = ".:"; rdynpath += ROOTLIBDIR;
+#else
+         rdynpath = ".:"; rdynpath += gRootDir; rdynpath += "/lib";
+#endif
       }
       TString ldpath;
 #if defined (R__AIX)
@@ -4633,9 +4641,16 @@ static const char *DynamicPath(const char *newpath = 0, Bool_t reset = kFALSE)
       else {
          dynpath = ldpath; dynpath += ":"; dynpath += rdynpath;
       }
-      if (!dynpath.Contains(TROOT::GetLibDir())) {
-         dynpath += ":"; dynpath += TROOT::GetLibDir();
+
+#ifdef ROOTLIBDIR
+      if (!dynpath.Contains(ROOTLIBDIR)) {
+         dynpath += ":"; dynpath += ROOTLIBDIR;
       }
+#else
+      if (!dynpath.Contains(TString::Format("%s/lib", gRootDir))) {
+         dynpath += ":"; dynpath += gRootDir; dynpath += "/lib";
+      }
+#endif
       if (gCling) {
          dynpath += ":"; dynpath += gCling->GetSTLIncludePath();
       } else
diff --git a/core/winnt/src/TWinNTSystem.cxx b/core/winnt/src/TWinNTSystem.cxx
index af673895494..ad36e2da8a7 100644
--- a/core/winnt/src/TWinNTSystem.cxx
+++ b/core/winnt/src/TWinNTSystem.cxx
@@ -362,7 +362,11 @@ namespace {
          TString rdynpath = gEnv ? gEnv->GetValue("Root.DynamicPath", (char*)0) : "";
          rdynpath.ReplaceAll("; ", ";");  // in case DynamicPath was extended
          if (rdynpath == "") {
-            rdynpath = ".;"; rdynpath += TROOT::GetBinDir();
+#ifdef ROOTBINDIR
+            rdynpath = ".;"; rdynpath += ROOTBINDIR;
+#else
+            rdynpath = ".;"; rdynpath += gRootDir; rdynpath += "/bin";
+#endif
          }
          TString path = gSystem->Getenv("PATH");
          if (path == "")
@@ -372,10 +376,15 @@ namespace {
          }
 
       }
-
-      if (!dynpath.Contains(TROOT::GetLibDir())) {
-         dynpath += ";"; dynpath += TROOT::GetLibDir();
+#ifdef ROOTLIBDIR
+      if (!dynpath.Contains(ROOTLIBDIR)) {
+         dynpath += ";"; dynpath += ROOTLIBDIR;
+      }
+#else
+      if (!dynpath.Contains(TString::Format("%s/lib", gRootDir))) {
+         dynpath += ";"; dynpath += gRootDir; dynpath += "/lib";
       }
+#endif
 
       return dynpath;
    }
@@ -814,8 +823,16 @@ namespace {
       }
 
       // determine the fileopen.C file path:
-      TString fileopen = "fileopen.C";
-      gSystem->PrependPathName(TROOT::GetMacroDir(), fileopen);
+      TString fileopen;
+#ifndef ROOT_PREFIX
+      fileopen += sys->TWinNTSystem::DriveName(buf);
+      fileopen += ":";
+      fileopen += sys->TWinNTSystem::DirName(sys->TWinNTSystem::DirName(buf));
+      fileopen += "\\macros";
+#else
+      fileopen += ROOTMACRODIR;
+#endif
+      fileopen += "\\fileopen.C";
 
       if (regROOTwrite) {
          // only write to registry if fileopen.C is readable
@@ -990,9 +1007,7 @@ fGUIThreadHandle(0), fGUIThreadId(0)
 
    char *buf = new char[MAX_MODULE_NAME32 + 1];
 
-#ifdef ROOTPREFIX
-   if (gSystem->Getenv("ROOTIGNOREPREFIX") {
-#endif
+#ifndef ROOTPREFIX
    // set ROOTSYS
    HMODULE hModCore = ::GetModuleHandle("libCore.dll");
    if (hModCore) {
@@ -1020,8 +1035,6 @@ fGUIThreadHandle(0), fGUIThreadId(0)
          }
       }
    }
-#ifdef ROOTPREFIX
-   }
 #endif
 
    UpdateRegistry(this, buf);
@@ -1099,17 +1112,23 @@ Bool_t TWinNTSystem::Init()
 
    fSigcnt = 0;
 
-   // This is a fallback in case TROOT::GetRootSys() can't determine ROOTSYS
-   static char lpFilename[MAX_PATH];
-   if (::GetModuleFileName(
-          NULL,                   // handle to module to find filename for
-          lpFilename,             // pointer to buffer to receive module path
-          sizeof(lpFilename))) {  // size of buffer, in characters
-      const char *dirName = DirName(DirName(lpFilename));
-      gRootDir = StrDup(dirName);
-   } else {
-      gRootDir = 0;
+#ifndef ROOTPREFIX
+   gRootDir = Getenv("ROOTSYS");
+   if (gRootDir == 0) {
+      static char lpFilename[MAX_PATH];
+      if (::GetModuleFileName(NULL,               // handle to module to find filename for
+                            lpFilename,           // pointer to buffer to receive module path
+                            sizeof(lpFilename)))  // size of buffer, in characters
+      {
+         const char *dirName = DirName(DirName(lpFilename));
+         gRootDir = StrDup(dirName);
+      } else {
+         gRootDir = 0;
+      }
    }
+#else
+   gRootDir= ROOTPREFIX;
+#endif
 
    // Increase the accuracy of Sleep() without needing to link to winmm.lib
    typedef UINT (WINAPI* LPTIMEBEGINPERIOD)( UINT uPeriod );
diff --git a/core/zip/CMakeLists.txt b/core/zip/CMakeLists.txt
index 2ab3b3a669b..e23ab045e1e 100644
--- a/core/zip/CMakeLists.txt
+++ b/core/zip/CMakeLists.txt
@@ -22,7 +22,6 @@ set(ZLIB_SRCS ${ZipOldSource} ${CMAKE_CURRENT_SOURCE_DIR}/src/Compression.cxx ${
 # Define all the header files which should be installed when
 # doing a "make install"
 install(FILES ${ZLIB_HEADERS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT headers)
-file(COPY ${ZLIB_HEADERS} DESTINATION ${CMAKE_BINARY_DIR}/include)
 set_property(GLOBAL APPEND PROPERTY ROOT_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/inc)
 
 ROOT_OBJECT_LIBRARY(Zip ${ZLIB_SRCS})
diff --git a/documentation/doxygen/converttonotebook.py b/documentation/doxygen/converttonotebook.py
index 5e40cdb766d..3b3f6e501e9 100755
--- a/documentation/doxygen/converttonotebook.py
+++ b/documentation/doxygen/converttonotebook.py
@@ -601,7 +601,7 @@ def declareNamespace(code):
 def rs401dGetFiles(code):
     if tutName == "rs401d_FeldmanCousins":
         code = code.replace(
-         """#if !defined(__CINT__) || defined(__MAKECINT__)\n#include "../tutorials/roostats/NuMuToNuE_Oscillation.h"\n#include "../tutorials/roostats/NuMuToNuE_Oscillation.cxx" // so that it can be executed directly\n#else\n#include "../tutorials/roostats/NuMuToNuE_Oscillation.cxx+" // so that it can be executed directly\n#endif""" , """TString tutDir = gROOT->GetTutorialDir();\nTString headerDir = TString::Format("#include \\\"%s/roostats/NuMuToNuE_Oscillation.h\\\"", tutDir.Data());\nTString impDir = TString::Format("#include \\\"%s/roostats/NuMuToNuE_Oscillation.cxx\\\"", tutDir.Data());\ngROOT->ProcessLine(headerDir);\ngROOT->ProcessLine(impDir);""")
+         """#if !defined(__CINT__) || defined(__MAKECINT__)\n#include "../tutorials/roostats/NuMuToNuE_Oscillation.h"\n#include "../tutorials/roostats/NuMuToNuE_Oscillation.cxx" // so that it can be executed directly\n#else\n#include "../tutorials/roostats/NuMuToNuE_Oscillation.cxx+" // so that it can be executed directly\n#endif""" , """std::string tutDir = gROOT->GetTutorialsDir();\nTString headerDir = TString::Format("#include \\\"%s/roostats/NuMuToNuE_Oscillation.h\\\"", tutDir.c_str());\nTString impDir = TString::Format("#include \\\"%s/roostats/NuMuToNuE_Oscillation.cxx\\\"", tutDir.c_str());\ngROOT->ProcessLine(headerDir);\ngROOT->ProcessLine(impDir);""")
     return code
 
 
diff --git a/geom/geom/src/TGeoElement.cxx b/geom/geom/src/TGeoElement.cxx
index 633328f62e0..ef82ca891cc 100644
--- a/geom/geom/src/TGeoElement.cxx
+++ b/geom/geom/src/TGeoElement.cxx
@@ -39,7 +39,6 @@ Table of elements
 #include "Riostream.h"
 
 #include "TSystem.h"
-#include "TROOT.h"
 #include "TObjArray.h"
 #include "TVirtualGeoPainter.h"
 #include "TGeoManager.h"
@@ -1129,8 +1128,12 @@ void TGeoElementTable::ImportElementsRN()
 {
    if (HasRNElements()) return;
    TGeoElementRN *elem;
-   TString rnf = "RadioNuclides.txt";
-   gSystem->PrependPathName(TROOT::GetEtcDir(), rnf);
+   TString rnf;
+#ifdef ROOTETCDIR
+   rnf.Form("%s/RadioNuclides.txt", ROOTETCDIR);
+#else
+   rnf.Form("%s/etc/RadioNuclides.txt", gSystem->Getenv("ROOTSYS"));
+#endif
    FILE *fp = fopen(rnf, "r");
    if (!fp) {
       Error("ImportElementsRN","File RadioNuclides.txt not found");
diff --git a/graf2d/asimage/src/TASImage.cxx b/graf2d/asimage/src/TASImage.cxx
index 9b22b97a65c..d3a4127face 100644
--- a/graf2d/asimage/src/TASImage.cxx
+++ b/graf2d/asimage/src/TASImage.cxx
@@ -360,33 +360,33 @@ TASImage::~TASImage()
 
 static void init_icon_paths()
 {
-   TString icon_path = gEnv->GetValue("Gui.IconPath", "");
-   if (icon_path.IsNull()) {
-      icon_path = "icons";
-      gSystem->PrependPathName(gSystem->HomeDirectory(), icon_path);
-#ifndef R__WIN32
-      icon_path = ".:" + icon_path + ":" + TROOT::GetIconPath() + ":" + EXTRAICONPATH;
-#else
-      icon_path = ".;" + icon_path + ";" + TROOT::GetIconPath() + ";" + EXTRAICONPATH;
+   const char *icons = "/icons";
+#ifdef R__WIN32
+      icons = "\\icons";
 #endif
-   }
 
-   Int_t cnt = 0;
-   Ssiz_t from = 0;
-   TString token;
-#ifndef R__WIN32
-   const char *delim = "/";
-#else
-   const char *delim = "\\";
+   TString homeIcons = gSystem->HomeDirectory();
+   homeIcons += icons;
+
+   TString rootIcons = gSystem->Getenv("ROOTSYS");
+   rootIcons += icons;
+
+   TString guiIcons = gEnv->GetValue("Gui.IconPath", "");
+
+   gIconPaths[0] = StrDup(".");
+   gIconPaths[1] = StrDup(homeIcons.Data());
+   gIconPaths[2] = StrDup(rootIcons.Data());
+   gIconPaths[3] = StrDup(guiIcons.Data());
+
+#ifdef ROOTICONPATH
+   gIconPaths[4] = StrDup(ROOTICONPATH);
 #endif
-   while (icon_path.Tokenize(token, from, delim) && cnt < 6) {
-      char *path = gSystem->ExpandPathName(token.Data());
-      if (path) {
-         gIconPaths[cnt] = path;
-         cnt++;
-      }
-   }
-   gIconPaths[cnt] = 0;
+
+#ifdef EXTRAICONPATH
+   gIconPaths[5] = StrDup(EXTRAICONPATH);
+#endif
+
+   gIconPaths[6] = 0;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -2595,19 +2595,14 @@ void TASImage::DrawText(Int_t x, Int_t y, const char *text, Int_t size,
 
    TString fn = font_name;
    fn.Strip();
-
-   // This is for backward compatibility...
-   if (fn.Last('/') == 0) fn = fn(1, fn.Length() - 1);
-
-   const char *ttpath = gEnv->GetValue("Root.TTFontPath",
-                                       TROOT::GetTTFFontDir());
-   char *tmpstr = gSystem->Which(ttpath, fn, kReadPermission);
-   fn = tmpstr;
-   delete [] tmpstr;
+   char *tmpstr = 0;
 
    if (fn.EndsWith(".pfa") || fn.EndsWith(".PFA") || fn.EndsWith(".pfb") || fn.EndsWith(".PFB") || fn.EndsWith(".ttf") || fn.EndsWith(".TTF") || fn.EndsWith(".otf") || fn.EndsWith(".OTF")) {
+      tmpstr = gSystem->ExpandPathName(fn.Data());
+      fn = tmpstr;
       ttfont = kTRUE;
    }
+   delete [] tmpstr;
 
    if (color) {
       parse_argb_color(color, &text_color);
diff --git a/graf2d/cocoa/src/QuartzWindow.mm b/graf2d/cocoa/src/QuartzWindow.mm
index a44aed24ef5..9a4f6044a43 100644
--- a/graf2d/cocoa/src/QuartzWindow.mm
+++ b/graf2d/cocoa/src/QuartzWindow.mm
@@ -40,7 +40,6 @@
 #include "TGClient.h"
 #include "TSystem.h"
 #include "TGCocoa.h"
-#include "TROOT.h"
 
 
 namespace ROOT {
@@ -808,7 +807,11 @@ NSCursor *CreateCustomCursor(ECursor currentCursor)
    }
 
    if (pngFileName) {
-      const char * const path = gSystem->Which(TROOT::GetIconPath(), pngFileName, kReadPermission);
+#ifdef ROOTICONPATH
+      const char * const path = gSystem->Which(ROOTICONPATH, pngFileName, kReadPermission);
+#else
+      const char * const path = gSystem->Which("$ROOTSYS/icons", pngFileName, kReadPermission);
+#endif
       const Util::ScopedArray<const char> arrayGuard(path);
 
       if (!path || path[0] == 0) {
@@ -3058,7 +3061,11 @@ void print_mask_info(ULong_t mask)
    }
 
    if (pngFileName) {
-      const char * const path = gSystem->Which(TROOT::GetIconPath(), pngFileName, kReadPermission);
+#ifdef ROOTICONPATH
+      const char * const path = gSystem->Which(ROOTICONPATH, pngFileName, kReadPermission);
+#else
+      const char * const path = gSystem->Which("$ROOTSYS/icons", pngFileName, kReadPermission);
+#endif
       const Util::ScopedArray<const char> arrayGuard(path);
 
       if (!path || path[0] == 0) {
diff --git a/graf2d/gpad/src/TClassTree.cxx b/graf2d/gpad/src/TClassTree.cxx
index f90062f65ee..a16d36c4d10 100644
--- a/graf2d/gpad/src/TClassTree.cxx
+++ b/graf2d/gpad/src/TClassTree.cxx
@@ -195,7 +195,11 @@ TClassTree::TClassTree()
    fNdata    = 0;
    SetLabelDx();
    SetYoffset(0);
-   SetSourceDir(".:src:" + TROOT::GetSourceDir());
+#ifdef ROOTSRCDIR
+   SetSourceDir(".:src:" ROOTSRCDIR);
+#else
+   SetSourceDir(".:src:$ROOTSYS/src");
+#endif
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -221,7 +225,11 @@ TClassTree::TClassTree(const char *name, const char *classes)
    fNdata    = 0;
    SetLabelDx();
    SetYoffset(0);
-   SetSourceDir(".:src:" + TROOT::GetSourceDir());
+#ifdef ROOTSRCDIR
+   SetSourceDir(".:src:" ROOTSRCDIR);
+#else
+   SetSourceDir(".:src:$ROOTSYS/src");
+#endif
 
    // draw list of classes (if specified)
    if (classes && strlen(classes)) {
diff --git a/graf2d/graf/src/TTF.cxx b/graf2d/graf/src/TTF.cxx
index adc614ac182..a6a7e02abcf 100644
--- a/graf2d/graf/src/TTF.cxx
+++ b/graf2d/graf/src/TTF.cxx
@@ -15,10 +15,12 @@
 Interface to the freetype 2 library.
 */
 
+// RConfigure.h is needed for TTFFONTDIR
+#include "RConfigure.h"
+
 #  include <ft2build.h>
 #  include FT_FREETYPE_H
 #  include FT_GLYPH_H
-#include "TROOT.h"
 #include "TTF.h"
 #include "TSystem.h"
 #include "TEnv.h"
@@ -413,7 +415,13 @@ Int_t TTF::SetTextFont(const char *fontname, Int_t italic)
 
    // try to load font (font must be in Root.TTFontPath resource)
    const char *ttpath = gEnv->GetValue("Root.TTFontPath",
-                                       TROOT::GetTTFFontDir());
+# ifdef TTFFONTDIR
+                                       TTFFONTDIR
+# else
+                                       "$(ROOTSYS)/fonts"
+# endif
+                                      );
+
    char *ttfont = gSystem->Which(ttpath, fontname, kReadPermission);
 
    if (!ttfont) {
@@ -535,7 +543,12 @@ void TTF::SetTextFont(Font_t fontnumber)
       // try to load font (font must be in Root.TTFontPath resource)
       // to see which fontset we have available
       const char *ttpath = gEnv->GetValue("Root.TTFontPath",
-                                          TROOT::GetTTFFontDir());
+#ifdef TTFFONTDIR
+                                          TTFFONTDIR
+#else
+                                          "$(ROOTSYS)/fonts"
+#endif
+                                         );
       char *ttfont = gSystem->Which(ttpath, gEnv->GetValue(fonttable[fontid][0], fonttable[fontid][1]), kReadPermission);
       if (ttfont) {
          delete [] ttfont;
diff --git a/graf2d/postscript/src/TPostScript.cxx b/graf2d/postscript/src/TPostScript.cxx
index 5de4b07e6a6..2af1ebdb516 100644
--- a/graf2d/postscript/src/TPostScript.cxx
+++ b/graf2d/postscript/src/TPostScript.cxx
@@ -1568,7 +1568,12 @@ void TPostScript::FontEmbed(void)
 
    // try to load font (font must be in Root.TTFontPath resource)
    const char *ttpath = gEnv->GetValue("Root.TTFontPath",
-                                       TROOT::GetTTFFontDir());
+#ifdef TTFFONTDIR
+                                       TTFFONTDIR
+#else // TTFFONTDIR
+                                       "$(ROOTSYS)/fonts"
+#endif // TTFFONTDIR
+                                       );
 
    for (Int_t fontid = 1; fontid < 30; fontid++) {
       if (fontid != 15 && MustEmbed[fontid-1]) {
diff --git a/graf2d/qt/src/TGQt.cxx b/graf2d/qt/src/TGQt.cxx
index 69e149a62e1..b376f8b549c 100644
--- a/graf2d/qt/src/TGQt.cxx
+++ b/graf2d/qt/src/TGQt.cxx
@@ -707,6 +707,13 @@ QPixmap *TGQt::MakeIcon(Int_t i)
                           GetSystemMetrics(SM_CYSMICON));
    HDC dc = tempIcon->handle();
    DrawIcon (dc, 0, 0, icon);
+#else
+# ifdef ROOTICONPATH
+   gSystem->ExpandPathName(ROOTICONPATH);
+# else
+   gSystem->ExpandPathName("$ROOTSYS/icons/");
+//   tempIcon =new QPixmap (16,16),
+# endif
 #endif
    return tempIcon;
 }
@@ -796,7 +803,13 @@ TQtApplication *TGQt::CreateQtApplicationImp()
    static TQtApplication *app = 0;
    if (!app) {
       //    app = new TQtApplication(gApplication->ApplicationName(),gApplication->Argc(),gApplication->Argv());
-      static TString argvString (TROOT::GetBinDir() + "/root.exe");
+      static TString argvString (
+#ifdef ROOTBINDIR
+             ROOTBINDIR "/root.exe"
+#else
+             "$ROOTSYS/bin/root.exe"
+#endif
+             );
       gSystem->ExpandPathName(argvString);
       static char *argv[] = {(char *)argvString.Data()};
       static int nArg = 1;
@@ -984,8 +997,14 @@ Bool_t TGQt::Init(void* /*display*/)
     }
 
     if (isXdfSupport && !symbolFontFound) {
-        // Load the local ROOT font
-        QString fontdir = TROOT::GetTTFFontDir().Data();
+// Load the local ROOT font
+       QString fontdir =
+#ifdef TTFFONTDIR
+         TTFFONTDIR
+#else
+         "$ROOTSYS/fonts"
+#endif
+        ;
         QString symbolFontFile = fontdir + "/" + QString(fSymbolFontFamily).toLower() + ".ttf";
         symbolFontFound = QFontDatabase::addApplicationFont(symbolFontFile);
     }
@@ -995,7 +1014,12 @@ Bool_t TGQt::Init(void* /*display*/)
         fontFamily = fSymbolFontFamily = "Arial";
         qDebug() << " Substitute it with \""<<fontFamily <<"\"";
         qDebug() << " Make sure your local \"~/.fonts.conf\" or \"/etc/fonts/fonts.conf\" file points to \""
-                 << TROOT::GetTTFFontDir()
+                 <<
+#ifdef TTFFONTDIR
+               TTFFONTDIR
+#else
+               "$ROOTSYS/fonts"
+#endif
                  << "\" directory to get the proper support for ROOT TLatex class";
         // create a custom codec
         new QSymbolCodec();
diff --git a/graf3d/gl/src/TGLFontManager.cxx b/graf3d/gl/src/TGLFontManager.cxx
index 9b888353622..068dcc93032 100644
--- a/graf3d/gl/src/TGLFontManager.cxx
+++ b/graf3d/gl/src/TGLFontManager.cxx
@@ -14,7 +14,6 @@
 #include "TGLFontManager.h"
 
 
-#include "TROOT.h"
 #include "TVirtualX.h"
 #include "TMath.h"
 #include "TSystem.h"
@@ -452,7 +451,11 @@ void TGLFontManager::RegisterFont(Int_t sizeIn, Int_t fileID, TGLFont::EMode mod
    if (it == fFontMap.end())
    {
       TString ttpath, file;
-      ttpath = gEnv->GetValue("Root.TTGLFontPath", TROOT::GetTTFFontDir());
+# ifdef TTFFONTDIR
+      ttpath = gEnv->GetValue("Root.TTGLFontPath", TTFFONTDIR );
+# else
+      ttpath = gEnv->GetValue("Root.TTGLFontPath", "$(ROOTSYS)/fonts");
+# endif
       {
          //For extenede we have both ttf and otf.
          char *fp = gSystem->Which(ttpath, fileID < fgExtendedFontStart ?
diff --git a/graf3d/gl/src/TGLSAViewer.cxx b/graf3d/gl/src/TGLSAViewer.cxx
index cc35bcc568e..ee13468ecef 100644
--- a/graf3d/gl/src/TGLSAViewer.cxx
+++ b/graf3d/gl/src/TGLSAViewer.cxx
@@ -669,7 +669,14 @@ Bool_t TGLSAViewer::ProcessFrameMessage(Long_t msg, Long_t parm1, Long_t)
          switch (parm1) {
          case kGLHelpAbout: {
 #ifdef R__UNIX
-            TString rootx = TROOT::GetBinDir() + "/root -a &";
+            TString rootx;
+#ifdef ROOTBINDIR
+            rootx = ROOTBINDIR;
+#else
+            rootx = gSystem->Getenv("ROOTSYS");
+            if (!rootx.IsNull()) rootx += "/bin";
+#endif
+            rootx += "/root -a &";
             gSystem->Exec(rootx);
 #else
 #ifdef WIN32
diff --git a/graf3d/gl/src/TGLText.cxx b/graf3d/gl/src/TGLText.cxx
index 3b3bd9941a2..7f2c17ab93e 100644
--- a/graf3d/gl/src/TGLText.cxx
+++ b/graf3d/gl/src/TGLText.cxx
@@ -197,7 +197,13 @@ void TGLText::SetGLTextFont(Font_t fontnumber)
 
    // try to load font (font must be in Root.TTFontPath resource)
    const char *ttpath = gEnv->GetValue("Root.TTFontPath",
-                                       TROOT::GetTTFFontDir());
+# ifdef TTFFONTDIR
+                                        TTFFONTDIR
+# else
+                                        "$(ROOTSYS)/fonts"
+# endif
+                                        );
+
    char *ttfont = gSystem->Which(ttpath, fontname, kReadPermission);
 
    if (fGLTextFont) delete fGLTextFont;
diff --git a/gui/gui/src/TGApplication.cxx b/gui/gui/src/TGApplication.cxx
index 5939d137565..b65cfad7656 100644
--- a/gui/gui/src/TGApplication.cxx
+++ b/gui/gui/src/TGApplication.cxx
@@ -84,7 +84,12 @@ TGApplication::TGApplication(const char *appClassName,
 
    if (strcmp(appClassName, "proofserv")) {
       const char *ttpath = gEnv->GetValue("Root.TTFontPath",
-                                          TROOT::GetTTFFontDir());
+#ifdef TTFFONTDIR
+                                          TTFFONTDIR);
+#else
+                                          "$(ROOTSYS)/fonts");
+#endif
+
       char *ttfont = gSystem->Which(ttpath, "arialbd.ttf", kReadPermission);
       // Added by cholm for use of DFSG - fonts - based on fix by Kevin
       if (!ttfont)
diff --git a/gui/gui/src/TGResourcePool.cxx b/gui/gui/src/TGResourcePool.cxx
index 4057f88eb50..df135dbd491 100644
--- a/gui/gui/src/TGResourcePool.cxx
+++ b/gui/gui/src/TGResourcePool.cxx
@@ -83,29 +83,46 @@ TGResourcePool::TGResourcePool(TGClient *client)
    TString framebgpixmap  = gEnv->GetValue("Gui.FrameBackgroundPixmap", "");
    TString docbgpixmap    = gEnv->GetValue("Gui.DocumentBackgroundPixmap", "");
 
-   TString icon_path = gEnv->GetValue("Gui.IconPath", "");
-   if (icon_path.IsNull()) {
-      icon_path = "icons";
-      gSystem->PrependPathName(gSystem->HomeDirectory(), icon_path);
-#ifndef R__WIN32
-      icon_path = ".:" + icon_path + ":" + TROOT::GetIconPath() + ":" + EXTRAICONPATH;
-#else
-      icon_path = ".;" + icon_path + ";" + TROOT::GetIconPath() + ";" + EXTRAICONPATH;
-#endif
-   }
+   TString icon_path;
+   TString mime_file;
+   TString line;
 
-   TString mime_file = ".root.mimes";
-   gSystem->PrependPathName(gSystem->HomeDirectory(), mime_file);
-   mime_file = gEnv->GetValue("Gui.MimeTypeFile", mime_file.Data());
+#ifndef R__WIN32
+# ifdef ROOTICONPATH
+   icon_path = TString::Format("%s/icons:%s:.:", gSystem->HomeDirectory(),
+                               ROOTICONPATH);
+#  ifdef EXTRAICONPATH
+   icon_path += gEnv->GetValue("Gui.IconPath", EXTRAICONPATH);
+#  else
+   icon_path += gEnv->GetValue("Gui.IconPath", "");
+#  endif
+# else
+   icon_path = TString::Format("%s/icons:%s/icons:.:", gSystem->HomeDirectory(),
+                                                       gSystem->Getenv("ROOTSYS"));
+   icon_path += gEnv->GetValue("Gui.IconPath", "");
+# endif
+   line = TString::Format("%s/.root.mimes", gSystem->HomeDirectory());
+
+   mime_file = gEnv->GetValue("Gui.MimeTypeFile", line.Data());
    char *mf = gSystem->ExpandPathName(mime_file.Data());
    if (mf) {
       mime_file = mf;
       delete [] mf;
    }
-   if (gSystem->AccessPathName(mime_file, kReadPermission)) {
-      mime_file = "root.mimes";
-      gSystem->PrependPathName(TROOT::GetEtcDir(), mime_file);
-   }
+   if (gSystem->AccessPathName(mime_file, kReadPermission))
+#ifdef ROOTETCDIR
+      mime_file = TString::Format("%s/root.mimes", ROOTETCDIR);
+#else
+      mime_file = TString::Format("%s/etc/root.mimes", gSystem->Getenv("ROOTSYS"));
+#endif
+#else // R__WIN32
+   icon_path = TString::Format("%s\\icons:.:\\", gSystem->Getenv("ROOTSYS"));
+   icon_path += gEnv->GetValue("Gui.IconPath", "");
+   line = TString::Format("%s\\root.mimes", gSystem->HomeDirectory());
+   mime_file = gEnv->GetValue("Gui.MimeTypeFile", line.Data());
+   if (gSystem->AccessPathName(mime_file, kReadPermission))
+      mime_file = TString::Format("%s\\etc\\root.mimes", gSystem->Getenv("ROOTSYS"));
+#endif
 
    // Setup colors...
    fClient->GetColorByName("white", fWhite);  // white and black always exist
diff --git a/gui/gui/src/TGSpeedo.cxx b/gui/gui/src/TGSpeedo.cxx
index a39dcdfe587..f28993cfc6d 100644
--- a/gui/gui/src/TGSpeedo.cxx
+++ b/gui/gui/src/TGSpeedo.cxx
@@ -119,7 +119,8 @@ void TGSpeedo::Build()
 {
    TString sc;
    Float_t step, mark[5];
-   TString ar = "arialbd.ttf";
+   TString fp = gEnv->GetValue("Root.TTFontPath", "");
+   TString ar = fp + "/arialbd.ttf";
    Int_t i, nexe, offset;
 
    const TGFont *counterFont = fClient->GetFont("-*-helvetica-bold-r-*-*-12-*-*-*-*-*-*-*");
@@ -527,7 +528,8 @@ void TGSpeedo::DrawText()
          delete fImage2;
       fImage2 = (TImage*)fImage->Clone("fImage2");
       if (!fImage2 || !fImage2->IsValid()) return;
-      TString ar = "arialbd.ttf";
+      TString fp = gEnv->GetValue("Root.TTFontPath", "");
+      TString ar = fp + "/arialbd.ttf";
       // format counter value
       Int_t nexe = 0;
       Int_t ww = fCounter;
@@ -607,7 +609,8 @@ void TGSpeedo::DoRedraw()
          delete fImage2;
       fImage2 = (TImage*)fImage->Clone("fImage2");
       if (!fImage2 || !fImage2->IsValid()) return;
-      TString ar = "arialbd.ttf";
+      TString fp = gEnv->GetValue("Root.TTFontPath", "");
+      TString ar = fp + "/arialbd.ttf";
       // format counter value
       Int_t nexe = 0;
       Int_t ww = fCounter;
diff --git a/gui/gui/src/TGTextEditor.cxx b/gui/gui/src/TGTextEditor.cxx
index c6abee5111d..aab053f7b95 100644
--- a/gui/gui/src/TGTextEditor.cxx
+++ b/gui/gui/src/TGTextEditor.cxx
@@ -842,7 +842,14 @@ void TGTextEditor::InterruptMacro()
 void TGTextEditor::About()
 {
 #ifdef R__UNIX
-   TString rootx = TROOT::GetBinDir() + "/root -a &";
+   TString rootx;
+# ifdef ROOTBINDIR
+   rootx = ROOTBINDIR;
+# else
+   rootx = gSystem->Getenv("ROOTSYS");
+   if (!rootx.IsNull()) rootx += "/bin";
+# endif
+   rootx += "/root -a &";
    gSystem->Exec(rootx);
 #else
 #ifdef WIN32
diff --git a/gui/gui/src/TRootBrowser.cxx b/gui/gui/src/TRootBrowser.cxx
index 700588f8a55..4d127151cbc 100644
--- a/gui/gui/src/TRootBrowser.cxx
+++ b/gui/gui/src/TRootBrowser.cxx
@@ -702,7 +702,14 @@ void TRootBrowser::HandleMenu(Int_t id)
       case kHelpAbout:
          {
 #ifdef R__UNIX
-            TString rootx = TROOT::GetBinDir() + "/root -a &";
+            TString rootx;
+# ifdef ROOTBINDIR
+            rootx = ROOTBINDIR;
+# else
+            rootx = gSystem->Getenv("ROOTSYS");
+            if (!rootx.IsNull()) rootx += "/bin";
+# endif
+            rootx += "/root -a &";
             gSystem->Exec(rootx);
 #else
 #ifdef WIN32
diff --git a/gui/gui/src/TRootBrowserLite.cxx b/gui/gui/src/TRootBrowserLite.cxx
index f934b806066..da2a1884698 100644
--- a/gui/gui/src/TRootBrowserLite.cxx
+++ b/gui/gui/src/TRootBrowserLite.cxx
@@ -1962,7 +1962,14 @@ Bool_t TRootBrowserLite::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
                   case kHelpAbout:
                      {
 #ifdef R__UNIX
-                        TString rootx = TROOT::GetBinDir() + "/root -a &";
+                        TString rootx;
+# ifdef ROOTBINDIR
+                        rootx = ROOTBINDIR;
+# else
+                        rootx = gSystem->Getenv("ROOTSYS");
+                        if (!rootx.IsNull()) rootx += "/bin";
+# endif
+                        rootx += "/root -a &";
                         gSystem->Exec(rootx);
 #else
 #ifdef WIN32
diff --git a/gui/gui/src/TRootCanvas.cxx b/gui/gui/src/TRootCanvas.cxx
index fe9ca9bff5f..d6832d44845 100644
--- a/gui/gui/src/TRootCanvas.cxx
+++ b/gui/gui/src/TRootCanvas.cxx
@@ -1192,7 +1192,14 @@ again:
                   case kHelpAbout:
                      {
 #ifdef R__UNIX
-                        TString rootx = TROOT::GetBinDir() + "/root -a &";
+                        TString rootx;
+# ifdef ROOTBINDIR
+                        rootx = ROOTBINDIR;
+# else
+                        rootx = gSystem->Getenv("ROOTSYS");
+                        if (!rootx.IsNull()) rootx += "/bin";
+# endif
+                        rootx += "/root -a &";
                         gSystem->Exec(rootx);
 #else
 #ifdef WIN32
diff --git a/gui/guihtml/src/TGHtmlBrowser.cxx b/gui/guihtml/src/TGHtmlBrowser.cxx
index 3eafaeddeea..912fbcbf269 100644
--- a/gui/guihtml/src/TGHtmlBrowser.cxx
+++ b/gui/guihtml/src/TGHtmlBrowser.cxx
@@ -629,7 +629,14 @@ Bool_t TGHtmlBrowser::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
                   case kM_HELP_ABOUT:
                      {
 #ifdef R__UNIX
-                        TString rootx = TROOT::GetBinDir() + "/root -a &";
+                        TString rootx;
+# ifdef ROOTBINDIR
+                        rootx = ROOTBINDIR;
+# else
+                        rootx = gSystem->Getenv("ROOTSYS");
+                        if (!rootx.IsNull()) rootx += "/bin";
+# endif
+                        rootx += "/root -a &";
                         gSystem->Exec(rootx);
 #else
 #ifdef WIN32
diff --git a/gui/sessionviewer/src/TSessionViewer.cxx b/gui/sessionviewer/src/TSessionViewer.cxx
index 569757ecc60..42aa22869b2 100644
--- a/gui/sessionviewer/src/TSessionViewer.cxx
+++ b/gui/sessionviewer/src/TSessionViewer.cxx
@@ -5812,7 +5812,14 @@ Bool_t TSessionViewer::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
                   case kHelpAbout:
                      {
 #ifdef R__UNIX
-		         TString rootx = TROOT::GetBinDir() + "/root -a &";
+                        TString rootx;
+# ifdef ROOTBINDIR
+                        rootx = ROOTBINDIR;
+# else
+                        rootx = gSystem->Getenv("ROOTSYS");
+                        if (!rootx.IsNull()) rootx += "/bin";
+# endif
+                        rootx += "/root -a &";
                         gSystem->Exec(rootx);
 #else
 #ifdef WIN32
diff --git a/html/src/THtml.cxx b/html/src/THtml.cxx
index 61f4c370824..1b602236ba1 100644
--- a/html/src/THtml.cxx
+++ b/html/src/THtml.cxx
@@ -1349,7 +1349,18 @@ const char* THtml::GetEtcDir() const
    R__LOCKGUARD(GetMakeClassMutex());
 
    fPathInfo.fEtcDir = "html";
-   gSystem->PrependPathName(TROOT::GetEtcDir(), fPathInfo.fEtcDir);
+
+#ifdef ROOTETCDIR
+   gSystem->PrependPathName(ROOTETCDIR, fPathInfo.fEtcDir);
+#else
+   gSystem->PrependPathName("etc", fPathInfo.fEtcDir);
+# ifdef ROOTPREFIX
+   gSystem->PrependPathName(ROOTPREFIX, fPathInfo.fEtcDir);
+# else
+   if (getenv("ROOTSYS"))
+      gSystem->PrependPathName(getenv("ROOTSYS"), fPathInfo.fEtcDir);
+# endif
+#endif
 
    return fPathInfo.fEtcDir;
 }
@@ -1660,7 +1671,12 @@ void THtml::CreateListOfClasses(const char* filter)
                   if (posSpace != std::string::npos)
                      lib.erase(posSpace);
                   if (rootLibs.find(lib) == rootLibs.end()) {
-                     TString rootlibdir = TROOT::GetLibDir();
+#ifdef ROOTLIBDIR
+                     TString rootlibdir = ROOTLIBDIR;
+#else
+                     TString rootlibdir = "lib";
+                     gSystem->PrependPathName(gRootDir, rootlibdir);
+#endif
                      TString sLib(lib);
                      if (sLib.Index('.') == -1) {
                         sLib += ".";
diff --git a/io/io/src/TFile.cxx b/io/io/src/TFile.cxx
index e58a7bfb24e..759835db019 100644
--- a/io/io/src/TFile.cxx
+++ b/io/io/src/TFile.cxx
@@ -3102,7 +3102,11 @@ void TFile::MakeProject(const char *dirname, const char * /*classes*/,
          return;
       }
       // Get Makefile.arch
-      TString mkarchsrc = TString::Format("%s/Makefile.arch", TROOT::GetEtcDir().Data());
+#ifdef ROOTETCDIR
+      TString mkarchsrc = TString::Format("%s/Makefile.arch", ROOTETCDIR);
+#else
+      TString mkarchsrc("$(ROOTSYS)/etc/Makefile.arch");
+#endif
       if (gSystem->ExpandPathName(mkarchsrc))
          Warning("MakeProject", "problems expanding '%s'", mkarchsrc.Data());
       TString mkarchdst = TString::Format("%s/Makefile.arch", clean_dirname.Data());
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index 2af4e8f4ec3..b1b51f8b154 100644
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -43,9 +43,9 @@ if(python)
   endforeach()
 
   install(FILES python/cmdLineUtils.py DESTINATION ${runtimedir})
-  install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m py_compile \$ENV{DESTDIR}${runtimedir}/cmdLineUtils.py)")
-  install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -O -m py_compile \$ENV{DESTDIR}${runtimedir}/cmdLineUtils.py)")
-  configure_file(python/cmdLineUtils.py ${localruntimedir}/cmdLineUtils.py @ONLY)
+  install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -m py_compile \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${runtimedir}/cmdLineUtils.py )")
+  install(CODE "execute_process(COMMAND ${PYTHON_EXECUTABLE} -O -m py_compile \$ENV{DESTDIR}\${CMAKE_INSTALL_PREFIX}/${runtimedir}/cmdLineUtils.py )")
+  configure_file(python/cmdLineUtils.py ${CMAKE_BINARY_DIR}/${runtimedir}/cmdLineUtils.py @ONLY)
 endif()
 
 
diff --git a/main/ModuleVars.mk b/main/ModuleVars.mk
index eaf5d69931a..22af989ef87 100644
--- a/main/ModuleVars.mk
+++ b/main/ModuleVars.mk
@@ -5,7 +5,7 @@
 
 ##### rootcling #####
 ROOTCLINGEXE    := bin/rootcling$(EXEEXT)
-ROOTCLINGSTAGE2 := ROOTIGNOREPREFIX=1 $(ROOTCLINGEXE) -rootbuild
+ROOTCLINGSTAGE2 := $(ROOTCLINGEXE) -rootbuild
 # Dependencies for all dictionaries
 ROOTCLINGSTAGE2DEP := $(ROOTCLINGEXE)
 
diff --git a/main/src/nbmain.cxx b/main/src/nbmain.cxx
index 55d4f2f3aa2..c183628f867 100644
--- a/main/src/nbmain.cxx
+++ b/main/src/nbmain.cxx
@@ -173,9 +173,15 @@ static bool CreateStamp(string dest)
 
 int main()
 {
-   string rootbin(TROOT::GetBinDir());
-   string rootlib(TROOT::GetLibDir());
-   string rootetc(TROOT::GetEtcDir());
+#ifdef ROOTPREFIX
+   string rootbin(ROOTBINDIR);
+   string rootlib(ROOTLIBDIR);
+   string rootetc(ROOTETCDIR);
+#else
+   string rootbin(getenv("ROOTSYS") + pathsep + "bin");
+   string rootlib(getenv("ROOTSYS") + pathsep + "lib");
+   string rootetc(getenv("ROOTSYS") + pathsep + "etc");
+#endif
 
    // If needed, install ROOT notebook files in the user's home directory
 #ifdef WIN32
diff --git a/main/src/rootcling.cxx b/main/src/rootcling.cxx
index d06fdb32dc8..77ce093963e 100644
--- a/main/src/rootcling.cxx
+++ b/main/src/rootcling.cxx
@@ -29,12 +29,13 @@ int main(int argc, char **argv)
    }
 
    ROOT::Internal::RootCling::DriverConfig config{};
+#ifdef R__HAVE_LLVMRESOURCEDIR
+   config.fLLVMResourceDir= "@R__LLVMRESOURCEDIR@";
+#endif
 
    config.fBuildingROOTStage1 = false;
    config.fPRootDir = &gRootDir;
    config.fTROOT__GetExtraInterpreterArgs = &TROOT__GetExtraInterpreterArgs;
-   config.fTROOT__GetIncludeDir = &TROOT__GetIncludeDir;
-   config.fTROOT__GetEtcDir = &TROOT__GetEtcDir;
    config.fTCling__GetInterpreter = &TCling__GetInterpreter;
    config.fInitializeStreamerInfoROOTFile = &InitializeStreamerInfoROOTFile;
    config.fAddStreamerInfoToROOTFile = &AddStreamerInfoToROOTFile;
diff --git a/math/mathcore/src/Integrator.cxx b/math/mathcore/src/Integrator.cxx
index 3bb538daa59..9b23f2e3ed4 100644
--- a/math/mathcore/src/Integrator.cxx
+++ b/math/mathcore/src/Integrator.cxx
@@ -22,6 +22,9 @@
 
 
 #include "RConfigure.h"
+// #ifndef ROOTINCDIR
+// #define MATH_NO_PLUGIN_MANAGER
+// #endif
 
 #include <algorithm>
 #include <functional>
diff --git a/montecarlo/eg/src/TDatabasePDG.cxx b/montecarlo/eg/src/TDatabasePDG.cxx
index 5d2da973cf1..5f7f220964e 100644
--- a/montecarlo/eg/src/TDatabasePDG.cxx
+++ b/montecarlo/eg/src/TDatabasePDG.cxx
@@ -564,8 +564,11 @@ void TDatabasePDG::ReadPDGTable(const char *FileName)
    const char *fn;
 
    if (!FileName[0]) {
-      default_name = "pdg_table.txt";
-      gSystem->PrependPathName(TROOT::GetEtcDir(), default_name);
+#ifdef ROOTETCDIR
+      default_name.Form("%s/pdg_table.txt", ROOTETCDIR);
+#else
+      default_name.Form("%s/etc/pdg_table.txt", gSystem->Getenv("ROOTSYS"));
+#endif
       fn = gEnv->GetValue("Root.DatabasePDG", default_name.Data());
    } else {
       fn = FileName;
diff --git a/net/auth/CMakeLists.txt b/net/auth/CMakeLists.txt
index be301ee02f5..965c484a3bd 100644
--- a/net/auth/CMakeLists.txt
+++ b/net/auth/CMakeLists.txt
@@ -25,6 +25,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/res)
 add_library(rsa STATIC ${CMAKE_CURRENT_SOURCE_DIR}/src/rsaaux.cxx
                        ${CMAKE_CURRENT_SOURCE_DIR}/src/rsalib.cxx
                        ${CMAKE_CURRENT_SOURCE_DIR}/src/rsafun.cxx)
+add_dependencies(rsa move_headers)
 
 if(ssl)
   include_directories(${OPENSSL_INCLUDE_DIR})
diff --git a/net/auth/src/DaemonUtils.cxx b/net/auth/src/DaemonUtils.cxx
index 21128e3d6e9..08fc40172ab 100644
--- a/net/auth/src/DaemonUtils.cxx
+++ b/net/auth/src/DaemonUtils.cxx
@@ -95,8 +95,18 @@ static Int_t SrvSetVars(string /*confdir*/)
 {
    // Executables and conf dirs
 
-   // Make rootbindir available to all the session via env
-   string execdir = TROOT::GetBinDir().Data();
+   string execdir, etcdir;
+#ifdef ROOTBINDIR
+   execdir = string(ROOTBINDIR);
+#endif
+#ifdef ROOTETCDIR
+   etcdir = string(ROOTETCDIR);
+#endif
+
+   // Define rootbindir if not done already
+   if (!execdir.length())
+      execdir = string(confdir).append("/bin");
+   // Make it available to all the session via env
    if (execdir.length()) {
       int len = 15 + execdir.length();
       char *tmp = new char[len+1];
@@ -107,8 +117,10 @@ static Int_t SrvSetVars(string /*confdir*/)
          return -1;
    }
 
-   // Make rootetcdir available to all the session via env
-   string etcdir = TROOT::GetEtcDir().Data();
+   // Define rootetcdir if not done already
+   if (!etcdir.length())
+      etcdir = string(confdir).append("/etc");
+   // Make it available to all the session via env
    if (etcdir.length()) {
       int len = 15 + etcdir.length();
       char *tmp = new char[len+1];
diff --git a/net/auth/src/TAuthenticate.cxx b/net/auth/src/TAuthenticate.cxx
index 9b3ef202c93..b7a2f37cfd7 100644
--- a/net/auth/src/TAuthenticate.cxx
+++ b/net/auth/src/TAuthenticate.cxx
@@ -4114,9 +4114,19 @@ Int_t TAuthenticate::ReadRootAuthrc()
          ::Info("TAuthenticate::ReadRootAuthrc",
                 "file %s cannot be read (errno: %d)", authrc, errno);
       delete [] authrc;
-      authrc = gSystem->ConcatFileName(TROOT::GetEtcDir(), "system.rootauthrc");
+#ifdef ROOTETCDIR
+      authrc = gSystem->ConcatFileName(ROOTETCDIR,"system.rootauthrc");
+#else
+      char etc[1024];
+#ifdef WIN32
+      snprintf(etc, 1024, "%s\\etc", gRootDir);
+#else
+      snprintf(etc, 1024, "%s/etc", gRootDir);
+#endif
+      authrc = gSystem->ConcatFileName(etc,"system.rootauthrc");
+#endif
       if (gDebug > 2)
-         ::Info("TAuthenticate::ReadRootAuthrc", "Checking system file: %s", authrc);
+         ::Info("TAuthenticate::ReadRootAuthrc", "Checking system file:%s",authrc);
       if (gSystem->AccessPathName(authrc, kReadPermission)) {
          if (gDebug > 1)
             ::Info("TAuthenticate::ReadRootAuthrc",
diff --git a/net/http/src/THttpServer.cxx b/net/http/src/THttpServer.cxx
index a612721ca13..c72565743ed 100644
--- a/net/http/src/THttpServer.cxx
+++ b/net/http/src/THttpServer.cxx
@@ -148,7 +148,11 @@ THttpServer::THttpServer(const char *engine) :
    if (jsrootsys != 0) fJSROOTSYS = jsrootsys;
 
    if (fJSROOTSYS.Length() == 0) {
-      TString jsdir = TString::Format("%s/http", TROOT::GetEtcDir().Data());
+#ifdef ROOTETCDIR
+      TString jsdir = TString::Format("%s/http", ROOTETCDIR);
+#else
+      TString jsdir("$(ROOTSYS)/etc/http");
+#endif
       if (gSystem->ExpandPathName(jsdir)) {
          Warning("THttpServer", "problems resolving '%s', use JSROOTSYS to specify $ROOTSYS/etc/http location", jsdir.Data());
          fJSROOTSYS = ".";
@@ -159,7 +163,18 @@ THttpServer::THttpServer(const char *engine) :
 
    AddLocation("currentdir/", ".");
    AddLocation("jsrootsys/", fJSROOTSYS);
-   AddLocation("rootsys/", TROOT::GetRootSys());
+
+   const char *rootsys = gSystem->Getenv("ROOTSYS");
+   if (rootsys != 0) {
+      AddLocation("rootsys/", rootsys);
+   } else {
+#ifdef ROOTPREFIX
+      TString sysdir = ROOTPREFIX;
+#else
+      TString sysdir = "$(ROOTSYS)";
+#endif
+      if (!gSystem->ExpandPathName(sysdir)) AddLocation("rootsys/", sysdir);
+   }
 
    fDefaultPage = fJSROOTSYS + "/files/online.htm";
    fDrawPage = fJSROOTSYS + "/files/draw.htm";
diff --git a/net/net/src/TApplicationServer.cxx b/net/net/src/TApplicationServer.cxx
index cb058f07a56..55bef560187 100644
--- a/net/net/src/TApplicationServer.cxx
+++ b/net/net/src/TApplicationServer.cxx
@@ -1275,7 +1275,17 @@ void TApplicationServer::ExecLogon()
    TString name = ".rootlogon.C";
    TString sname = "system";
    sname += name;
-   char *s = gSystem->ConcatFileName(TROOT::GetEtcDir(), sname);
+#ifdef ROOTETCDIR
+   char *s = gSystem->ConcatFileName(ROOTETCDIR, sname);
+#else
+   TString etc = gRootDir;
+#ifdef WIN32
+   etc += "\\etc";
+#else
+   etc += "/etc";
+#endif
+   char *s = gSystem->ConcatFileName(etc, sname);
+#endif
    if (!gSystem->AccessPathName(s, kReadPermission)) {
       ProcessFile(s);
    }
diff --git a/net/net/src/TServerSocket.cxx b/net/net/src/TServerSocket.cxx
index da7129be5e5..dc1cd5ed791 100644
--- a/net/net/src/TServerSocket.cxx
+++ b/net/net/src/TServerSocket.cxx
@@ -335,7 +335,22 @@ Bool_t TServerSocket::Authenticate(TSocket *sock)
       }
    }
 
-   TString confdir = TROOT::GetRootSys();
+   TString confdir;
+#ifndef ROOTPREFIX
+   // try to guess the config directory...
+   if (gSystem->Getenv("ROOTSYS")) {
+      confdir = TString(gSystem->Getenv("ROOTSYS"));
+   } else {
+      // Try to guess it from 'root.exe' path
+      char *rootexe = gSystem->Which(gSystem->Getenv("PATH"),
+                                     "root.exe", kExecutePermission);
+      confdir = rootexe;
+      confdir.Resize(confdir.Last('/'));
+      delete [] rootexe;
+   }
+#else
+   confdir = TString(ROOTPREFIX);
+#endif
    if (!confdir.Length()) {
       Error("Authenticate", "config dir undefined");
       return kFALSE;
diff --git a/net/rootd/src/rootd.cxx b/net/rootd/src/rootd.cxx
index 14e185cc8e6..4bb8f21c3a2 100644
--- a/net/rootd/src/rootd.cxx
+++ b/net/rootd/src/rootd.cxx
@@ -2524,13 +2524,10 @@ int main(int argc, char **argv)
 
    if (argc > 0) {
       confdir = std::string(*argv);
-   }
-
-#ifdef ROOTPREFIX
-   if (getenv("IGNOREROOTPREFIX")) {
-#endif
+   } else {
+      // try to guess the config directory...
+#ifndef ROOTPREFIX
       if (!confdir.length()) {
-         // try to guess the config directory...
          if (getenv("ROOTSYS")) {
             confdir = getenv("ROOTSYS");
             if (gDebug > 0)
@@ -2541,26 +2538,31 @@ int main(int argc, char **argv)
                ErrorInfo("main: no config directory specified");
          }
       }
-      rootbindir = std::string(confdir).append("/bin");
-      rootetcdir = std::string(confdir).append("/etc");
-#ifdef ROOTPREFIX
-   }
-   else {
-      if (!confdir.length())
-         confdir = ROOTPREFIX;
-      rootbindir = ROOTBINDIR;
-      rootetcdir = ROOTETCDIR;
+#else
+      confdir = ROOTPREFIX;
+#endif
    }
+#ifdef ROOTBINDIR
+   rootbindir= ROOTBINDIR;
+#endif
+#ifdef ROOTETCDIR
+   rootetcdir= ROOTETCDIR;
 #endif
 
-   // Make rootbindir available to all the session via env
+   // Define rootbindir if not done already
+   if (!rootbindir.length())
+      rootbindir = std::string(confdir).append("/bin");
+   // Make it available to all the session via env
    if (rootbindir.length()) {
       char *tmp1 = new char[15 + rootbindir.length()];
       sprintf(tmp1, "ROOTBINDIR=%s", rootbindir.c_str());
       putenv(tmp1);
    }
 
-   // Make rootetcdir available to all the session via env
+   // Define rootetcdir if not done already
+   if (!rootetcdir.length())
+      rootetcdir = std::string(confdir).append("/etc");
+   // Make it available to all the session via env
    if (rootetcdir.length()) {
       char *tmp1 = new char[15 + rootetcdir.length()];
       sprintf(tmp1, "ROOTETCDIR=%s", rootetcdir.c_str());
diff --git a/net/rpdutils/CMakeLists.txt b/net/rpdutils/CMakeLists.txt
index c5edfd48efe..90fda2fc3a5 100644
--- a/net/rpdutils/CMakeLists.txt
+++ b/net/rpdutils/CMakeLists.txt
@@ -35,6 +35,7 @@ endif()
 
 #---static library needed for rootd and proofd --------------------------------------------
 add_library(rpdutil STATIC ${rpdutilsrcs})
+add_dependencies(rpdutil move_headers)
 
 ROOT_LINKER_LIBRARY(SrvAuth rpdutils.cxx ssh.cxx LIBRARIES rpdutil rsa ${CRYPTLIBS} ${GLOBUS_LIBRARIES} ${OPENSSL_LIBRARIES} DEPENDENCIES Net BUILTINS OPENSSL)
 
diff --git a/proof/proof/src/TProofLite.cxx b/proof/proof/src/TProofLite.cxx
index 5f473c3bd32..4a5666580fb 100644
--- a/proof/proof/src/TProofLite.cxx
+++ b/proof/proof/src/TProofLite.cxx
@@ -409,7 +409,17 @@ Int_t TProofLite::GetNumberOfWorkers(const char *url)
    if (fgWrksMax == -2) {
       // Find the max number of workers, if any
       TString sysname = "system.rootrc";
-      char *s = gSystem->ConcatFileName(TROOT::GetEtcDir(), sysname);
+#ifdef ROOTETCDIR
+      char *s = gSystem->ConcatFileName(ROOTETCDIR, sysname);
+#else
+      TString etc = gRootDir;
+#ifdef WIN32
+      etc += "\\etc";
+#else
+      etc += "/etc";
+#endif
+      char *s = gSystem->ConcatFileName(etc, sysname);
+#endif
       TEnv sysenv(0);
       sysenv.ReadFile(s, kEnvGlobal);
       fgWrksMax = sysenv.GetValue("ProofLite.MaxWorkers", -1);
@@ -755,9 +765,17 @@ Int_t TProofLite::SetProofServEnv(const char *ord)
       return -1;
    }
    // ROOTSYS
-   fprintf(fenv, "export ROOTSYS=%s\n", TROOT::GetRootSys().Data());
+#ifdef R__HAVE_CONFIG
+   fprintf(fenv, "export ROOTSYS=%s\n", ROOTPREFIX);
+#else
+   fprintf(fenv, "export ROOTSYS=%s\n", gSystem->Getenv("ROOTSYS"));
+#endif
    // Conf dir
-   fprintf(fenv, "export ROOTCONFDIR=%s\n", TROOT::GetRootSys().Data());
+#ifdef R__HAVE_CONFIG
+   fprintf(fenv, "export ROOTCONFDIR=%s\n", ROOTETCDIR);
+#else
+   fprintf(fenv, "export ROOTCONFDIR=%s\n", gSystem->Getenv("ROOTSYS"));
+#endif
    // TMPDIR
    fprintf(fenv, "export TMPDIR=%s\n", gSystem->TempDirectory());
    // Log file in the log dir
diff --git a/proof/proof/src/TProofServ.cxx b/proof/proof/src/TProofServ.cxx
index fcf64400bd4..73bf0d3d1db 100644
--- a/proof/proof/src/TProofServ.cxx
+++ b/proof/proof/src/TProofServ.cxx
@@ -2964,7 +2964,13 @@ Int_t TProofServ::SetupCommon()
 #ifdef R__UNIX
    // Add bindir to PATH
    TString path(gSystem->Getenv("PATH"));
-   TString bindir(TROOT::GetBinDir());
+   TString bindir;
+# ifdef ROOTBINDIR
+   bindir = ROOTBINDIR;
+# else
+   bindir = gSystem->Getenv("ROOTSYS");
+   if (!bindir.IsNull()) bindir += "/bin";
+# endif
    // Augment PATH, if required
    // ^<compiler>, <compiler>, ^<sysbin>, <sysbin>
    TString paths = gEnv->GetValue("ProofServ.BinPaths", "");
diff --git a/proof/proof/src/TSlaveLite.cxx b/proof/proof/src/TSlaveLite.cxx
index 2cc26bee8c1..76adef2b6fb 100644
--- a/proof/proof/src/TSlaveLite.cxx
+++ b/proof/proof/src/TSlaveLite.cxx
@@ -88,8 +88,13 @@ void TSlaveLite::Init()
 {
    // Command to be executed
    TString cmd;
+#ifdef R__HAVE_CONFIG
    cmd.Form(". %s/worker-%s.env; export ROOTBINDIR=\"%s\"; %s/proofserv proofslave lite %d %d 0&",
-            fWorkDir.Data(), fOrdinal.Data(), TROOT::GetBinDir().Data(), TROOT::GetBinDir().Data(),
+            fWorkDir.Data(), fOrdinal.Data(), ROOTBINDIR, ROOTBINDIR,
+#else
+   cmd.Form(". %s/worker-%s.env; export ROOTBINDIR=\"%s/bin\"; %s/bin/proofserv proofslave lite %d %d 0&",
+            fWorkDir.Data(), fOrdinal.Data(), gSystem->Getenv("ROOTSYS"), gSystem->Getenv("ROOTSYS"),
+#endif
             gSystem->GetPid(), gDebug);
    // Execute
    if (gSystem->Exec(cmd) != 0) {
diff --git a/proof/proofbench/CMakeLists.txt b/proof/proofbench/CMakeLists.txt
index 839e5075313..aa2d4b24fc0 100644
--- a/proof/proofbench/CMakeLists.txt
+++ b/proof/proofbench/CMakeLists.txt
@@ -14,7 +14,7 @@ ROOT_INSTALL_HEADERS(OPTIONS REGEX "TSel" EXCLUDE)
 # Generation and installation of the PAR files required by the benchmark 
 add_custom_target(ProofBenchPARFiles ALL DEPENDS ${CMAKE_BINARY_DIR}/etc/proof/proofbench/ProofBenchCPUSel.par
                                                  ${CMAKE_BINARY_DIR}/etc/proof/proofbench/ProofBenchDataSel.par)
-add_dependencies(ProofBenchPARFiles move_artifacts)
+add_dependencies(ProofBenchPARFiles move_headers) # The /etc directory from sources is copied when moving the headers
 add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/etc/proof/proofbench/ProofBenchCPUSel.par
                           ${CMAKE_BINARY_DIR}/etc/proof/proofbench/ProofBenchDataSel.par
     COMMAND etc/proof/utils/makepbenchpars.sh ARGS ProofBenchCPUSel ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} 
diff --git a/proof/proofbench/src/TProofBench.cxx b/proof/proofbench/src/TProofBench.cxx
index 21333d3433b..39426ef6385 100644
--- a/proof/proofbench/src/TProofBench.cxx
+++ b/proof/proofbench/src/TProofBench.cxx
@@ -1338,7 +1338,11 @@ Int_t TProofBench::MakeDataSet(const char *dset, Long64_t nevt, const char *fnro
       // Is it the default selector?
       if (fDataGenSel == kPROOF_BenchSelDataGenDef) {
          // Load the parfile
-         TString par = TString::Format("%s/%s%s.par", TROOT::GetEtcDir().Data(), kPROOF_BenchParDir, kPROOF_BenchDataSelPar);
+#ifdef R__HAVE_CONFIG
+         TString par = TString::Format("%s/%s%s.par", ROOTETCDIR, kPROOF_BenchParDir, kPROOF_BenchDataSelPar);
+#else
+         TString par = TString::Format("$ROOTSYS/etc/%s%s.par", kPROOF_BenchParDir, kPROOF_BenchDataSelPar);
+#endif
          Info("MakeDataSet", "uploading '%s' ...", par.Data());
          if (fProof->UploadPackage(par) != 0) {
             Error("MakeDataSet", "problems uploading '%s' - cannot continue", par.Data());
diff --git a/proof/proofbench/src/TProofBenchDataSet.cxx b/proof/proofbench/src/TProofBenchDataSet.cxx
index 4e71937cb76..3951c2d72c8 100644
--- a/proof/proofbench/src/TProofBenchDataSet.cxx
+++ b/proof/proofbench/src/TProofBenchDataSet.cxx
@@ -25,7 +25,6 @@ Handle operations on datasets used by ProofBench
 #include "TMap.h"
 #include "TProof.h"
 #include "TProofBenchTypes.h"
-#include "TROOT.h"
 
 
 ClassImp(TProofBenchDataSet)
@@ -145,7 +144,11 @@ Int_t TProofBenchDataSet::Handle(const char *dset, TObject *type)
    TString selName("TSelHandleDataSet");
    if (!TClass::GetClass(selName)) {
       // Load the parfile
-      TString par = TString::Format("%s/%s%s.par", TROOT::GetEtcDir().Data(), kPROOF_BenchParDir, kPROOF_BenchDataSelPar);
+#ifdef R__HAVE_CONFIG
+      TString par = TString::Format("%s/%s%s.par", ROOTETCDIR, kPROOF_BenchParDir, kPROOF_BenchDataSelPar);
+#else
+      TString par = TString::Format("$ROOTSYS/etc/%s%s.par", kPROOF_BenchParDir, kPROOF_BenchDataSelPar);
+#endif
       Info("Handle", "Uploading '%s' ...", par.Data());
       if (fProof->UploadPackage(par) != 0) {
          Error("Handle", "problems uploading '%s' - cannot continue", par.Data());
diff --git a/proof/proofbench/src/TProofBenchRunCPU.cxx b/proof/proofbench/src/TProofBenchRunCPU.cxx
index a2a10a8bc79..c355cd07ddf 100644
--- a/proof/proofbench/src/TProofBenchRunCPU.cxx
+++ b/proof/proofbench/src/TProofBenchRunCPU.cxx
@@ -274,7 +274,11 @@ void TProofBenchRunCPU::Run(Long64_t nevents, Int_t start, Int_t stop,
       // Is it the default selector?
       if (fSelName == kPROOF_BenchSelCPUDef) {
          // Load the parfile
-         TString par = TString::Format("%s/%s%s.par", TROOT::GetEtcDir().Data(), kPROOF_BenchParDir, kPROOF_BenchCPUSelPar);
+#ifdef R__HAVE_CONFIG
+         TString par = TString::Format("%s/%s%s.par", ROOTETCDIR, kPROOF_BenchParDir, kPROOF_BenchCPUSelPar);
+#else
+         TString par = TString::Format("$ROOTSYS/etc/%s%s.par", kPROOF_BenchParDir, kPROOF_BenchCPUSelPar);
+#endif
          Info("Run", "Uploading '%s' ...", par.Data());
          if (fProof->UploadPackage(par) != 0) {
             Error("Run", "problems uploading '%s' - cannot continue", par.Data());
diff --git a/proof/proofbench/src/TProofBenchRunDataRead.cxx b/proof/proofbench/src/TProofBenchRunDataRead.cxx
index 6eedc89deb5..c5d0bd966cf 100644
--- a/proof/proofbench/src/TProofBenchRunDataRead.cxx
+++ b/proof/proofbench/src/TProofBenchRunDataRead.cxx
@@ -162,7 +162,11 @@ void TProofBenchRunDataRead::Run(const char *dset, Int_t start, Int_t stop,
       // Is it the default selector?
       if (fSelName == kPROOF_BenchSelDataDef) {
          // Load the parfile
-         TString par = TString::Format("%s/%s%s.par", TROOT::GetEtcDir().Data(), kPROOF_BenchParDir, kPROOF_BenchDataSelPar);
+#ifdef R__HAVE_CONFIG
+         TString par = TString::Format("%s/%s%s.par", ROOTETCDIR, kPROOF_BenchParDir, kPROOF_BenchDataSelPar);
+#else
+         TString par = TString::Format("$ROOTSYS/etc/%s%s.par", kPROOF_BenchParDir, kPROOF_BenchDataSelPar);
+#endif
          Info("Run", "Uploading '%s' ...", par.Data());
          if (fProof->UploadPackage(par) != 0) {
             Error("Run", "problems uploading '%s' - cannot continue", par.Data());
diff --git a/proof/proofd/src/XrdROOT.cxx b/proof/proofd/src/XrdROOT.cxx
index 9b6ff1293bc..53ecdb61be4 100644
--- a/proof/proofd/src/XrdROOT.cxx
+++ b/proof/proofd/src/XrdROOT.cxx
@@ -384,19 +384,11 @@ int XrdROOTMgr::Config(bool rcf)
    } else {
       // Check the ROOT dirs
       if (fROOT.size() <= 0) {
-         XrdOucString dir, bd, ld, id, dd;
 #ifdef R__HAVE_CONFIG
-         if (getenv("ROOTIGNOREPREFIX"))
-#endif
-            dir = getenv("ROOTSYS");
-#ifdef R__HAVE_CONFIG
-         else {
-            dir = ROOTPREFIX;
-            bd = ROOTBINDIR;
-            ld = ROOTLIBDIR;
-            id = ROOTINCDIR;
-            dd = ROOTDATADIR;
-         }
+         XrdOucString dir(ROOTPREFIX), bd(ROOTBINDIR), ld(ROOTLIBDIR),
+                      id(ROOTINCDIR), dd(ROOTDATADIR);
+#else
+         XrdOucString dir(getenv("ROOTSYS")), bd, ld, id, dd;
 #endif
          // None defined: use ROOTSYS as default, if any; otherwise we fail
          if (dir.length() > 0) {
diff --git a/proof/proofd/src/proofd.cxx b/proof/proofd/src/proofd.cxx
index 80aac3e581e..18841b1c81f 100644
--- a/proof/proofd/src/proofd.cxx
+++ b/proof/proofd/src/proofd.cxx
@@ -1001,48 +1001,49 @@ int main(int argc, char **argv)
 
    if (argc > 0) {
       gConfDir = std::string(*argv);
-   }
-
-#ifdef ROOTPREFIX
-   if (getenv("IGNOREROOTPREFIX")) {
-#endif
-      if (!gConfDir.length()) {
-         // try to guess the config directory...
-         if (getenv("ROOTSYS")) {
-            gConfDir = getenv("ROOTSYS");
-            if (gDebug > 0)
-               ErrorInfo("main: no config directory specified using"
-                         " ROOTSYS (%s)", gConfDir.c_str());
-         } else {
-            Error(ErrFatal, -1, "main: no config directory specified");
-         }
+   } else {
+      // try to guess the config directory...
+#ifndef ROOTDATADIR
+      if (getenv("ROOTSYS")) {
+         gConfDir = getenv("ROOTSYS");
+         if (gDebug > 0)
+            ErrorInfo("main: no config directory specified using ROOTSYS (%s)",
+                      gConfDir.c_str());
+      } else {
+         Error(ErrFatal, -1, "main: no config directory specified");
       }
-      gRootBinDir = std::string(gConfDir).append("/bin");
-      rootetcdir = std::string(gConfDir).append("/etc");
-#ifdef ROOTPREFIX
-   }
-   else  {
-      if (!gConfDir.length())
-         gConfDir = ROOTPREFIX;
-      gRootBinDir = ROOTBINDIR;
-      rootetcdir = ROOTETCDIR;
+#else
+      gConfDir = ROOTDATADIR;
+#endif
    }
+#ifdef ROOTBINDIR
+   gRootBinDir= ROOTBINDIR;
+#endif
+#ifdef ROOTETCDIR
+   rootetcdir= ROOTETCDIR;
 #endif
 
-   // make sure gRootBinDir contains the executable we want to run
+   // Define gRootBinDir if not done already
+   if (!gRootBinDir.length())
+      gRootBinDir = std::string(gConfDir).append("/bin");
+
+   // make sure it contains the executable we want to run
    std::string arg0 = std::string(gRootBinDir).append("/proofserv");
    if (access(arg0.c_str(), X_OK) == -1) {
       Error(ErrFatal,-1,"main: incorrect config directory specified (%s)",
                         gConfDir.c_str());
    }
-   // Make gRootBinDir available to all the session via env
+   // Make it available to all the session via env
    if (gRootBinDir.length()) {
       char *tmp = new char[15 + gRootBinDir.length()];
       snprintf(tmp, 15 + gRootBinDir.length(), "ROOTBINDIR=%s", gRootBinDir.c_str());
       putenv(tmp);
    }
 
-   // Make rootetcdir available to all the session via env
+   // Define rootetcdir if not done already
+   if (!rootetcdir.length())
+      rootetcdir = std::string(gConfDir).append("/etc");
+   // Make it available to all the session via env
    if (rootetcdir.length()) {
       char *tmp = new char[15 + rootetcdir.length()];
       snprintf(tmp, 15 + rootetcdir.length(), "ROOTETCDIR=%s", rootetcdir.c_str());
diff --git a/roofit/histfactory/CMakeLists.txt b/roofit/histfactory/CMakeLists.txt
index fd891511909..7a81cee2cb9 100644
--- a/roofit/histfactory/CMakeLists.txt
+++ b/roofit/histfactory/CMakeLists.txt
@@ -22,4 +22,10 @@ install(FILES ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/prepareHistFactory
                             WORLD_EXECUTE WORLD_READ
                 DESTINATION ${CMAKE_INSTALL_BINDIR})
 
-ROOT_INSTALL_HEADERS()
+
+#ROOT_INSTALL_HEADERS()
+install(DIRECTORY inc/RooStats/HistFactory/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/RooStats/HistFactory 
+                       COMPONENT headers
+                       PATTERN ".svn" EXCLUDE
+                       REGEX "LinkDef" EXCLUDE )
+set_property(GLOBAL APPEND PROPERTY ROOT_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/inc)
diff --git a/roofit/histfactory/config/prepareHistFactory b/roofit/histfactory/config/prepareHistFactory
index e4c3fa6a611..72712542088 100755
--- a/roofit/histfactory/config/prepareHistFactory
+++ b/roofit/histfactory/config/prepareHistFactory
@@ -2,10 +2,16 @@
 
 # HistFactory workplace setup script
 
-ROOTETCDIR=`root -b -q -l -n -e "std::cout << TROOT::GetEtcDir() << std::endl;" | tail -1`
+ROOTPREFDIR=`root-config --prefix`
+ROOTETCDIR=`root-config --etcdir`
 echo "Using etcdir "$ROOTETCDIR
-ROOTTUTDIR=`root -b -q -l -n -e "std::cout << TROOT::GetTutorialDir() << std::endl;" | tail -1`
-echo "Using tutorials dir" $ROOTTUTDIR 
+ROOTTUTDIR=$ROOTPREFDIR/tutorials
+if test -e $ROOTTUTDIR; then
+    echo "Using tutorials dir" $ROOTTUTDIR 
+else     
+    ROOTTUTDIR=${ROOTPREFDIR}/share/doc/root/tutorials
+    echo "Using tutorials dir" $ROOTTUTDIR 
+fi
 
 if [ $# -eq 1 ]
 then
diff --git a/roofit/roostats/CMakeLists.txt b/roofit/roostats/CMakeLists.txt
index 2434418a1bc..8f432460138 100644
--- a/roofit/roostats/CMakeLists.txt
+++ b/roofit/roostats/CMakeLists.txt
@@ -8,4 +8,9 @@ ROOT_GENERATE_DICTIONARY(G__RooStats RooStats/*.h MODULE RooStats LINKDEF LinkDe
 ROOT_LINKER_LIBRARY(RooStats  *.cxx G__RooStats.cxx LIBRARIES Core 
                                DEPENDENCIES RooFit RooFitCore Tree RIO Hist Matrix MathCore Minuit Foam Graf Gpad )
 
-ROOT_INSTALL_HEADERS()
+#ROOT_INSTALL_HEADERS()
+install(DIRECTORY inc/RooStats/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/RooStats
+                       COMPONENT headers
+                       PATTERN ".svn" EXCLUDE
+                       REGEX "LinkDef" EXCLUDE )
+set_property(GLOBAL APPEND PROPERTY ROOT_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/inc)
diff --git a/rootx/src/rootx.cxx b/rootx/src/rootx.cxx
index 1e63cf7f3c8..76817cc6827 100644
--- a/rootx/src/rootx.cxx
+++ b/rootx/src/rootx.cxx
@@ -218,6 +218,7 @@ static STRUCT_UTMP *SearchEntry(int n, const char *tty)
    return 0;
 }
 
+#ifndef ROOTPREFIX
 static const char *GetExePath()
 {
    static std::string exepath;
@@ -264,6 +265,7 @@ static void SetRootSys()
       delete [] ep;
    }
 }
+#endif
 
 static void SetDisplay()
 {
@@ -312,9 +314,7 @@ static void SetDisplay()
 
 static void SetLibraryPath()
 {
-#ifdef ROOTPREFIX
-   if (getenv("ROOTIGNOREPREFIX")) {
-#endif
+#ifndef ROOTLIBDIR
    // Set library path for the different platforms.
 
    char *msg;
@@ -361,8 +361,6 @@ static void SetLibraryPath()
    }
 #  endif
    putenv(msg);
-#ifdef ROOTPREFIX
-   }
 #endif
 }
 
@@ -460,9 +458,7 @@ int main(int argc, char **argv)
    char **argvv;
    char  arg0[kMAXPATHLEN];
 
-#ifdef ROOTPREFIX
-   if (getenv("ROOTIGNOREPREFIX")) {
-#endif
+#ifndef ROOTPREFIX
    // Try to set ROOTSYS depending on pathname of the executable
    SetRootSys();
 
@@ -471,8 +467,6 @@ int main(int argc, char **argv)
               argv[0], argv[0]);
       return 1;
    }
-#ifdef ROOTPREFIX
-   }
 #endif
 
    // In batch mode don't show splash screen, idem for no logo mode,
@@ -497,20 +491,23 @@ int main(int argc, char **argv)
    if (notebook) {
       // Build command
 #ifdef ROOTBINDIR
-      if (getenv("ROOTIGNOREPREFIX"))
-#endif
-         snprintf(arg0, sizeof(arg0), "%s/bin/%s", getenv("ROOTSYS"), ROOTNBBINARY);
-#ifdef ROOTBINDIR
-      else
-         snprintf(arg0, sizeof(arg0), "%s/%s", ROOTBINDIR, ROOTNBBINARY);
+      snprintf(arg0, sizeof(arg0), "%s/%s", ROOTBINDIR, ROOTNBBINARY);
+#else
+      snprintf(arg0, sizeof(arg0), "%s/bin/%s", getenv("ROOTSYS"), ROOTNBBINARY);
 #endif
 
       // Execute ROOT notebook binary
       execl(arg0, arg0, NULL);
-
+  
       // Exec failed
-      fprintf(stderr, "%s: can't start ROOT notebook -- this option is only available when building with CMake, please check that %s exists\n",
-              argv[0], arg0);
+#ifndef ROOTBINDIR
+      fprintf(stderr,
+              "%s: can't start ROOT notebook -- this option is only available when building with CMake, please check that %s/bin/%s exists\n",
+              argv[0], getenv("ROOTSYS"), ROOTNBBINARY);
+#else
+      fprintf(stderr, "%s: can't start ROOT notebook -- this option is only available when building with CMake, please check that %s/%s exists\n",
+              argv[0], ROOTBINDIR, ROOTNBBINARY);
+#endif
 
       return 1;
    }
@@ -607,12 +604,9 @@ int main(int argc, char **argv)
    // Build argv vector
    argvv = new char* [argc+2];
 #ifdef ROOTBINDIR
-   if (getenv("ROOTIGNOREPREFIX"))
-#endif
-      snprintf(arg0, sizeof(arg0), "%s/bin/%s", getenv("ROOTSYS"), ROOTBINARY);
-#ifdef ROOTBINDIR
-   else
-      snprintf(arg0, sizeof(arg0), "%s/%s", ROOTBINDIR, ROOTBINARY);
+   snprintf(arg0, sizeof(arg0), "%s/%s", ROOTBINDIR, ROOTBINARY);
+#else
+   snprintf(arg0, sizeof(arg0), "%s/bin/%s", getenv("ROOTSYS"), ROOTBINARY);
 #endif
    argvv[0] = arg0;
    argvv[1] = (char *) "-splash";
@@ -628,8 +622,14 @@ int main(int argc, char **argv)
    execv(arg0, argvv);
 
    // Exec failed
-   fprintf(stderr, "%s: can't start ROOT -- check that %s exists!\n",
-           argv[0], arg0);
+#ifndef ROOTBINDIR
+   fprintf(stderr,
+           "%s: can't start ROOT -- check that %s/bin/%s exists!\n",
+           argv[0], getenv("ROOTSYS"), ROOTBINARY);
+#else
+   fprintf(stderr, "%s: can't start ROOT -- check that %s/%s exists!\n",
+           argv[0], ROOTBINDIR, ROOTBINARY);
+#endif
 
    return 1;
 }
diff --git a/test/RootIDE/TGRootIDE.cxx b/test/RootIDE/TGRootIDE.cxx
index ad6a8bfd1dd..66a06f3ce19 100644
--- a/test/RootIDE/TGRootIDE.cxx
+++ b/test/RootIDE/TGRootIDE.cxx
@@ -1270,7 +1270,14 @@ void TGRootIDE::InterruptMacro()
 void TGRootIDE::About()
 {
 #ifdef R__UNIX
-   TString rootx = TROOT::GetBinDir() + "/root -a &";
+   TString rootx;
+# ifdef ROOTBINDIR
+   rootx = ROOTBINDIR;
+# else
+   rootx = gSystem->Getenv("ROOTSYS");
+   if (!rootx.IsNull()) rootx += "/bin";
+# endif
+   rootx += "/root -a &";
    gSystem->Exec(rootx);
 #else
 #ifdef WIN32
diff --git a/test/rhtml/rhtml.cxx b/test/rhtml/rhtml.cxx
index 002c4e531b2..354d2b65995 100644
--- a/test/rhtml/rhtml.cxx
+++ b/test/rhtml/rhtml.cxx
@@ -476,7 +476,14 @@ Bool_t TGHtmlBrowser::ProcessMessage(Long_t msg, Long_t parm1, Long_t)
                   case M_HELP_ABOUT:
                      {
 #ifdef R__UNIX
-                        TString rootx = TROOT::GetBinDir() + "/root -a &";
+                        TString rootx;
+# ifdef ROOTBINDIR
+                        rootx = ROOTBINDIR;
+# else
+                        rootx = gSystem->Getenv("ROOTSYS");
+                        if (!rootx.IsNull()) rootx += "/bin";
+# endif
+                        rootx += "/root -a &";
                         gSystem->Exec(rootx);
 #else
 #ifdef WIN32
diff --git a/tmva/tmva/CMakeLists.txt b/tmva/tmva/CMakeLists.txt
index 921ff91e771..aba77cd35ad 100644
--- a/tmva/tmva/CMakeLists.txt
+++ b/tmva/tmva/CMakeLists.txt
@@ -59,6 +59,7 @@ if(CUDA_FOUND)
   CUDA_ADD_LIBRARY(dnn_cuda ${DNN_CUDA_FILES})
   set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DDNNCUDA")
   set(DNN_CUDA_LIBRARIES dnn_cuda ${CUDA_CUBLAS_LIBRARIES})
+  add_dependencies(dnn_cuda move_headers)
 else()
   set(DNN_CUDA_LIBRARIES)
   set(installoptions ${installoptions} OPTIONS REGEX "Cuda" EXCLUDE)
@@ -83,6 +84,8 @@ ROOT_LINKER_LIBRARY(TMVA *.cxx G__TMVA.cxx ${DNN_FILES} ${DNN_CPU_FILES}
 
 ROOT_INSTALL_HEADERS(${installoptions})
 
+set_property(GLOBAL APPEND PROPERTY ROOT_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/inc)
+
 if(NOT gnuinstall)
   install(DIRECTORY test DESTINATION tmva 
   FILES_MATCHING PATTERN "*.C" 
diff --git a/tmva/tmva/Module.mk b/tmva/tmva/Module.mk
index 74c443a0c46..d03c5a4843a 100644
--- a/tmva/tmva/Module.mk
+++ b/tmva/tmva/Module.mk
@@ -116,12 +116,12 @@ $(TMVALIB):     $(TMVAO) $(TMVADO) $(ORDER_) $(MAINLIBS) $(TMVALIBDEP)
 $(call pcmrule,TMVA)
 	$(noop)
 
-$(TMVADS):      $(TMVA_NOICC_REL) $(TMVAL0) $(TMVALS) $(ROOTCLINGEXE) $(call pcmdep,TMVA)
+$(TMVADS):      $(TMVA_REL) $(TMVAL0) $(TMVALS) $(ROOTCLINGEXE) $(call pcmdep,TMVA)
 		$(MAKEDIR)
 		@echo "Generating dictionary $@..."
 		$(ROOTCLINGSTAGE2) -f $@ $(call dictModule,TMVA) -c -writeEmptyRootPCM $(patsubst include/%,%,$(TMVA_NOICC_REL)) -I$(ROOT_SRCDIR) $(TMVAL0)
 
-$(TMVAMAP):     $(TMVA_NOICC_REL) $(TMVAL0) $(TMVALS) $(ROOTCLINGEXE) $(call pcmdep,TMVA)
+$(TMVAMAP):     $(TMVA_REL) $(TMVAL0) $(TMVALS) $(ROOTCLINGEXE) $(call pcmdep,TMVA)
 		$(MAKEDIR)
 		@echo "Generating rootmap $@..."
 		$(ROOTCLINGSTAGE2) -r $(TMVADS) $(call dictModule,TMVA) -c -I$(ROOT_SRCDIR) $(TMVA_NOICC_REL) $(TMVAL0)
diff --git a/tmva/tmvagui/CMakeLists.txt b/tmva/tmvagui/CMakeLists.txt
index fd1b3f1a428..1feb86df648 100644
--- a/tmva/tmvagui/CMakeLists.txt
+++ b/tmva/tmvagui/CMakeLists.txt
@@ -31,7 +31,11 @@ ROOT_GENERATE_DICTIONARY(G__TMVAGui ${theaders1}   MODULE TMVAGui LINKDEF LinkDe
 ROOT_LINKER_LIBRARY(TMVAGui *.cxx G__TMVAGui.cxx LIBRARIES Core
                     DEPENDENCIES RIO Hist Tree TreeViewer  MLP Minuit XMLIO TMVA Gui)
 
-ROOT_INSTALL_HEADERS()
+install(DIRECTORY inc/TMVA/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/TMVA
+                            COMPONENT headers
+                            PATTERN ".svn" EXCLUDE
+                            REGEX "LinkDef" EXCLUDE )
+set_property(GLOBAL APPEND PROPERTY ROOT_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/inc)
 
 if(NOT gnuinstall)
   install(DIRECTORY test DESTINATION tmva 
diff --git a/tree/treeviewer/src/TTreeViewer.cxx b/tree/treeviewer/src/TTreeViewer.cxx
index 9eaf83acd1b..9e26fc98518 100644
--- a/tree/treeviewer/src/TTreeViewer.cxx
+++ b/tree/treeviewer/src/TTreeViewer.cxx
@@ -2048,7 +2048,14 @@ Bool_t TTreeViewer::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
                   case kHelpAbout:
                      {
 #ifdef R__UNIX
-                        TString rootx = TROOT::GetBinDir() + "/root -a &";
+                        TString rootx;
+# ifdef ROOTBINDIR
+                        rootx = ROOTBINDIR;
+# else
+                        rootx = gSystem->Getenv("ROOTSYS");
+                        if (!rootx.IsNull()) rootx += "/bin";
+# endif
+                        rootx += "/root -a &";
                         gSystem->Exec(rootx);
 #else
 #ifdef WIN32
diff --git a/tutorials/eve/SplitGLView.C b/tutorials/eve/SplitGLView.C
index 268ffd16927..c4cfe5ed496 100644
--- a/tutorials/eve/SplitGLView.C
+++ b/tutorials/eve/SplitGLView.C
@@ -291,7 +291,8 @@ void TGShapedToolTip::Refresh()
    const char *str = fText.Data();
    char *string = strdup(str);
    Int_t nlines = 0, size = fTextH;
-   TString ar = "arial.ttf";
+   TString fp = gEnv->GetValue("Root.TTFontPath", "");
+   TString ar = fp + "/arial.ttf";
    char *s = strtok((char *)string, "\n");
    TImage *img = (TImage*)fImage->Clone("img");
    img->DrawText(fTextX, fTextY+(nlines*size), s, size, fTextCol, ar);
@@ -1019,7 +1020,14 @@ void SplitGLView::HandleMenu(Int_t id)
       case kHelpAbout:
          {
 #ifdef R__UNIX
-            TString rootx = TROOT::GetBinDir() + "/root -a &";
+            TString rootx;
+# ifdef ROOTBINDIR
+            rootx = ROOTBINDIR;
+# else
+            rootx = gSystem->Getenv("ROOTSYS");
+            if (!rootx.IsNull()) rootx += "/bin";
+# endif
+            rootx += "/root -a &";
             gSystem->Exec(rootx);
 #else
 #ifdef WIN32
diff --git a/tutorials/fit/fit1.C b/tutorials/fit/fit1.C
index 4c6fe2472ce..17a6322af4b 100644
--- a/tutorials/fit/fit1.C
+++ b/tutorials/fit/fit1.C
@@ -35,7 +35,7 @@ void fit1() {
    // We connect the ROOT file generated in a previous tutorial
    // (see <a href="fillrandom.C.nbconvert.ipynb">Filling histograms with random numbers from a function</a>) 
    //
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    dir.Append("/fit/");
    TFile *file = TFile::Open("fillrandom.root");
    if (!file) {
diff --git a/tutorials/fit/fitslicesy.C b/tutorials/fit/fitslicesy.C
index b48c27a2e0b..ba694cb0b66 100644
--- a/tutorials/fit/fitslicesy.C
+++ b/tutorials/fit/fitslicesy.C
@@ -23,7 +23,7 @@ void fitslicesy() {
    gStyle->SetTitleH(0.1);
 
 // Connect the input file and get the 2-d histogram in memory
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    dir.Append("/hsimple.C");
    dir.ReplaceAll("/./","/");
    if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
diff --git a/tutorials/fit/myfit.C b/tutorials/fit/myfit.C
index 70f5aa16142..c707edc1277 100644
--- a/tutorials/fit/myfit.C
+++ b/tutorials/fit/myfit.C
@@ -25,7 +25,7 @@ Double_t fitf(Double_t *x, Double_t *par)
 }
 void myfit()
 {
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    dir.Append("/hsimple.C");
    dir.ReplaceAll("/./","/");
    if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
diff --git a/tutorials/foam/foam_demopers.C b/tutorials/foam/foam_demopers.C
index 7e7be9a1442..1e4a024819e 100644
--- a/tutorials/foam/foam_demopers.C
+++ b/tutorials/foam/foam_demopers.C
@@ -24,7 +24,7 @@ Int_t foam_demopers()
    gSystem->Load("libFoam");
 
    // need to load the foam_demo tutorial for the definition of the function
-   TString macroName = gROOT->GetTutorialDir();
+   TString macroName = gROOT->GetTutorialsDir();
    macroName.Append("/foam/foam_demo.C");
    gROOT->ProcessLine(TString::Format(".L %s+",macroName.Data()));
 
diff --git a/tutorials/geom/runplugin.C b/tutorials/geom/runplugin.C
index f3694fa4067..9fbff154fb9 100644
--- a/tutorials/geom/runplugin.C
+++ b/tutorials/geom/runplugin.C
@@ -27,7 +27,7 @@ void runplugin()
 {
 
 
-   TString tutdir = gROOT->GetTutorialDir();
+   TString tutdir = gROOT->GetTutorialsDir();
    gROOT->ProcessLine(".x " + tutdir + "/geom/rootgeom.C");
    plugin = new iterplugin();
    gGeoManager->GetGeomPainter()->SetIteratorPlugin(plugin);
diff --git a/tutorials/graphics/earth.C b/tutorials/graphics/earth.C
index e33a8fe9df7..85889ab49f2 100644
--- a/tutorials/graphics/earth.C
+++ b/tutorials/graphics/earth.C
@@ -26,7 +26,7 @@ TCanvas *earth(){
    TH2F *hs = new TH2F("hs","Sinusoidal",180, -180, 180, 181, -90.5, 90.5);
    TH2F *hp = new TH2F("hp","Parabolic", 180, -180, 180, 181, -90.5, 90.5);
 
-   TString dat = gROOT->GetTutorialDir();
+   TString dat = gROOT->GetTutorialsDir();
    dat.Append("/graphics/earth.dat");
    dat.ReplaceAll("/./","/");
 
diff --git a/tutorials/graphics/psview.C b/tutorials/graphics/psview.C
index 205a8b81c97..63a42ec91b6 100644
--- a/tutorials/graphics/psview.C
+++ b/tutorials/graphics/psview.C
@@ -32,7 +32,7 @@ void psview()
    gROOT->SetBatch(1);
 
    // create a PostScript file
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    dir.Append("/graphics/feynman.C");
    gROOT->Macro(dir);
    gPad->Print("feynman.eps");
diff --git a/tutorials/graphs/motorcycle.C b/tutorials/graphs/motorcycle.C
index 294c83d4a01..8c12977bf52 100644
--- a/tutorials/graphs/motorcycle.C
+++ b/tutorials/graphs/motorcycle.C
@@ -43,7 +43,7 @@ void DrawSmooth(Int_t pad, const char *title, const char *xt, const char *yt)
 void motorcycle()
 {
 // data taken from R library MASS: mcycle.txt
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    dir.Append("/graphs/");
    dir.ReplaceAll("/./","/");
 
diff --git a/tutorials/hist/FirstContour.C b/tutorials/hist/FirstContour.C
index 4368f216441..f06f551040f 100644
--- a/tutorials/hist/FirstContour.C
+++ b/tutorials/hist/FirstContour.C
@@ -13,7 +13,7 @@
 
 void FirstContour()
 {
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    dir.Append("/hsimple.C");
    dir.ReplaceAll("/./","/");
    if (!gInterpreter->IsLoaded(dir.Data())) gInterpreter->LoadMacro(dir.Data());
diff --git a/tutorials/hist/h1draw.C b/tutorials/hist/h1draw.C
index b8e9065e628..f8c15d0e85a 100644
--- a/tutorials/hist/h1draw.C
+++ b/tutorials/hist/h1draw.C
@@ -25,7 +25,7 @@
 
 void h1draw()
 {
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    dir.Append("/hsimple.C");
    dir.ReplaceAll("/./","/");
    if (gBenchmark->GetBench("hsimple") < 0) gInterpreter->LoadMacro(dir.Data());
diff --git a/tutorials/hist/hbars.C b/tutorials/hist/hbars.C
index 534af10d156..778d2d4a92d 100644
--- a/tutorials/hist/hbars.C
+++ b/tutorials/hist/hbars.C
@@ -10,7 +10,7 @@
 
 TCanvas *hbars() {
      // Try to open first the file cernstaff.root in tutorials/tree directory
-   TString filedir = gROOT->GetTutorialDir();
+   TString filedir = gROOT->GetTutorialsDir();
    filedir += TString("/tree/");
    TString filename = "cernstaff.root";
    bool fileNotFound = gSystem->AccessPathName(filename); // note opposite return code
diff --git a/tutorials/hsimple.C b/tutorials/hsimple.C
index cf91cf03810..e98ebccc56b 100644
--- a/tutorials/hsimple.C
+++ b/tutorials/hsimple.C
@@ -34,7 +34,7 @@
 TFile *hsimple(Int_t getFile=0)
 {
    TString filename = "hsimple.root";
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    dir.ReplaceAll("/./","/");
    TFile *hfile = 0;
    if (getFile) {
diff --git a/tutorials/image/rose_image.C b/tutorials/image/rose_image.C
index 529dd87a086..10554d7ae50 100644
--- a/tutorials/image/rose_image.C
+++ b/tutorials/image/rose_image.C
@@ -20,7 +20,7 @@ TCanvas *c1;
 
 void rose_image()
 {
-   TString dir = TROOT::GetTutorialDir();
+   TString dir = TROOT::GetTutorialsDir();
 
    TImage *img = TImage::Open(dir + "/image/rose512.jpg");
 
@@ -32,8 +32,9 @@ void rose_image()
    img->SetConstRatio(0);
    img->SetImageQuality(TAttImage::kImgBest);
 
-   TString bc = "BlackChancery.ttf";
-   TString ar = "arial.ttf";
+   TString fp = gEnv->GetValue("Root.TTFontPath", "");
+   TString bc = fp + "/BlackChancery.ttf";
+   TString ar = fp + "/arial.ttf";
 
    // draw text over image with funny font
    img->DrawText(120, 160, "Hello World!", 32,
diff --git a/tutorials/io/importCode.C b/tutorials/io/importCode.C
index e850c5b6363..9799610d861 100644
--- a/tutorials/io/importCode.C
+++ b/tutorials/io/importCode.C
@@ -54,7 +54,7 @@ void importdir(const char *dirname) {
 }
 void importCode() {
    TFile *f = new TFile("code.root","recreate");
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    importdir(dir); //change the directory as you like
    delete f;
 }
diff --git a/tutorials/io/mergeSelective.C b/tutorials/io/mergeSelective.C
index b3dcf46146c..9daff2808e3 100644
--- a/tutorials/io/mergeSelective.C
+++ b/tutorials/io/mergeSelective.C
@@ -49,7 +49,7 @@ void mergeSelective(Int_t nfiles=5)
    // Create the files to be merged
    TStopwatch timer;
    timer.Start();
-   TString tutdir = gROOT->GetTutorialDir();
+   TString tutdir = gROOT->GetTutorialsDir();
    if (gROOT->LoadMacro(tutdir + "/hsimple.C")) return;
    Int_t i;
    for (i=0; i<nfiles; i++) CreateFile(Form("tomerge%03d.root",i));
diff --git a/tutorials/io/testMergeCont.C b/tutorials/io/testMergeCont.C
index 98cb1ead741..96f2cbef85d 100644
--- a/tutorials/io/testMergeCont.C
+++ b/tutorials/io/testMergeCont.C
@@ -39,7 +39,7 @@ TSeqCollection *GetCollection()
 
 void testMergeCont()
 {
-   TString tutdir = gROOT->GetTutorialDir();
+   TString tutdir = gROOT->GetTutorialsDir();
    gROOT->LoadMacro(tutdir+"/hsimple.C");
    TList *list1 = (TList *)GetCollection();
    TList *inputs = new TList();
diff --git a/tutorials/multicore/mp103_processSelector.C b/tutorials/multicore/mp103_processSelector.C
index 3272f414278..a564c390a7f 100644
--- a/tutorials/multicore/mp103_processSelector.C
+++ b/tutorials/multicore/mp103_processSelector.C
@@ -26,7 +26,7 @@ int mp103_processSelector(){
   // MacOSX may generate connection to WindowServer errors
   gROOT->SetBatch(kTRUE);
 
-  TString selectorPath = gROOT->GetTutorialDir();
+  TString selectorPath = gROOT->GetTutorialsDir();
   selectorPath += "/tree/h1analysis.C+";
   std::cout << "selector used is: "<< selectorPath<<"\n";
   TSelector *sel = TSelector::GetSelector(selectorPath);
diff --git a/tutorials/pyroot/benchmarks.py b/tutorials/pyroot/benchmarks.py
index 0de6d4d9716..108cadd5aba 100644
--- a/tutorials/pyroot/benchmarks.py
+++ b/tutorials/pyroot/benchmarks.py
@@ -45,7 +45,7 @@ def bexec( dir, macro, bench ):
 ## --------------------------------------------------------------------------
 if __name__ == '__main__':
 
-   macrodir = os.path.join(str(ROOT.gROOT.GetTutorialDir()), 'pyroot')
+   macrodir = os.path.join(ROOT.gROOT.GetTutorialsDir(), 'pyroot')
 
  # window for keeping track of bench marks that are run
    bench = ROOT.TCanvas( 'bench','Benchmarks Summary', -1000, 50, 200, 500 )
diff --git a/tutorials/pyroot/fit1.py b/tutorials/pyroot/fit1.py
index 6f1eda7d11c..4f939bbb462 100644
--- a/tutorials/pyroot/fit1.py
+++ b/tutorials/pyroot/fit1.py
@@ -51,7 +51,7 @@ h1f.Fit( 'sqroot' )
 fitlabel = TPaveText( 0.6, 0.3, 0.9, 0.80, 'NDC' )
 fitlabel.SetTextAlign( 12 )
 fitlabel.SetFillColor( 42 )
-fitlabel.ReadFile(path.join(str(gROOT.GetTutorialDir()), 'pyroot', 'fit1_py.py'))
+fitlabel.ReadFile(path.join(gROOT.GetTutorialsDir(), 'pyroot', 'fit1_py.py'))
 fitlabel.Draw()
 c1.Update()
 gBenchmark.Show( 'fit1' )
diff --git a/tutorials/pyroot/geometry.py b/tutorials/pyroot/geometry.py
index 7d14c4e3631..45a18cd96b0 100644
--- a/tutorials/pyroot/geometry.py
+++ b/tutorials/pyroot/geometry.py
@@ -10,7 +10,7 @@
 import os
 import ROOT
 
-macrodir = os.path.join(str(ROOT.gROOT.GetTutorialDir()), 'pyroot')
+macrodir = os.path.join(ROOT.gROOT.GetTutorialsDir(), 'pyroot')
 
 # the na49.C file was generated, so no python conversion is provided
 ROOT.gROOT.Macro( ROOT.gSystem.UnixPathName( os.path.join( macrodir, os.pardir, 'geom', 'na49.C' ) ) )
diff --git a/tutorials/pyroot/rootmarks.py b/tutorials/pyroot/rootmarks.py
index 63367d0b2e2..2fdc756aa45 100644
--- a/tutorials/pyroot/rootmarks.py
+++ b/tutorials/pyroot/rootmarks.py
@@ -13,7 +13,7 @@
 import os
 import ROOT
 
-macrodir = os.path.join(str(ROOT.gROOT.GetTutorialDir()), 'pyroot')
+macrodir = os.path.join(ROOT.gROOT.GetTutorialsDir(), 'pyroot')
 
 # use ROOT macro to make sure that bench numbers get updated in one place
 ROOT.gROOT.Macro( ROOT.gSystem.UnixPathName( os.path.join( macrodir, os.pardir, 'rootmarks.C' ) ) )
diff --git a/tutorials/pyroot/staff.py b/tutorials/pyroot/staff.py
index 274607557f4..55dc83053b9 100644
--- a/tutorials/pyroot/staff.py
+++ b/tutorials/pyroot/staff.py
@@ -47,7 +47,7 @@ def staff():
     tree.Branch( 'Nation', AddressOf( staff, 'Nation' ), 'Nation/C' )
 
     # note that the branches Division and Nation cannot be on the first branch
-    fname = os.path.join(str(ROOT.gROOT.GetTutorialDir()), 'tree', 'cernstaff.dat')
+    fname = os.path.join(ROOT.gROOT.GetTutorialsDir(), 'tree', 'cernstaff.dat')
     for line in open(fname).readlines():
         t = list(filter( lambda x: x, re.split( '\s+', line ) ) )
         staff.Category = int(t[0])             # assign as integers
diff --git a/tutorials/roofit/rf505_asciicfg.C b/tutorials/roofit/rf505_asciicfg.C
index 1b60124d4ee..9e149a0a695 100644
--- a/tutorials/roofit/rf505_asciicfg.C
+++ b/tutorials/roofit/rf505_asciicfg.C
@@ -60,9 +60,9 @@ void rf505_asciicfg()
    params->writeToFile("rf505_asciicfg_example.txt") ;
 
 
-   TString dir1 = gROOT->GetTutorialDir() ;
+   TString dir1 = gROOT->GetTutorialsDir() ;
    dir1.Append("/roofit/rf505_asciicfg.txt") ;
-   TString dir2 = gROOT->GetTutorialDir() ;
+   TString dir2 = gROOT->GetTutorialsDir() ;
    dir2.Append("/roofit/rf505_asciicfg_example.txt") ;
    // R e a d    p a r a m e t e r s   f r o m    a s c i i   f i l e 
    // ----------------------------------------------------------------
diff --git a/tutorials/spectrum/Background_compton.C b/tutorials/spectrum/Background_compton.C
index d5ffb8c9138..34192cf9b8f 100644
--- a/tutorials/spectrum/Background_compton.C
+++ b/tutorials/spectrum/Background_compton.C
@@ -19,7 +19,7 @@ void Background_compton() {
 
    TH1F *d1 = new TH1F("d1","",nbins,xmin,xmax);
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    TH1F *back = (TH1F*) f->Get("back3");
diff --git a/tutorials/spectrum/Background_decr.C b/tutorials/spectrum/Background_decr.C
index 4e14f7e2b68..08fa60a3023 100644
--- a/tutorials/spectrum/Background_decr.C
+++ b/tutorials/spectrum/Background_decr.C
@@ -18,7 +18,7 @@ void Background_decr() {
 
    TH1F *d    = new TH1F("d","",nbins,xmin,xmax);
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    TH1F *back = (TH1F*) f->Get("back1");
diff --git a/tutorials/spectrum/Background_incr.C b/tutorials/spectrum/Background_incr.C
index 580791a366b..4dc63ce404e 100644
--- a/tutorials/spectrum/Background_incr.C
+++ b/tutorials/spectrum/Background_incr.C
@@ -18,7 +18,7 @@ void Background_incr() {
 
    TH1F *d    = new TH1F("d","",nbins,xmin,xmax);
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    TH1F *back = (TH1F*) f->Get("back1");
diff --git a/tutorials/spectrum/Background_order.C b/tutorials/spectrum/Background_order.C
index 0e7be3bd4ad..465ae17e7fe 100644
--- a/tutorials/spectrum/Background_order.C
+++ b/tutorials/spectrum/Background_order.C
@@ -22,7 +22,7 @@ void Background_order() {
    TH1F *d3 = new TH1F("d3","",nbins,xmin,xmax);
    TH1F *d4 = new TH1F("d4","",nbins,xmin,xmax);
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    TH1F *back = (TH1F*) f->Get("back2");
diff --git a/tutorials/spectrum/Background_smooth.C b/tutorials/spectrum/Background_smooth.C
index a3e82578a4c..5b30df09b15 100644
--- a/tutorials/spectrum/Background_smooth.C
+++ b/tutorials/spectrum/Background_smooth.C
@@ -20,7 +20,7 @@ void Background_smooth() {
    TH1F *d1 = new TH1F("d1","",nbins,xmin,xmax);
    TH1F *d2 = new TH1F("d2","",nbins,xmin,xmax);
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    TH1F *back = (TH1F*) f->Get("back1");
diff --git a/tutorials/spectrum/Background_width.C b/tutorials/spectrum/Background_width.C
index 24f5c443ac0..29bd4bd6f2c 100644
--- a/tutorials/spectrum/Background_width.C
+++ b/tutorials/spectrum/Background_width.C
@@ -17,7 +17,7 @@ void Background_width() {
    Double_t source[nbins];
    gROOT->ForceStyle();
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    TH1F *back = (TH1F*) f->Get("back1");
diff --git a/tutorials/spectrum/Background_width2.C b/tutorials/spectrum/Background_width2.C
index 62046dd4b2a..db8c67330ee 100644
--- a/tutorials/spectrum/Background_width2.C
+++ b/tutorials/spectrum/Background_width2.C
@@ -22,7 +22,7 @@ void Background_width2() {
    TH1F *d3 = new TH1F("d3","",nbins,xmin,xmax);
    TH1F *d4 = new TH1F("d4","",nbins,xmin,xmax);
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    TH1F *back = (TH1F*) f->Get("back2");
diff --git a/tutorials/spectrum/Deconvolution.C b/tutorials/spectrum/Deconvolution.C
index da07f76583a..f5283a67122 100644
--- a/tutorials/spectrum/Deconvolution.C
+++ b/tutorials/spectrum/Deconvolution.C
@@ -17,7 +17,7 @@ void Deconvolution() {
    Double_t response[nbins];
    gROOT->ForceStyle();
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    TH1F *h = (TH1F*) f->Get("decon1");
diff --git a/tutorials/spectrum/DeconvolutionRL_wide.C b/tutorials/spectrum/DeconvolutionRL_wide.C
index d7a19d123e4..f292c5e0279 100644
--- a/tutorials/spectrum/DeconvolutionRL_wide.C
+++ b/tutorials/spectrum/DeconvolutionRL_wide.C
@@ -17,7 +17,7 @@ void DeconvolutionRL_wide() {
    Double_t response[nbins];
    gROOT->ForceStyle();
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    TH1F* h = (TH1F*) f->Get("decon3");
diff --git a/tutorials/spectrum/DeconvolutionRL_wide_boost.C b/tutorials/spectrum/DeconvolutionRL_wide_boost.C
index 81765044441..0cdeb1904c8 100644
--- a/tutorials/spectrum/DeconvolutionRL_wide_boost.C
+++ b/tutorials/spectrum/DeconvolutionRL_wide_boost.C
@@ -17,7 +17,7 @@ void DeconvolutionRL_wide_boost() {
    Double_t response[nbins];
    gROOT->ForceStyle();
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    TH1F* h = (TH1F*) f->Get("decon3");
diff --git a/tutorials/spectrum/Deconvolution_wide.C b/tutorials/spectrum/Deconvolution_wide.C
index 7257d8dcd43..e4bb70db7aa 100644
--- a/tutorials/spectrum/Deconvolution_wide.C
+++ b/tutorials/spectrum/Deconvolution_wide.C
@@ -17,7 +17,7 @@ void Deconvolution_wide() {
    Double_t response[nbins];
    gROOT->ForceStyle();
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    TH1F *h = (TH1F*) f->Get("decon3");
diff --git a/tutorials/spectrum/Deconvolution_wide_boost.C b/tutorials/spectrum/Deconvolution_wide_boost.C
index 8f3fd455894..8aa1adf5d62 100644
--- a/tutorials/spectrum/Deconvolution_wide_boost.C
+++ b/tutorials/spectrum/Deconvolution_wide_boost.C
@@ -20,7 +20,7 @@ void Deconvolution_wide_boost() {
    TH1F *h = new TH1F("h","Deconvolution",nbins,xmin,xmax);
    TH1F *d = new TH1F("d","",nbins,xmin,xmax);
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    h = (TH1F*) f->Get("decon3");
diff --git a/tutorials/spectrum/SearchHR1.C b/tutorials/spectrum/SearchHR1.C
index c2a7ca3f2f2..7117ce75dae 100644
--- a/tutorials/spectrum/SearchHR1.C
+++ b/tutorials/spectrum/SearchHR1.C
@@ -21,7 +21,7 @@ void SearchHR1() {
    Double_t source[nbins], dest[nbins];
    gROOT->ForceStyle();
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    TH1F *h = (TH1F*) f->Get("back2");
diff --git a/tutorials/spectrum/SearchHR3.C b/tutorials/spectrum/SearchHR3.C
index 8778ae64e53..553449f47c2 100644
--- a/tutorials/spectrum/SearchHR3.C
+++ b/tutorials/spectrum/SearchHR3.C
@@ -22,7 +22,7 @@ void SearchHR3() {
    Double_t source[nbins], dest[nbins];
    gROOT->ForceStyle();
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    TH1F *h = (TH1F*) f->Get("back2");
diff --git a/tutorials/spectrum/Smoothing.C b/tutorials/spectrum/Smoothing.C
index 1892444e272..9e99fb210c0 100644
--- a/tutorials/spectrum/Smoothing.C
+++ b/tutorials/spectrum/Smoothing.C
@@ -16,7 +16,7 @@ void Smoothing() {
    Double_t source[nbins];
    gROOT->ForceStyle();
 
-   TString dir  = gROOT->GetTutorialDir();
+   TString dir  = gROOT->GetTutorialsDir();
    TString file = dir+"/spectrum/TSpectrum.root";
    TFile *f     = new TFile(file.Data());
    TH1F *h = (TH1F*) f->Get("back1");
diff --git a/tutorials/tmva/TMVAClassificationCategory.C b/tutorials/tmva/TMVAClassificationCategory.C
index 66cfc3224a0..2577c156bbc 100644
--- a/tutorials/tmva/TMVAClassificationCategory.C
+++ b/tutorials/tmva/TMVAClassificationCategory.C
@@ -89,7 +89,7 @@ void TMVAClassificationCategory()
    TString fname = TString(gSystem->DirName(__FILE__) ) + "/data/";
    if (gSystem->AccessPathName( fname + "toy_sigbkg_categ_offset.root")) {
       // if directory data not found try using tutorials dir
-      fname = gROOT->GetTutorialDir() + "/tmva/data/";
+      fname = TString(gROOT->GetTutorialsDir()) + "/tmva/data/";
    }
    if (UseOffsetMethod) fname += "toy_sigbkg_categ_offset.root";
    else                 fname += "toy_sigbkg_categ_varoff.root";
diff --git a/tutorials/tmva/TMVAClassificationCategoryApplication.C b/tutorials/tmva/TMVAClassificationCategoryApplication.C
index 7cc2e00428c..8dd2bf23712 100644
--- a/tutorials/tmva/TMVAClassificationCategoryApplication.C
+++ b/tutorials/tmva/TMVAClassificationCategoryApplication.C
@@ -85,7 +85,7 @@ void TMVAClassificationCategoryApplication()
    TString fname = TString(gSystem->DirName(__FILE__) ) + "/data/";
    // if directory data not found try using tutorials dir
    if (gSystem->AccessPathName( fname + "toy_sigbkg_categ_offset.root"  )) {
-      fname = gROOT->GetTutorialDir() + "/tmva/data/";
+      fname = TString(gROOT->GetTutorialsDir()) + "/tmva/data/";
    }
    if (UseOffsetMethod) fname += "toy_sigbkg_categ_offset.root";
    else                 fname += "toy_sigbkg_categ_varoff.root";
diff --git a/tutorials/tmva/TMVAMulticlass.C b/tutorials/tmva/TMVAMulticlass.C
index 76efd1d2fc0..129723834f9 100644
--- a/tutorials/tmva/TMVAMulticlass.C
+++ b/tutorials/tmva/TMVAMulticlass.C
@@ -98,7 +98,7 @@ void TMVAMulticlass( TString myMethodList = "" )
    }
    else {
       std::cout << "Creating testdata...." << std::endl;
-      TString createDataMacro = gROOT->GetTutorialDir() + "/tmva/createData.C";
+      TString createDataMacro = TString(gROOT->GetTutorialsDir()) + "/tmva/createData.C";
       gROOT->ProcessLine(TString::Format(".L %s",createDataMacro.Data()));
       gROOT->ProcessLine("create_MultipleBackground(2000)");
       std::cout << " created tmva_example_multiple_background.root for tests of the multiclass features"<<std::endl;
diff --git a/tutorials/tmva/TMVAMultipleBackgroundExample.C b/tutorials/tmva/TMVAMultipleBackgroundExample.C
index 66db511fc6a..1185f796a6e 100644
--- a/tutorials/tmva/TMVAMultipleBackgroundExample.C
+++ b/tutorials/tmva/TMVAMultipleBackgroundExample.C
@@ -476,7 +476,7 @@ void TMVAMultipleBackgroundExample()
         << "========================" << endl
         << endl;
 
-   TString createDataMacro = gROOT->GetTutorialDir() + "/tmva/createData.C";
+   TString createDataMacro = TString(gROOT->GetTutorialsDir()) + "/tmva/createData.C";
    gROOT->ProcessLine(TString::Format(".L %s",createDataMacro.Data()));
    gROOT->ProcessLine("create_MultipleBackground(2000)");
 
diff --git a/tutorials/tmva/keras/MulticlassKeras.py b/tutorials/tmva/keras/MulticlassKeras.py
index 417472d1e73..34da4fa3c44 100755
--- a/tutorials/tmva/keras/MulticlassKeras.py
+++ b/tutorials/tmva/keras/MulticlassKeras.py
@@ -19,7 +19,7 @@ factory = TMVA.Factory('TMVAClassification', output,
 
 # Load data
 if not isfile('tmva_example_multiple_background.root'):
-    createDataMacro = str(gROOT.GetTutorialDir()) + '/tmva/createData.C'
+    createDataMacro = gROOT.GetTutorialsDir() + '/tmva/createData.C'
     print(createDataMacro)
     gROOT.ProcessLine('.L {}'.format(createDataMacro))
     gROOT.ProcessLine('create_MultipleBackground(4000)')
diff --git a/tutorials/tree/basic.C b/tutorials/tree/basic.C
index 2c52265c203..328645b2e66 100644
--- a/tutorials/tree/basic.C
+++ b/tutorials/tree/basic.C
@@ -12,7 +12,7 @@
 void basic() {
 // read file $ROOTSYS/tutorials/tree/basic.dat
 // this file has 3 columns of float data
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    dir.Append("/tree/");
    dir.ReplaceAll("/./","/");
    ifstream in;
diff --git a/tutorials/tree/basic2.C b/tutorials/tree/basic2.C
index 2a4abbd1bf0..f88e22cd621 100644
--- a/tutorials/tree/basic2.C
+++ b/tutorials/tree/basic2.C
@@ -10,7 +10,7 @@
 /// \author Rene Brun
 
 void basic2() {
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    dir.Append("/tree/");
    dir.ReplaceAll("/./","/");
 
diff --git a/tutorials/tree/cernbuild.C b/tutorials/tree/cernbuild.C
index 69d68f44803..1159c539d9d 100644
--- a/tutorials/tree/cernbuild.C
+++ b/tutorials/tree/cernbuild.C
@@ -25,7 +25,7 @@ TFile *cernbuild(Int_t getFile=0, Int_t print=1) {
    //The input file cern.dat is a copy of the CERN staff data base
    //from 1988
    TString filename = "cernstaff.root";
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    dir.Append("/tree/");
    dir.ReplaceAll("/./","/");
    FILE *fp = fopen(Form("%scernstaff.dat",dir.Data()),"r");
diff --git a/tutorials/tree/cernstaff.C b/tutorials/tree/cernstaff.C
index 013a7c24952..4006b2622c5 100644
--- a/tutorials/tree/cernstaff.C
+++ b/tutorials/tree/cernstaff.C
@@ -9,7 +9,7 @@
 /// \author Rene Brun
 
 void cernstaff () {
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    dir.Append("/tree/cernstaff.C");
    if (gSystem->AccessPathName("cernstaff.root")) {
       gROOT->SetMacroPath(dir);
diff --git a/tutorials/tree/jets.C b/tutorials/tree/jets.C
index 795702ae766..70a9687c5d5 100644
--- a/tutorials/tree/jets.C
+++ b/tutorials/tree/jets.C
@@ -99,7 +99,7 @@ void jets(Int_t nev=100, Int_t npileup=200, Bool_t secondrun = true) {
 //void jets(Int_t nev=100, Int_t npileup=200, Bool_t secondrun);
 void jets(Int_t nev=100, Int_t npileup=200) {
    gSystem->Load("libPhysics");
-   TString tutdir = gROOT->GetTutorialDir();
+   TString tutdir = gROOT->GetTutorialsDir();
    gROOT->ProcessLine(".L " + tutdir + "/tree/JetEvent.cxx+");
    gROOT->ProcessLine("#define JETS_SECOND_RUN yes");
    gROOT->ProcessLine("#include \"" __FILE__ "\"");
diff --git a/tutorials/tree/ntuple1.C b/tutorials/tree/ntuple1.C
index f416bb06188..2a9248b4a76 100644
--- a/tutorials/tree/ntuple1.C
+++ b/tutorials/tree/ntuple1.C
@@ -31,7 +31,7 @@ void ntuple1() {
    //
    // Connect ROOT histogram/ntuple demonstration file
    // generated by example $ROOTSYS/tutorials/hsimple.C.
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    dir.Append("/hsimple.C");
    dir.ReplaceAll("/./","/");
    if (gBenchmark->GetBench("hsimple") < 0) gInterpreter->LoadMacro(dir.Data());
diff --git a/tutorials/xml/DOMParsePerson.C b/tutorials/xml/DOMParsePerson.C
index cd56ae8d208..c8b17d2ed24 100644
--- a/tutorials/xml/DOMParsePerson.C
+++ b/tutorials/xml/DOMParsePerson.C
@@ -234,7 +234,7 @@ void DOMParsePerson()
 {
    PersonList personlist;
    gROOT->ProcessLine(".O 0");
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    if (personlist.ParseFile(dir+"/xml/person.xml") == 0)
       cout << personlist << endl;
 }
diff --git a/tutorials/xml/DOMRecursive.C b/tutorials/xml/DOMRecursive.C
index 717c940e585..36a2f53cd18 100644
--- a/tutorials/xml/DOMRecursive.C
+++ b/tutorials/xml/DOMRecursive.C
@@ -54,7 +54,7 @@ void ParseContext(TXMLNode *node)
 void DOMRecursive()
 {
   TDOMParser *domParser = new TDOMParser();
-  TString dir = gROOT->GetTutorialDir();
+  TString dir = gROOT->GetTutorialsDir();
   domParser->SetValidate(false); // do not validate with DTD
   domParser->ParseFile(dir+"/xml/person.xml");
 
diff --git a/tutorials/xml/SAXHandler.C b/tutorials/xml/SAXHandler.C
index 639a31dbeea..694b653728b 100644
--- a/tutorials/xml/SAXHandler.C
+++ b/tutorials/xml/SAXHandler.C
@@ -104,6 +104,6 @@ void SAXHandler()
    SaxHandler *saxHandler = new SaxHandler();
 
    saxParser->ConnectToHandler("SaxHandler", saxHandler);
-   TString dir = gROOT->GetTutorialDir();
+   TString dir = gROOT->GetTutorialsDir();
    saxParser->ParseFile(dir+"/xml/saxexample.xml");
 }
-- 
GitLab