[ci skip] includes: detabify/dewhitespace stg/SMP.h
[ghc.git] / validate
index 889c0e8..8ea9eac 100755 (executable)
--- a/validate
+++ b/validate
@@ -22,9 +22,7 @@ Flags:
   --fast            Omit dyn way, omit binary distribution
   --slow            Build stage2 with -DDEBUG.
                     2008-07-01: 14% slower than the default.
-  --no-dph:         Skip requiring libraries/dph. In --slow mode, these tests
-                    can take a substantial amount of time, and on some platforms
-                    with broken linkers, we don't want to try compiling it.
+  --dph:            Also build libraries/dph and run associated tests.
   --help            shows this usage help.
 
   Set environment variable 'CPUS' to number of cores, to exploit
@@ -39,7 +37,7 @@ no_clean=0
 testsuite_only=0
 hpc=NO
 speed=NORMAL
-skip_dph=0
+use_dph=0
 
 while [ $# -gt 0 ]
 do
@@ -62,8 +60,11 @@ do
     --normal)
         speed=NORMAL
         ;;
-    --no-dph)
-        skip_dph=1
+    --no-dph) # for backward compat
+        use_dph=0
+        ;;
+    --dph)
+        use_dph=1
         ;;
     --help)
         show_help
@@ -87,6 +88,32 @@ check_packages () {
     echo "== End $1 package check"
 }
 
+detect_cpu_count () {
+    if [ "$CPUS" = "" ]; then
+        # Windows standard environment variable
+        CPUS="$NUMBER_OF_PROCESSORS"
+    fi
+
+    if [ "$CPUS" = "" ]; then
+        # Linux
+        CPUS=`getconf _NPROCESSORS_ONLN 2>/dev/null`
+    fi
+
+    if [ "$CPUS" = "" ]; then
+        # FreeBSD
+        CPUS=`getconf NPROCESSORS_ONLN 2>/dev/null`
+    fi
+
+    if [ "$CPUS" = "" ]; then
+        # nothing helped
+        CPUS="1"
+    fi
+
+    echo "using ${CPUS} CPUs" >&2
+}
+
+detect_cpu_count
+
 if ! [ -d testsuite ]
 then
     echo 'Could not find the testsuite for validation' >&2
@@ -94,11 +121,7 @@ then
 fi
 
 if [ "$THREADS" = "" ]; then
-    if [ "$CPUS" = "" ]; then
-        threads=2
-    else
-        threads=$(($CPUS + 1)) # `expr $CPUS + 1`
-    fi
+    threads=$(($CPUS + 1)) # `expr $CPUS + 1`
 else
     threads="$THREADS"
 fi
@@ -121,10 +144,10 @@ if [ $no_clean -eq 0 ]; then
         INSTDIR=`cygpath -m "$INSTDIR"`
     fi
 
-    if [ $skip_dph -eq 1 ]; then
-        /usr/bin/perl -w boot --validate
-    else
+    if [ $use_dph -eq 1 ]; then
         /usr/bin/perl -w boot --validate --required-tag=dph
+    else
+        /usr/bin/perl -w boot --validate
     fi
     ./configure --prefix="$INSTDIR" $config_args
 fi
@@ -135,6 +158,12 @@ echo "Validating=YES"       >  mk/are-validating.mk
 echo "ValidateSpeed=$speed" >> mk/are-validating.mk
 echo "ValidateHpc=$hpc"     >> mk/are-validating.mk
 
+if [ $use_dph -eq 1 ]; then
+    echo "BUILD_DPH=YES"    >> mk/are-validating.mk
+else
+    echo "BUILD_DPH=NO"     >> mk/are-validating.mk
+fi
+
 $make -j$threads
 # For a "debug make", add "--debug=b --debug=m"