diff --git a/bin/dunecontrol b/bin/dunecontrol
index efefe8c06dd0a38c4e6cb9988cf7929dd7e00e55..8e49d25c457a0e4bb875683b7bb21ed152f6bab2 100755
--- a/bin/dunecontrol
+++ b/bin/dunecontrol
@@ -229,12 +229,11 @@ extract_multiarch(){
   fi
   if test "x$USE_CMAKE" = "xyes"; then
     load_opts "cmake"
-    my_cxx_compiler=`echo $CMAKE_FLAGS | $GREP CXX | $SED "s/.*CXX=[\"']\?\([$BLANK'\"]*\)[\"']\?.*/\1/"`
   fi
   if test "x$my_cxx_compiler" == "x"; then
     load_opts "configure"
-    my_cxx_compiler=`echo $CONFIGURE_FLAGS | $GREP CXX| $SED "s/.*CXX=[\"']\?\([^$BLANK'\"]*\)[\"']\?.*/\1/"`
   fi
+  my_cxx_compiler=`echo $CMD_FLAGS | $GREP CXX | $SED "s/.*CXX=[\"']\{0,1\}\([^$BLANK'\"]*\)[\"']\{0,1\}.*/\1/"`
   if test "x$my_cxx_compiler" == "x"; then
     set +e #error in the multiarch detection should not be fatal.
     $(which cc &>/dev/null)
@@ -254,15 +253,6 @@ extract_multiarch(){
 
 export PREFIX_DIR="`canonicalpath "$0"`/.."
 
-extract_multiarch
-
-# create PKG_CONFIG_PATH for installed dune modules
-for i in $MULTIARCH_LIBDIR lib64 lib32 lib; do
-  if test -d "$PREFIX_DIR/$i/pkgconfig"; then
-    export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PREFIX_DIR/$i/pkgconfig"
-  fi
-done
-
 # Read the modules find part
 . "$PREFIX_DIR/lib/dunemodules.lib"
 
@@ -996,6 +986,15 @@ while test $# -gt 0; do
     shift
 done
 
+extract_multiarch
+
+# create PKG_CONFIG_PATH for installed dune modules
+for i in $MULTIARCH_LIBDIR lib64 lib32 lib; do
+  if test -d "$PREFIX_DIR/$i/pkgconfig"; then
+    export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$PREFIX_DIR/$i/pkgconfig"
+  fi
+done
+
 # we assume there should be a command...
 if test "x$command" = "x"; then
   usage