diff --git a/src/buildtools/gn.pro b/src/buildtools/gn.pro
index f8f8b20da3a3497fcac287e4702de01efdf797f2..829e7a31af3ac2891df8b205f6d62033e7899ec3 100644
--- a/src/buildtools/gn.pro
+++ b/src/buildtools/gn.pro
@@ -1,36 +1,30 @@
 TEMPLATE = aux
-CONFIG += release
-
 option(host_build)
 
-defineReplace(buildGn) {
-    gn_args = $$1
-    out = $$gnPath()
-    !qtConfig(system-ninja): ninja_path = "--path $$ninjaPath()"
-    # check if it is not already build
-    !exists($$out) {
-        mkpath($$dirname(out))
-        src_3rd_party_dir = $$absolute_path("$${getChromiumSrcDir()}/../", "$$QTWEBENGINE_ROOT")
-        gn_bootstrap = $$system_path($$absolute_path(chromium/tools/gn/bootstrap/bootstrap.py, $$src_3rd_party_dir))
-        gn_args = $$system_quote($$gn_args)
-        gn_configure = $$system_quote($$gn_bootstrap) --shadow --gn-gen-args=$$gn_args $$ninja_path
-        !system("cd $$system_quote($$system_path($$dirname(out))) && $$pythonPathForSystem() $$gn_configure") {
-            error("GN build error!")
-        }
-    }
-}
+!debug_and_release: CONFIG += release
 
 isQtMinimum(5, 8) {
     include($$QTWEBENGINE_OUT_ROOT/qtwebengine-config.pri)
     QT_FOR_CONFIG += webengine-private
 }
 
-!qtConfig(system-gn) {
-    buildgn.target = build_gn
-    buildgn.commands = $$buildGn($$gnArgs())
-    QMAKE_EXTRA_TARGETS += buildgn
-
-    default_target.target = first
-    default_target.depends = buildgn
-    QMAKE_EXTRA_TARGETS += default_target
+build_pass|!debug_and_release {
+    !qtConfig(system-gn): CONFIG(release, debug|release) {
+        buildgn.target = build_gn
+        gn_args = $$gnArgs()
+        out = $$gnPath()
+        !qtConfig(system-ninja): ninja_path = "--path $$ninjaPath()"
+        # check if it is not already build
+        !exists($$out) {
+            mkpath($$dirname(out))
+            src_3rd_party_dir = $$absolute_path("$${getChromiumSrcDir()}/../", "$$QTWEBENGINE_ROOT")
+            gn_bootstrap = $$system_path($$absolute_path(chromium/tools/gn/bootstrap/bootstrap.py, $$src_3rd_party_dir))
+            gn_args = $$system_quote($$gn_args)
+            gn_configure = $$system_quote($$gn_bootstrap) --shadow --gn-gen-args=$$gn_args $$ninja_path
+            !system("cd $$system_quote($$system_path($$dirname(out))) && $$pythonPathForSystem() $$gn_configure") {
+                error("GN build error!")
+            }
+        }
+        QMAKE_DISTCLEAN += $$out
+    }
 }
diff --git a/src/buildtools/ninja.pro b/src/buildtools/ninja.pro
index 0a01f1f4e81de0001d573a5b936b5216cd7c3f7a..1b17c6dfa8f417e31fe78bc4e44942adef77999a 100644
--- a/src/buildtools/ninja.pro
+++ b/src/buildtools/ninja.pro
@@ -1,31 +1,25 @@
 TEMPLATE = aux
-CONFIG += release
 
-defineReplace(buildNinja) {
-   out = $$ninjaPath()
-   # check if it is not already build
-   !exists($$out) {
-       mkpath($$dirname(out))
-       src_3rd_party_dir = $$absolute_path("$${getChromiumSrcDir()}/../", "$$QTWEBENGINE_ROOT")
-       ninja_configure =  $$system_quote($$system_path($$absolute_path(ninja/configure.py, $$src_3rd_party_dir)))
-       !system("cd $$system_quote($$system_path($$dirname(out))) && $$pythonPathForSystem() $$ninja_configure --bootstrap") {
-            error("NINJA build error!")
-       }
-   }
-}
+!debug_and_release: CONFIG += release
 
 isQtMinimum(5, 8) {
     include($$QTWEBENGINE_OUT_ROOT/qtwebengine-config.pri)
     QT_FOR_CONFIG += webengine-private
 }
 
-!qtConfig(system-ninja) {
-    buildninja.target = build_ninja
-    buildninja.commands = $$buildNinja()
-    QMAKE_EXTRA_TARGETS += buildninja
-
-    default_target.target = first
-    default_target.depends = buildninja
-    QMAKE_EXTRA_TARGETS += default_target
+build_pass|!debug_and_release {
+    !qtConfig(system-ninja): CONFIG(release, debug|release) {
+        out = $$ninjaPath()
+        # check if it is not already build
+        !exists($$out) {
+            mkpath($$dirname(out))
+            src_3rd_party_dir = $$absolute_path("$${getChromiumSrcDir()}/../", "$$QTWEBENGINE_ROOT")
+            ninja_configure =  $$system_quote($$system_path($$absolute_path(ninja/configure.py, $$src_3rd_party_dir)))
+            !system("cd $$system_quote($$system_path($$dirname(out))) && $$pythonPathForSystem() $$ninja_configure --bootstrap") {
+                error("NINJA build error!")
+            }
+        }
+    QMAKE_DISTCLEAN += $$out
+    }
 }
 
diff --git a/src/core/gn_run.pro b/src/core/gn_run.pro
index b6966a51d04a2cb5efa3702808a4c00717ea9b0e..ee4e7892e6efa81fb67706aa4d3a4a54c47850b4 100644
--- a/src/core/gn_run.pro
+++ b/src/core/gn_run.pro
@@ -5,13 +5,6 @@ isQtMinimum(5, 8) {
 
 TEMPLATE = aux
 
-defineReplace(runGn) {
-    message("Running: $$1")
-    !system($$1) {
-        error("GN run error!")
-    }
-}
-
 qtConfig(debug_and_release): CONFIG += debug_and_release build_all
 
 qtConfig(system-ninja) {
@@ -42,17 +35,22 @@ build_pass|!debug_and_release {
         gn_args += is_debug=false
     }
 
-    gn_args += "qtwebengine_target=\"$$shell_path($$OUT_PWD/$$getConfigDir()):QtWebEngineCore\""
+    gn_args += "qtwebengine_target=\"$$system_path($$OUT_PWD/$$getConfigDir()):QtWebEngineCore\""
 
     !qtConfig(system-gn) {
-        gn_binary = $$shell_quote($$shell_path($$gnPath()))
+        gn_binary = $$system_quote($$system_path($$gnPath()))
     }
 
-    gn_args = $$shell_quote($$gn_args)
-    gn_src_root = $$shell_quote($$shell_path($$QTWEBENGINE_ROOT/$$getChromiumSrcDir()))
-    gn_build_root = $$shell_quote($$shell_path($$OUT_PWD/$$getConfigDir()))
+    gn_args = $$system_quote($$gn_args)
+    gn_src_root = $$system_quote($$system_path($$QTWEBENGINE_ROOT/$$getChromiumSrcDir()))
+    gn_build_root = $$system_quote($$system_path($$OUT_PWD/$$getConfigDir()))
     gn_python = "--script-executable=$$pythonPathForSystem()"
-    $$runGn($$gn_binary gen $$gn_build_root $$gn_python --args=$$gn_args --root=$$gn_src_root)
+    gn_run = $$gn_binary gen $$gn_build_root $$gn_python --args=$$gn_args --root=$$gn_src_root
+
+    message("Running: $$gn_run ")
+    !system($$gn_run) {
+        error("GN run error!")
+    }
 
     runninja.commands = $$NINJA \$\(NINJAFLAGS\) -C $$gn_build_root QtWebEngineCore
     QMAKE_EXTRA_TARGETS += runninja