@@ -19,18 +19,24 @@ import Control.Monad (when)
1919import Data.FileEmbed (embedFile)
2020import System.Environment (getExecutablePath)
2121import System.Directory (doesFileExist)
22+import System.FilePath (takeDirectory)
2223
24+import qualified Data.Text as T
2325import qualified Data.ByteString.Char8 as B
2426
2527generateMakefile :: IO ()
2628generateMakefile = do
27− makefileExists <- doesFileExist "Makefile"
29+ makefileExists <- doesFileExist makefilename
2830 when (not makefileExists) $ do
2931 let makefile = $(embedFile "pcc/Makefile")
3032 exePath <- getExecutablePath
3133 putStrLn ""
32− putStrLn $ "Generating Makefile... " ++ "pcc executable location " ++ exePath
33− writeFile "Makefile" $ replace makefile pccPath exePath
34+ putStrLn $ "Generating " ++ makefilename ++ "... " ++ "pcc executable location " ++ exePath
35+ writeFile makefilename . T.unpack $
36+ T.replace
37+ pathPlaceholder
38+ (T.pack $ takeDirectory exePath)
39+ (T.pack $ B.unpack makefile)
3440 putStrLn "Done"
3541 putStrLn ""
3642 putStrLn "Run 'make' or 'make release' to build an optimized release build."
@@ -42,23 +48,34 @@ generateMakefile = do
4248
4349generatePackagefile :: IO ()
4450generatePackagefile = do
45− pkgfileExists <- doesFileExist "psc-package.json"
51+ pkgfileExists <- doesFileExist packagefilename
4652 when (not pkgfileExists) $ do
4753 let pkgfile = $(embedFile "pcc/psc-package.json")
4854 putStrLn ""
49− putStrLn "Generating psc-package.json..."
50− writeFile "psc-package.json" $ B.unpack pkgfile
55+ putStrLn $ "Generating " ++ packagefilename ++ "..."
56+ writeFile packagefilename $ B.unpack pkgfile
5157 putStrLn "Done"
5258 putStrLn "Use the 'psc-package' utility to install or update packages."
5359
54−replace :: B.ByteString -> B.ByteString -> String -> String
55−replace s orig repl = replace'
56− where
57− replace'
58− | (p1, p2) <- B.breakSubstring orig s,
59− not (B.null p2) = B.unpack p1 ++ repl ++ trim (B.unpack p2)
60− | otherwise = B.unpack s
61− trim = drop (B.length orig)
60+generateXcodefile :: IO ()
61+generateXcodefile = do
62+ xcodefileExists <- doesFileExist xcodefilename
63+ when (not xcodefileExists) $ do
64+ let xcodefile = $(embedFile "pcc/psc-xcode.sh")
65+ putStrLn ""
66+ putStrLn $ "Generating " ++ xcodefilename ++ "..."
67+ writeFile xcodefilename $ B.unpack xcodefile
68+ putStrLn "Done"
69+ putStrLn "Add this file to an Xcode 'Run Script' build phase."
70+
71+makefilename :: String
72+makefilename = "Makefile"
73+
74+packagefilename :: String
75+packagefilename = "psc-package.json"
76+
77+xcodefilename :: String
78+xcodefilename = "psc-xcode.sh"
6279
63−pccPath :: B.ByteString
64−pccPath = "{bin/pcc}"
80+pathPlaceholder :: T.Text
81+pathPlaceholder = "{{path}}"