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

Safe HaskellNone
LanguageHaskell98

Development.Shake.Language.C.Rules

Description

This module provides a few high-level rules for building executables and libraries. Below is an example that builds both a static library and an executable. See Development.Shake.Language.C.ToolChain for examples of toolchain definitions.

let toolChain = ...
lib <- staticLibrary toolChain "libexample.a" (pure mempty) (pure ["example_lib.c"])
exe <- staticLibrary toolChain ("example" <.> exe) (pure mempty) (pure ["example_exe.c"])
want [lib, exe]

Sometimes you want to structure your project in a set of static libraries that are later linked into one or more executables. For Shake to recognise the libraries as dependencies of the executable you need to add them to the localLibraries field of the BuildFlags record:

let toolChain = ...
    buildFlags = ...
lib <- staticLibrary toolChain "libexample.a"
        (pure buildFlags)
        (pure ["example_lib.c"])
exe <- executable toolChain ("example" <.> exe)
        (pure $ buildFlags . append localLibraries [lib])
        (pure ["example_exe.c"])
want [exe]

The rule functions expect their arguments in the Action monad in order to be able to derive them from side-effecting configuration actions. For example it can be useful to determine certain toolchain settings either from the environment, or from configuration files. Using Control.Applicative we could write:

Android.toolChain
  <$> getEnvWithDefault
        (error "ANDROID_NDK is undefined")
        "ANDROID_NDK"
  <*> pure (Android.sdkVersion 9)
  <*> pure (LLVM, Version [3,4] [])
  <*> pure (Android.target (Arm Armv7))

Synopsis

Documentation

executable Source

Arguments

:: Action ToolChain

Action returning a target ToolChain

-> FilePath

Output file

-> Action (BuildFlags -> BuildFlags)

Action returning a BuildFlags modifier

-> Action [FilePath]

Action returning a list of input source files

-> Rules FilePath

Rule returning the output file path

Shake rule for building an executable.

staticLibrary Source

Arguments

:: Action ToolChain

Action returning a target ToolChain

-> FilePath

Output file

-> Action (BuildFlags -> BuildFlags)

Action returning a BuildFlags modifier

-> Action [FilePath]

Action returning a list of input source files

-> Rules FilePath

Rule returning the output file path

Shake rule for building a static library.

sharedLibrary Source

Arguments

:: Action ToolChain

Action returning a target ToolChain

-> FilePath

Output file

-> Action (BuildFlags -> BuildFlags)

Action returning a BuildFlags modifier

-> Action [FilePath]

Action returning a list of input source files

-> Rules FilePath

Rule returning the output file path

Shake rule for building a shared (dynamically linked) library.

loadableLibrary Source

Arguments

:: Action ToolChain

Action returning a target ToolChain

-> FilePath

Output file

-> Action (BuildFlags -> BuildFlags)

Action returning a BuildFlags modifier

-> Action [FilePath]

Action returning a list of input source files

-> Rules FilePath

Rule returning the output file path

Shake rule for building a dynamically loadable library.