diff --git a/compiler/main/SysTools.lhs b/compiler/main/SysTools.lhs
index a4ea987be7aaff8e865a1c48733a9af370819bca..5c64a34650c479b54edd47eb1ac1712439456633 100644
--- a/compiler/main/SysTools.lhs
+++ b/compiler/main/SysTools.lhs
@@ -504,8 +504,8 @@ cleanTempFilesExcept dflags dont_delete
    $ do let ref = filesToClean dflags
         files <- readIORef ref
         let (to_keep, to_delete) = partition (`elem` dont_delete) files
-        removeTmpFiles dflags to_delete
         writeIORef ref to_keep
+        removeTmpFiles dflags to_delete
 
 
 -- find a temporary name that doesn't already exist.
diff --git a/rts/Capability.c b/rts/Capability.c
index 6216489ead27978fee8d27eeea09e937eda232cc..0586cf2f9b77430247214aff7977254aba911a12 100644
--- a/rts/Capability.c
+++ b/rts/Capability.c
@@ -857,9 +857,8 @@ markCapability (evac_fn evac, void *user, Capability *cap,
 #if defined(THREADED_RTS)
     evac(user, (StgClosure **)(void *)&cap->inbox);
 #endif
-
-    for (incall = cap->suspended_ccalls; incall != NULL; 
-         incall = incall->next) {
+    for (incall = cap->suspended_ccalls; incall != NULL;
+         incall=incall->next) {
         evac(user, (StgClosure **)(void *)&incall->suspended_tso);
     }
 
diff --git a/rts/Stats.c b/rts/Stats.c
index 5f18a560211a614cc2d81005ebc8753f5cfc95c3..1162d2be0d3c657c62bf5052ec5b3fde480151d7 100644
--- a/rts/Stats.c
+++ b/rts/Stats.c
@@ -165,12 +165,12 @@ initStats1 (void)
 	statsPrintf("    Alloc    Copied     Live    GC    GC     TOT     TOT  Page Flts\n");
 	statsPrintf("    bytes     bytes     bytes  user  elap    user    elap\n");
     }
-    GC_coll_cpu = 
-	(Ticks *)stgMallocBytes(
+    GC_coll_cpu =
+        (Ticks *)stgMallocBytes(
 	    sizeof(Ticks)*total_generations,
 	    "initStats");
-    GC_coll_elapsed = 
-	(Ticks *)stgMallocBytes(
+    GC_coll_elapsed =
+        (Ticks *)stgMallocBytes(
 	    sizeof(Ticks)*total_generations,
 	    "initStats");
     GC_coll_max_pause =
@@ -339,12 +339,12 @@ stat_endGC (gc_thread *gct,
         }
 
 	if (RtsFlags.GcFlags.giveStats == VERBOSE_GC_STATS) {
-	    nat faults = getPageFaults();
+            nat faults = getPageFaults();
 	    
 	    statsPrintf("%9ld %9ld %9ld",
 		    alloc*sizeof(W_), copied*sizeof(W_), 
 			live*sizeof(W_));
-	    statsPrintf(" %5.2f %5.2f %7.2f %7.2f %4ld %4ld  ", 
+            statsPrintf(" %5.2f %5.2f %7.2f %7.2f %4ld %4ld  ",
 		    TICK_TO_DBL(gc_cpu),
 		    TICK_TO_DBL(gc_elapsed),
 		    TICK_TO_DBL(cpu),
@@ -365,10 +365,10 @@ stat_endGC (gc_thread *gct,
             }
             statsPrintf("\n");
 	    GC_end_faults = faults;
-	    statsFlush();
+            statsFlush();
 	}
 
-	GC_coll_cpu[gen_ix] += gc_cpu;
+        GC_coll_cpu[gen_ix] += gc_cpu;
 	GC_coll_elapsed[gen_ix] += gc_elapsed;
         if (GC_coll_max_pause[gen_ix] < gc_elapsed) {
             GC_coll_max_pause[gen_ix] = gc_elapsed;
@@ -580,7 +580,7 @@ stat_exit(int alloc)
             }
         }
 
-	if (RtsFlags.GcFlags.giveStats >= SUMMARY_GC_STATS) {
+        if (RtsFlags.GcFlags.giveStats >= SUMMARY_GC_STATS) {
 	    showStgWord64(GC_tot_alloc*sizeof(W_), 
 				 temp, rtsTrue/*commas*/);
 	    statsPrintf("%16s bytes allocated in the heap\n", temp);
@@ -599,7 +599,7 @@ stat_exit(int alloc)
 
 	    if ( residency_samples > 0 ) {
 		showStgWord64(max_residency*sizeof(W_), 
-				     temp, rtsTrue/*commas*/);
+                                     temp, rtsTrue/*commas*/);
 		statsPrintf("%16s bytes maximum residency (%ld sample(s))\n",
 			temp, residency_samples);
 	    }
diff --git a/rts/Task.c b/rts/Task.c
index aa17749e2a3b00c7f26245534963260d982de3c0..5f2ec5b818792c56865f00290b547527025b950d 100644
--- a/rts/Task.c
+++ b/rts/Task.c
@@ -323,10 +323,10 @@ taskTimeStamp (Task *task USED_IF_THREADS)
     currentUserTime = getThreadCPUTime();
     currentElapsedTime = getProcessElapsedTime();
 
-    task->mut_time = 
-	currentUserTime - task->muttimestart - task->gc_time;
+    task->mut_time =
+        currentUserTime - task->muttimestart - task->gc_time;
     task->mut_etime = 
-	currentElapsedTime - task->elapsedtimestart - task->gc_etime;
+        currentElapsedTime - task->elapsedtimestart - task->gc_etime;
 
     if (task->gc_time   < 0) { task->gc_time   = 0; }
     if (task->gc_etime  < 0) { task->gc_etime  = 0; }
diff --git a/rts/sm/GC.c b/rts/sm/GC.c
index a6427788577ef826f39fdf5e3a942b952bc07cfc..ba4aab2dd892f07011a283b2ce75bf6af9a2df83 100644
--- a/rts/sm/GC.c
+++ b/rts/sm/GC.c
@@ -200,6 +200,7 @@ GarbageCollect (nat N, // generation to collect
   ASSERT(sizeof(gen_workspace) == 16 * sizeof(StgWord));
   // otherwise adjust the padding in gen_workspace.
 
+  // this is the main thread
   SET_GCT(gc_threads[cap->no]);
 
   gct->gc_type = gc_type;
diff --git a/rts/sm/GCThread.h b/rts/sm/GCThread.h
index dde9fe2ae2873cfdfcb843154e289575de88695b..15e104a9c31fc613ffc10c3f241787fece999f87 100644
--- a/rts/sm/GCThread.h
+++ b/rts/sm/GCThread.h
@@ -169,7 +169,7 @@ typedef struct gc_thread_ {
                                    // instead of the to-space
                                    // corresponding to the object
 
-    lnat thunk_selector_depth;     // used to avoid unbounded recursion in 
+    lnat thunk_selector_depth;     // used to avoid unbounded recursion in
                                    // evacuate() for THUNK_SELECTOR
 
     nat collect_gen;               // maximum generation (no) to collect
diff --git a/utils/ghc-pkg/ghc.mk b/utils/ghc-pkg/ghc.mk
index d0381147453568f424a9ae0b1c77cdd4245bc122..6bc9be57a4bc3bdb7377365651e30a4fefe88540 100644
--- a/utils/ghc-pkg/ghc.mk
+++ b/utils/ghc-pkg/ghc.mk
@@ -44,9 +44,11 @@ endif
 
 endif
 
-# depend on ghc-cabal, otherwise we build Cabal twice when building in parallel
+# depend on ghc-cabal, otherwise we build Cabal twice when building in parallel.
+# (ghc-cabal is an order-only dependency, we don't need to rebuild ghc-pkg
+# if ghc-cabal is newer).
 # The binary package is not warning-clean, so we need a few -fno-warns here.
-utils/ghc-pkg/dist/build/$(utils/ghc-pkg_dist_PROG)$(exeext): utils/ghc-pkg/Main.hs utils/ghc-pkg/Version.hs $(GHC_CABAL_INPLACE) | bootstrapping/. $$(dir $$@)/.
+utils/ghc-pkg/dist/build/$(utils/ghc-pkg_dist_PROG)$(exeext): utils/ghc-pkg/Main.hs utils/ghc-pkg/Version.hs | bootstrapping/. $$(dir $$@)/. $(GHC_CABAL_INPLACE) 
 	"$(GHC)" $(SRC_HC_OPTS) --make utils/ghc-pkg/Main.hs -o $@ \
 	       -no-user-package-conf \
 	       -Wall -fno-warn-unused-imports \