--- haskell-platform-2013.2.0.0/scripts/install.sh	2013-05-04 22:56:20.000000000 +0200
+++ install.sh	2013-10-26 13:32:07.708258933 +0200
@@ -15,12 +15,21 @@
 
 install_pkg () {
   PKG=$1
+  IDX=$2
 
   cd "packages/${PKG}" 2> /dev/null \
     || die "The directory for the component ${PKG} is missing"
 
   [ -x Setup ] || die "The ${PKG}/Setup script does not exist or cannot be run"
 
+if [ -n "${DESTDIR}" ]; then
+  ./Setup copy ${VERBOSE} \
+    || die "Installing the ${PKG} component failed"
+    
+  ./Setup register ${VERBOSE} --gen-pkg-config="${DESTDIR}/load/${IDX}-${PKG}.conf" \
+    || die "Generating the registration information for the package ${PKG} failed"
+else
+
   ./Setup copy ${VERBOSE} \
     || die "Installing the ${PKG} component failed"
 
@@ -36,18 +45,23 @@
     ${GHC_PKG} update ${GHC_PKG_DB} "${PKG}.conf" \
       || die "Registering the package ${PKG} failed"
   fi
+fi
 
   cd ../..
 }
 
+mkdir -p "${DESTDIR}/load"
+
 # Actually do something!
+i=000
 for pkg in `cat packages/platform.packages`; do
   if is_pkg_installed "${pkg}"; then
     true
   else
     echo "Installing ${pkg}..."
-    install_pkg ${pkg}
+    install_pkg ${pkg} ${i}
   fi
+  i=$(printf "%03d" $(expr ${i} + 1))
 done
 
 echo
