diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,20 @@
+# Changelog for `ktx-build`
+
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
+and this project adheres to the
+[Haskell Package Versioning Policy](https://pvp.haskell.org/).
+
+## WIP
+
+Initial release.
+
+- `type: slug` targets build Slug bundles from TrueType `glyf` outlines, read with ttf-reader.
+  They need no `size`, `format` or `target`.
+  A malformed font fails the build with its path.
+  Malformed glyph outlines are listed by glyph id, including the composite glyphs built on them.
+- Output paths with unfilled `{{...}}` placeholders fail the config parse.
+- JPEG images (`.jpg`, `.jpeg`) are texture sources, like PNG.
+- `capHeight` fixes fonts whose OS/2 `sCapHeight` doesn't match their capitals. `measure` takes the top of the H outline, and a number sets the height in font units. `declared`, the default, keeps the font's own value.
+  The later stages of a target read a copy of its source with the new value in OS/2. Its planes and its bundled shaping data then agree on the cap height. Targets without the option build as before.
diff --git a/README.md b/README.md
new file mode 100644
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# ktx-build
+
+TBD
diff --git a/app/Build/Atlas.hs b/app/Build/Atlas.hs
new file mode 100644
--- /dev/null
+++ b/app/Build/Atlas.hs
@@ -0,0 +1,61 @@
+{-# OPTIONS_GHC -Wno-orphans #-}
+module Build.Atlas where
+
+import Data.Aeson
+import Data.Char (toLower)
+import Data.Maybe
+import Development.Shake
+import Development.Shake.Classes
+
+import Graphics.MSDF.Atlas.Layout (AtlasType(..))
+import GHC.Generics (Generic)
+
+instance Hashable AtlasType
+instance Binary AtlasType
+instance NFData AtlasType
+
+data AtlasJob = AtlasJob
+  { atlasType :: AtlasType
+  , size :: Float
+  , aemRange :: Maybe (Float, Float)
+  } deriving (Show, Eq, Generic)
+
+instance FromJSON AtlasJob where
+  parseJSON = withObject "AtlasJob" \job -> do
+    atlasType <- job .: "type"
+    size <- job .: "size"
+    aemRange <- job .:? "aemrange"
+    pure AtlasJob{..}
+
+instance Hashable AtlasJob
+instance Binary AtlasJob
+instance NFData AtlasJob
+
+msdfAtlasGen :: AtlasJob -> FilePath -> FilePath -> FilePath -> Action ()
+msdfAtlasGen AtlasJob{..} ttf json png = do
+  gen_ <- getEnv "MSDF_ATLAS_GEN"
+  cmd_
+    (fromMaybe "msdf-atlas-gen.caps" gen_)
+    [ "-caps" -- XXX: requires caps fork
+    , "-allglyphs"
+    , "-font", ttf
+    , "-json", json
+    , "-imageout", png
+    , "-type", map toLower $ show atlasType
+    , "-size", show size
+    ]
+    aemRangeArgs
+    -- XXX: TODO: pull from job options
+    [ "-potr" :: String
+    , "-yorigin", "top"
+    , "-pxpadding", "4"
+    , "-pxalign", "on"
+    , "-seed", "42"
+    ]
+  where
+    aemRangeArgs =
+      case aemRange of
+        Nothing ->
+          []
+        Just (lower, upper) ->
+          ["-aemrange", show lower, show upper]
diff --git a/app/Build/CapHeight.hs b/app/Build/CapHeight.hs
new file mode 100644
--- /dev/null
+++ b/app/Build/CapHeight.hs
@@ -0,0 +1,100 @@
+module Build.CapHeight
+  ( CapHeight(..)
+  , Capped(..)
+  , capped
+  ) where
+
+import Codec.TTF.Reader qualified as TTF
+import Control.DeepSeq (NFData, force)
+import Control.Exception (evaluate, try)
+import Control.Monad (unless, when)
+import Data.Binary (Binary)
+import Data.Bits (shiftL, shiftR, (.&.), (.|.))
+import Data.ByteString (ByteString)
+import Data.ByteString qualified as ByteString
+import Data.Hashable (Hashable)
+import GHC.Generics (Generic)
+
+data CapHeight
+  = Declared
+  | Measured
+  | Units Int
+  deriving (Show, Eq, Generic)
+
+instance Hashable CapHeight
+instance Binary CapHeight
+instance NFData CapHeight
+
+data Capped = Capped
+  { declared :: Int
+  , applied :: Int
+  , font :: ByteString
+  }
+
+capped :: FilePath -> CapHeight -> ByteString -> IO Capped
+capped path wanted bytes = do
+  os2 <-
+    case TTF.lookupTableRecord tables TTF.TableTag_OS_2 of
+      TTF.NoTableRecord -> failWith "no OS/2 table"
+      found -> pure found
+  let os2Data = TTF.getTableData bytes os2
+  when (ByteString.length os2Data < sCapHeight + 2 || word16 os2Data 0 < 2) $
+    failWith "the OS/2 table is too old to declare a cap height"
+
+  let declared = word16 os2Data sCapHeight
+  applied <-
+    case wanted of
+      Declared -> pure declared
+      Units units -> pure units
+      Measured -> measuredH
+
+  unless (applied > 0 && applied < 0x8000) $
+    failWith $ "cap height out of range: " <> show applied
+
+  pure Capped
+    { declared
+    , applied
+    , font = putWord16 (os2.offset + sCapHeight) applied bytes
+    }
+  where
+    failWith message = fail $ path <> ": " <> message
+
+    tables = TTF.readTableDirectory bytes
+
+    measuredH = do
+      measured <- try @TTF.TTFException . evaluate . force $ capTop tables bytes
+      case measured of
+        Left err -> failWith $ show err <> " while measuring H"
+        Right Nothing -> failWith "no outline for H"
+        Right (Just top) -> pure top
+
+sCapHeight :: Int
+sCapHeight = 88
+
+capTop :: TTF.TableRecords -> ByteString -> Maybe Int
+capTop tables bytes =
+  case TTF.lookupGlyphId (TTF.readCMap $ table TTF.TableTag_cmap) 'H' of
+    TTF.NoGlyphId ->
+      Nothing
+    glyphId -> do
+      contours <- TTF.readGlyphOutline loca (table TTF.TableTag_glyf) glyphId
+      case [point.y | contour <- contours, segment <- TTF.contourSegments contour, point <- points segment] of
+        [] -> Nothing
+        ys -> Just . round $ maximum ys
+  where
+    table tag = TTF.getTableData bytes (TTF.lookupTableRecord tables tag)
+    numGlyphs = TTF.readNumGlyphs (table TTF.TableTag_maxp)
+    loca = TTF.readLoca (TTF.readIndexToLocFormat (table TTF.TableTag_head)) numGlyphs (table TTF.TableTag_loca)
+
+    points = \case
+      TTF.LineSegment a b -> [a, b]
+      TTF.QuadraticSegment a c b -> [a, c, b]
+
+word16 :: ByteString -> Int -> Int
+word16 bytes at = fromIntegral (ByteString.index bytes at) `shiftL` 8 .|. fromIntegral (ByteString.index bytes (at + 1))
+
+putWord16 :: Int -> Int -> ByteString -> ByteString
+putWord16 at value bytes =
+  ByteString.take at bytes
+    <> ByteString.pack [fromIntegral $ value `shiftR` 8 .&. 0xFF, fromIntegral $ value .&. 0xFF]
+    <> ByteString.drop (at + 2) bytes
diff --git a/app/Build/Job.hs b/app/Build/Job.hs
new file mode 100644
--- /dev/null
+++ b/app/Build/Job.hs
@@ -0,0 +1,227 @@
+{-# OPTIONS_GHC -Wno-orphans #-}
+
+module Build.Job
+ ( Job(..)
+ , JobType(..)
+ , parseJobsFile
+ ) where
+
+import Data.Aeson
+
+import Control.DeepSeq (NFData(..))
+import Control.Monad (unless, when)
+import Control.Monad.IO.Class (MonadIO(..))
+import Data.Aeson.Key qualified as Key
+import Data.Aeson.KeyMap qualified as KM
+import Data.Aeson.Types (Parser)
+import Data.Binary (Binary(..))
+import Data.Foldable (foldl')
+import Data.Hashable (Hashable(..))
+import Data.List qualified as L
+import Data.Maybe (fromMaybe)
+import Data.String (IsString)
+import Data.Text qualified as T
+import Data.Yaml qualified as Y
+import GHC.Generics (Generic)
+import System.FilePath (takeBaseName, takeExtension)
+
+import Build.Atlas (AtlasJob (..))
+import Build.CapHeight (CapHeight(..))
+import Graphics.MSDF.Atlas.Layout (AtlasType(..))
+
+data JobType
+  = Atlas AtlasJob
+  | Slug
+  | Texture
+  deriving (Show, Eq, Generic)
+
+instance Hashable JobType
+instance Binary JobType
+instance NFData JobType
+
+data Job = Job
+  { jobSource :: FilePath
+  , jobId :: String
+  , jobOutput :: FilePath
+  , jobType :: JobType
+  , jobFormat :: String -- ^ ktx create --format R8_UNORM
+  , jobTarget :: String -- ^ ktx transcode --target bc7
+  , jobCapHeight :: CapHeight
+  } deriving (Show, Eq, Generic)
+
+instance Hashable Job
+instance Binary Job
+instance NFData Job
+
+parseJobsFile :: (MonadFail m, MonadIO m) => FilePath -> m [Job]
+parseJobsFile source = do
+  config <- liftIO $ Y.decodeFileThrow source
+  case Y.parseEither flattenJobs config of
+    Left err -> fail $ "YAML Config Error: " ++ err
+    Right jobs -> pure jobs
+
+extend :: Object -> [Object] -> Object
+extend kv = foldl' (flip KM.union) kv
+
+flattenJobs :: Value -> Parser [Job]
+flattenJobs root = do
+  (globalCtx, global) <- withObject "Root" (pure . collect) root
+
+  flatten global "Collection" \globalOpts (collectionId, collection) -> do
+    let collectionCtx = extend globalOpts ["collection" .= collectionId]
+    flatten collection "Source" \collectionOpts (sourcePath, source') -> do
+      let
+        sourceCtx = extend collectionOpts
+          [ "source" .= sourcePath
+          , "basename" .= takeBaseName (Key.toString sourcePath)
+          ]
+
+      source <-
+        case source' of
+          Object o | KM.null o ->
+            pure $ Object $ KM.singleton "default" (Object mempty)
+          Object _ ->
+            pure source'
+          huh ->
+            fail $ "Unexpected source type: " <> takeWhile (/= ' ') (show huh)
+
+      flatten source "Target" \sourceOpts (targetId, target) -> do
+        let targetCtx = extend sourceOpts [ "id" .= targetId]
+        let scopes = [targetCtx, sourceCtx, collectionCtx, globalCtx]
+        job <- parseJob scopes target
+        pure [job]
+
+-- | Pick up all the ttf sources into the default collection
+collect :: Object -> (Object, Value)
+collect root = (rootOptions, Object $ inject (KM.fromList collections))
+  where
+    (rootOptions, children) = splitOptions root
+    (sources, collections) = L.partition isSource children
+    inject = case sources of
+      [] -> id -- Do not inject empty "default" collection
+      defaultCollection -> KM.insert "default" (Object $ KM.fromList defaultCollection)
+    isSource (k, _) = any (`T.isSuffixOf` Key.toText k) (".ttf" : imageExtensions)
+
+parseJob :: [Object] -> Value -> Parser Job
+parseJob scopes = withObject "Job" \jobOpts -> do
+  let job = mconcat $ jobOpts : scopes
+  jobSource <- job .: "source"
+  jobId <- job .: "id"
+  jobOutput <- T.unpack . applyTemplate job <$> job .: "output"
+  when ("{{" `L.isInfixOf` jobOutput) $
+    fail $ "Unfilled template in output: " <> jobOutput
+
+  (jobType, jobCapHeight) <- case takeExtension jobSource of
+    ext | ext `elem` imageExtensions ->
+      pure (Texture, Declared)
+    ".ttf" -> do
+      kind <- job .:? "type"
+      fontType <-
+        if kind == Just ("slug" :: T.Text)
+          then pure Slug
+          else Atlas <$> parseJSON (Object job)
+      capHeight <- job .:? "capHeight" >>= traverse parseCapHeight
+      pure (fontType, fromMaybe Declared capHeight)
+    ext ->
+      fail $ "Unsupported source extension: " <> ext
+
+  (jobFormat, jobTarget) <- case jobType of
+    Slug ->
+      pure (slugFormat, "none")
+    _ -> do
+      let
+        (defaultFormat, defaultTarget) = case jobType of
+          Atlas AtlasJob{atlasType = MTSDF} -> ("R8G8B8A8_UNORM", "bc7")
+          Atlas AtlasJob{atlasType = MSDF} -> ("R8G8B8_UNORM", "bc7")
+          _ -> ("R8_UNORM", "bc4")
+
+      format <- job .:? "format" .!= (if jobType == Texture then "R8G8B8A8_SRGB" else defaultFormat)
+      unless (elem format validFormats) $
+        fail $ "Bad format: " <> show format <> ". Must be one of:\n" <> L.intercalate "\n" validFormats
+
+      target <- job .:? "target" .!= (if jobType == Texture then "bc7" else defaultTarget)
+      unless (elem target validTargets) $
+        fail $ "Bad target: " <> show target <> ". Must be one of: " <> L.intercalate " | " validTargets
+
+      pure (format, target)
+
+  pure Job{..}
+
+parseCapHeight :: Value -> Parser CapHeight
+parseCapHeight = \case
+  String "declared" -> pure Declared
+  String "measure" -> pure Measured
+  Number units
+    | units > 0 && units == fromInteger (round units) -> pure . Units $ round units
+  huh ->
+    fail $ "capHeight must be declared, measure or a positive whole number of font units, not " <> show huh
+
+imageExtensions :: IsString s => [s]
+imageExtensions = [".png", ".jpg", ".jpeg"]
+
+slugFormat :: String
+slugFormat = "R16G16B16A16_SFLOAT"
+
+flatten :: Value -> String -> (Object -> (Key, Value) -> Parser [a]) -> Parser [a]
+flatten parentVal childLabel next = withObject childLabel step parentVal
+  where
+    step parent = do
+      let (parentOptions, children) = splitOptions parent
+      fmap concat $ traverse (next parentOptions) children
+
+applyTemplate :: Object -> T.Text -> T.Text
+applyTemplate context templ = foldl' go templ (KM.toList context)
+  where
+    go acc (k, v) = case v of
+      String t -> replace k t acc
+      Number n -> replace k (T.pack vs) acc
+        where
+          ni = floor n
+          vs =
+            if fromInteger ni == n then
+              show ni
+            else
+              show n
+      _ -> acc
+    replace k = T.replace ("{{" <> Key.toText k <> "}}")
+
+splitOptions :: KM.KeyMap a -> (KM.KeyMap a, [(Key, a)])
+splitOptions obj = (KM.fromList $ map stripOption opts, rest)
+  where
+    (opts, rest) = L.partition isOption $ KM.toList obj
+    isOption (k, _) = "_" `T.isPrefixOf` Key.toText k
+    stripOption (k, v) =
+      case T.uncons (Key.toText k) of
+        Just ('_', k') -> (Key.fromText k', v)
+        _ -> (k, v)
+
+validFormats :: [String]
+validFormats =
+  [ "R8_UNORM"
+  , "R8_SRGB"
+  , "R8G8_UNORM"
+  , "R8G8_SRGB"
+  , "R8G8B8_UNORM"
+  , "R8G8B8_SRGB"
+  , "R8G8B8A8_UNORM"
+  , "R8G8B8A8_SRGB"
+  ]
+
+-- From `ktx transcode --help`
+validTargets :: [String]
+validTargets =
+  [ "etc-rgb"
+  , "etc-rgba"
+  , "eac-r11"
+  , "eac-rg11"
+  , "bc1"
+  , "bc3"
+  , "bc4"
+  , "bc5"
+  , "bc7"
+  , "astc"
+  , "r8"
+  , "rg8"
+  , "rgb8"
+  , "rgba8"
+  ]
diff --git a/app/Build/Ktx2.hs b/app/Build/Ktx2.hs
new file mode 100644
--- /dev/null
+++ b/app/Build/Ktx2.hs
@@ -0,0 +1,46 @@
+module Build.Ktx2 where
+
+import Data.List (isSuffixOf)
+import Development.Shake
+
+ktxCreate :: FilePath -> String -> FilePath -> Action ()
+ktxCreate png format uastc = do
+  let tf = if "_SRGB" `isSuffixOf` format then "srgb" else "linear"
+  cmd_
+    (Traced "ktx-create")
+    [ "ktx", "create"
+    , "--encode", "uastc"
+    , "--uastc-quality", "4"
+    , "--uastc-rdo"
+    , "--assign-tf", tf
+    , "--convert-tf", tf
+    , "--format", format
+    , "--zstd", "3"
+    , png
+    , uastc
+    ]
+
+ktxCreateRaw :: FilePath -> String -> Int -> Int -> FilePath -> Action ()
+ktxCreateRaw raw format width height ktx2 = do
+  cmd_
+    (Traced "ktx-create-raw")
+    [ "ktx", "create"
+    , "--raw"
+    , "--format", format
+    , "--width", show width
+    , "--height", show height
+    , "--zstd", "19"
+    , raw
+    , ktx2
+    ]
+
+ktxTranscode :: FilePath -> String -> FilePath -> Action ()
+ktxTranscode uastc target ktx2 = do
+  cmd_
+    (Traced "ktx-transcode")
+    [ "ktx", "transcode"
+    , "--target", target
+    , "--zstd", "22"
+    , uastc
+    , ktx2
+    ]
diff --git a/app/Build/Slug.hs b/app/Build/Slug.hs
new file mode 100644
--- /dev/null
+++ b/app/Build/Slug.hs
@@ -0,0 +1,59 @@
+module Build.Slug
+  ( outlines
+  ) where
+
+import Codec.Ktx2.Font.Slug (Curve(..), FillRule(..), Point(..), Shape(..))
+import Codec.TTF.Reader qualified as TTF
+import Control.DeepSeq (force)
+import Control.Exception (evaluate, throw, try)
+import Control.Monad (unless)
+import Data.ByteString qualified as ByteString
+import Data.Foldable (for_)
+import Data.Traversable (for)
+
+outlines :: FilePath -> IO [Shape]
+outlines path = do
+  bytes <- ByteString.readFile path
+  let
+    tables = TTF.readTableDirectory bytes
+    record tag = TTF.lookupTableRecord tables tag
+    table tag = TTF.getTableData bytes (record tag)
+    numGlyphs = TTF.readNumGlyphs (table TTF.TableTag_maxp)
+    loca = TTF.readLoca (TTF.readIndexToLocFormat (table TTF.TableTag_head)) numGlyphs (table TTF.TableTag_loca)
+    glyf = table TTF.TableTag_glyf
+    glyphIds = [0 .. numGlyphs - 1]
+    segmentsOf glyphId =
+      maybe (throw TTF.MalformedTTF) (map TTF.contourSegments) $
+        TTF.readGlyphOutline loca glyf glyphId
+
+  unless (TTF.readFontFormat bytes == Just TTF.TrueType && hasTable (record TTF.TableTag_glyf)) $
+    fail $ path <> ": no TrueType glyf outlines"
+
+  for_ [("loca", () <$ evaluate loca), ("glyf", () <$ evaluate glyf)] \(name, check) ->
+    try @TTF.TTFException check >>= \case
+      Left err -> fail $ path <> ": " <> show err <> " in the " <> name <> " table"
+      Right () -> pure ()
+
+  parsed <- for glyphIds \glyphId ->
+    try @TTF.TTFException . evaluate . force $ segmentsOf glyphId
+
+  let malformed = [glyphId | (glyphId, Left _) <- zip glyphIds parsed]
+  unless (null malformed) $
+    fail $ path <> ": malformed outlines for glyphs " <> show malformed
+
+  pure [toShape segments | Right segments <- parsed]
+  where
+    hasTable = \case
+      TTF.NoTableRecord -> False
+      _ -> True
+
+toShape :: [[TTF.Segment]] -> Shape
+toShape = Shape NonZero . filter (not . null) . map (map toCurve)
+
+toCurve :: TTF.Segment -> Curve
+toCurve = \case
+  TTF.LineSegment a b -> Curve (toPoint a) (toPoint b) (toPoint b)
+  TTF.QuadraticSegment a c b -> Curve (toPoint a) (toPoint c) (toPoint b)
+
+toPoint :: TTF.Point -> Point
+toPoint p = Point (realToFrac p.x) (realToFrac p.y)
diff --git a/app/Main.hs b/app/Main.hs
new file mode 100644
--- /dev/null
+++ b/app/Main.hs
@@ -0,0 +1,176 @@
+{-# LANGUAGE TypeFamilies #-}
+
+import Control.Monad (void)
+import Data.Foldable
+import Data.Map.Strict qualified as Map
+import Development.Shake
+import Development.Shake.Classes
+import Development.Shake.FilePath
+import GHC.Generics (Generic)
+
+import Build.Atlas (msdfAtlasGen, AtlasJob (..))
+import Build.CapHeight (CapHeight(..), Capped(..))
+import Build.CapHeight qualified as CapHeight
+import Build.Job (Job(..), JobType(..), parseJobsFile)
+import Build.Ktx2 (ktxCreate, ktxCreateRaw, ktxTranscode)
+import Build.Slug qualified as Slug
+import Codec.Ktx2.Font (bundleFont, bundleSlug, packSlugFont, slugVersion)
+import Codec.Ktx2.Font.Slug qualified as Slug
+import Data.Aeson qualified as Aeson
+import Data.ByteString qualified as ByteString
+import Data.Vector qualified as Vector
+import System.Directory (getFileSize)
+
+{- | The job options a build stage ran with.
+
+Most of them (format, target, aemrange and, depending on the output template,
+even size and type) don't show up in the output path. Without an oracle to
+depend on, editing them in the config leaves the stale artifacts in place.
+Each stage asks only for the options it consumes, so retargeting the
+transcode doesn't regenerate the atlas.
+-}
+data JobParams = JobParams Stage FilePath
+  deriving (Show, Eq, Generic)
+
+instance Hashable JobParams
+instance Binary JobParams
+instance NFData JobParams
+
+data Stage
+  = AtlasStage -- ^ Source and atlas generator options.
+  | CreateStage -- ^ Source and texture format.
+  | TranscodeStage -- ^ Transcode target.
+  | OutlineStage
+  | CapStage
+  deriving (Show, Eq, Generic)
+
+instance Hashable Stage
+instance Binary Stage
+instance NFData Stage
+
+type instance RuleResult JobParams = String
+
+main :: IO ()
+main = shakeArgs shakeOptions $ do
+  let buildDir = shakeFiles shakeOptions </> "build"
+  phony "clean" $
+    removeFilesAfter buildDir ["//*"]
+  want ["assets.yaml", "all"]
+
+  jobs <- parseJobsFile "assets.yaml"
+
+  let jobIndex = Map.fromList [(jobOutput, job) | job@Job{jobOutput} <- jobs]
+  askJob <- addOracle \key@(JobParams stage output) ->
+    case Map.lookup output jobIndex of
+      Nothing ->
+        fail $ "No job for " <> show key
+      Just Job{jobSource, jobType, jobFormat, jobTarget, jobCapHeight} ->
+        pure case stage of
+          AtlasStage -> withCapHeight $ show (jobSource, jobType)
+          OutlineStage -> withCapHeight $ show (jobSource, jobType, slugVersion)
+          CreateStage -> show (jobSource, jobFormat)
+          TranscodeStage -> jobTarget
+          CapStage -> show (jobSource, jobCapHeight)
+        where
+          withCapHeight =
+            case jobCapHeight of
+              Declared -> id
+              capHeight -> (<> " " <> show capHeight)
+
+  "all" ~>
+    need [jobOutput | Job{jobOutput} <- jobs]
+
+  for_ jobs \job@Job{jobType, jobOutput} -> do
+    let needStage stage = void . askJob $ JobParams stage jobOutput
+    case jobType of
+      Atlas args -> fontSource buildDir needStage job >>= \source -> atlasJob buildDir needStage source job args
+      Slug -> fontSource buildDir needStage job >>= \source -> slugJob buildDir needStage source job
+      Texture -> textureJob buildDir needStage job
+
+fontSource :: FilePath -> (Stage -> Action ()) -> Job -> Rules FilePath
+fontSource buildDir needStage Job{..} =
+  case jobCapHeight of
+    Declared ->
+      pure jobSource
+    capHeight -> do
+      capped %> \out -> do
+        needStage CapStage
+        need [jobSource]
+        result <- traced "cap-height" $
+          ByteString.readFile jobSource >>= CapHeight.capped jobSource capHeight
+        putInfo $ jobSource <> ": cap height " <> show result.declared <> " -> " <> show result.applied
+        liftIO $ ByteString.writeFile out result.font
+      pure capped
+  where
+    capped = buildDir </> jobOutput -<.> "ttf"
+
+atlasJob :: FilePath -> (Stage -> Action ()) -> FilePath -> Job -> AtlasJob -> Rules ()
+atlasJob buildDir needStage source Job{..} args = do
+  jobOutput %> \ktxf -> do
+    needStage AtlasStage
+    need [json, ktx2]
+    traced "ktxf-bundle" $
+      bundleFont source json ktx2 ktxf
+
+  ktx2 %> \_ -> do
+    needStage TranscodeStage
+    need [uastc]
+    ktxTranscode uastc jobTarget ktx2
+
+  uastc %> \_ -> do
+    needStage CreateStage
+    need [png]
+    ktxCreate png jobFormat uastc
+
+  [json, png] &%> \_ -> do
+    needStage AtlasStage
+    need [source]
+    msdfAtlasGen args source json png
+  where
+    ktx2 = buildDir </> jobOutput -<.> "ktx2"
+    uastc = buildDir </> jobOutput -<.> "uastc"
+    png = buildDir </> jobOutput -<.> "png"
+    json = buildDir </> jobOutput -<.> "json"
+
+slugJob :: FilePath -> (Stage -> Action ()) -> FilePath -> Job -> Rules ()
+slugJob buildDir needStage source Job{..} = do
+  jobOutput %> \ktxf -> do
+    needStage OutlineStage
+    need [glyphs, bands, ktx2]
+    traced "ktxf-bundle" do
+      glyphTable <- Aeson.eitherDecodeFileStrict glyphs >>= either fail pure
+      bandValues <- ByteString.readFile bands >>= either fail pure . Slug.decodeBands
+      bundleSlug source Slug.Tables{bands = bandValues, glyphs = Vector.fromList glyphTable} ktx2 ktxf
+
+  ktx2 %> \_ -> do
+    needStage CreateStage
+    need [curves]
+    bytes <- liftIO $ getFileSize curves
+    ktxCreateRaw curves jobFormat Slug.dataWidth (fromIntegral bytes `div` (8 * Slug.dataWidth)) ktx2
+
+  [curves, bands, glyphs] &%> \_ -> do
+    needStage OutlineStage
+    need [source]
+    traced "slug-pack" do
+      packed <- Slug.outlines source >>= packSlugFont source
+      ByteString.writeFile curves $ Slug.encodeCurves packed.curves
+      ByteString.writeFile bands $ Slug.encodeBands packed.tables.bands
+      Aeson.encodeFile glyphs $ Vector.toList packed.tables.glyphs
+  where
+    ktx2 = buildDir </> jobOutput -<.> "ktx2"
+    curves = buildDir </> jobOutput -<.> "curves"
+    bands = buildDir </> jobOutput -<.> "bands"
+    glyphs = buildDir </> jobOutput -<.> "glyphs.json"
+
+textureJob :: FilePath -> (Stage -> Action ()) -> Job -> Rules ()
+textureJob buildDir needStage Job{..} = do
+  jobOutput %> \out -> do
+    needStage TranscodeStage
+    need [uastc]
+    ktxTranscode uastc jobTarget out
+  uastc %> \_ -> do
+    needStage CreateStage
+    need [jobSource]
+    ktxCreate jobSource jobFormat uastc
+  where
+    uastc = buildDir </> jobOutput -<.> "uastc"
diff --git a/ktx-build.cabal b/ktx-build.cabal
new file mode 100644
--- /dev/null
+++ b/ktx-build.cabal
@@ -0,0 +1,85 @@
+cabal-version: 2.2
+
+-- This file has been generated from package.yaml by hpack version 0.39.6.
+--
+-- see: https://github.com/sol/hpack
+
+name:           ktx-build
+version:        0.1.0.0
+synopsis:       Shake builder for KTX
+category:       Graphics
+author:         IC Rainbow
+maintainer:     aenor.realm@gmail.com
+copyright:      2026 IC Rainbow
+license:        BSD-3-Clause
+build-type:     Simple
+extra-source-files:
+    README.md
+extra-doc-files:
+    CHANGELOG.md
+
+source-repository head
+  type: git
+  location: https://gitlab.com/dpwiz/ktx
+
+flag executables
+  manual: True
+  default: False
+
+executable ktx-build
+  main-is: Main.hs
+  other-modules:
+      Build.Atlas
+      Build.CapHeight
+      Build.Job
+      Build.Ktx2
+      Build.Slug
+      Paths_ktx_build
+  autogen-modules:
+      Paths_ktx_build
+  hs-source-dirs:
+      app
+  default-extensions:
+      BlockArguments
+      DeriveGeneric
+      DeriveTraversable
+      DerivingStrategies
+      DerivingVia
+      DuplicateRecordFields
+      ImplicitParams
+      ImportQualifiedPost
+      LambdaCase
+      NamedFieldPuns
+      NoFieldSelectors
+      OverloadedRecordDot
+      OverloadedStrings
+      PatternSynonyms
+      RankNTypes
+      RecordWildCards
+      StrictData
+      TupleSections
+      TypeApplications
+      ViewPatterns
+  ghc-options: -Wall -Wcompat -Widentities -Wincomplete-record-updates -Wincomplete-uni-patterns -Wmissing-home-modules -Wpartial-fields -Wredundant-constraints -threaded -rtsopts -with-rtsopts=-N
+  build-depends:
+      aeson
+    , base >=4.11 && <5
+    , binary
+    , bytestring
+    , containers
+    , deepseq
+    , directory
+    , filepath
+    , hashable
+    , ktx-font >=0.4.0.0
+    , msdf-atlas
+    , shake
+    , shower
+    , text
+    , ttf-reader
+    , unordered-containers
+    , vector
+    , yaml
+  default-language: Haskell2010
+  if !flag(executables)
+    buildable: False
