New patches: [unrevert anonymous**20071125165009] < > { hunk ./Distribution/Slackware/SlackBuild.hs 1 -module Distribution.Slackware.SlackBuild - ( SlackBuildConfig (..) - , defaultSlackBuildConfig - , slackBuild - , slackDoInst - , slackDesc - , slackRequired - ) where - -import Distribution.Package -import Distribution.PackageDescription -import Distribution.Version - -data SlackBuildConfig = - SBConfig { arch :: String - , build :: Int - , builder :: String - , prefix :: String - , setup :: String - , runhaskell :: String - , hoogle :: Bool - , haddock :: Bool - , linkSource :: Bool - , hscolour :: String - , usePrefix :: Bool - , files :: [FilePath] - } deriving Show - -defaultSlackBuildConfig :: SlackBuildConfig -defaultSlackBuildConfig = - SBConfig { arch = "i486" - , build = 1 - , builder = "hsb" - , prefix = "/usr" - , setup = "Setup.hs" - , runhaskell = "runhaskell" - , hoogle = True - , haddock = True - , linkSource = False - , hscolour = [] - , usePrefix = False - , files = ["README"] - } - -slackBuild :: SlackBuildConfig -> PackageDescription -> String -slackBuild c d = unlines $ - map unlines [ header - , varSection - , unpackSection - , buildSection - , stripSection - , installSection - , when (lib && hoogle c) hoogleSection - , docSection - , pkgSection - ] - where - lib = hasLibs d - name = pkgName . package $ d - version = showVersion . pkgVersion . package $ d - s = pad . setup $ c - run = runhaskell c - wrap l r m = l ++ m ++ r - pad = wrap " " " " - - header = - ["#!/bin/sh" - , wrap "# Build" "for Slackware" . pad $ name - , legalNotice - ] - - varSection = - [ "CWD=`pwd`" - , "VERSION=" ++ version - , wrap "ARCH=${ARCH:-" "}" (arch c) - , wrap "BUILD=${BUILD:-" "}" (show (build c) ++ builder c) - ] - - unpackSection = - [ "PKG=/tmp/package-" ++ name - , "rm -rf $PKG" - , "mkdir $PKG" - , "cd /tmp" - , wrap "tar xzvf $CWD/" "-$VERSION.tar.gz" name - , wrap "cd `basename " "-$VERSION i`" name - ] - - buildSection = - [ "chown -R root:root ." - , unwords configure - , wrap run "build" s - , when (haddock c) $ unlines $ haddockGen (not lib) - , wrap run "copy --destdir=$PKG" s - , when lib register - ] - - configure = - [ wrap run "configure --prefix=" s ++ prefix c - , when lib "-p" - ] - - haddockGen b = - [ wrap run "haddock" s ++ when b " --executables" ++ - when (linkSource c) " --hyperlink-source" ++ - when (hscolour c /= []) " --hscolour-css=" ++ (hscolour c) - , when (hoogle c) (wrap run "haddock --hoogle" s) ++ - when b " --executables" - ] - - register = wrap run "register --gen-script" s - - stripSection = - [ "( cd $PKG" - , " find . | xargs file | grep \"executable\" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null" - , " find . | xargs file | grep \"shared object\" | grep ELF | cut -f 1 -d : | xargs strip --strip-unneeded 2> /dev/null" - , ")" - , "gzip -9 $PKG/usr/man/man?/*" - ] - - installSection = - [ "mkdir -p $PKG/install" - , "cat $CWD/doinst.sh > $PKG/install/doinst.sh" - , "cat $CWD/slack-desc > $PKG/install/slack-desc" - , when lib "cat register.sh > $PKG/install/register.sh" - ] - - hoogleSection = - [ "mkdir -p $PKG/var/spool/hoogle/" - , "cp $PKG/usr/share/doc/" ++ name ++ "-$VERSION/html/" ++ name ++ "-$VERSION.txt $PKG/var/spool/hoogle/" - ] - - docSection = - [ wrap "mkdir -p $PKG/usr/doc/" "-$VERSION" name - , "cp -a \\" - , wrap " " " \\" (unwords otherFiles) - , wrap " $PKG/usr/doc/" "-$VERSION" name - ] - - otherFiles = licenseFile d : files c - - pkgSection = - [ "cd $PKG" - , wrap "makepkg -l y -c n ../" "-$VERSION-$ARCH-$BUILD.tgz" ((when (usePrefix c) "hs-") ++ name) - ] - - legalNotice = - "# This script has been generated by a computer programm\n" ++ - "# and is not eligible for copyright protection.\n" - -slackDoInst :: SlackBuildConfig -> PackageDescription -> String -slackDoInst c d = - unlines [ when (hasLibs d) "( sh /install/register.sh ; rm /install/register.sh )" - , when (haddock c && hoogle c) "( rm /var/spool/hoogle/hoogle ; cat /var/spool/hoogle/*txt >> /var/spool/hoogle/hoogle )" - ] - -slackDesc :: SlackBuildConfig -> PackageDescription -> String -slackDesc c d = format $ - [ name - , emptyLine - , synopsis d - , emptyLine - , desc d - ] - ++ filter (not . null) - [ concatIf (copyright d) "copyright:" - , concatIf (author d) "author:" - , concatIf (maintainer d) "maintainer:" - , concatIf (homepage d) "homepage:" - ] - ++ endNote - where - desc = format . lines . description - - name = pkgName . package $ d - - concatIf p s = when (p /= []) (s ++ " " ++ p) - - format [] = [] - format (x:xs) = when (usePrefix c) "hs-" ++ - name ++ ": " ++ x ++ "\n" ++ format xs - - endNote = [emptyLine, "Package created with HSlackBuilder"] - - emptyLine = [] - - -slackRequired :: PackageDescription -> String -slackRequired d = - format [check p v | (Dependency p v) <- buildDepends d] - where - format = unlines . filter (not . null) - check p v = when (needed p) $ p ++ version v - needed = not . flip elem ghc_packages - version s - | showVersionRange s == "-any" = [] - | otherwise = showVersionRange s - -when :: Bool -> [a] -> [a] -when p x = if p then x else [] - -ghc_packages :: [String] -ghc_packages = [ "Cabal" - , "array" - , "base" - , "filepath" - , "haskell98" - , "parsec" - , "readline" - , "regex-base" - , "regex-posix" - , "regex-compat" - , "stm" - , "template-haskell" - , "unix" - , "bytestring" - , "old-locale" - , "old-time" - , "process" - , "containers" - ] rmfile ./Distribution/Slackware/SlackBuild.hs rmdir ./Distribution/Slackware rmdir ./Distribution hunk ./LICENSE 1 -Copyright (c) Andrea Rossato - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -3. Neither the name of the author nor the names of his contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. rmfile ./LICENSE hunk ./Main.hs 1 ------------------------------------------------------------------------------ --- | --- Module : Main --- Copyright : (c) Andrea Rossato 2007 --- License : BSD3-style (see LICENSE) --- --- Maintainer : andrea.rossato@unibz.it --- Stability : stable --- Portability : portable --- --- --- HSlackBuilder is a script to automatically generate slackBuild --- scripts from a cabal package --- ------------------------------------------------------------------------------ - -module Main where - -import Prelude hiding (catch) -import Control.Exception -import Control.Monad -import Data.IORef -import Data.Maybe ( listToMaybe ) -import Data.Char ( isSpace ) -import Distribution.Package ( PackageIdentifier (..) - , parsePackageId - , showPackageId ) -import Distribution.PackageDescription ( finalizePackageDescription - , readPackageDescription ) -import Distribution.Simple.Compiler -import Distribution.Simple.Configure ( configCompiler - , getInstalledPackages ) -import Distribution.Simple.Program ( defaultProgramConfiguration ) -import Distribution.Verbosity ( normal ) -import Distribution.Version ( Version, Dependency (..) ) -import System.Cmd -import System.Console.GetOpt -import System.Directory ( getTemporaryDirectory ) -import System.Environment -import System.Exit -import System.FilePath.Posix -import System.Posix.Files (fileExist ) -import Text.ParserCombinators.ReadP ( readP_to_S ) -import Distribution.Slackware.SlackBuild - -main :: IO () -main = do - args <- getArgs - (o,f) <- getOpts args - i <- newIORef defaultSlackBuildConfig - doOpts i o - c <- readIORef i - (ghc, ghc_conf) <- configCompiler (Just GHC) Nothing Nothing - defaultProgramConfiguration normal - dep <- getInstalledPackages normal ghc GlobalPackageDB ghc_conf - (name,set,gpd) <- case f of - [cf] -> do (n,s,t) <- checksCabalPackage cf - d <- readPackageDescription normal (t n <.> "cabal") - return (n,s,d) - _ -> error $ "No Cabal package specified!\n" ++ usage - let conf = c { setup = set } - pd = finalizePackageDescription [] dep "LINUX" (arch conf) - (showCompilerId ghc, compilerVersion ghc) gpd - case pd of - Right (d,_) -> do - putStrLn $ "writing " ++ name <.> "SlackBuild" ++ "..." - writeFile (name <.> "SlackBuild") $ slackBuild conf d - putStrLn $ "writing doinst.sh..." - writeFile "doinst.sh" $ slackDoInst conf d - putStrLn $ "writing slack-desc..." - writeFile "slack-desc" $ slackDesc conf d - putStrLn $ "writing slack-required..." - writeFile "slack-required" $ slackRequired d - putStrLn $ "Done!" - Left mis -> do - putStrLn "Missing dependencies:" - printDepList mis - -checksCabalPackage :: FilePath -> IO (String,FilePath,FilePath) -checksCabalPackage file = do - let name = takeFileName file - pid = takeBaseName . takeBaseName $ name - (n,_) <- checkName pid - tmp <- getTemporaryDirectory - let tmpf = tmp pid - rawSystem "tar" ["-C",tmp,"-xzf",file] `catch` - \_ -> error ("could not extract " ++ n ++ " from " ++ file) - -- check the setup script - b <- fileExist (tmpf "Setup.hs") - set <- if (not b) - then do - b' <- fileExist (tmpf "Setup.lhs") - when (not b') $ error "Cannot find a valid Setup file in the cabal package." - return "Setup.lhs" - else return "Setup.hs" - return (n,set,tmpf) - - -checkName :: FilePath -> IO (String, Version) -checkName f = do - PackageIdentifier n v <- case readPackageId f of - Just i | showPackageId i == f -> return i - _ -> error $ "malformed package identifier " ++ f - return (n,v) - -readPackageId :: String -> Maybe PackageIdentifier -readPackageId str = - listToMaybe [ p | (p, rest) <- readP_to_S parsePackageId str - , null (dropWhile isSpace rest)] - -printDepList :: [Dependency] -> IO () -printDepList [] = return () -printDepList ((Dependency s _):xs) = do - putStrLn s - printDepList xs - --- $options --- --- The needed boilerplate code for parsing command line options - -data Opts = Help - | Version - | LinkSource - | HsColour String - | UsePrefix - | Build String - | Arch String - deriving Show - -options :: [OptDescr Opts] -options = - [ Option ['h','?' ] ["help" ] (NoArg Help ) "This help" - , Option ['V' ] ["version" ] (NoArg Version ) "Show version information" - , Option ['b' ] ["build-number"] (ReqArg Build "build number" ) "The build number" - , Option ['a' ] ["arch" ] (ReqArg Arch "architecture" ) "The architecture" - , Option ['l' ] ["link" ] (NoArg LinkSource ) "The Haddock documentation will link the source code" - , Option ['p' ] ["hs-prefix" ] (NoArg UsePrefix ) "Use an hs prefix in package name" - , Option ['c' ] ["hs-colour" ] (ReqArg HsColour "path to css") "The source code will be colorize with hs-colour" - ] - -getOpts :: [String] -> IO ([Opts], [String]) -getOpts argv = - case getOpt Permute options argv of - (o,n,[]) -> return (o,n) - (_,_,errs) -> error (concat errs ++ usage) - -usage :: String -usage = (usageInfo header options) ++ footer - where header = "Usage: cabal2slackBuild [OPTION...] FILE\nOptions:" - footer = "\nMail bug reports and suggestions to " ++ mail - -version :: String -version = "cabal2slackBuild 0.0.1 (C) 2007 Andrea Rossato " ++ mail ++ legal - -mail :: String -mail = "\n" - -legal :: String -legal = "\nThis program is distributed in the hope that it will be useful,\n" ++ - "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" ++ - "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n" ++ - "See the License for more details." - -doOpts :: IORef SlackBuildConfig -> [Opts] -> IO () -doOpts _ [] = return () -doOpts conf (o:oo) = - case o of - Help -> putStr usage >> exitWith ExitSuccess - Version -> putStrLn version >> exitWith ExitSuccess - LinkSource -> modifyIORef conf (\c -> c { linkSource = True }) >> go - UsePrefix -> modifyIORef conf (\c -> c { usePrefix = True }) >> go - HsColour s -> modifyIORef conf (\c -> c { hscolour = s }) >> go - Build s -> modifyIORef conf (\c -> c { build = read s }) >> go - Arch s -> modifyIORef conf (\c -> c { arch = s }) >> go - where - go = doOpts conf oo rmfile ./Main.hs hunk ./Setup.lhs 1 -#!/usr/bin/env runhaskell - -> import Distribution.Simple -> main = defaultMainWithHooks defaultUserHooks rmfile ./Setup.lhs hunk ./hslackbuilder.cabal 1 -name: hslackbulder -version: 0.0.1 -homepage: http://code.haskell.org/~arossato/hslackbuilder -synopsis: HSlackBuilder automatically generates slackBuild from cabal packages -description: HSlackBuilder automatically generates slackBuild from cabal packages -category: Distribution -license: BSD3 -license-file: LICENSE -author: Andrea Rossato -maintainer: andrea.rossato@unibz.it -cabal-version: >= 1.2 -flag small_base - description: Choose the new smaller, split-up base package. - -library - exposed-modules: Distribution.Slackware.SlackBuild - ghc-options: -funbox-strict-fields -Wall -Werror -optl-Wl,-s - ghc-prof-options: -prof -auto-all - if flag(small_base) - build-depends: base >= 3 - else - build-depends: base < 3 - build-depends: Cabal >= 1.2, unix, filepath - -executable cabal2slackBuild - main-is: Main.hs - other-Modules: Distribution.Slackware.SlackBuild - ghc-options: -funbox-strict-fields -Wall -Werror -optl-Wl,-s - ghc-prof-options: -prof -auto-all - if flag(small_base) - build-depends: base >= 3 - else - build-depends: base < 3 - build-depends: Cabal >= 1.2, unix, filepath - rmfile ./hslackbuilder.cabal } Context: [init Andrea Rossato **20071125164741] Patch bundle hash: 8244983d68408a0c250ae8b71523a7ef7b902fe7