diff -rN -u old-cabal-rpm.darcs/src/Distribution/Package/Rpm.hs new-cabal-rpm.darcs/src/Distribution/Package/Rpm.hs
--- old-cabal-rpm.darcs/src/Distribution/Package/Rpm.hs	2008-08-29 14:09:57.000000000 +1000
+++ new-cabal-rpm.darcs/src/Distribution/Package/Rpm.hs	2008-08-29 14:09:57.000000000 +1000
@@ -149,20 +149,18 @@
     (compiler, pkgDesc) <- simplePackageDescription genPkgDesc flags
     let verbose = rpmVerbosity flags
         tmpDir = tgtPfx </> "src"
-    flip mapM_ ["BUILD", "RPMS", "SOURCES", "SPECS", "SRPMS"] $ \ subDir -> do
-      createDirectoryIfMissing True (tgtPfx </> subDir)
-    let specsDir = tgtPfx </> "SPECS"
+    createDirectoryIfMissing True (tgtPfx </> "rpm")
+    let rpmDir = tgtPfx </> "rpm"
     lbi <- localBuildInfo pkgDesc flags
     bracket (setFileCreationMask 0o022) setFileCreationMask $ \ _ -> do
       autoreconf verbose pkgDesc
       (specFile, extraDocs) <- createSpecFile True pkgDesc flags compiler
-                               specsDir
+                               rpmDir
       tree <- prepareTree pkgDesc verbose (Just lbi) False tmpDir
               knownSuffixHandlers 0
       mapM_ (copyTo verbose tree) extraDocs
-      createArchive pkgDesc verbose (Just lbi) tmpDir (tgtPfx </> "SOURCES")
-      ret <- system ("rpmbuild -ba --define \"_topdir " ++ tgtPfx ++ "\" " ++
-                     specFile)
+      createArchive pkgDesc verbose (Just lbi) tmpDir tgtPfx
+      ret <- system ("rpmbuild -ba --define \"_topdir " ++ rpmDir ++ "\" --define \"_sourcedir "  ++ tgtPfx ++ "\" " ++ specFile)
       case ret of
         ExitSuccess -> return ()
         ExitFailure n -> die ("rpmbuild failed with status " ++ show n)
@@ -196,25 +194,24 @@
     defRelease <- defaultRelease now
     let pkg = package pkgDesc
         verbose = rpmVerbosity flags
-        origName = pkgName pkg
-        name = maybe (map toLower origName) id (rpmName flags)
+        name = maybe (pkgName pkg) id (rpmName flags)
         version = maybe ((showVersion . pkgVersion) pkg) id (rpmVersion flags)
         release = maybe defRelease id (rpmRelease flags)
-        specPath = tgtPfx </> name ++ ".spec"
         group = "Development/Languages"
         buildRoot = "%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)"
         cmplrVersion = compilerVersion compiler
         doHaddock = rpmHaddock flags && hasLibs pkgDesc
         flavor = compilerFlavor compiler
         isExec = isExecutable pkgDesc
-        subPackage = if isExec then "-n %{hsc_name}-%{lc_name}" else ""
-    (cmplr, runner) <- case flavor of
-                         GHC -> return ("ghc", "runghc")
-                         Hugs -> return ("hugs", "runhugs")
-                         JHC -> return ("jhc", "runjhc")
-                         NHC -> return ("nhc", "runnhc")
-                         (OtherCompiler s) -> return (s, "run" ++ s)
+        subPackage = if isExec then " -n %{hsc_name}-%{pkg_name}" else ""
+    cmplr <- case flavor of
+                         GHC -> return "ghc"
+                         Hugs -> return "hugs"
+                         JHC -> return "jhc"
+                         NHC -> return "nhc"
+                         (OtherCompiler s) -> return s
                          _ -> die $ show flavor ++ " is not supported"
+    let specPath = tgtPfx </> (if isExec then name else cmplr ++ "-" ++ name) ++ ".spec"
     unless force $ do
         specAlreadyExists <- doesFileExist specPath
         when specAlreadyExists $
@@ -230,25 +227,22 @@
         putNewline = hPutStrLn h ""
         put s = hPutStrLn h s
         putDef v s = put $ "%define " ++ v ++ ' ' : s
-        putSetup s = put $ runner ++ " Setup " ++ s
+        putSetup s = put $ "%{_cabal}" ++ " " ++ s
         date = formatTime defaultTimeLocale "%a %b %d %Y" now
+    put "# Haskell package name"
+    putDef "pkg_name" name
+    put "# Haskell compiler"
     putDef "hsc_name" cmplr
     putDef "hsc_version" $ showVersion cmplrVersion
-    putDef "hsc_namever" $ compilerNameVersion compiler
-    put "# Original Haskell package name, and lowercased form."
-    putDef "pkg_name" origName
-    putDef "lc_name" name
-    putDef "pkg_libdir" "%{_libdir}/%{hsc_name}-%{hsc_version}/%{pkg_name}-%{version}"
-    putDef "tar_dir" "%{_builddir}/%{?buildsubdir}"
     putNewline
+    putDef "pkg_libdir" "%{_libdir}/%{hsc_name}-%{hsc_version}/%{pkg_name}-%{version}"
+    putDef "_cabal" $ "%{_bindir}/run" ++ "%{hsc_name}" ++ " Setup"
     put "# Haskell compilers do not emit debug information."
     putDef "debug_package" "%{nil}"
     putNewline
     
-    when isExec $ do
-      putHdr "Name" "%{lc_name}"
-    unless isExec $ do
-      putHdr "Name" "%{hsc_name}-%{lc_name}"
+    if isExec then putHdr "Name" "%{pkg_name}"
+              else putHdr "Name" "%{hsc_name}-%{pkg_name}"
     putHdr "Version" version
     putHdr "Release" $ release ++ "%{?dist}"
     putHdr "License" $ (showLicense . license) pkgDesc
@@ -266,7 +260,7 @@
                   else rstrip (== '.') syn'
     when synTooLong $
         warn verbose "The synopsis for this package spans multiple lines."
-    putHdrD "Summary" summary "This package has no summary"
+    putHdrD "Summary" summary "FIXME: This package has no summary"
     putHdr "BuildRoot" buildRoot
     putHdr "BuildRequires" buildReq
     -- External libraries incur both build-time and runtime
@@ -279,16 +273,14 @@
     unless isExec $ do
       putHdr_ "Requires" extraReq
       putHdr_ "Requires" runtimeReq
-      putHdr "Provides" "%{pkg_name}-%{hsc_namever} = %{version}"
 
     putNewline
-    putNewline
 
     let putDesc = do
         put $ if (null . description) pkgDesc
               then if synTooLong
                    then syn
-                   else "This package does not have a description."
+                   else "FIXME: This package does not have a description."
               else description pkgDesc
     put "%description"
     putDesc
@@ -303,17 +295,15 @@
        management system. -}
 
     when isExec $ withLib pkgDesc () $ \_ -> do
-        put "%package -n %{hsc_name}-%{lc_name}"
-        putHdrD "Summary" summary "This library package has no summary"
+        put "%package -n %{hsc_name}-%{pkg_name}"
+        putHdrD "Summary" summary "FIXME: This library package has no summary"
         putHdr "Group" "Development/Libraries"
         putHdr "Requires" "%{hsc_name} = %{hsc_version}"
         putHdr_ "Requires" extraReq
         putHdr_ "Requires" runtimeReq
-        putHdr "Provides" "%{pkg_name}-%{hsc_namever} = %{version}"
-        putNewline
         putNewline
 
-        put "%description -n %{hsc_name}-%{lc_name}"
+        put "%description -n %{hsc_name}-%{pkg_name}"
         putDesc
         putNewline
         put "This package contains libraries for %{hsc_name} %{hsc_version}."
@@ -321,15 +311,13 @@
         putNewline
 
     when (rpmLibProf flags) $ do
-        put "%package -n %{hsc_name}-%{lc_name}-prof"
-        putHdr "Summary" "Profiling libraries for %{hsc_name}-%{lc_name}"
+        put "%package -n %{hsc_name}-%{pkg_name}-prof"
+        putHdr "Summary" "Profiling libraries for %{hsc_name}-%{pkg_name}"
         putHdr "Group" "Development/Libraries"
-        putHdr "Requires" "%{hsc_name}-%{lc_name} = %{version}"
-        putHdr "Provides" "%{pkg_name}-%{hsc_namever}-prof = %{version}"
-        putNewline
+        putHdr "Requires" "%{hsc_name}-%{pkg_name} = %{version}-%{release}"
         putNewline
 
-        put "%description -n %{hsc_name}-%{lc_name}-prof"
+        put "%description -n %{hsc_name}-%{pkg_name}-prof"
         putDesc
         putNewline
         put "This package contains profiling libraries for %{hsc_name} %{hsc_version}."
@@ -344,14 +332,14 @@
     put "%build"
     put "if [ -f configure.ac -a ! -f configure ]; then autoreconf; fi"
     putSetup ("configure --prefix=%{_prefix} --libdir=%{_libdir} " ++
-              "--docdir=%{_docdir}/%{hsc_name}-%{lc_name}-%{version} " ++
+              "--docdir=%{_docdir}/%{hsc_name}-%{pkg_name}-%{version} " ++
               "--libsubdir='$compiler/$pkgid' " ++
               (let cfg = rpmConfigurationsFlags flags
                in if null cfg
                   then ""
                   else "--flags='" ++ joinConfigurations cfg ++ "' ") ++
               (if (rpmLibProf flags) then "--enable" else "--disable") ++
-              "-library-profiling --" ++ cmplr)
+              "-library-profiling --" ++ "%{hsc_name}")
     withLib pkgDesc () $ \_ -> do
         hPutStr h "if "
         putSetup "makefile -f cabal-rpm.mk"
@@ -374,15 +362,16 @@
     putSetup "copy --destdir=${RPM_BUILD_ROOT}"
     withLib pkgDesc () $ \_ -> do
         put "install -m 755 register.sh unregister.sh ${RPM_BUILD_ROOT}%{pkg_libdir}"
-        put "cd ${RPM_BUILD_ROOT}"
-        put "echo '%defattr (-,root,root,-)' > %{tar_dir}/%{name}-files.prof"
-        put "find .%{pkg_libdir} \\( -name '*_p.a' -o -name '*.p_hi' \\) | sed s/^.// >> %{tar_dir}/%{name}-files.prof"
-        put "echo '%defattr (-,root,root,-)' > %{tar_dir}/%{name}-files.nonprof"
-        put "find .%{pkg_libdir} -type d | sed 's/^./%dir /' >> %{tar_dir}/%{name}-files.nonprof"
-        put "find .%{pkg_libdir} ! \\( -type d -o -name '*_p.a' -o -name '*.p_hi' \\) | sed s/^.// >> %{tar_dir}/%{name}-files.nonprof"
-        put "sed 's,^/,%exclude /,' %{tar_dir}/%{name}-files.prof >> %{tar_dir}/%{name}-files.nonprof"
+        putNewline
+        put "rm -f %{name}.files %{name}-prof.files"
+        put "echo '%defattr(-,root,root,-)' > %{name}-prof.files"
+        put "find ${RPM_BUILD_ROOT}%{pkg_libdir} \\( -name '*_p.a' -o -name '*.p_hi' \\) >> %{name}-prof.files"
+        put "echo '%defattr(-,root,root,-)' > %{name}.files"
+        put "find ${RPM_BUILD_ROOT}%{pkg_libdir} -type d | sed 's/^/%dir /' >> %{name}.files"
+        put "find ${RPM_BUILD_ROOT}%{pkg_libdir} ! \\( -type d -o -name '*_p.a' -o -name '*.p_hi' \\) >> %{name}.files"
+        put $ "sed -i -e \"s!${RPM_BUILD_ROOT}!!g\"" ++ " " ++ "%{name}.files %{name}-prof.files"
     putNewline
-    put "cd ${RPM_BUILD_ROOT}/%{_datadir}/doc/%{hsc_name}-%{lc_name}-%{version}"
+    put "cd ${RPM_BUILD_ROOT}/%{_datadir}/doc/%{hsc_name}-%{pkg_name}-%{version}"
     put $ "rm -rf doc " ++ concat (intersperse " " docs)
     putNewline
     putNewline
@@ -405,12 +394,12 @@
            same location as the about-to-be-installed library's
            script. -}
 
-        put $ "%pre " ++ subPackage
+        put $ "%pre" ++ subPackage
         put "[ \"$1\" = 2 ] && %{pkg_libdir}/unregister.sh >&/dev/null || :"
         putNewline
         putNewline
 
-        put $ "%post " ++ subPackage
+        put $ "%post" ++ subPackage
         put "%{pkg_libdir}/register.sh >&/dev/null"
         putNewline
         putNewline
@@ -420,7 +409,7 @@
            runtime's package system will be left with a phantom record
            for a package it can no longer use. -}
 
-        put $ "%preun " ++ subPackage
+        put $ "%preun" ++ subPackage
         put "%{pkg_libdir}/unregister.sh >&/dev/null"
         putNewline
         putNewline
@@ -430,12 +419,12 @@
            Cabal name+version, even though the RPM release differs);
            therefore, we must attempt to re-register it. -}
 
-        put $ "%postun " ++ subPackage
+        put $ "%postun" ++ subPackage
         put "[ \"$1\" = 1 ] && %{pkg_libdir}/register.sh >& /dev/null || :"
         putNewline
         putNewline
 
-        put $ "%files " ++ subPackage ++ " -f %{name}-files.nonprof"
+        put $ "%files" ++ subPackage ++ " -f %{name}.files"
         when doHaddock $
             put "%doc dist/doc/html"
         when ((not . null) docs) $
@@ -444,7 +433,7 @@
         putNewline
 
         when (rpmLibProf flags) $ do
-            put "%files -n %{hsc_name}-%{lc_name}-prof -f %{name}-files.prof"
+            put "%files -n %{hsc_name}-%{pkg_name}-prof -f %{name}-prof.files"
             put $ "%doc " ++ licenseFile pkgDesc
             putNewline
             putNewline
@@ -454,7 +443,7 @@
       put "%defattr (-,root,root,-)"
     withExe pkgDesc $ \exe -> put $ "%{_bindir}/" ++ exeName exe
     when (((not . null . dataFiles) pkgDesc) && isExec) $
-        put "%{_datadir}/%{lc_name}-%{version}"
+        put "%{_datadir}/%{pkg_name}-%{version}"
 
     -- Add the license file to the main package only if it wouldn't
     -- otherwise be empty.
@@ -537,18 +526,12 @@
              -> IO String
 
 showBuildReq verbose haddock c pkgDesc = do
-    cPkg <- case compilerFlavor c of
-              GHC -> return "ghc"
-              Hugs -> return "hugs98"
-              _ -> die $ "cannot deal with compiler " ++ show c
-    let cVersion = pkgVersion $ compilerId c
-        myDeps = [Dependency cPkg (ThisVersion cVersion)] ++
-                 if haddock then [Dependency "haddock" AnyVersion] else []
+    let myDeps = if haddock then [Dependency "haddock" AnyVersion] else []
         externalDeps = filter (not . isBundled c)
                        (buildDepends pkgDesc)
     exReqs <- mapM (showRpmReq verbose (virtualPackage c)) externalDeps
     myReqs <- mapM (showRpmReq verbose id) myDeps
-    return $ (commaSep . concat) (myReqs ++ exReqs)
+    return $ "%{hsc_name} = %{hsc_version}, " ++ (commaSep . concat) (myReqs ++ exReqs)
 
 -- | Represent a dependency in a form suitable for an RPM spec file.
 

