diff options
author | Brad Richardson <everythingfunctional@protonmail.com> | 2020-06-15 19:59:58 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-15 19:59:58 -0700 |
commit | 410537bbe21c91a4ec27e45ead99a9f83454c099 (patch) | |
tree | 58f186a47143392564cae718abb9017293e5e3d4 /src/Build.hs | |
parent | f97260ef5b5dfe9e2872394a4539090e71e1ceff (diff) | |
parent | df531fcffdd5c7b6233d0107152725ce3f8f22c1 (diff) | |
download | fpm-410537bbe21c91a4ec27e45ead99a9f83454c099.tar.gz fpm-410537bbe21c91a4ec27e45ead99a9f83454c099.zip |
Merge pull request #99 from everythingfunctional/MakefileSupport
Add support for Makefiles and generic build scripts
Diffstat (limited to 'src/Build.hs')
-rw-r--r-- | src/Build.hs | 63 |
1 files changed, 61 insertions, 2 deletions
diff --git a/src/Build.hs b/src/Build.hs index 913e754..67ec2f9 100644 --- a/src/Build.hs +++ b/src/Build.hs @@ -1,6 +1,8 @@ +{-# LANGUAGE MultiWayIf #-} module Build ( buildLibrary , buildProgram + , buildWithScript ) where @@ -10,7 +12,10 @@ import Data.Char ( isAsciiLower , isDigit , toLower ) -import Data.List ( intercalate ) +import Data.List ( intercalate + , isSuffixOf + ) +import Data.List.Utils ( replace ) import qualified Data.Map as Map import Data.Maybe ( fromMaybe , mapMaybe @@ -42,8 +47,13 @@ import Development.Shake.FilePath ( dropExtension , (<.>) , (-<.>) ) -import System.Directory ( makeAbsolute ) +import System.Directory ( createDirectoryIfMissing + , makeAbsolute + , withCurrentDirectory + ) +import System.Environment ( setEnv ) import System.FilePath ( splitDirectories ) +import System.Process ( system ) import Text.ParserCombinators.ReadP ( ReadP , char , eof @@ -359,3 +369,52 @@ digit = satisfy isDigit underscore :: ReadP Char underscore = char '_' + +buildWithScript + :: String + -> FilePath + -> FilePath + -> FilePath + -> [String] + -> String + -> [FilePath] + -> IO (FilePath) +buildWithScript script projectDirectory buildDirectory compiler flags libraryName otherLibraryDirectories + = do + absoluteBuildDirectory <- makeAbsolute buildDirectory + createDirectoryIfMissing True absoluteBuildDirectory + absoluteLibraryDirectories <- mapM makeAbsolute otherLibraryDirectories + setEnv "FC" compiler + setEnv "FFLAGS" (intercalate " " flags) + setEnv "BUILD_DIR" $ unWindowsPath absoluteBuildDirectory + setEnv + "INCLUDE_DIRS" + (intercalate " " (map unWindowsPath absoluteLibraryDirectories)) + let archiveFile = + (unWindowsPath absoluteBuildDirectory) + ++ "/lib" + ++ libraryName + <.> "a" + withCurrentDirectory + projectDirectory + if + | isMakefile script -> system + ("make -f " ++ script ++ " " ++ archiveFile) + | otherwise -> system (script ++ " " ++ archiveFile) + return archiveFile + +isMakefile :: String -> Bool +isMakefile script | script == "Makefile" = True + | script == "makefile" = True + | ".mk" `isSuffixOf` script = True + | otherwise = False + +unWindowsPath :: String -> String +unWindowsPath = changeSeparators . removeDriveLetter + +removeDriveLetter :: String -> String +removeDriveLetter path | ':' `elem` path = (tail . dropWhile (/= ':')) path + | otherwise = path + +changeSeparators :: String -> String +changeSeparators = replace "\\" "/" |