Index: tests/Makefile.am
===================================================================
--- tests/Makefile.am	(revision 15f9c8ecb4774ba04edf4275b58d7a51566350ab)
+++ tests/Makefile.am	(revision 34e1494bbcc17cbde2f469d23ea2db3b4585e6cb)
@@ -43,7 +43,13 @@
 	-DIN_DIR="${abs_srcdir}/.in/"
 
+# adjust CC to current flags
 CC = $(if $(DISTCC_CFA_PATH),distcc $(DISTCC_CFA_PATH) -dist-tree -in-tree,@CFACC@ ${DEBUG_FLAGS} ${INSTALL_FLAGS} ${ARCH_FLAGS})
+CFACC = $(CC)
+
+# get local binary for depedencies
 CFACCBIN = @CFACC@
-CFACC = $(CC)
+
+# adjusted CC but without the actual distcc call
+CFACCLOCAL = $(if $(DISTCC_CFA_PATH),$(DISTCC_CFA_PATH) -dist-tree -in-tree,@CFACC@ ${DEBUG_FLAGS} ${INSTALL_FLAGS} ${ARCH_FLAGS})
 
 PRETTY_PATH=mkdir -p $(dir $(abspath ${@})) && cd ${srcdir} &&
@@ -89,11 +95,5 @@
 
 # Use for all tests, make sure the path are correct and all flags are added
-CFACOMPILETEST=$(PRETTY_PATH) $(CFACOMPILE) $(shell realpath --relative-to=${srcdir} ${<}) $($(shell echo "${@}_FLAGS" | sed 's/-\|\//_/g'))
-
-# Use for tests that either generate an executable, print directly to stdout or the make command is expected to fail
-CFATEST_STDOUT=$(CFACOMPILETEST) -o $(abspath ${@})
-
-# Use for tests where the make command is expecte to succeed but the expected.txt should be compared to stderr
-CFATEST_STDERR=$(CFACOMPILETEST) 2> $(abspath ${@})
+CFACOMPILETEST=$(PRETTY_PATH) $(CFACOMPILE) $(shell realpath --relative-to=${srcdir} ${<}) $($(shell echo "${@}_FLAGSCFA" | sed 's/-\|\//_/g'))
 
 #----------------------------------------------------------------------------------------------------------------
@@ -101,65 +101,60 @@
 # implicit rule so not all test require a rule
 # split into two steps to support compiling remotely using distcc
+# don't use distcc to do the linking because distcc doesn't do linking
 % : %.cfa $(CFACCBIN)
 	$(CFACOMPILETEST) -c -o $(abspath ${@}).o
-	$(CFACC) $(abspath ${@}).o -o $(abspath ${@})
+	$(CFACCLOCAL) $($(shell echo "${@}_FLAGSLD" | sed 's/-\|\//_/g')) $(abspath ${@}).o -o $(abspath ${@})
 
-# second implicit rule for programs that don't produce an executable
-# still in two steps for distcc
-declarationSpecifier gccExtensions extension attributes functions KRfunctions : % : %.cfa $(CFACCBIN)
-	$(CFACOMPILETEST) -CFA -XCFA -p -o $(abspath ${@}).o
-	mv $(abspath ${@}).o $(abspath ${@})
-
+# implicit rule for c++ test
+# convient for testing the testsuite itself but not actuall used
 % : %.cpp
 	$(PRETTY_PATH) $(CXXCOMPILE) $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
 
 #------------------------------------------------------------------------------
-# TARGET WITH STANDARD RULE BUT CUSTOM FLAGS
+# TARGETS WITH CUSTOM FLAGS
 #------------------------------------------------------------------------------
-# Expected failures
-declarationSpecifier_FLAGS= -CFA -XCFA -p
-gccExtensions_FLAGS= -CFA -XCFA -p
-extension_FLAGS= -CFA -XCFA -p
-attributes_FLAGS= -CFA -XCFA -p
-functions_FLAGS= -CFA -XCFA -p
-KRfunctions_FLAGS= -CFA -XCFA -p
-gmp_FLAGS= -lgmp
+# custom libs
+gmp_FLAGSLD= -lgmp
 
 #------------------------------------------------------------------------------
-# Expected failures
-completeTypeError_FLAGS= -DERR1
+# Generated code
+GENERATED_CODE = declarationSpecifier gccExtensions extension attributes functions KRfunctions
+$(GENERATED_CODE): % : %.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -CFA -XCFA -p -c -fsyntax-only -o $(abspath ${@})
+
+# Use for tests where the make command is expected to succeed but the expected.txt should be compared to stderr
+EXPECT_STDERR = builtins/sync warnings/self-assignment
+$(EXPECT_STDERR): % : %.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -c -fsyntax-only 2> $(abspath ${@})
 
 #------------------------------------------------------------------------------
 # CUSTOM TARGET
 #------------------------------------------------------------------------------
-typedefRedef-ERR1: typedefRedef.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR1
+# expected failures
+# use custom target since they require a custom define and custom dependencies
+alloc-ERROR : alloc.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR1 -c -fsyntax-only -o $(abspath ${@})
 
-alloc-ERROR: alloc.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR1
+typedefRedef-ERR1 : typedefRedef.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR1 -c -fsyntax-only -o $(abspath ${@})
 
-nested-types-ERR1: nested-types.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR1
+nested-types-ERR1 : nested-types.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR1 -c -fsyntax-only -o $(abspath ${@})
 
-nested-types-ERR2: nested-types.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR2
+nested-types-ERR2 : nested-types.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR2 -c -fsyntax-only -o $(abspath ${@})
 
-raii/dtor-early-exit-ERR1: raii/dtor-early-exit.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR1
+raii/memberCtors-ERR1 : raii/memberCtors.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR1 -c -fsyntax-only -o $(abspath ${@})
 
-raii/dtor-early-exit-ERR2: raii/dtor-early-exit.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR2
+raii/ctor-autogen-ERR1 : raii/ctor-autogen.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR1 -c -fsyntax-only -o $(abspath ${@})
 
-raii/memberCtors-ERR1: raii/memberCtors.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR1
+raii/dtor-early-exit-ERR1 : raii/dtor-early-exit.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR1 -c -fsyntax-only -o $(abspath ${@})
 
-raii/ctor-autogen-ERR1: raii/ctor-autogen.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR1
+raii/dtor-early-exit-ERR2 : raii/dtor-early-exit.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR2 -c -fsyntax-only -o $(abspath ${@})
 
-#builtins
-builtins/sync: builtins/sync.cfa $(CFACCBIN)
-	$(CFATEST_STDERR) -fsyntax-only
-
-# Warnings
-warnings/self-assignment: warnings/self-assignment.cfa $(CFACCBIN)
-	$(CFATEST_STDERR) -fsyntax-only
+#------------------------------------------------------------------------------
+# Other targets
Index: tests/Makefile.in
===================================================================
--- tests/Makefile.in	(revision 15f9c8ecb4774ba04edf4275b58d7a51566350ab)
+++ tests/Makefile.in	(revision 34e1494bbcc17cbde2f469d23ea2db3b4585e6cb)
@@ -212,4 +212,6 @@
 AWK = @AWK@
 BUILD_IN_TREE_FLAGS = @BUILD_IN_TREE_FLAGS@
+
+# adjust CC to current flags
 CC = $(if $(DISTCC_CFA_PATH),distcc $(DISTCC_CFA_PATH) -dist-tree -in-tree,@CFACC@ ${DEBUG_FLAGS} ${INSTALL_FLAGS} ${ARCH_FLAGS})
 CCAS = @CCAS@
@@ -395,5 +397,10 @@
 	-DIN_DIR="${abs_srcdir}/.in/"
 
+
+# get local binary for depedencies
 CFACCBIN = @CFACC@
+
+# adjusted CC but without the actual distcc call
+CFACCLOCAL = $(if $(DISTCC_CFA_PATH),$(DISTCC_CFA_PATH) -dist-tree -in-tree,@CFACC@ ${DEBUG_FLAGS} ${INSTALL_FLAGS} ${ARCH_FLAGS})
 PRETTY_PATH = mkdir -p $(dir $(abspath ${@})) && cd ${srcdir} &&
 avl_test_SOURCES = avltree/avl_test.cfa avltree/avl0.cfa avltree/avl1.cfa avltree/avl2.cfa avltree/avl3.cfa avltree/avl4.cfa avltree/avl-private.cfa
@@ -404,27 +411,18 @@
 
 # Use for all tests, make sure the path are correct and all flags are added
-CFACOMPILETEST = $(PRETTY_PATH) $(CFACOMPILE) $(shell realpath --relative-to=${srcdir} ${<}) $($(shell echo "${@}_FLAGS" | sed 's/-\|\//_/g'))
-
-# Use for tests that either generate an executable, print directly to stdout or the make command is expected to fail
-CFATEST_STDOUT = $(CFACOMPILETEST) -o $(abspath ${@})
-
-# Use for tests where the make command is expecte to succeed but the expected.txt should be compared to stderr
-CFATEST_STDERR = $(CFACOMPILETEST) 2> $(abspath ${@})
+CFACOMPILETEST = $(PRETTY_PATH) $(CFACOMPILE) $(shell realpath --relative-to=${srcdir} ${<}) $($(shell echo "${@}_FLAGSCFA" | sed 's/-\|\//_/g'))
 
 #------------------------------------------------------------------------------
-# TARGET WITH STANDARD RULE BUT CUSTOM FLAGS
+# TARGETS WITH CUSTOM FLAGS
 #------------------------------------------------------------------------------
-# Expected failures
-declarationSpecifier_FLAGS = -CFA -XCFA -p
-gccExtensions_FLAGS = -CFA -XCFA -p
-extension_FLAGS = -CFA -XCFA -p
-attributes_FLAGS = -CFA -XCFA -p
-functions_FLAGS = -CFA -XCFA -p
-KRfunctions_FLAGS = -CFA -XCFA -p
-gmp_FLAGS = -lgmp
+# custom libs
+gmp_FLAGSLD = -lgmp
 
 #------------------------------------------------------------------------------
-# Expected failures
-completeTypeError_FLAGS = -DERR1
+# Generated code
+GENERATED_CODE = declarationSpecifier gccExtensions extension attributes functions KRfunctions
+
+# Use for tests where the make command is expected to succeed but the expected.txt should be compared to stderr
+EXPECT_STDERR = builtins/sync warnings/self-assignment
 all: all-am
 
@@ -809,51 +807,49 @@
 # implicit rule so not all test require a rule
 # split into two steps to support compiling remotely using distcc
+# don't use distcc to do the linking because distcc doesn't do linking
 % : %.cfa $(CFACCBIN)
 	$(CFACOMPILETEST) -c -o $(abspath ${@}).o
-	$(CFACC) $(abspath ${@}).o -o $(abspath ${@})
-
-# second implicit rule for programs that don't produce an executable
-# still in two steps for distcc
-declarationSpecifier gccExtensions extension attributes functions KRfunctions : % : %.cfa $(CFACCBIN)
-	$(CFACOMPILETEST) -CFA -XCFA -p -o $(abspath ${@}).o
-	mv $(abspath ${@}).o $(abspath ${@})
-
+	$(CFACCLOCAL) $($(shell echo "${@}_FLAGSLD" | sed 's/-\|\//_/g')) $(abspath ${@}).o -o $(abspath ${@})
+
+# implicit rule for c++ test
+# convient for testing the testsuite itself but not actuall used
 % : %.cpp
 	$(PRETTY_PATH) $(CXXCOMPILE) $(shell realpath --relative-to=${srcdir} ${<}) -o $(abspath ${@})
+$(GENERATED_CODE): % : %.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -CFA -XCFA -p -c -fsyntax-only -o $(abspath ${@})
+$(EXPECT_STDERR): % : %.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -c -fsyntax-only 2> $(abspath ${@})
 
 #------------------------------------------------------------------------------
 # CUSTOM TARGET
 #------------------------------------------------------------------------------
-typedefRedef-ERR1: typedefRedef.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR1
-
-alloc-ERROR: alloc.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR1
-
-nested-types-ERR1: nested-types.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR1
-
-nested-types-ERR2: nested-types.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR2
-
-raii/dtor-early-exit-ERR1: raii/dtor-early-exit.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR1
-
-raii/dtor-early-exit-ERR2: raii/dtor-early-exit.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR2
-
-raii/memberCtors-ERR1: raii/memberCtors.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR1
-
-raii/ctor-autogen-ERR1: raii/ctor-autogen.cfa $(CFACCBIN)
-	$(CFATEST_STDOUT) -DERR1
-
-#builtins
-builtins/sync: builtins/sync.cfa $(CFACCBIN)
-	$(CFATEST_STDERR) -fsyntax-only
-
-# Warnings
-warnings/self-assignment: warnings/self-assignment.cfa $(CFACCBIN)
-	$(CFATEST_STDERR) -fsyntax-only
+# expected failures
+# use custom target since they require a custom define and custom dependencies
+alloc-ERROR : alloc.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR1 -c -fsyntax-only -o $(abspath ${@})
+
+typedefRedef-ERR1 : typedefRedef.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR1 -c -fsyntax-only -o $(abspath ${@})
+
+nested-types-ERR1 : nested-types.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR1 -c -fsyntax-only -o $(abspath ${@})
+
+nested-types-ERR2 : nested-types.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR2 -c -fsyntax-only -o $(abspath ${@})
+
+raii/memberCtors-ERR1 : raii/memberCtors.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR1 -c -fsyntax-only -o $(abspath ${@})
+
+raii/ctor-autogen-ERR1 : raii/ctor-autogen.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR1 -c -fsyntax-only -o $(abspath ${@})
+
+raii/dtor-early-exit-ERR1 : raii/dtor-early-exit.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR1 -c -fsyntax-only -o $(abspath ${@})
+
+raii/dtor-early-exit-ERR2 : raii/dtor-early-exit.cfa $(CFACCBIN)
+	$(CFACOMPILETEST) -DERR2 -c -fsyntax-only -o $(abspath ${@})
+
+#------------------------------------------------------------------------------
+# Other targets
 
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
Index: tests/pybin/tools.py
===================================================================
--- tests/pybin/tools.py	(revision 15f9c8ecb4774ba04edf4275b58d7a51566350ab)
+++ tests/pybin/tools.py	(revision 34e1494bbcc17cbde2f469d23ea2db3b4585e6cb)
@@ -261,5 +261,12 @@
 			os.write(int(make_jobs_fds.group(3)), tokens)
 		else :
-			options.jobs = multiprocessing.cpu_count()
+			if settings.distribute:
+				ret, jstr = sh("distcc", "-j", output_file=subprocess.PIPE, ignore_dry_run=True)
+				if ret == 0:
+					options.jobs = int(jstr.strip())
+				else :
+					options.jobs = multiprocessing.cpu_count()
+			else:
+				options.jobs = multiprocessing.cpu_count()
 	else :
 		force = True
