git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
C++: add xcode support
commitf6c70bca56e7dd18d9368f741d78adc0442e6899 authorAndy Arvanitis <andyarvanitis@gmail.com> dateFri 18 Nov 2016, 22:58 (10 years ago) parent69cb2e4
4 files changed+84−7
pcc/Main.hs+9 pcc/Makefile+1−1 pcc/Makefile.hs+26−6 pcc/psc-xcode.sh+48
pcc/Main.hs+9
@@ -54,6 +54,7 @@ data PCCMakeOptions = PCCMakeOptions
5454 , pccmOpts :: P.Options
5555 , pccmUsePrefix :: Bool
5656 , pccmJSONErrors :: Bool
57+ , pccmXcode :: Bool
5758 }
5859
5960-- | Argumnets: verbose, use JSON, warnings, errors
@@ -77,6 +78,8 @@ printWarningsAndErrors verbose True warnings errors = do
7778compile :: PCCMakeOptions -> IO ()
7879compile PCCMakeOptions{..} = do
7980 input <- globWarningOnMisses (unless pccmJSONErrors . warnFileTypeNotFound) pccmInput
81+ when pccmXcode $ do
82+ generateXcodefile
8083 when (null input && not pccmJSONErrors) $ do
8184 generatePackagefile
8285 generateMakefile
@@ -165,6 +168,11 @@ dumpCoreFn = switch $
165168 long "dump-corefn"
166169 <> help "Dump the (functional) core representation of the compiled code at output/*/corefn.json"
167170
171+xcode :: Parser Bool
172+xcode = switch $
173+ long "xcode"
174+ <> help "Generate support files for Xcode"
175+
168176options :: Parser P.Options
169177options = P.Options <$> noTco
170178 <*> noMagicDo
@@ -181,6 +189,7 @@ pccMakeOptions = PCCMakeOptions <$> many inputFile
181189 <*> options
182190 <*> (not <$> noPrefix)
183191 <*> jsonErrors
192+ <*> xcode
184193
185194main :: IO ()
186195main = do
pcc/Makefile+1−1
@@ -15,7 +15,7 @@
1515# You can also edit the generated version of this file directly.
1616#
1717PCC := {{path}}/pcc
18−PSC_PACKAGE := psc-package
18+PSC_PACKAGE := {{path}}/psc-package
1919PURESCRIPT_PKGS := .psc-package
2020PURESCRIPT_SRC := src
2121OUTPUT := output
pcc/Makefile.hs+26−6
@@ -26,13 +26,13 @@ import qualified Data.ByteString.Char8 as B
2626
2727generateMakefile :: IO ()
2828generateMakefile = do
29− makefileExists <- doesFileExist "Makefile"
29+ makefileExists <- doesFileExist makefilename
3030 when (not makefileExists) $ do
3131 let makefile = $(embedFile "pcc/Makefile")
3232 exePath <- getExecutablePath
3333 putStrLn ""
34− putStrLn $ "Generating Makefile... " ++ "pcc executable location " ++ exePath
35− writeFile "Makefile" . T.unpack $
34+ putStrLn $ "Generating " ++ makefilename ++ "... " ++ "pcc executable location " ++ exePath
35+ writeFile makefilename . T.unpack $
3636 T.replace
3737 pathPlaceholder
3838 (T.pack $ takeDirectory exePath)
@@ -48,14 +48,34 @@ generateMakefile = do
4848
4949generatePackagefile :: IO ()
5050generatePackagefile = do
51− pkgfileExists <- doesFileExist "psc-package.json"
51+ pkgfileExists <- doesFileExist packagefilename
5252 when (not pkgfileExists) $ do
5353 let pkgfile = $(embedFile "pcc/psc-package.json")
5454 putStrLn ""
55− putStrLn "Generating psc-package.json..."
56− writeFile "psc-package.json" $ B.unpack pkgfile
55+ putStrLn $ "Generating " ++ packagefilename ++ "..."
56+ writeFile packagefilename $ B.unpack pkgfile
5757 putStrLn "Done"
5858 putStrLn "Use the 'psc-package' utility to install or update packages."
5959
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"
79+
6080pathPlaceholder :: T.Text
6181pathPlaceholder = "{{path}}"
pcc/psc-xcode.shnew file+48
@@ -0,0 +1,48 @@
1+# Xcode support script. Intended to be added to and called from "Run Script" build phase.
2+#
3+#!/bin/sh
4+
5+echo "CONFIGURATION =" "$CONFIGURATION"
6+echo "ARCHITECTURES =" "$ARCHS"
7+
8+IS_DEBUG="$PROJECT_TEMP_DIR/is_debug"
9+IS_RELEASE="$PROJECT_TEMP_DIR/is_release"
10+
11+if [[ "$CONFIGURATION" == "Debug" ]] ; then
12+ if [ ! -f "$IS_DEBUG" ] ; then
13+ make clean
14+ touch "$IS_DEBUG"
15+ fi
16+ rm "$IS_RELEASE" > /dev/null 2>&1 || true
17+ OBJECT_TYPE=debug-object
18+else
19+ if [ ! -f "$IS_RELEASE" ] ; then
20+ make clean
21+ touch "$IS_RELEASE"
22+ fi
23+ rm "$IS_DEBUG" > /dev/null 2>&1 || true
24+ OBJECT_TYPE=release-object
25+fi
26+
27+## Create compiler switches for architectures
28+#
29+for arch_ in $ARCHS ; do
30+ ARCH_OPTS+="-arch $arch_ "
31+ if ! file output/bin/purescript.o | grep -q $arch_; then
32+ make clean
33+ fi
34+ # TODO: make this more future-proof
35+ # Note: -flto optimization causes problems with the source-level
36+ # debugger. Disable bitcode temporarily if necessary.
37+ if [[ $ENABLE_BITCODE == YES && $arch == arm64 ]] ; then
38+ FLTO="-flto"
39+ fi
40+done
41+
42+## Look for psc-package, in case it's already in the PATH
43+#
44+if [ -x "$(command -v psc-package)" ] ; then
45+ PSC_PKG="PSC_PACKAGE=$(command -v psc-package)"
46+fi
47+
48+make $OBJECT_TYPE ${PSC_PKG} CXXFLAGS="$ARCH_OPTS $FLTO -isysroot $SDKROOT" LD="clang -Wl,-r -nostdlib $ARCH_OPTS" -j`sysctl -n hw.ncpu`