1 2{- 3 Hake: a meta build system for Barrelfish 4 5 Copyright (c) 2009, 2015, ETH Zurich. 6 All rights reserved. 7 8 This file is distributed under the terms in the attached LICENSE file. 9 If you do not find this file, copies can be found by writing to: 10 ETH Zurich D-INFK, Universitaetstasse 6, CH-8092 Zurich. Attn: Systems Group. 11-} 12 13 14import Data.Dynamic 15import Data.List 16import Data.Maybe 17import Data.Char 18 19import System.Directory 20import System.Environment 21import System.Exit 22import System.FilePath 23import System.IO 24import Debug.Trace 25 26-- Generate enume for flounder endpoint types. do it here as 27-- Hake knows all the files 28-- 29 30isIf :: FilePath -> Bool 31isIf = (== ".if") . takeExtension 32 33makeFlounderTypes :: String -> String -> String -> IO() 34makeFlounderTypes src build arch = do 35 let fileName = build ++ "/" ++ arch ++ "/include/if/if_types.h" 36 let dirName = build ++ "/" ++ arch ++ "/include/if" 37 38 createDirectoryIfMissing True dirName 39 writeFile fileName "" 40 41 h <- openFile(fileName) WriteMode 42 43 baseDir <- getDirectoryContents (src </> "if") >>= return. filter isIf 44 archDir <- getDirectoryContents (src </> "if/arch") >>= return. filter isIf 45 hPutStrLn h "#ifndef IF_TYPES_H" 46 hPutStrLn h "#define IF_TYPES_H" 47 hPutStrLn h "" 48 hPutStrLn h "// all the endpoint types generate from files" 49 hPutStrLn h "enum endpoint_types {" 50 hPutStrLn h "\tIF_TYPE_DUMMY = 0," 51 mapM_ (\x -> hPutStrLn h $ "\tIF_TYPE_" ++ ((map toUpper (takeBaseName x)) ++ ",")) baseDir 52 mapM_ (\x -> hPutStrLn h $ "\tIF_TYPE_" ++ ((map toUpper (takeBaseName x)) ++ ",")) archDir 53 hPutStrLn h "\tIF_TYPE_MAX" 54 hPutStrLn h "};" 55 hPutStrLn h "#endif" 56 57 hFlush h 58 hClose h 59 60 61main :: IO () 62main = 63 do 64 argv <- System.Environment.getArgs 65 case argv of 66 [src_dir, build_dir, arch, out] -> do 67 makeFlounderTypes src_dir build_dir arch 68 _ -> do 69 hPutStrLn stderr "Usage: floundertypes <src_dir> <build_dir> <arch>" 70 exitWith (ExitFailure 1) 71