Ticket #8781: support-non-GNU-solaris-nm.patch

File support-non-GNU-solaris-nm.patch, 3.7 KB (added by maeder, 13 months ago)

alternative patch

  • utils/deriveConstants/DeriveConstants.hs

    From 67009763927e4d61fb11c0c4fd75d4d9dd236390 Mon Sep 17 00:00:00 2001
    From: Christian Maeder <[email protected]>
    Date: Thu, 3 Apr 2014 10:00:07 +0200
    Subject: [PATCH] Extract derived constants from nm output for various OSes
     differently. In order to avoid querying the nm version that
     does not work on Mac OS X we use the "nm -P" output that is
     supposed to produce (more portable) POSIX output and works
     on all tested OSes (MinGW, Mac OS X, Solaris and Linux
     using GNU nm) although slightly different (as documented).
     The "nm -P" output is actually only needed to recognize the
     output of a non-GNU Solaris nm (all other OSes produce sane
     outut using "nm" only).
    
    ---
     utils/deriveConstants/DeriveConstants.hs |   37 ++++++++++++------------------
     1 Datei geändert, 15 Zeilen hinzugefügt(+), 22 Zeilen entfernt(-)
    
    diff --git a/utils/deriveConstants/DeriveConstants.hs b/utils/deriveConstants/DeriveConstants.hs
    index 8c943f0..6bfce24 100644
    a b getWanted verbose tmpdir gccProgram gccFlags nmProgram 
    641641             oFile = tmpdir </> "tmp.o" 
    642642         writeFile cFile cStuff 
    643643         execute verbose gccProgram (gccFlags ++ ["-c", cFile, "-o", oFile]) 
    644          xs <- readProcess nmProgram [oFile] "" 
     644         xs <- readProcess nmProgram ["-P", oFile] "" 
    645645         let ls = lines xs 
    646646             ms = map parseNmLine ls 
    647647             m = Map.fromList $ catMaybes ms 
    getWanted verbose tmpdir gccProgram gccFlags nmProgram 
    710710          doWanted (ClosurePayloadMacro {}) = [] 
    711711          doWanted (FieldTypeGcptrMacro {}) = [] 
    712712 
    713           -- parseNmLine parses nm output that looks like 
    714           -- "0000000b C derivedConstantMAX_Vanilla_REG" 
     713          -- parseNmLine parses "nm -P" output that looks like 
     714          -- "derivedConstantMAX_Vanilla_REG C 0000000b 0000000b" (GNU nm) 
     715          -- "_derivedConstantMAX_Vanilla_REG C b 0" (Mac OS X) 
     716          -- "_derivedConstantMAX_Vanilla_REG C 000000b" (MinGW) 
     717          -- "derivedConstantMAX_Vanilla_REG D        1        b" (Solaris) 
    715718          -- and returns ("MAX_Vanilla_REG", 11) 
    716           parseNmLine xs0 = case break (' ' ==) xs0 of 
    717                             (x1, ' ' : xs1) -> 
    718                                 case break (' ' ==) xs1 of 
    719                                 (x2, ' ' : x3) -> 
    720                                     case readHex x1 of 
    721                                     [(size, "")] -> 
    722                                         case x2 of 
    723                                         "C" -> 
    724                                             let x3' = case x3 of 
    725                                                       '_' : rest -> rest 
    726                                                       _          -> x3 
    727                                             in case stripPrefix prefix x3' of 
    728                                                Just name -> 
    729                                                    Just (name, size) 
    730                                                _ -> Nothing 
    731                                         _ -> Nothing 
    732                                     _ -> Nothing 
    733                                 _ -> Nothing 
    734                             _ -> Nothing 
     719          parseNmLine line 
     720              = case words line of 
     721                ('_' : n) : "C" : s : _ -> mkP n s 
     722                n : "C" : s : _ -> mkP n s 
     723                [n, "D", _, s] -> mkP n s 
     724                _ -> Nothing 
     725              where mkP r s = case (stripPrefix prefix r, readHex s) of 
     726                        (Just name, [(size, "")]) -> Just (name, size) 
     727                        _ -> Nothing 
    735728 
    736729          -- If an Int value is larger than 2^28 or smaller 
    737730          -- than -2^28, then fail.