diff --git a/config.mk b/config.mk index 97782f200..a474ff0ba 100644 --- a/config.mk +++ b/config.mk @@ -14,7 +14,7 @@ RANLIB ?=ranlib CABAL :=cabal # IDRIS_ENABLE_STATS should not be set in final release # Any flags defined here which alter the RTS API must also be added to src/IRTS/CodegenC.hs -CFLAGS :=-O2 -Wall -std=c99 -D_POSIX_C_SOURCE=200809L -DHAS_PTHREAD -DIDRIS_ENABLE_STATS $(CFLAGS) +CFLAGS :=-O2 -Wall -std=c99 -pipe -fdata-sections -ffunction-sections -D_POSIX_C_SOURCE=200809L -DHAS_PTHREAD -DIDRIS_ENABLE_STATS $(CFLAGS) # CABALFLAGS := CABALFLAGS += --enable-tests diff --git a/src/IRTS/CodegenC.hs b/src/IRTS/CodegenC.hs index d0b356bfa..2e5554341 100644 --- a/src/IRTS/CodegenC.hs +++ b/src/IRTS/CodegenC.hs @@ -79,18 +79,22 @@ codegenC' defs out exec incs objs libs flags exports iface dbg libFlags <- getLibFlags incFlags <- getIncFlags envFlags <- getEnvFlags - let stackFlag = if isWindows then ["-Wl,--stack,16777216"] else [] + let stripFlag = if isDarwin then "-dead_strip" else "-Wl,-gc-sections" + let stackFlags = if isWindows then ["-Wl,--stack,16777216"] else [] + let linkFlags = stripFlag : stackFlags let args = gccDbg dbg ++ gccFlags iface ++ -- # Any flags defined here which alter the RTS API must also be added to config.mk - ["-std=c99", "-D_POSIX_C_SOURCE=200809L", "-DHAS_PTHREAD", "-DIDRIS_ENABLE_STATS", - "-I."] ++ objs ++ envFlags ++ - (if (exec == Executable) then [] else ["-c"]) ++ + [ "-std=c99", "-pipe" + , "-fdata-sections", "-ffunction-sections" + , "-D_POSIX_C_SOURCE=200809L", "-DHAS_PTHREAD", "-DIDRIS_ENABLE_STATS" + , "-I."] ++ objs ++ envFlags ++ + (if (exec == Executable) then linkFlags else ["-c"]) ++ [tmpn] ++ (if not iface then libFlags else []) ++ incFlags ++ (if not iface then libs else []) ++ - flags ++ stackFlag ++ + flags ++ ["-o", out] -- putStrLn (show args) exit <- rawSystem comp args diff --git a/src/Util/System.hs b/src/Util/System.hs index 658345aa7..37cfc771a 100644 --- a/src/Util/System.hs +++ b/src/Util/System.hs @@ -10,6 +10,7 @@ module Util.System( tempfile , withTempdir , rmFile , catchIO + , isDarwin , isWindows , writeSource , writeSourceText @@ -50,6 +51,9 @@ catchIO = CE.catch isWindows :: Bool isWindows = os `elem` ["win32", "mingw32", "cygwin32"] +isDarwin :: Bool +isDarwin = os == "darwin" + -- | Create a temp file with the extensiom ext (in the format ".xxx") tempfile :: String -> IO (FilePath, Handle) tempfile ext = do dir <- getTemporaryDirectory