-# depend on ghc-cabal, otherwise we build Cabal twice when building in parallel
-utils/ghc-pkg/dist/build/$(utils/ghc-pkg_dist_PROG)$(exeext): utils/ghc-pkg/Main.hs utils/ghc-pkg/Version.hs $(GHC_CABAL_INPLACE) $(MKDIRHIER)
- $(MKDIRHIER) bootstrapping
- $(MKDIRHIER) utils/ghc-pkg/dist/build
- $(GHC) --make utils/ghc-pkg/Main.hs -o $@ \
- -Wall \
+else
+
+$(GHC_PKG_INPLACE) : utils/ghc-pkg/dist/build/$(utils/ghc-pkg_dist_PROG)$(exeext) | $$(dir $$@)/. $(INPLACE_PACKAGE_CONF)/.
+ "$(RM)" $(RM_OPTS) $(INPLACE_PACKAGE_CONF)/*
+ifeq "$(Windows)" "YES"
+ cp $< $@
+else
+ "$(RM)" $(RM_OPTS) $@
+ echo "#!/bin/sh" >>$@
+ echo "PKGCONF=$(TOP)/$(INPLACE_PACKAGE_CONF)" >>$@
+ echo '$(TOP)/$< --global-conf $$PKGCONF $${1+"$$@"}' >> $@
+ chmod +x $@
+endif
+
+endif
+
+# 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 | 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 \