diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -1,40 +1,21 @@
--- Note: to bootstrap uuagc with a commandline uuagc,
--- pass the -DEXTERNAL_UUAGC to GHC
--- when building setup.hs. This can be accomplished using
--- cabal install with --ghc-options="-DEXTERNAL_UUAGC".
---
--- When this option is used, a cabal flag will be set so
--- that the Haskell sources will be regenerated from
--- the attribute grammar sources
---
--- Note: it would be nicer if this behavior could be enabled
--- with a configure flag. However, a compiled Setup.hs is
--- required in order to perform 'configure', so configure
--- flags are regarded too late in the process.
--- Also note that this Setup.hs has conditional package
--- requirements depending on what code is used.
-
 {-# OPTIONS_GHC -fno-warn-warnings-deprecations #-}
-{-# LANGUAGE CPP #-}
 module Main where
 
-#ifdef EXTERNAL_UUAGC
 import System.Environment (getArgs)
-import Distribution.Simple (defaultMainWithHooksArgs)
+import Distribution.Simple (defaultMainWithHooksArgs, UserHooks (..), simpleUserHooks)
+import Distribution.Simple.LocalBuildInfo (flagAssignment)
 import Distribution.Simple.UUAGC (uuagcUserHook)
-
-main :: IO ()
-main = args >>= defaultMainWithHooksArgs uuagcUserHook
-
-args :: IO [String]
-args = do
-  as <- getArgs
-  let addFlags | "configure" `elem` as = ("--flags=bootstrap_external" :)
-               | otherwise             = id
-  return (addFlags as)
-#else
-import Distribution.Simple (defaultMain, defaultMainWithHooksArgs)
+import Distribution.Types.Flag (lookupFlagAssignment, mkFlagName)
+import Debug.Trace
 
 main :: IO ()
-main = defaultMain
-#endif
+main = do
+  args <- getArgs
+  defaultMainWithHooksArgs hooks args
+  where
+    hooks = uuagcUserHook { buildHook = myBuildHook }
+    myBuildHook pd lbi uh bf
+      | lookupFlagAssignment (mkFlagName "bootstrap_external") (flagAssignment lbi) == Just True
+      = buildHook uuagcUserHook pd lbi uh bf
+      | otherwise
+      = buildHook simpleUserHooks pd lbi uh bf
diff --git a/src-generated/AbstractSyntax.hs b/src-generated/AbstractSyntax.hs
--- a/src-generated/AbstractSyntax.hs
+++ b/src-generated/AbstractSyntax.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/AbstractSyntax.ag)
+-- UUAGC 0.9.57 (src-ag/AbstractSyntax.ag)
 module AbstractSyntax where
 {-# LINE 2 "src-ag/AbstractSyntax.ag" #-}
 
diff --git a/src-generated/Code.hs b/src-generated/Code.hs
--- a/src-generated/Code.hs
+++ b/src-generated/Code.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/Code.ag)
+-- UUAGC 0.9.57 (src-ag/Code.ag)
 module Code where
 {-# LINE 2 "src-ag/Code.ag" #-}
 
diff --git a/src-generated/CodeSyntax.hs b/src-generated/CodeSyntax.hs
--- a/src-generated/CodeSyntax.hs
+++ b/src-generated/CodeSyntax.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/CodeSyntax.ag)
+-- UUAGC 0.9.57 (src-ag/CodeSyntax.ag)
 module CodeSyntax where
 {-# LINE 2 "src-ag/CodeSyntax.ag" #-}
 
diff --git a/src-generated/ConcreteSyntax.hs b/src-generated/ConcreteSyntax.hs
--- a/src-generated/ConcreteSyntax.hs
+++ b/src-generated/ConcreteSyntax.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/ConcreteSyntax.ag)
+-- UUAGC 0.9.57 (src-ag/ConcreteSyntax.ag)
 module ConcreteSyntax where
 {-# LINE 2 "src-ag/ConcreteSyntax.ag" #-}
 
diff --git a/src-generated/DeclBlocks.hs b/src-generated/DeclBlocks.hs
--- a/src-generated/DeclBlocks.hs
+++ b/src-generated/DeclBlocks.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/DeclBlocks.ag)
+-- UUAGC 0.9.57 (src-ag/DeclBlocks.ag)
 module DeclBlocks where
 {-# LINE 2 "src-ag/DeclBlocks.ag" #-}
 
diff --git a/src-generated/ErrorMessages.hs b/src-generated/ErrorMessages.hs
--- a/src-generated/ErrorMessages.hs
+++ b/src-generated/ErrorMessages.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/ErrorMessages.ag)
+-- UUAGC 0.9.57 (src-ag/ErrorMessages.ag)
 module ErrorMessages where
 {-# LINE 2 "src-ag/ErrorMessages.ag" #-}
 
diff --git a/src-generated/ExecutionPlan.hs b/src-generated/ExecutionPlan.hs
--- a/src-generated/ExecutionPlan.hs
+++ b/src-generated/ExecutionPlan.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/ExecutionPlan.ag)
+-- UUAGC 0.9.57 (src-ag/ExecutionPlan.ag)
 module ExecutionPlan where
 {-# LINE 2 "src-ag/ExecutionPlan.ag" #-}
 
diff --git a/src-generated/Expression.hs b/src-generated/Expression.hs
--- a/src-generated/Expression.hs
+++ b/src-generated/Expression.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/Expression.ag)
+-- UUAGC 0.9.57 (src-ag/Expression.ag)
 module Expression where
 {-# LINE 2 "src-ag/Expression.ag" #-}
 
diff --git a/src-generated/HsToken.hs b/src-generated/HsToken.hs
--- a/src-generated/HsToken.hs
+++ b/src-generated/HsToken.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/HsToken.ag)
+-- UUAGC 0.9.57 (src-ag/HsToken.ag)
 module HsToken where
 {-# LINE 2 "src-ag/HsToken.ag" #-}
 
diff --git a/src-generated/Interfaces.hs b/src-generated/Interfaces.hs
--- a/src-generated/Interfaces.hs
+++ b/src-generated/Interfaces.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/Interfaces.ag)
+-- UUAGC 0.9.57 (src-ag/Interfaces.ag)
 module Interfaces where
 {-# LINE 2 "src-ag/Interfaces.ag" #-}
 
diff --git a/src-generated/LOAG/Rep.hs b/src-generated/LOAG/Rep.hs
--- a/src-generated/LOAG/Rep.hs
+++ b/src-generated/LOAG/Rep.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/LOAG/Rep.ag)
+-- UUAGC 0.9.57 (src-ag/LOAG/Rep.ag)
 module LOAG.Rep where
 
 import CommonTypes
diff --git a/src-generated/Macro.hs b/src-generated/Macro.hs
--- a/src-generated/Macro.hs
+++ b/src-generated/Macro.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/Macro.ag)
+-- UUAGC 0.9.57 (src-ag/Macro.ag)
 module Macro where
 {-# LINE 4 "src-ag/Macro.ag" #-}
 
diff --git a/src-generated/Patterns.hs b/src-generated/Patterns.hs
--- a/src-generated/Patterns.hs
+++ b/src-generated/Patterns.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/Patterns.ag)
+-- UUAGC 0.9.57 (src-ag/Patterns.ag)
 module Patterns where
 {-# LINE 2 "src-ag/Patterns.ag" #-}
 
diff --git a/src-generated/VisagePatterns.hs b/src-generated/VisagePatterns.hs
--- a/src-generated/VisagePatterns.hs
+++ b/src-generated/VisagePatterns.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/VisagePatterns.ag)
+-- UUAGC 0.9.57 (src-ag/VisagePatterns.ag)
 module VisagePatterns where
 {-# LINE 2 "src-ag/VisagePatterns.ag" #-}
 
diff --git a/src-generated/VisageSyntax.hs b/src-generated/VisageSyntax.hs
--- a/src-generated/VisageSyntax.hs
+++ b/src-generated/VisageSyntax.hs
@@ -1,6 +1,6 @@
 
 
--- UUAGC 0.9.56 (src-ag/VisageSyntax.ag)
+-- UUAGC 0.9.57 (src-ag/VisageSyntax.ag)
 module VisageSyntax where
 {-# LINE 2 "src-ag/VisageSyntax.ag" #-}
 
diff --git a/src/LOAG/Chordal.hs b/src/LOAG/Chordal.hs
--- a/src/LOAG/Chordal.hs
+++ b/src/LOAG/Chordal.hs
@@ -133,7 +133,7 @@
                     , let pred = varMap M.! (i,s)
                     ]
             forM dps $ \(f,t) -> do
-                modifyArray edp t (f `IS.insert`)
+                LOAG.Common.modifyArray edp t (f `IS.insert`)
             f_idsf <- freeze idsf
             f_idst <- freeze idst
             f_edp  <- freeze edp
@@ -145,10 +145,10 @@
                   -> IOArray Vertex Vertices
                   -> IO [()]
                 addEdges (f,t) es (idsf,idst) edp = do
-                    modifyArray idsf f (t `IS.insert`)
-                    modifyArray idst t (f `IS.insert`)
+                    LOAG.Common.modifyArray idsf f (t `IS.insert`)
+                    LOAG.Common.modifyArray idst t (f `IS.insert`)
                     forM es $ \(f,t) -> do --edp does not reflect flow
-                        modifyArray edp t (f `IS.insert`)                
+                        LOAG.Common.modifyArray edp t (f `IS.insert`)
 
 noCyclesNt :: Sat -> NtGraph -> IO ()
 noCyclesNt sat g  | IM.null g  = return ()
diff --git a/src/LOAG/Optimise.hs b/src/LOAG/Optimise.hs
--- a/src/LOAG/Optimise.hs
+++ b/src/LOAG/Optimise.hs
@@ -210,8 +210,8 @@
           -> (IOArray Vertex Vertices, IOArray Vertex Vertices)
           -> IO ()
         addEdges (f,t) (idsf,idst) = do
-            modifyArray idsf f (t `IS.insert`)
-            modifyArray idst t (f `IS.insert`)
+            LOAG.Common.modifyArray idsf f (t `IS.insert`)
+            LOAG.Common.modifyArray idst t (f `IS.insert`)
  
 -- | count the (max, avg, total) number of visits
 getVisCount :: [Nt] -> InterfaceRes -> VisCount
diff --git a/uuagc.cabal b/uuagc.cabal
--- a/uuagc.cabal
+++ b/uuagc.cabal
@@ -1,7 +1,7 @@
 cabal-version: >= 1.10
 build-type: Custom
 name: uuagc
-version: 0.9.56
+version: 0.9.57
 license: BSD3
 license-file: LICENSE
 maintainer: Jeroen Bransen
@@ -20,8 +20,6 @@
 extra-source-files: src-ag/*.lag
 extra-source-files: src-ag/LOAG/*.ag
 
--- This flag will be set by Setup.hs, use
--- cabal configure --ghc-options="-DEXTERNAL_UUAGC"
 flag bootstrap_external
    description: Use an external uuagc executable for bootstrapping
    default: False
@@ -33,7 +31,7 @@
    manual: True
 
 custom-setup
-  setup-depends: base >= 4 && < 5, Cabal >= 1.24 && < 3.11, uuagc-cabal >= 1.0
+  setup-depends: base >= 4 && < 5, Cabal >= 2.0 && < 3.15, uuagc-cabal >= 1.0
 
 executable uuagc
    build-depends: uuagc-cabal >= 1.0.3.0
@@ -55,8 +53,12 @@
    build-depends: haskell-src-exts >= 1.11.1
    build-depends: filepath >= 1.1.0.4
    build-depends: aeson >= 1.4.7.1, bytestring >= 0.9.2.1
-   hs-source-dirs: src, src-version, src-ag, src-options
-   if !flag(bootstrap_external)
+   hs-source-dirs: src, src-version, src-options
+   if flag(bootstrap_external)
+      -- we need to avoid any *.ag files if we're not bootstrapping,
+      -- because we now always use the ag preprocessor.
+      hs-source-dirs: src-ag
+   else
       hs-source-dirs: src-generated
    exposed-modules: UU.UUAGC, UU.UUAGC.Version
    default-extensions: TypeSynonymInstances, MultiParamTypeClasses
