shake-language-c-0.12.0: Utilities for cross-compiling with Shake

Safe HaskellNone
LanguageHaskell98

Development.Shake.Language.C.BuildFlags

Contents

Description

The BuildFlags record is an abstraction for various toolchain flags for building executables and libraries from source files in a C-based language. It's intended to be toolchain-independent, but currently there's a bias towards binutils/gcc/clang toolchains.

Synopsis

Source Language

data Language Source #

Source language.

Currently something derived from C.

Constructors

C

Plain old C

Cpp

C++

ObjC

Objective-C

ObjCpp

Objective-C with C++ (Apple extension)

Build flags

data BuildFlags Source #

Record type for abstracting various toolchain command line flags.

BuildFlags is an instance of Default, you can create a default record with def. BuildFlags is also an instance Monoid, you can create an empty record with mempty and append flags with mappend. def and mempty are synonyms:

>>> (def :: BuildFlags) == (mempty :: BuildFlags)
True

Record accessors are Lenses from the fclabels package, which makes accessing and modifying record fields a bit more convenient. fclabels was chosen over lens because it has far fewer dependencies, which is convenient when installing the Shake build system in a per-project cabal sandbox. We might switch to lens when it gets included in the Haskell platform.

There are two convenience functions for working with BuildFlags record fields containing lists of flags, append and prepend. Since most combinators in this library expect a function BuildFlags -> BuildFlags, the following is a common idiom:

buildFlags . append systemIncludes ["path"]

Note that when modifying the same record field, order of function composition matters and you might want to use the arrow combinator >>> for appending in source statement order:

>>> :{
  get systemIncludes
    $ append systemIncludes ["path1"] . append systemIncludes ["path2"]
    $ mempty
:}
["path2","path1"]
>>> :{
  get systemIncludes
    $ append systemIncludes ["path1"] >>> append systemIncludes ["path2"]
    $ mempty
:}
["path1","path2"]

See Development.Shake.Language.C.Rules for how to use BuildFlags in build product rules.

System include directories, referenced by #include <...> in code and usually passed to the compiler with the -isystem flag.

userIncludes :: forall cat. ArrowApply cat => Lens cat BuildFlags [FilePath] Source #

User include directories, referenced by #include "..." in code and usually passed to the compiler with the -I flag.

defines :: forall cat. ArrowApply cat => Lens cat BuildFlags [(String, Maybe String)] Source #

Preprocessor defines, a list of pairs of names with or without a value.

Other preprocessor flags.

Compiler flags, either generic ones or for a specific source Language.

libraryPath :: forall cat. ArrowApply cat => Lens cat BuildFlags [FilePath] Source #

Linker search path for libraries.

libraries :: forall cat. ArrowApply cat => Lens cat BuildFlags [String] Source #

List of libraries to link against. Note that you should use the library name without the lib prefix and without extension.

linkerFlags :: forall cat. ArrowApply cat => Lens cat BuildFlags [String] Source #

Flags passed to the linker.

Locally built static libraries to be linked against. See also the corresponding section in the manual.

archiverFlags :: forall cat. ArrowApply cat => Lens cat BuildFlags [String] Source #

Flags passed to the object archiver. ** Utilities for toolchain writers

defineFlags :: BuildFlags -> [String] Source #

Construct preprocessor flags from the defines field of BuildFlags.

compilerFlagsFor :: Maybe Language -> BuildFlags -> [String] Source #

Return a list of compiler flags for a specific source language.

Working with config files

fromConfig :: (Functor m, Monad m) => (String -> m (Maybe String)) -> m (BuildFlags -> BuildFlags) Source #

Construct a BuildFlags modifier function from a config file.

See also Development.Shake.Language.C.Config.

Utilities

(>>>=) :: Monad m => m (a -> b) -> m (b -> c) -> m (a -> c) Source #

Utility function for composing functions in a monad.

append Source #

Arguments

:: Monoid a 
=> (f :-> a)

lens

-> a

stuff to append

-> f

original record

-> f

modified record

Append stuff to the Monoid in record field specified by lens.

prepend Source #

Arguments

:: Monoid a 
=> (f :-> a)

lens

-> a

stuff to prepend

-> f

original record

-> f

modified record

Prepend stuff to the Monoid in record field specified by lens.