packages feed

futhask-1.0.0: src/CabalGen.hs

{-# LANGUAGE OverloadedStrings #-}

module CabalGen where
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Encoding as T
import Backends

indent = T.unlines . map ("  " <>) . T.lines
formatItems items = T.unlines $ map (\(a, b) -> a <> ": " <> b) items
formatSection title items = title <> "\n" <> (indent $ formatItems items)
formatList items = "\n" <> indent (T.unlines items)

cabalFile futhaskVersion futhaskBaseVersion name libname version backend = cabalVersion <> comment <> header <> library
    where
        cabalVersion = "cabal-version: 3.0\n"
        comment = "--This file was generated by futhask version " <> futhaskVersion <> "\n" 
        header = formatItems[ ("name", name), ("version", version) ]
        library = formatSection "library" 
            [ ("build-depends", formatList depends)
            , ("hs-source-dirs", "src")
            , ("c-sources", "src.c" )
            , ("include-dirs", formatList includeDirs)
            , ("extra-lib-dirs", formatList libDirs)
            , ("extra-libraries", formatList libs)
            , ("exposed-modules", formatList modules)
            , ("default-language", language) ]
        language = "GHC2024"--"Haskell2010"
        modules = libname : map ((libname <> ".") <>) 
            [ "Raw"
            , "Raw.Context"
            , "Raw.Types"
            , "Raw.TypeDec"
            , "Raw.TypeOps"
            , "Raw.EntryPoints" 
            , "Context"
            , "Monad"
            , "Types"
            , "TypeDec"
            , "TypeOps"
            , "EntryPoints"
            , "Conversion"
            , "Unpacked.Types"
            , "Native.Types" ]
            
        depends =
            [ "base >= 4 && < 5,"
            , "futhask-base == " <> futhaskBaseVersion ]
        includeDirs = case backend of
            OpenCL -> [""]
            Cuda -> ["/usr/local/cuda/include"]
            Hip -> ["/opt/rocm/include"]
            _ -> []
        libDirs = case backend of
            OpenCL -> [""]
            Cuda -> ["/usr/local/cuda/lib64"]
            Hip -> ["/opt/rocm/lib"]
            _ -> [""]
        libs = case backend of
            OpenCL -> ["OpenCL"]
            Cuda -> ["cuda", "cudart", "nvrtc"]
            Hip -> ["hiprtc", "amdhip64"]
            _ -> []