Add rules to make sure subdirs are always built before testdirs

Merged Ondřej Surý requested to merge ondrej/fix-freebsd-make-v9_11 into v9_11

(cherry picked from commit 723433cb)

Merge request reports