----------- The main flags themselves ------------------
dynamic_flags :: [Flag (CmdLineP DynFlags)]
dynamic_flags = [
    Flag "n"        (NoArg (addWarn "The -n flag is deprecated and no longer has any effect"))
  , Flag "cpp"      (NoArg (setExtensionFlag Opt_Cpp))
  , Flag "F"        (NoArg (setGeneralFlag Opt_Pp))
  , Flag "#include"
         (HasArg (\s -> do addCmdlineHCInclude s
                           addWarn "-#include and INCLUDE pragmas are deprecated: They no longer have any effect"))
  , Flag "v"        (OptIntSuffix setVerbosity)

  , Flag "j"        (OptIntSuffix (\n -> upd (\d -> d {parMakeCount = n})))

        ------- ways --------------------------------------------------------
  , Flag "prof"           (NoArg (addWay WayProf))
  , Flag "eventlog"       (NoArg (addWay WayEventLog))
  , Flag "parallel"       (NoArg (addWay WayPar))
  , Flag "gransim"        (NoArg (addWay WayGran))
  , Flag "smp"            (NoArg (addWay WayThreaded >> deprecate "Use -threaded instead"))
  , Flag "debug"          (NoArg (addWay WayDebug))
  , Flag "ndp"            (NoArg (addWay WayNDP))
  , Flag "threaded"       (NoArg (addWay WayThreaded))

  , Flag "ticky"          (NoArg (setGeneralFlag Opt_Ticky >> addWay WayDebug))

    -- -ticky enables ticky-ticky code generation, and also implies -debug which
    -- is required to get the RTS ticky support.

        ----- Linker --------------------------------------------------------
  , Flag "static"         (NoArg removeWayDyn)
  , Flag "dynamic"        (NoArg (addWay WayDyn))
    -- ignored for compat w/ gcc:
  , Flag "rdynamic"       (NoArg (return ()))
  , Flag "relative-dynlib-paths"  (NoArg (setGeneralFlag Opt_RelativeDynlibPaths))

        ------- Specific phases  --------------------------------------------
    -- need to appear before -pgmL to be parsed as LLVM flags.
  , Flag "pgmlo"          (hasArg (\f -> alterSettings (\s -> s { sPgm_lo  = (f,[])})))
  , Flag "pgmlc"          (hasArg (\f -> alterSettings (\s -> s { sPgm_lc  = (f,[])})))
  , Flag "pgmL"           (hasArg (\f -> alterSettings (\s -> s { sPgm_L   = f})))
  , Flag "pgmP"           (hasArg setPgmP)
  , Flag "pgmF"           (hasArg (\f -> alterSettings (\s -> s { sPgm_F   = f})))
  , Flag "pgmc"           (hasArg (\f -> alterSettings (\s -> s { sPgm_c   = (f,[])})))
  , Flag "pgmm"           (HasArg (\_ -> addWarn "The -pgmm flag does nothing; it will be removed in a future GHC release"))
  , Flag "pgms"           (hasArg (\f -> alterSettings (\s -> s { sPgm_s   = (f,[])})))
  , Flag "pgma"           (hasArg (\f -> alterSettings (\s -> s { sPgm_a   = (f,[])})))
  , Flag "pgml"           (hasArg (\f -> alterSettings (\s -> s { sPgm_l   = (f,[])})))
  , Flag "pgmdll"         (hasArg (\f -> alterSettings (\s -> s { sPgm_dll = (f,[])})))
  , Flag "pgmwindres"     (hasArg (\f -> alterSettings (\s -> s { sPgm_windres = f})))
  , Flag "pgmlibtool"     (hasArg (\f -> alterSettings (\s -> s { sPgm_libtool = f})))

    -- need to appear before -optl/-opta to be parsed as LLVM flags.
  , Flag "optlo"          (hasArg (\f -> alterSettings (\s -> s { sOpt_lo  = f : sOpt_lo s})))
  , Flag "optlc"          (hasArg (\f -> alterSettings (\s -> s { sOpt_lc  = f : sOpt_lc s})))
  , Flag "optL"           (hasArg (\f -> alterSettings (\s -> s { sOpt_L   = f : sOpt_L s})))
  , Flag "optP"           (hasArg addOptP)
  , Flag "optF"           (hasArg (\f -> alterSettings (\s -> s { sOpt_F   = f : sOpt_F s})))
  , Flag "optc"           (hasArg addOptc)
  , Flag "optm"           (HasArg (\_ -> addWarn "The -optm flag does nothing; it will be removed in a future GHC release"))
  , Flag "opta"           (hasArg (\f -> alterSettings (\s -> s { sOpt_a   = f : sOpt_a s})))
  , Flag "optl"           (hasArg addOptl)
  , Flag "optwindres"     (hasArg (\f -> alterSettings (\s -> s { sOpt_windres = f : sOpt_windres s})))

  , Flag "split-objs"
         (NoArg (if can_split
                 then setGeneralFlag Opt_SplitObjs
                 else addWarn "ignoring -fsplit-objs"))

        -------- ghc -M -----------------------------------------------------
  , Flag "dep-suffix"     (hasArg addDepSuffix)
  , Flag "optdep-s"       (hasArgDF addDepSuffix "Use -dep-suffix instead")
  , Flag "dep-makefile"   (hasArg setDepMakefile)
  , Flag "optdep-f"       (hasArgDF setDepMakefile "Use -dep-makefile instead")
  , Flag "optdep-w"       (NoArg  (deprecate "doesn't do anything"))
  , Flag "include-pkg-deps"         (noArg (setDepIncludePkgDeps True))
  , Flag "optdep--include-prelude"  (noArgDF (setDepIncludePkgDeps True) "Use -include-pkg-deps instead")
  , Flag "optdep--include-pkg-deps" (noArgDF (setDepIncludePkgDeps True) "Use -include-pkg-deps instead")
  , Flag "exclude-module"           (hasArg addDepExcludeMod)
  , Flag "optdep--exclude-module"   (hasArgDF addDepExcludeMod "Use -exclude-module instead")
  , Flag "optdep-x"                 (hasArgDF addDepExcludeMod "Use -exclude-module instead")

        -------- Linking ----------------------------------------------------
  , Flag "no-link"            (noArg (\d -> d{ ghcLink=NoLink }))
  , Flag "shared"             (noArg (\d -> d{ ghcLink=LinkDynLib }))
  , Flag "staticlib"          (noArg (\d -> d{ ghcLink=LinkStaticLib }))
  , Flag "dynload"            (hasArg parseDynLibLoaderMode)
  , Flag "dylib-install-name" (hasArg setDylibInstallName)
    -- -dll-split is an internal flag, used only during the GHC build
  , Flag "dll-split"          (hasArg (\f d -> d{ dllSplitFile = Just f, dllSplit = Nothing }))

        ------- Libraries ---------------------------------------------------
  , Flag "L"   (Prefix addLibraryPath)
  , Flag "l"   (hasArg (addLdInputs . Option . ("-l" ++)))

        ------- Frameworks --------------------------------------------------
        -- -framework-path should really be -F ...
  , Flag "framework-path" (HasArg addFrameworkPath)
  , Flag "framework"      (hasArg addCmdlineFramework)

        ------- Output Redirection ------------------------------------------
  , Flag "odir"              (hasArg setObjectDir)
  , Flag "o"                 (sepArg (setOutputFile . Just))
  , Flag "dyno"              (sepArg (setDynOutputFile . Just))
  , Flag "ohi"               (hasArg (setOutputHi . Just ))
  , Flag "osuf"              (hasArg setObjectSuf)
  , Flag "dynosuf"           (hasArg setDynObjectSuf)
  , Flag "hcsuf"             (hasArg setHcSuf)
  , Flag "hisuf"             (hasArg setHiSuf)
  , Flag "dynhisuf"          (hasArg setDynHiSuf)
  , Flag "hidir"             (hasArg setHiDir)
  , Flag "tmpdir"            (hasArg setTmpDir)
  , Flag "stubdir"           (hasArg setStubDir)
  , Flag "dumpdir"           (hasArg setDumpDir)
  , Flag "outputdir"         (hasArg setOutputDir)
  , Flag "ddump-file-prefix" (hasArg (setDumpPrefixForce . Just))

  , Flag "dynamic-too"       (NoArg (setGeneralFlag Opt_BuildDynamicToo))

        ------- Keeping temporary files -------------------------------------
     -- These can be singular (think ghc -c) or plural (think ghc --make)
  , Flag "keep-hc-file"     (NoArg (setGeneralFlag Opt_KeepHcFiles))
  , Flag "keep-hc-files"    (NoArg (setGeneralFlag Opt_KeepHcFiles))
  , Flag "keep-s-file"      (NoArg (setGeneralFlag Opt_KeepSFiles))
  , Flag "keep-s-files"     (NoArg (setGeneralFlag Opt_KeepSFiles))
  , Flag "keep-raw-s-file"  (NoArg (addWarn "The -keep-raw-s-file flag does nothing; it will be removed in a future GHC release"))
  , Flag "keep-raw-s-files" (NoArg (addWarn "The -keep-raw-s-files flag does nothing; it will be removed in a future GHC release"))
  , Flag "keep-llvm-file"   (NoArg (do setObjTarget HscLlvm
                                       setGeneralFlag Opt_KeepLlvmFiles))
  , Flag "keep-llvm-files"  (NoArg (do setObjTarget HscLlvm
                                       setGeneralFlag Opt_KeepLlvmFiles))
     -- This only makes sense as plural
  , Flag "keep-tmp-files"   (NoArg (setGeneralFlag Opt_KeepTmpFiles))

        ------- Miscellaneous ----------------------------------------------
  , Flag "no-auto-link-packages" (NoArg (unSetGeneralFlag Opt_AutoLinkPackages))
  , Flag "no-hs-main"     (NoArg (setGeneralFlag Opt_NoHsMain))
  , Flag "with-rtsopts"   (HasArg setRtsOpts)
  , Flag "rtsopts"        (NoArg (setRtsOptsEnabled RtsOptsAll))
  , Flag "rtsopts=all"    (NoArg (setRtsOptsEnabled RtsOptsAll))
  , Flag "rtsopts=some"   (NoArg (setRtsOptsEnabled RtsOptsSafeOnly))
  , Flag "rtsopts=none"   (NoArg (setRtsOptsEnabled RtsOptsNone))
  , Flag "no-rtsopts"     (NoArg (setRtsOptsEnabled RtsOptsNone))
  , Flag "main-is"        (SepArg setMainIs)
  , Flag "haddock"        (NoArg (setGeneralFlag Opt_Haddock))
  , Flag "haddock-opts"   (hasArg addHaddockOpts)
  , Flag "hpcdir"         (SepArg setOptHpcDir)
  , Flag "ghci-script"    (hasArg addGhciScript)
  , Flag "interactive-print" (hasArg setInteractivePrint)
  , Flag "ticky-allocd"      (NoArg (setGeneralFlag Opt_Ticky_Allocd))
  , Flag "ticky-LNE"         (NoArg (setGeneralFlag Opt_Ticky_LNE))
  , Flag "ticky-dyn-thunk"   (NoArg (setGeneralFlag Opt_Ticky_Dyn_Thunk))
        ------- recompilation checker --------------------------------------
  , Flag "recomp"         (NoArg (do unSetGeneralFlag Opt_ForceRecomp
                                     deprecate "Use -fno-force-recomp instead"))
  , Flag "no-recomp"      (NoArg (do setGeneralFlag Opt_ForceRecomp
                                     deprecate "Use -fforce-recomp instead"))

        ------ HsCpp opts ---------------------------------------------------
  , Flag "D"              (AnySuffix (upd . addOptP))
  , Flag "U"              (AnySuffix (upd . addOptP))

        ------- Include/Import Paths ----------------------------------------
  , Flag "I"              (Prefix    addIncludePath)
  , Flag "i"              (OptPrefix addImportPath)

        ------ Output style options -----------------------------------------
  , Flag "dppr-user-length" (intSuffix (\n d -> d{ pprUserLength = n }))
  , Flag "dppr-cols"        (intSuffix (\n d -> d{ pprCols = n }))
  , Flag "dtrace-level"     (intSuffix (\n d -> d{ traceLevel = n }))
  -- Suppress all that is suppressable in core dumps.
  -- Except for uniques, as some simplifier phases introduce new varibles that
  -- have otherwise identical names.
  , Flag "dsuppress-all"    (NoArg $ do setGeneralFlag Opt_SuppressCoercions
                                        setGeneralFlag Opt_SuppressVarKinds
                                        setGeneralFlag Opt_SuppressModulePrefixes
                                        setGeneralFlag Opt_SuppressTypeApplications
                                        setGeneralFlag Opt_SuppressIdInfo
                                        setGeneralFlag Opt_SuppressTypeSignatures)

        ------ Debugging ----------------------------------------------------
  , Flag "dstg-stats"     (NoArg (setGeneralFlag Opt_StgStats))

  , Flag "ddump-cmm"               (setDumpFlag Opt_D_dump_cmm)
  , Flag "ddump-cmm-raw"           (setDumpFlag Opt_D_dump_cmm_raw)
  , Flag "ddump-cmm-cfg"           (setDumpFlag Opt_D_dump_cmm_cfg)
  , Flag "ddump-cmm-cbe"           (setDumpFlag Opt_D_dump_cmm_cbe)
  , Flag "ddump-cmm-proc"          (setDumpFlag Opt_D_dump_cmm_proc)
  , Flag "ddump-cmm-sink"          (setDumpFlag Opt_D_dump_cmm_sink)
  , Flag "ddump-cmm-sp"            (setDumpFlag Opt_D_dump_cmm_sp)
  , Flag "ddump-cmm-procmap"       (setDumpFlag Opt_D_dump_cmm_procmap)
  , Flag "ddump-cmm-split"         (setDumpFlag Opt_D_dump_cmm_split)
  , Flag "ddump-cmm-info"          (setDumpFlag Opt_D_dump_cmm_info)
  , Flag "ddump-cmm-cps"           (setDumpFlag Opt_D_dump_cmm_cps)
  , Flag "ddump-core-stats"        (setDumpFlag Opt_D_dump_core_stats)
  , Flag "ddump-asm"               (setDumpFlag Opt_D_dump_asm)
  , Flag "ddump-asm-native"        (setDumpFlag Opt_D_dump_asm_native)
  , Flag "ddump-asm-liveness"      (setDumpFlag Opt_D_dump_asm_liveness)
  , Flag "ddump-asm-regalloc"      (setDumpFlag Opt_D_dump_asm_regalloc)
  , Flag "ddump-asm-conflicts"     (setDumpFlag Opt_D_dump_asm_conflicts)
  , Flag "ddump-asm-regalloc-stages" (setDumpFlag Opt_D_dump_asm_regalloc_stages)
  , Flag "ddump-asm-stats"         (setDumpFlag Opt_D_dump_asm_stats)
  , Flag "ddump-asm-expanded"      (setDumpFlag Opt_D_dump_asm_expanded)
  , Flag "ddump-llvm"              (NoArg (do setObjTarget HscLlvm
                                              setDumpFlag' Opt_D_dump_llvm))
  , Flag "ddump-deriv"             (setDumpFlag Opt_D_dump_deriv)
  , Flag "ddump-ds"                (setDumpFlag Opt_D_dump_ds)
  , Flag "ddump-foreign"           (setDumpFlag Opt_D_dump_foreign)
  , Flag "ddump-inlinings"         (setDumpFlag Opt_D_dump_inlinings)
  , Flag "ddump-rule-firings"      (setDumpFlag Opt_D_dump_rule_firings)
  , Flag "ddump-rule-rewrites"     (setDumpFlag Opt_D_dump_rule_rewrites)
  , Flag "ddump-simpl-trace"       (setDumpFlag Opt_D_dump_simpl_trace)
  , Flag "ddump-occur-anal"        (setDumpFlag Opt_D_dump_occur_anal)
  , Flag "ddump-parsed"            (setDumpFlag Opt_D_dump_parsed)
  , Flag "ddump-rn"                (setDumpFlag Opt_D_dump_rn)
  , Flag "ddump-core-pipeline"     (setDumpFlag Opt_D_dump_core_pipeline)
  , Flag "ddump-simpl"             (setDumpFlag Opt_D_dump_simpl)
  , Flag "ddump-simpl-iterations"  (setDumpFlag Opt_D_dump_simpl_iterations)
  , Flag "ddump-simpl-phases"      (OptPrefix setDumpSimplPhases)
  , Flag "ddump-spec"              (setDumpFlag Opt_D_dump_spec)
  , Flag "ddump-prep"              (setDumpFlag Opt_D_dump_prep)
  , Flag "ddump-stg"               (setDumpFlag Opt_D_dump_stg)
  , Flag "ddump-stranal"           (setDumpFlag Opt_D_dump_stranal)
  , Flag "ddump-tc"                (setDumpFlag Opt_D_dump_tc)
  , Flag "ddump-types"             (setDumpFlag Opt_D_dump_types)
  , Flag "ddump-rules"             (setDumpFlag Opt_D_dump_rules)
  , Flag "ddump-cse"               (setDumpFlag Opt_D_dump_cse)
  , Flag "ddump-worker-wrapper"    (setDumpFlag Opt_D_dump_worker_wrapper)
  , Flag "ddump-rn-trace"          (setDumpFlag Opt_D_dump_rn_trace)
  , Flag "ddump-if-trace"          (setDumpFlag Opt_D_dump_if_trace)
  , Flag "ddump-cs-trace"          (setDumpFlag Opt_D_dump_cs_trace)
  , Flag "ddump-tc-trace"          (setDumpFlag Opt_D_dump_tc_trace)
  , Flag "ddump-vt-trace"          (setDumpFlag Opt_D_dump_vt_trace)
  , Flag "ddump-splices"           (setDumpFlag Opt_D_dump_splices)
  , Flag "ddump-rn-stats"          (setDumpFlag Opt_D_dump_rn_stats)
  , Flag "ddump-opt-cmm"           (setDumpFlag Opt_D_dump_opt_cmm)
  , Flag "ddump-simpl-stats"       (setDumpFlag Opt_D_dump_simpl_stats)
  , Flag "ddump-bcos"              (setDumpFlag Opt_D_dump_BCOs)
  , Flag "dsource-stats"           (setDumpFlag Opt_D_source_stats)
  , Flag "dverbose-core2core"      (NoArg (do setVerbosity (Just 2)
                                              setVerboseCore2Core))
  , Flag "dverbose-stg2stg"        (setDumpFlag Opt_D_verbose_stg2stg)
  , Flag "ddump-hi"                (setDumpFlag Opt_D_dump_hi)
  , Flag "ddump-minimal-imports"   (NoArg (setGeneralFlag Opt_D_dump_minimal_imports))
  , Flag "ddump-vect"              (setDumpFlag Opt_D_dump_vect)
  , Flag "ddump-hpc"               (setDumpFlag Opt_D_dump_ticked) -- back compat
  , Flag "ddump-ticked"            (setDumpFlag Opt_D_dump_ticked)
  , Flag "ddump-mod-cycles"        (setDumpFlag Opt_D_dump_mod_cycles)
  , Flag "ddump-view-pattern-commoning" (setDumpFlag Opt_D_dump_view_pattern_commoning)
  , Flag "ddump-to-file"           (NoArg (setGeneralFlag Opt_DumpToFile))
  , Flag "ddump-hi-diffs"          (setDumpFlag Opt_D_dump_hi_diffs)
  , Flag "ddump-rtti"              (setDumpFlag Opt_D_dump_rtti)
  , Flag "dcore-lint"              (NoArg (setGeneralFlag Opt_DoCoreLinting))
  , Flag "dstg-lint"               (NoArg (setGeneralFlag Opt_DoStgLinting))
  , Flag "dcmm-lint"               (NoArg (setGeneralFlag Opt_DoCmmLinting))
  , Flag "dasm-lint"               (NoArg (setGeneralFlag Opt_DoAsmLinting))
  , Flag "dshow-passes"            (NoArg (do forceRecompile
                                              setVerbosity $ Just 2))
  , Flag "dfaststring-stats"       (NoArg (setGeneralFlag Opt_D_faststring_stats))
  , Flag "dno-llvm-mangler"        (NoArg (setGeneralFlag Opt_NoLlvmMangler)) -- hidden flag

        ------ Machine dependant (-m<blah>) stuff ---------------------------

  , Flag "monly-2-regs" (NoArg (addWarn "The -monly-2-regs flag does nothing; it will be removed in a future GHC release"))
  , Flag "monly-3-regs" (NoArg (addWarn "The -monly-3-regs flag does nothing; it will be removed in a future GHC release"))
  , Flag "monly-4-regs" (NoArg (addWarn "The -monly-4-regs flag does nothing; it will be removed in a future GHC release"))
  , Flag "msse"         (versionSuffix (\maj min d -> d{ sseVersion = Just (maj, min) }))
  , Flag "mavx"         (noArg (\d -> d{ avx = True }))
  , Flag "mavx2"        (noArg (\d -> d{ avx2 = True }))
  , Flag "mavx512cd"    (noArg (\d -> d{ avx512cd = True }))
  , Flag "mavx512er"    (noArg (\d -> d{ avx512er = True }))
  , Flag "mavx512f"     (noArg (\d -> d{ avx512f = True }))
  , Flag "mavx512pf"    (noArg (\d -> d{ avx512pf = True }))

     ------ Warning opts -------------------------------------------------
  , Flag "W"      (NoArg (mapM_ setWarningFlag minusWOpts))
  , Flag "Werror" (NoArg (setGeneralFlag           Opt_WarnIsError))
  , Flag "Wwarn"  (NoArg (unSetGeneralFlag         Opt_WarnIsError))
  , Flag "Wall"   (NoArg (mapM_ setWarningFlag minusWallOpts))
  , Flag "Wnot"   (NoArg (do upd (\dfs -> dfs {warningFlags = IntSet.empty})
                             deprecate "Use -w instead"))
  , Flag "w"      (NoArg (upd (\dfs -> dfs {warningFlags = IntSet.empty})))

        ------ Plugin flags ------------------------------------------------
  , Flag "fplugin-opt" (hasArg addPluginModuleNameOption)
  , Flag "fplugin"     (hasArg addPluginModuleName)

        ------ Optimisation flags ------------------------------------------
  , Flag "O"      (noArgM (setOptLevel 1))
  , Flag "Onot"   (noArgM (\dflags -> do deprecate "Use -O0 instead"
                                         setOptLevel 0 dflags))
  , Flag "Odph"   (noArgM setDPHOpt)
  , Flag "O"      (optIntSuffixM (\mb_n -> setOptLevel (mb_n `orElse` 1)))
                -- If the number is missing, use 1


  , Flag "fmax-relevant-binds"         (intSuffix (\n d -> d{ maxRelevantBinds = Just n }))
  , Flag "fno-max-relevant-binds"      (noArg (\d -> d{ maxRelevantBinds = Nothing }))
  , Flag "fsimplifier-phases"          (intSuffix (\n d -> d{ simplPhases = n }))
  , Flag "fmax-simplifier-iterations"  (intSuffix (\n d -> d{ maxSimplIterations = n }))
  , Flag "fsimpl-tick-factor"          (intSuffix (\n d -> d{ simplTickFactor = n }))
  , Flag "fspec-constr-threshold"      (intSuffix (\n d -> d{ specConstrThreshold = Just n }))
  , Flag "fno-spec-constr-threshold"   (noArg (\d -> d{ specConstrThreshold = Nothing }))
  , Flag "fspec-constr-count"          (intSuffix (\n d -> d{ specConstrCount = Just n }))
  , Flag "fno-spec-constr-count"       (noArg (\d -> d{ specConstrCount = Nothing }))
  , Flag "fspec-constr-recursive"      (intSuffix (\n d -> d{ specConstrRecursive = n }))
  , Flag "fliberate-case-threshold"    (intSuffix (\n d -> d{ liberateCaseThreshold = Just n }))
  , Flag "fno-liberate-case-threshold" (noArg (\d -> d{ liberateCaseThreshold = Nothing }))
  , Flag "frule-check"                 (sepArg (\s d -> d{ ruleCheck = Just s }))
  , Flag "fcontext-stack"              (intSuffix (\n d -> d{ ctxtStkDepth = n }))
  , Flag "fstrictness-before"          (intSuffix (\n d -> d{ strictnessBefore = n : strictnessBefore d }))
  , Flag "ffloat-lam-args"             (intSuffix (\n d -> d{ floatLamArgs = Just n }))
  , Flag "ffloat-all-lams"             (noArg (\d -> d{ floatLamArgs = Nothing }))

  , Flag "fhistory-size"               (intSuffix (\n d -> d{ historySize = n }))

  , Flag "funfolding-creation-threshold" (intSuffix   (\n d -> d {ufCreationThreshold = n}))
  , Flag "funfolding-use-threshold"      (intSuffix   (\n d -> d {ufUseThreshold = n}))
  , Flag "funfolding-fun-discount"       (intSuffix   (\n d -> d {ufFunAppDiscount = n}))
  , Flag "funfolding-dict-discount"      (intSuffix   (\n d -> d {ufDictDiscount = n}))
  , Flag "funfolding-keeness-factor"     (floatSuffix (\n d -> d {ufKeenessFactor = n}))

  , Flag "fmax-worker-args" (intSuffix (\n d -> d {maxWorkerArgs = n}))

  , Flag "fghci-hist-size" (intSuffix (\n d -> d {ghciHistSize = n}))

        ------ Profiling ----------------------------------------------------

        -- OLD profiling flags
  , Flag "auto-all"              (noArg (\d -> d { profAuto = ProfAutoAll } ))
  , Flag "no-auto-all"           (noArg (\d -> d { profAuto = NoProfAuto } ))
  , Flag "auto"                  (noArg (\d -> d { profAuto = ProfAutoExports } ))
  , Flag "no-auto"               (noArg (\d -> d { profAuto = NoProfAuto } ))
  , Flag "caf-all"               (NoArg (setGeneralFlag Opt_AutoSccsOnIndividualCafs))
  , Flag "no-caf-all"            (NoArg (unSetGeneralFlag Opt_AutoSccsOnIndividualCafs))

        -- NEW profiling flags
  , Flag "fprof-auto"             (noArg (\d -> d { profAuto = ProfAutoAll } ))
  , Flag "fprof-auto-top"         (noArg (\d -> d { profAuto = ProfAutoTop } ))
  , Flag "fprof-auto-exported"    (noArg (\d -> d { profAuto = ProfAutoExports } ))
  , Flag "fprof-auto-calls"       (noArg (\d -> d { profAuto = ProfAutoCalls } ))
  , Flag "fno-prof-auto"          (noArg (\d -> d { profAuto = NoProfAuto } ))

        ------ Compiler flags -----------------------------------------------

  , Flag "fasm"             (NoArg (setObjTarget HscAsm))
  , Flag "fvia-c"           (NoArg
         (addWarn "The -fvia-c flag does nothing; it will be removed in a future GHC release"))
  , Flag "fvia-C"           (NoArg
         (addWarn "The -fvia-C flag does nothing; it will be removed in a future GHC release"))
  , Flag "fllvm"            (NoArg (setObjTarget HscLlvm))

  , Flag "fno-code"         (NoArg (do upd $ \d -> d{ ghcLink=NoLink }
                                       setTarget HscNothing))
  , Flag "fbyte-code"       (NoArg (setTarget HscInterpreted))
  , Flag "fobject-code"     (NoArg (setTargetWithPlatform defaultHscTarget))
  , Flag "fglasgow-exts"    (NoArg (enableGlasgowExts >> deprecate "Use individual extensions instead"))
  , Flag "fno-glasgow-exts" (NoArg (disableGlasgowExts >> deprecate "Use individual extensions instead"))

        ------ Safe Haskell flags -------------------------------------------
  , Flag "fpackage-trust"   (NoArg setPackageTrust)
  , Flag "fno-safe-infer"   (NoArg (setSafeHaskell Sf_None))
  , Flag "fPIC"             (NoArg (setGeneralFlag Opt_PIC))
  , Flag "fno-PIC"          (NoArg (unSetGeneralFlag Opt_PIC))
 ]
 ++ map (mkFlag turnOn  ""     setGeneralFlag  ) negatableFlags
 ++ map (mkFlag turnOff "no-"  unSetGeneralFlag) negatableFlags
 ++ map (mkFlag turnOn  "d"    setGeneralFlag  ) dFlags
 ++ map (mkFlag turnOff "dno-" unSetGeneralFlag) dFlags
 ++ map (mkFlag turnOn  "f"    setGeneralFlag  ) fFlags
 ++ map (mkFlag turnOff "fno-" unSetGeneralFlag) fFlags
 ++ map (mkFlag turnOn  "f"    setWarningFlag  ) fWarningFlags
 ++ map (mkFlag turnOff "fno-" unSetWarningFlag) fWarningFlags
 ++ map (mkFlag turnOn  "f"    setExtensionFlag  ) fLangFlags
 ++ map (mkFlag turnOff "fno-" unSetExtensionFlag) fLangFlags
 ++ map (mkFlag turnOn  "X"    setExtensionFlag  ) xFlags
 ++ map (mkFlag turnOff "XNo"  unSetExtensionFlag) xFlags
 ++ map (mkFlag turnOn  "X"    setLanguage) languageFlags
 ++ map (mkFlag turnOn  "X"    setSafeHaskell) safeHaskellFlags
 ++ [ Flag "XGenerics"       (NoArg (deprecate "it does nothing; look into -XDefaultSignatures and -XDeriveGeneric for generic programming support."))
    , Flag "XNoGenerics"     (NoArg (deprecate "it does nothing; look into -XDefaultSignatures and -XDeriveGeneric for generic programming support.")) ]

pa
dynamic_flags :: [Flag (CmdLineP DynFlags)]
dynamic_flags = [
    Flag "n"        (NoArg (addWarn "The -n flag is deprecated and no longer has any effect"))
  , Flag "cpp"      (NoArg (setExtensionFlag Opt_Cpp))
  , Flag "F"        (NoArg (setGeneralFlag Opt_Pp))
  , Flag "#include"
         (HasArg (\s -> do addCmdlineHCInclude s
                           addWarn "-#include and INCLUDE pragmas are deprecated: They no longer have any effect"))
  , Flag "v"        (OptIntSuffix setVerbosity)

  , Flag "j"        (OptIntSuffix (\n -> upd (\d -> d {parMakeCount = n})))

        ------- ways --------------------------------------------------------
  , Flag "prof"           (NoArg (addWay WayProf))
  , Flag "eventlog"       (NoArg (addWay WayEventLog))
  , Flag "parallel"       (NoArg (addWay WayPar))
  , Flag "gransim"        (NoArg (addWay WayGran))
  , Flag "smp"            (NoArg (addWay WayThreaded >> deprecate "Use -threaded instead"))
  , Flag "debug"          (NoArg (addWay WayDebug))
  , Flag "ndp"            (NoArg (addWay WayNDP))
  , Flag "threaded"       (NoArg (addWay WayThreaded))

  , Flag "ticky"          (NoArg (setGeneralFlag Opt_Ticky >> addWay WayDebug))

    -- -ticky enables ticky-ticky code generation, and also implies -debug which
    -- is required to get the RTS ticky support.

        ----- Linker --------------------------------------------------------
  , Flag "static"         (NoArg removeWayDyn)
  , Flag "dynamic"        (NoArg (addWay WayDyn))
    -- ignored for compat w/ gcc:
  , Flag "rdynamic"       (NoArg (return ()))
  , Flag "relative-dynlib-paths"  (NoArg (setGeneralFlag Opt_RelativeDynlibPaths))

        ------- Specific phases  --------------------------------------------
    -- need to appear before -pgmL to be parsed as LLVM flags.
  , Flag "pgmlo"          (hasArg (\f -> alterSettings (\s -> s { sPgm_lo  = (f,[])})))
  , Flag "pgmlc"          (hasArg (\f -> alterSettings (\s -> s { sPgm_lc  = (f,[])})))
  , Flag "pgmL"           (hasArg (\f -> alterSettings (\s -> s { sPgm_L   = f})))
  , Flag "pgmP"           (hasArg setPgmP)
  , Flag "pgmF"           (hasArg (\f -> alterSettings (\s -> s { sPgm_F   = f})))
  , Flag "pgmc"           (hasArg (\f -> alterSettings (\s -> s { sPgm_c   = (f,[])})))
  , Flag "pgmm"           (HasArg (\_ -> addWarn "The -pgmm flag does nothing; it will be removed in a future GHC release"))
  , Flag "pgms"           (hasArg (\f -> alterSettings (\s -> s { sPgm_s   = (f,[])})))
  , Flag "pgma"           (hasArg (\f -> alterSettings (\s -> s { sPgm_a   = (f,[])})))
  , Flag "pgml"           (hasArg (\f -> alterSettings (\s -> s { sPgm_l   = (f,[])})))
  , Flag "pgmdll"         (hasArg (\f -> alterSettings (\s -> s { sPgm_dll = (f,[])})))
  , Flag "pgmwindres"     (hasArg (\f -> alterSettings (\s -> s { sPgm_windres = f})))
  , Flag "pgmlibtool"     (hasArg (\f -> alterSettings (\s -> s { sPgm_libtool = f})))

    -- need to appear before -optl/-opta to be parsed as LLVM flags.
  , Flag "optlo"          (hasArg (\f -> alterSettings (\s -> s { sOpt_lo  = f : sOpt_lo s})))
  , Flag "optlc"          (hasArg (\f -> alterSettings (\s -> s { sOpt_lc  = f : sOpt_lc s})))
  , Flag "optL"           (hasArg (\f -> alterSettings (\s -> s { sOpt_L   = f : sOpt_L s})))
  , Flag "optP"           (hasArg addOptP)
  , Flag "optF"           (hasArg (\f -> alterSettings (\s -> s { sOpt_F   = f : sOpt_F s})))
  , Flag "optc"           (hasArg addOptc)
  , Flag "optm"           (HasArg (\_ -> addWarn "The -optm flag does nothing; it will be removed in a future GHC release"))
  , Flag "opta"           (hasArg (\f -> alterSettings (\s -> s { sOpt_a   = f : sOpt_a s})))
  , Flag "optl"           (hasArg addOptl)
  , Flag "optwindres"     (hasArg (\f -> alterSettings (\s -> s { sOpt_windres = f : sOpt_windres s})))

  , Flag "split-objs"
         (NoArg (if can_split
                 then setGeneralFlag Opt_SplitObjs
                 else addWarn "ignoring -fsplit-objs"))

        -------- ghc -M -----------------------------------------------------
  , Flag "dep-suffix"     (hasArg addDepSuffix)
  , Flag "optdep-s"       (hasArgDF addDepSuffix "Use -dep-suffix instead")
  , Flag "dep-makefile"   (hasArg setDepMakefile)
  , Flag "optdep-f"       (hasArgDF setDepMakefile "Use -dep-makefile instead")
  , Flag "optdep-w"       (NoArg  (deprecate "doesn't do anything"))
  , Flag "include-pkg-deps"         (noArg (setDepIncludePkgDeps True))
  , Flag "optdep--include-prelude"  (noArgDF (setDepIncludePkgDeps True) "Use -include-pkg-deps instead")
  , Flag "optdep--include-pkg-deps" (noArgDF (setDepIncludePkgDeps True) "Use -include-pkg-deps instead")
  , Flag "exclude-module"           (hasArg addDepExcludeMod)
  , Flag "optdep--exclude-module"   (hasArgDF addDepExcludeMod "Use -exclude-module instead")
  , Flag "optdep-x"                 (hasArgDF addDepExcludeMod "Use -exclude-module instead")

        -------- Linking ----------------------------------------------------
  , Flag "no-link"            (noArg (\d -> d{ ghcLink=NoLink }))
  , Flag "shared"             (noArg (\d -> d{ ghcLink=LinkDynLib }))
  , Flag "staticlib"          (noArg (\d -> d{ ghcLink=LinkStaticLib }))
  , Flag "dynload"            (hasArg parseDynLibLoaderMode)
  , Flag "dylib-install-name" (hasArg setDylibInstallName)
    -- -dll-split is an internal flag, used only during the GHC build
  , Flag "dll-split"          (hasArg (\f d -> d{ dllSplitFile = Just f, dllSplit = Nothing }))

        ------- Libraries ---------------------------------------------------
  , Flag "L"   (Prefix addLibraryPath)
  , Flag "l"   (hasArg (addLdInputs . Option . ("-l" ++)))

        ------- Frameworks --------------------------------------------------
        -- -framework-path should really be -F ...
  , Flag "framework-path" (HasArg addFrameworkPath)
  , Flag "framework"      (hasArg addCmdlineFramework)

        ------- Output Redirection ------------------------------------------
  , Flag "odir"              (hasArg setObjectDir)
  , Flag "o"                 (sepArg (setOutputFile . Just))
  , Flag "dyno"              (sepArg (setDynOutputFile . Just))
  , Flag "ohi"               (hasArg (setOutputHi . Just ))
  , Flag "osuf"              (hasArg setObjectSuf)
  , Flag "dynosuf"           (hasArg setDynObjectSuf)
  , Flag "hcsuf"             (hasArg setHcSuf)
  , Flag "hisuf"             (hasArg setHiSuf)
  , Flag "dynhisuf"          (hasArg setDynHiSuf)
  , Flag "hidir"             (hasArg setHiDir)
  , Flag "tmpdir"            (hasArg setTmpDir)
  , Flag "stubdir"           (hasArg setStubDir)
  , Flag "dumpdir"           (hasArg setDumpDir)
  , Flag "outputdir"         (hasArg setOutputDir)
  , Flag "ddump-file-prefix" (hasArg (setDumpPrefixForce . Just))

  , Flag "dynamic-too"       (NoArg (setGeneralFlag Opt_BuildDynamicToo))

        ------- Keeping temporary files -------------------------------------
     -- These can be singular (think ghc -c) or plural (think ghc --make)
  , Flag "keep-hc-file"     (NoArg (setGeneralFlag Opt_KeepHcFiles))
  , Flag "keep-hc-files"    (NoArg (setGeneralFlag Opt_KeepHcFiles))
  , Flag "keep-s-file"      (NoArg (setGeneralFlag Opt_KeepSFiles))
  , Flag "keep-s-files"     (NoArg (setGeneralFlag Opt_KeepSFiles))
  , Flag "keep-raw-s-file"  (NoArg (addWarn "The -keep-raw-s-file flag does nothing; it will be removed in a future GHC release"))
  , Flag "keep-raw-s-files" (NoArg (addWarn "The -keep-raw-s-files flag does nothing; it will be removed in a future GHC release"))
  , Flag "keep-llvm-file"   (NoArg (do setObjTarget HscLlvm
                                       setGeneralFlag Opt_KeepLlvmFiles))
  , Flag "keep-llvm-files"  (NoArg (do setObjTarget HscLlvm
                                       setGeneralFlag Opt_KeepLlvmFiles))
     -- This only makes sense as plural
  , Flag "keep-tmp-files"   (NoArg (setGeneralFlag Opt_KeepTmpFiles))

        ------- Miscellaneous ----------------------------------------------
  , Flag "no-auto-link-packages" (NoArg (unSetGeneralFlag Opt_AutoLinkPackages))
  , Flag "no-hs-main"     (NoArg (setGeneralFlag Opt_NoHsMain))
  , Flag "with-rtsopts"   (HasArg setRtsOpts)
  , Flag "rtsopts"        (NoArg (setRtsOptsEnabled RtsOptsAll))
  , Flag "rtsopts=all"    (NoArg (setRtsOptsEnabled RtsOptsAll))
  , Flag "rtsopts=some"   (NoArg (setRtsOptsEnabled RtsOptsSafeOnly))
  , Flag "rtsopts=none"   (NoArg (setRtsOptsEnabled RtsOptsNone))
  , Flag "no-rtsopts"     (NoArg (setRtsOptsEnabled RtsOptsNone))
  , Flag "main-is"        (SepArg setMainIs)
  , Flag "haddock"        (NoArg (setGeneralFlag Opt_Haddock))
  , Flag "haddock-opts"   (hasArg addHaddockOpts)
  , Flag "hpcdir"         (SepArg setOptHpcDir)
  , Flag "ghci-script"    (hasArg addGhciScript)
  , Flag "interactive-print" (hasArg setInteractivePrint)
  , Flag "ticky-allocd"      (NoArg (setGeneralFlag Opt_Ticky_Allocd))
  , Flag "ticky-LNE"         (NoArg (setGeneralFlag Opt_Ticky_LNE))
  , Flag "ticky-dyn-thunk"   (NoArg (setGeneralFlag Opt_Ticky_Dyn_Thunk))
        ------- recompilation checker --------------------------------------
  , Flag "recomp"         (NoArg (do unSetGeneralFlag Opt_ForceRecomp
                                     deprecate "Use -fno-force-recomp instead"))
  , Flag "no-recomp"      (NoArg (do setGeneralFlag Opt_ForceRecomp
                                     deprecate "Use -fforce-recomp instead"))

        ------ HsCpp opts ---------------------------------------------------
  , Flag "D"              (AnySuffix (upd . addOptP))
  , Flag "U"              (AnySuffix (upd . addOptP))

        ------- Include/Import Paths ----------------------------------------
  , Flag "I"              (Prefix    addIncludePath)
  , Flag "i"              (OptPrefix addImportPath)

        ------ Output style options -----------------------------------------
  , Flag "dppr-user-length" (intSuffix (\n d -> d{ pprUserLength = n }))
  , Flag "dppr-cols"        (intSuffix (\n d -> d{ pprCols = n }))
  , Flag "dtrace-level"     (intSuffix (\n d -> d{ traceLevel = n }))
  -- Suppress all that is suppressable in core dumps.
  -- Except for uniques, as some simplifier phases introduce new varibles that
  -- have otherwise identical names.
  , Flag "dsuppress-all"    (NoArg $ do setGeneralFlag Opt_SuppressCoercions
                                        setGeneralFlag Opt_SuppressVarKinds
                                        setGeneralFlag Opt_SuppressModulePrefixes
                                        setGeneralFlag Opt_SuppressTypeApplications
                                        setGeneralFlag Opt_SuppressIdInfo
                                        setGeneralFlag Opt_SuppressTypeSignatures)

        ------ Debugging ----------------------------------------------------
  , Flag "dstg-stats"     (NoArg (setGeneralFlag Opt_StgStats))

  , Flag "ddump-cmm"               (setDumpFlag Opt_D_dump_cmm)
  , Flag "ddump-cmm-raw"           (setDumpFlag Opt_D_dump_cmm_raw)
  , Flag "ddump-cmm-cfg"           (setDumpFlag Opt_D_dump_cmm_cfg)
  , Flag "ddump-cmm-cbe"           (setDumpFlag Opt_D_dump_cmm_cbe)
  , Flag "ddump-cmm-proc"          (setDumpFlag Opt_D_dump_cmm_proc)
  , Flag "ddump-cmm-sink"          (setDumpFlag Opt_D_dump_cmm_sink)
  , Flag "ddump-cmm-sp"            (setDumpFlag Opt_D_dump_cmm_sp)
  , Flag "ddump-cmm-procmap"       (setDumpFlag Opt_D_dump_cmm_procmap)
  , Flag "ddump-cmm-split"         (setDumpFlag Opt_D_dump_cmm_split)
  , Flag "ddump-cmm-info"          (setDumpFlag Opt_D_dump_cmm_info)
  , Flag "ddump-cmm-cps"           (setDumpFlag Opt_D_dump_cmm_cps)
  , Flag "ddump-core-stats"        (setDumpFlag Opt_D_dump_core_stats)
  , Flag "ddump-asm"               (setDumpFlag Opt_D_dump_asm)
  , Flag "ddump-asm-native"        (setDumpFlag Opt_D_dump_asm_native)
  , Flag "ddump-asm-liveness"      (setDumpFlag Opt_D_dump_asm_liveness)
  , Flag "ddump-asm-regalloc"      (setDumpFlag Opt_D_dump_asm_regalloc)
  , Flag "ddump-asm-conflicts"     (setDumpFlag Opt_D_dump_asm_conflicts)
  , Flag "ddump-asm-regalloc-stages" (setDumpFlag Opt_D_dump_asm_regalloc_stages)
  , Flag "ddump-asm-stats"         (setDumpFlag Opt_D_dump_asm_stats)
  , Flag "ddump-asm-expanded"      (setDumpFlag Opt_D_dump_asm_expanded)
  , Flag "ddump-llvm"              (NoArg (do setObjTarget HscLlvm
                                              setDumpFlag' Opt_D_dump_llvm))
  , Flag "ddump-deriv"             (setDumpFlag Opt_D_dump_deriv)
  , Flag "ddump-ds"                (setDumpFlag Opt_D_dump_ds)
  , Flag "ddump-foreign"           (setDumpFlag Opt_D_dump_foreign)
  , Flag "ddump-inlinings"         (setDumpFlag Opt_D_dump_inlinings)
  , Flag "ddump-rule-firings"      (setDumpFlag Opt_D_dump_rule_firings)
  , Flag "ddump-rule-rewrites"     (setDumpFlag Opt_D_dump_rule_rewrites)
  , Flag "ddump-simpl-trace"       (setDumpFlag Opt_D_dump_simpl_trace)
  , Flag "ddump-occur-anal"        (setDumpFlag Opt_D_dump_occur_anal)
  , Flag "ddump-parsed"            (setDumpFlag Opt_D_dump_parsed)
  , Flag "ddump-rn"                (setDumpFlag Opt_D_dump_rn)
  , Flag "ddump-core-pipeline"     (setDumpFlag Opt_D_dump_core_pipeline)
  , Flag "ddump-simpl"             (setDumpFlag Opt_D_dump_simpl)
  , Flag "ddump-simpl-iterations"  (setDumpFlag Opt_D_dump_simpl_iterations)
  , Flag "ddump-simpl-phases"      (OptPrefix setDumpSimplPhases)
  , Flag "ddump-spec"              (setDumpFlag Opt_D_dump_spec)
  , Flag "ddump-prep"              (setDumpFlag Opt_D_dump_prep)
  , Flag "ddump-stg"               (setDumpFlag Opt_D_dump_stg)
  , Flag "ddump-stranal"           (setDumpFlag Opt_D_dump_stranal)
  , Flag "ddump-tc"                (setDumpFlag Opt_D_dump_tc)
  , Flag "ddump-types"             (setDumpFlag Opt_D_dump_types)
  , Flag "ddump-rules"             (setDumpFlag Opt_D_dump_rules)
  , Flag "ddump-cse"               (setDumpFlag Opt_D_dump_cse)
  , Flag "ddump-worker-wrapper"    (setDumpFlag Opt_D_dump_worker_wrapper)
  , Flag "ddump-rn-trace"          (setDumpFlag Opt_D_dump_rn_trace)
  , Flag "ddump-if-trace"          (setDumpFlag Opt_D_dump_if_trace)
  , Flag "ddump-cs-trace"          (setDumpFlag Opt_D_dump_cs_trace)
  , Flag "ddump-tc-trace"          (setDumpFlag Opt_D_dump_tc_trace)
  , Flag "ddump-vt-trace"          (setDumpFlag Opt_D_dump_vt_trace)
  , Flag "ddump-splices"           (setDumpFlag Opt_D_dump_splices)
  , Flag "ddump-rn-stats"          (setDumpFlag Opt_D_dump_rn_stats)
  , Flag "ddump-opt-cmm"           (setDumpFlag Opt_D_dump_opt_cmm)
  , Flag "ddump-simpl-stats"       (setDumpFlag Opt_D_dump_simpl_stats)
  , Flag "ddump-bcos"              (setDumpFlag Opt_D_dump_BCOs)
  , Flag "dsource-stats"           (setDumpFlag Opt_D_source_stats)
  , Flag "dverbose-core2core"      (NoArg (do setVerbosity (Just 2)
                                              setVerboseCore2Core))
  , Flag "dverbose-stg2stg"        (setDumpFlag Opt_D_verbose_stg2stg)
  , Flag "ddump-hi"                (setDumpFlag Opt_D_dump_hi)
  , Flag "ddump-minimal-imports"   (NoArg (setGeneralFlag Opt_D_dump_minimal_imports))
  , Flag "ddump-vect"              (setDumpFlag Opt_D_dump_vect)
  , Flag "ddump-hpc"               (setDumpFlag Opt_D_dump_ticked) -- back compat
  , Flag "ddump-ticked"            (setDumpFlag Opt_D_dump_ticked)
  , Flag "ddump-mod-cycles"        (setDumpFlag Opt_D_dump_mod_cycles)
  , Flag "ddump-view-pattern-commoning" (setDumpFlag Opt_D_dump_view_pattern_commoning)
  , Flag "ddump-to-file"           (NoArg (setGeneralFlag Opt_DumpToFile))
  , Flag "ddump-hi-diffs"          (setDumpFlag Opt_D_dump_hi_diffs)
  , Flag "ddump-rtti"              (setDumpFlag Opt_D_dump_rtti)
  , Flag "dcore-lint"              (NoArg (setGeneralFlag Opt_DoCoreLinting))
  , Flag "dstg-lint"               (NoArg (setGeneralFlag Opt_DoStgLinting))
  , Flag "dcmm-lint"               (NoArg (setGeneralFlag Opt_DoCmmLinting))
  , Flag "dasm-lint"               (NoArg (setGeneralFlag Opt_DoAsmLinting))
  , Flag "dshow-passes"            (NoArg (do forceRecompile
                                              setVerbosity $ Just 2))
  , Flag "dfaststring-stats"       (NoArg (setGeneralFlag Opt_D_faststring_stats))
  , Flag "dno-llvm-mangler"        (NoArg (setGeneralFlag Opt_NoLlvmMangler)) -- hidden flag

        ------ Machine dependant (-m<blah>) stuff ---------------------------

  , Flag "monly-2-regs" (NoArg (addWarn "The -monly-2-regs flag does nothing; it will be removed in a future GHC release"))
  , Flag "monly-3-regs" (NoArg (addWarn "The -monly-3-regs flag does nothing; it will be removed in a future GHC release"))
  , Flag "monly-4-regs" (NoArg (addWarn "The -monly-4-regs flag does nothing; it will be removed in a future GHC release"))
  , Flag "msse"         (versionSuffix (\maj min d -> d{ sseVersion = Just (maj, min) }))
  , Flag "mavx"         (noArg (\d -> d{ avx = True }))
  , Flag "mavx2"        (noArg (\d -> d{ avx2 = True }))
  , Flag "mavx512cd"    (noArg (\d -> d{ avx512cd = True }))
  , Flag "mavx512er"    (noArg (\d -> d{ avx512er = True }))
  , Flag "mavx512f"     (noArg (\d -> d{ avx512f = True }))
  , Flag "mavx512pf"    (noArg (\d -> d{ avx512pf = True }))

     ------ Warning opts -------------------------------------------------
  , Flag "W"      (NoArg (mapM_ setWarningFlag minusWOpts))
  , Flag "Werror" (NoArg (setGeneralFlag           Opt_WarnIsError))
  , Flag "Wwarn"  (NoArg (unSetGeneralFlag         Opt_WarnIsError))
  , Flag "Wall"   (NoArg (mapM_ setWarningFlag minusWallOpts))
  , Flag "Wnot"   (NoArg (do upd (\dfs -> dfs {warningFlags = IntSet.empty})
                             deprecate "Use -w instead"))
  , Flag "w"      (NoArg (upd (\dfs -> dfs {warningFlags = IntSet.empty})))

        ------ Plugin flags ------------------------------------------------
  , Flag "fplugin-opt" (hasArg addPluginModuleNameOption)
  , Flag "fplugin"     (hasArg addPluginModuleName)

        ------ Optimisation flags ------------------------------------------
  , Flag "O"      (noArgM (setOptLevel 1))
  , Flag "Onot"   (noArgM (\dflags -> do deprecate "Use -O0 instead"
                                         setOptLevel 0 dflags))
  , Flag "Odph"   (noArgM setDPHOpt)
  , Flag "O"      (optIntSuffixM (\mb_n -> setOptLevel (mb_n `orElse` 1)))
                -- If the number is missing, use 1


  , Flag "fmax-relevant-binds"         (intSuffix (\n d -> d{ maxRelevantBinds = Just n }))
  , Flag "fno-max-relevant-binds"      (noArg (\d -> d{ maxRelevantBinds = Nothing }))
  , Flag "fsimplifier-phases"          (intSuffix (\n d -> d{ simplPhases = n }))
  , Flag "fmax-simplifier-iterations"  (intSuffix (\n d -> d{ maxSimplIterations = n }))
  , Flag "fsimpl-tick-factor"          (intSuffix (\n d -> d{ simplTickFactor = n }))
  , Flag "fspec-constr-threshold"      (intSuffix (\n d -> d{ specConstrThreshold = Just n }))
  , Flag "fno-spec-constr-threshold"   (noArg (\d -> d{ specConstrThreshold = Nothing }))
  , Flag "fspec-constr-count"          (intSuffix (\n d -> d{ specConstrCount = Just n }))
  , Flag "fno-spec-constr-count"       (noArg (\d -> d{ specConstrCount = Nothing }))
  , Flag "fspec-constr-recursive"      (intSuffix (\n d -> d{ specConstrRecursive = n }))
  , Flag "fliberate-case-threshold"    (intSuffix (\n d -> d{ liberateCaseThreshold = Just n }))
  , Flag "fno-liberate-case-threshold" (noArg (\d -> d{ liberateCaseThreshold = Nothing }))
  , Flag "frule-check"                 (sepArg (\s d -> d{ ruleCheck = Just s }))
  , Flag "fcontext-stack"              (intSuffix (\n d -> d{ ctxtStkDepth = n }))
  , Flag "fstrictness-before"          (intSuffix (\n d -> d{ strictnessBefore = n : strictnessBefore d }))
  , Flag "ffloat-lam-args"             (intSuffix (\n d -> d{ floatLamArgs = Just n }))
  , Flag "ffloat-all-lams"             (noArg (\d -> d{ floatLamArgs = Nothing }))

  , Flag "fhistory-size"               (intSuffix (\n d -> d{ historySize = n }))

  , Flag "funfolding-creation-threshold" (intSuffix   (\n d -> d {ufCreationThreshold = n}))
  , Flag "funfolding-use-threshold"      (intSuffix   (\n d -> d {ufUseThreshold = n}))
  , Flag "funfolding-fun-discount"       (intSuffix   (\n d -> d {ufFunAppDiscount = n}))
  , Flag "funfolding-dict-discount"      (intSuffix   (\n d -> d {ufDictDiscount = n}))
  , Flag "funfolding-keeness-factor"     (floatSuffix (\n d -> d {ufKeenessFactor = n}))

  , Flag "fmax-worker-args" (intSuffix (\n d -> d {maxWorkerArgs = n}))

  , Flag "fghci-hist-size" (intSuffix (\n d -> d {ghciHistSize = n}))

        ------ Profiling ----------------------------------------------------

        -- OLD profiling flags
  , Flag "auto-all"              (noArg (\d -> d { profAuto = ProfAutoAll } ))
  , Flag "no-auto-all"           (noArg (\d -> d { profAuto = NoProfAuto } ))
  , Flag "auto"                  (noArg (\d -> d { profAuto = ProfAutoExports } ))
  , Flag "no-auto"               (noArg (\d -> d { profAuto = NoProfAuto } ))
  , Flag "caf-all"               (NoArg (setGeneralFlag Opt_AutoSccsOnIndividualCafs))
  , Flag "no-caf-all"            (NoArg (unSetGeneralFlag Opt_AutoSccsOnIndividualCafs))

        -- NEW profiling flags
  , Flag "fprof-auto"             (noArg (\d -> d { profAuto = ProfAutoAll } ))
  , Flag "fprof-auto-top"         (noArg (\d -> d { profAuto = ProfAutoTop } ))
  , Flag "fprof-auto-exported"    (noArg (\d -> d { profAuto = ProfAutoExports } ))
  , Flag "fprof-auto-calls"       (noArg (\d -> d { profAuto = ProfAutoCalls } ))
  , Flag "fno-prof-auto"          (noArg (\d -> d { profAuto = NoProfAuto } ))

        ------ Compiler flags -----------------------------------------------

  , Flag "fasm"             (NoArg (setObjTarget HscAsm))
  , Flag "fvia-c"           (NoArg
         (addWarn "The -fvia-c flag does nothing; it will be removed in a future GHC release"))
  , Flag "fvia-C"           (NoArg
         (addWarn "The -fvia-C flag does nothing; it will be removed in a future GHC release"))
  , Flag "fllvm"            (NoArg (setObjTarget HscLlvm))

  , Flag "fno-code"         (NoArg (do upd $ \d -> d{ ghcLink=NoLink }
                                       setTarget HscNothing))
  , Flag "fbyte-code"       (NoArg (setTarget HscInterpreted))
  , Flag "fobject-code"     (NoArg (setTargetWithPlatform defaultHscTarget))
  , Flag "fglasgow-exts"    (NoArg (enableGlasgowExts >> deprecate "Use individual extensions instead"))
  , Flag "fno-glasgow-exts" (NoArg (disableGlasgowExts >> deprecate "Use individual extensions instead"))

        ------ Safe Haskell flags -------------------------------------------
  , Flag "fpackage-trust"   (NoArg setPackageTrust)
  , Flag "fno-safe-infer"   (NoArg (setSafeHaskell Sf_None))
  , Flag "fPIC"             (NoArg (setGeneralFlag Opt_PIC))
  , Flag "fno-PIC"          (NoArg (unSetGeneralFlag Opt_PIC))
 ]
 ++ map (mkFlag turnOn  ""     setGeneralFlag  ) negatableFlags
 ++ map (mkFlag turnOff "no-"  unSetGeneralFlag) negatableFlags
 ++ map (mkFlag turnOn  "d"    setGeneralFlag  ) dFlags
 ++ map (mkFlag turnOff "dno-" unSetGeneralFlag) dFlags
 ++ map (mkFlag turnOn  "f"    setGeneralFlag  ) fFlags
 ++ map (mkFlag turnOff "fno-" unSetGeneralFlag) fFlags
 ++ map (mkFlag turnOn  "f"    setWarningFlag  ) fWarningFlags
 ++ map (mkFlag turnOff "fno-" unSetWarningFlag) fWarningFlags
 ++ map (mkFlag turnOn  "f"    setExtensionFlag  ) fLangFlags
 ++ map (mkFlag turnOff "fno-" unSetExtensionFlag) fLangFlags
 ++ map (mkFlag turnOn  "X"    setExtensionFlag  ) xFlags
 ++ map (mkFlag turnOff "XNo"  unSetExtensionFlag) xFlags
 ++ map (mkFlag turnOn  "X"    setLanguage) languageFlags
 ++ map (mkFlag turnOn  "X"    setSafeHaskell) safeHaskellFlags
 ++ [ Flag "XGenerics"       (NoArg (deprecate "it does nothing; look into -XDefaultSignatures and -XDeriveGeneric for generic programming support."))
    , Flag "XNoGenerics"     (NoArg (deprecate "it does nothing; look into -XDefaultSignatures and -XDeriveGeneric for generic programming support.")) ]
dynamic_flags = [
    Flag "n"        (NoArg (addWarn "The -n flag is deprecated and no longer has any effect"))
  , Flag "cpp"      (NoArg (setExtensionFlag Opt_Cpp))
  , Flag "F"        (NoArg (setGeneralFlag Opt_Pp))
  , Flag "#include"
         (HasArg (\s -> do addCmdlineHCInclude s
                           addWarn "-#include and INCLUDE pragmas are deprecated: They no longer have any effect"))
  , Flag "v"        (OptIntSuffix setVerbosity)

  , Flag "j"        (OptIntSuffix (\n -> upd (\d -> d {parMakeCount = n})))

        ------- ways --------------------------------------------------------
  , Flag "prof"           (NoArg (addWay WayProf))
  , Flag "eventlog"       (NoArg (addWay WayEventLog))
  , Flag "parallel"       (NoArg (addWay WayPar))
  , Flag "gransim"        (NoArg (addWay WayGran))
  , Flag "smp"            (NoArg (addWay WayThreaded >> deprecate "Use -threaded instead"))
  , Flag "debug"          (NoArg (addWay WayDebug))
  , Flag "ndp"            (NoArg (addWay WayNDP))
  , Flag "threaded"       (NoArg (addWay WayThreaded))

  , Flag "ticky"          (NoArg (setGeneralFlag Opt_Ticky >> addWay WayDebug))

    -- -ticky enables ticky-ticky code generation, and also implies -debug which
    -- is required to get the RTS ticky support.

        ----- Linker --------------------------------------------------------
  , Flag "static"         (NoArg removeWayDyn)
  , Flag "dynamic"        (NoArg (addWay WayDyn))
    -- ignored for compat w/ gcc:
  , Flag "rdynamic"       (NoArg (return ()))
  , Flag "relative-dynlib-paths"  (NoArg (setGeneralFlag Opt_RelativeDynlibPaths))

        ------- Specific phases  --------------------------------------------
    -- need to appear before -pgmL to be parsed as LLVM flags.
  , Flag "pgmlo"          (hasArg (\f -> alterSettings (\s -> s { sPgm_lo  = (f,[])})))
  , Flag "pgmlc"          (hasArg (\f -> alterSettings (\s -> s { sPgm_lc  = (f,[])})))
  , Flag "pgmL"           (hasArg (\f -> alterSettings (\s -> s { sPgm_L   = f})))
  , Flag "pgmP"           (hasArg setPgmP)
  , Flag "pgmF"           (hasArg (\f -> alterSettings (\s -> s { sPgm_F   = f})))
  , Flag "pgmc"           (hasArg (\f -> alterSettings (\s -> s { sPgm_c   = (f,[])})))
  , Flag "pgmm"           (HasArg (\_ -> addWarn "The -pgmm flag does nothing; it will be removed in a future GHC release"))
  , Flag "pgms"           (hasArg (\f -> alterSettings (\s -> s { sPgm_s   = (f,[])})))
  , Flag "pgma"           (hasArg (\f -> alterSettings (\s -> s { sPgm_a   = (f,[])})))
  , Flag "pgml"           (hasArg (\f -> alterSettings (\s -> s { sPgm_l   = (f,[])})))
  , Flag "pgmdll"         (hasArg (\f -> alterSettings (\s -> s { sPgm_dll = (f,[])})))
  , Flag "pgmwindres"     (hasArg (\f -> alterSettings (\s -> s { sPgm_windres = f})))
  , Flag "pgmlibtool"     (hasArg (\f -> alterSettings (\s -> s { sPgm_libtool = f})))

    -- need to appear before -optl/-opta to be parsed as LLVM flags.
  , Flag "optlo"          (hasArg (\f -> alterSettings (\s -> s { sOpt_lo  = f : sOpt_lo s})))
  , Flag "optlc"          (hasArg (\f -> alterSettings (\s -> s { sOpt_lc  = f : sOpt_lc s})))
  , Flag "optL"           (hasArg (\f -> alterSettings (\s -> s { sOpt_L   = f : sOpt_L s})))
  , Flag "optP"           (hasArg addOptP)
  , Flag "optF"           (hasArg (\f -> alterSettings (\s -> s { sOpt_F   = f : sOpt_F s})))
  , Flag "optc"           (hasArg addOptc)
  , Flag "optm"           (HasArg (\_ -> addWarn "The -optm flag does nothing; it will be removed in a future GHC release"))
  , Flag "opta"           (hasArg (\f -> alterSettings (\s -> s { sOpt_a   = f : sOpt_a s})))
  , Flag "optl"           (hasArg addOptl)
  , Flag "optwindres"     (hasArg (\f -> alterSettings (\s -> s { sOpt_windres = f : sOpt_windres s})))

  , Flag "split-objs"
         (NoArg (if can_split
                 then setGeneralFlag Opt_SplitObjs
                 else addWarn "ignoring -fsplit-objs"))

        -------- ghc -M -----------------------------------------------------
  , Flag "dep-suffix"     (hasArg addDepSuffix)
  , Flag "optdep-s"       (hasArgDF addDepSuffix "Use -dep-suffix instead")
  , Flag "dep-makefile"   (hasArg setDepMakefile)
  , Flag "optdep-f"       (hasArgDF setDepMakefile "Use -dep-makefile instead")
  , Flag "optdep-w"       (NoArg  (deprecate "doesn't do anything"))
  , Flag "include-pkg-deps"         (noArg (setDepIncludePkgDeps True))
  , Flag "optdep--include-prelude"  (noArgDF (setDepIncludePkgDeps True) "Use -include-pkg-deps instead")
  , Flag "optdep--include-pkg-deps" (noArgDF (setDepIncludePkgDeps True) "Use -include-pkg-deps instead")
  , Flag "exclude-module"           (hasArg addDepExcludeMod)
  , Flag "optdep--exclude-module"   (hasArgDF addDepExcludeMod "Use -exclude-module instead")
  , Flag "optdep-x"                 (hasArgDF addDepExcludeMod "Use -exclude-module instead")

        -------- Linking ----------------------------------------------------
  , Flag "no-link"            (noArg (\d -> d{ ghcLink=NoLink }))
  , Flag "shared"             (noArg (\d -> d{ ghcLink=LinkDynLib }))
  , Flag "staticlib"          (noArg (\d -> d{ ghcLink=LinkStaticLib }))
  , Flag "dynload"            (hasArg parseDynLibLoaderMode)
  , Flag "dylib-install-name" (hasArg setDylibInstallName)
    -- -dll-split is an internal flag, used only during the GHC build
  , Flag "dll-split"          (hasArg (\f d -> d{ dllSplitFile = Just f, dllSplit = Nothing }))

        ------- Libraries ---------------------------------------------------
  , Flag "L"   (Prefix addLibraryPath)
  , Flag "l"   (hasArg (addLdInputs . Option . ("-l" ++)))

        ------- Frameworks --------------------------------------------------
        -- -framework-path should really be -F ...
  , Flag "framework-path" (HasArg addFrameworkPath)
  , Flag "framework"      (hasArg addCmdlineFramework)

        ------- Output Redirection ------------------------------------------
  , Flag "odir"              (hasArg setObjectDir)
  , Flag "o"                 (sepArg (setOutputFile . Just))
  , Flag "dyno"              (sepArg (setDynOutputFile . Just))
  , Flag "ohi"               (hasArg (setOutputHi . Just ))
  , Flag "osuf"              (hasArg setObjectSuf)
  , Flag "dynosuf"           (hasArg setDynObjectSuf)
  , Flag "hcsuf"             (hasArg setHcSuf)
  , Flag "hisuf"             (hasArg setHiSuf)
  , Flag "dynhisuf"          (hasArg setDynHiSuf)
  , Flag "hidir"             (hasArg setHiDir)
  , Flag "tmpdir"            (hasArg setTmpDir)
  , Flag "stubdir"           (hasArg setStubDir)
  , Flag "dumpdir"           (hasArg setDumpDir)
  , Flag "outputdir"         (hasArg setOutputDir)
  , Flag "ddump-file-prefix" (hasArg (setDumpPrefixForce . Just))

  , Flag "dynamic-too"       (NoArg (setGeneralFlag Opt_BuildDynamicToo))

        ------- Keeping temporary files -------------------------------------
     -- These can be singular (think ghc -c) or plural (think ghc --make)
  , Flag "keep-hc-file"     (NoArg (setGeneralFlag Opt_KeepHcFiles))
  , Flag "keep-hc-files"    (NoArg (setGeneralFlag Opt_KeepHcFiles))
  , Flag "keep-s-file"      (NoArg (setGeneralFlag Opt_KeepSFiles))
  , Flag "keep-s-files"     (NoArg (setGeneralFlag Opt_KeepSFiles))
  , Flag "keep-raw-s-file"  (NoArg (addWarn "The -keep-raw-s-file flag does nothing; it will be removed in a future GHC release"))
  , Flag "keep-raw-s-files" (NoArg (addWarn "The -keep-raw-s-files flag does nothing; it will be removed in a future GHC release"))
  , Flag "keep-llvm-file"   (NoArg (do setObjTarget HscLlvm
                                       setGeneralFlag Opt_KeepLlvmFiles))
  , Flag "keep-llvm-files"  (NoArg (do setObjTarget HscLlvm
                                       setGeneralFlag Opt_KeepLlvmFiles))
     -- This only makes sense as plural
  , Flag "keep-tmp-files"   (NoArg (setGeneralFlag Opt_KeepTmpFiles))

        ------- Miscellaneous ----------------------------------------------
  , Flag "no-auto-link-packages" (NoArg (unSetGeneralFlag Opt_AutoLinkPackages))
  , Flag "no-hs-main"     (NoArg (setGeneralFlag Opt_NoHsMain))
  , Flag "with-rtsopts"   (HasArg setRtsOpts)
  , Flag "rtsopts"        (NoArg (setRtsOptsEnabled RtsOptsAll))
  , Flag "rtsopts=all"    (NoArg (setRtsOptsEnabled RtsOptsAll))
  , Flag "rtsopts=some"   (NoArg (setRtsOptsEnabled RtsOptsSafeOnly))
  , Flag "rtsopts=none"   (NoArg (setRtsOptsEnabled RtsOptsNone))
  , Flag "no-rtsopts"     (NoArg (setRtsOptsEnabled RtsOptsNone))
  , Flag "main-is"        (SepArg setMainIs)
  , Flag "haddock"        (NoArg (setGeneralFlag Opt_Haddock))
  , Flag "haddock-opts"   (hasArg addHaddockOpts)
  , Flag "hpcdir"         (SepArg setOptHpcDir)
  , Flag "ghci-script"    (hasArg addGhciScript)
  , Flag "interactive-print" (hasArg setInteractivePrint)
  , Flag "ticky-allocd"      (NoArg (setGeneralFlag Opt_Ticky_Allocd))
  , Flag "ticky-LNE"         (NoArg (setGeneralFlag Opt_Ticky_LNE))
  , Flag "ticky-dyn-thunk"   (NoArg (setGeneralFlag Opt_Ticky_Dyn_Thunk))
        ------- recompilation checker --------------------------------------
  , Flag "recomp"         (NoArg (do unSetGeneralFlag Opt_ForceRecomp
                                     deprecate "Use -fno-force-recomp instead"))
  , Flag "no-recomp"      (NoArg (do setGeneralFlag Opt_ForceRecomp
                                     deprecate "Use -fforce-recomp instead"))

        ------ HsCpp opts ---------------------------------------------------
  , Flag "D"              (AnySuffix (upd . addOptP))
  , Flag "U"              (AnySuffix (upd . addOptP))

        ------- Include/Import Paths ----------------------------------------
  , Flag "I"              (Prefix    addIncludePath)
  , Flag "i"              (OptPrefix addImportPath)

        ------ Output style options -----------------------------------------
  , Flag "dppr-user-length" (intSuffix (\n d -> d{ pprUserLength = n }))
  , Flag "dppr-cols"        (intSuffix (\n d -> d{ pprCols = n }))
  , Flag "dtrace-level"     (intSuffix (\n d -> d{ traceLevel = n }))
  -- Suppress all that is suppressable in core dumps.
  -- Except for uniques, as some simplifier phases introduce new varibles that
  -- have otherwise identical names.
  , Flag "dsuppress-all"    (NoArg $ do setGeneralFlag Opt_SuppressCoercions
                                        setGeneralFlag Opt_SuppressVarKinds
                                        setGeneralFlag Opt_SuppressModulePrefixes
                                        setGeneralFlag Opt_SuppressTypeApplications
                                        setGeneralFlag Opt_SuppressIdInfo
                                        setGeneralFlag Opt_SuppressTypeSignatures)

        ------ Debugging ----------------------------------------------------
  , Flag "dstg-stats"     (NoArg (setGeneralFlag Opt_StgStats))

  , Flag "ddump-cmm"               (setDumpFlag Opt_D_dump_cmm)
  , Flag "ddump-cmm-raw"           (setDumpFlag Opt_D_dump_cmm_raw)
  , Flag "ddump-cmm-cfg"           (setDumpFlag Opt_D_dump_cmm_cfg)
  , Flag "ddump-cmm-cbe"           (setDumpFlag Opt_D_dump_cmm_cbe)
  , Flag "ddump-cmm-proc"          (setDumpFlag Opt_D_dump_cmm_proc)
  , Flag "ddump-cmm-sink"          (setDumpFlag Opt_D_dump_cmm_sink)
  , Flag "ddump-cmm-sp"            (setDumpFlag Opt_D_dump_cmm_sp)
  , Flag "ddump-cmm-procmap"       (setDumpFlag Opt_D_dump_cmm_procmap)
  , Flag "ddump-cmm-split"         (setDumpFlag Opt_D_dump_cmm_split)
  , Flag "ddump-cmm-info"          (setDumpFlag Opt_D_dump_cmm_info)
  , Flag "ddump-cmm-cps"           (setDumpFlag Opt_D_dump_cmm_cps)
  , Flag "ddump-core-stats"        (setDumpFlag Opt_D_dump_core_stats)
  , Flag "ddump-asm"               (setDumpFlag Opt_D_dump_asm)
  , Flag "ddump-asm-native"        (setDumpFlag Opt_D_dump_asm_native)
  , Flag "ddump-asm-liveness"      (setDumpFlag Opt_D_dump_asm_liveness)
  , Flag "ddump-asm-regalloc"      (setDumpFlag Opt_D_dump_asm_regalloc)
  , Flag "ddump-asm-conflicts"     (setDumpFlag Opt_D_dump_asm_conflicts)
  , Flag "ddump-asm-regalloc-stages" (setDumpFlag Opt_D_dump_asm_regalloc_stages)
  , Flag "ddump-asm-stats"         (setDumpFlag Opt_D_dump_asm_stats)
  , Flag "ddump-asm-expanded"      (setDumpFlag Opt_D_dump_asm_expanded)
  , Flag "ddump-llvm"              (NoArg (do setObjTarget HscLlvm
                                              setDumpFlag' Opt_D_dump_llvm))
  , Flag "ddump-deriv"             (setDumpFlag Opt_D_dump_deriv)
  , Flag "ddump-ds"                (setDumpFlag Opt_D_dump_ds)
  , Flag "ddump-foreign"           (setDumpFlag Opt_D_dump_foreign)
  , Flag "ddump-inlinings"         (setDumpFlag Opt_D_dump_inlinings)
  , Flag "ddump-rule-firings"      (setDumpFlag Opt_D_dump_rule_firings)
  , Flag "ddump-rule-rewrites"     (setDumpFlag Opt_D_dump_rule_rewrites)
  , Flag "ddump-simpl-trace"       (setDumpFlag Opt_D_dump_simpl_trace)
  , Flag "ddump-occur-anal"        (setDumpFlag Opt_D_dump_occur_anal)
  , Flag "ddump-parsed"            (setDumpFlag Opt_D_dump_parsed)
  , Flag "ddump-rn"                (setDumpFlag Opt_D_dump_rn)
  , Flag "ddump-core-pipeline"     (setDumpFlag Opt_D_dump_core_pipeline)
  , Flag "ddump-simpl"             (setDumpFlag Opt_D_dump_simpl)
  , Flag "ddump-simpl-iterations"  (setDumpFlag Opt_D_dump_simpl_iterations)
  , Flag "ddump-simpl-phases"      (OptPrefix setDumpSimplPhases)
  , Flag "ddump-spec"              (setDumpFlag Opt_D_dump_spec)
  , Flag "ddump-prep"              (setDumpFlag Opt_D_dump_prep)
  , Flag "ddump-stg"               (setDumpFlag Opt_D_dump_stg)
  , Flag "ddump-stranal"           (setDumpFlag Opt_D_dump_stranal)
  , Flag "ddump-tc"                (setDumpFlag Opt_D_dump_tc)
  , Flag "ddump-types"             (setDumpFlag Opt_D_dump_types)
  , Flag "ddump-rules"             (setDumpFlag Opt_D_dump_rules)
  , Flag "ddump-cse"               (setDumpFlag Opt_D_dump_cse)
  , Flag "ddump-worker-wrapper"    (setDumpFlag Opt_D_dump_worker_wrapper)
  , Flag "ddump-rn-trace"          (setDumpFlag Opt_D_dump_rn_trace)
  , Flag "ddump-if-trace"          (setDumpFlag Opt_D_dump_if_trace)
  , Flag "ddump-cs-trace"          (setDumpFlag Opt_D_dump_cs_trace)
  , Flag "ddump-tc-trace"          (setDumpFlag Opt_D_dump_tc_trace)
  , Flag "ddump-vt-trace"          (setDumpFlag Opt_D_dump_vt_trace)
  , Flag "ddump-splices"           (setDumpFlag Opt_D_dump_splices)
  , Flag "ddump-rn-stats"          (setDumpFlag Opt_D_dump_rn_stats)
  , Flag "ddump-opt-cmm"           (setDumpFlag Opt_D_dump_opt_cmm)
  , Flag "ddump-simpl-stats"       (setDumpFlag Opt_D_dump_simpl_stats)
  , Flag "ddump-bcos"              (setDumpFlag Opt_D_dump_BCOs)
  , Flag "dsource-stats"           (setDumpFlag Opt_D_source_stats)
  , Flag "dverbose-core2core"      (NoArg (do setVerbosity (Just 2)
                                              setVerboseCore2Core))
  , Flag "dverbose-stg2stg"        (setDumpFlag Opt_D_verbose_stg2stg)
  , Flag "ddump-hi"                (setDumpFlag Opt_D_dump_hi)
  , Flag "ddump-minimal-imports"   (NoArg (setGeneralFlag Opt_D_dump_minimal_imports))
  , Flag "ddump-vect"              (setDumpFlag Opt_D_dump_vect)
  , Flag "ddump-hpc"               (setDumpFlag Opt_D_dump_ticked) -- back compat
  , Flag "ddump-ticked"            (setDumpFlag Opt_D_dump_ticked)
  , Flag "ddump-mod-cycles"        (setDumpFlag Opt_D_dump_mod_cycles)
  , Flag "ddump-view-pattern-commoning" (setDumpFlag Opt_D_dump_view_pattern_commoning)
  , Flag "ddump-to-file"           (NoArg (setGeneralFlag Opt_DumpToFile))
  , Flag "ddump-hi-diffs"          (setDumpFlag Opt_D_dump_hi_diffs)
  , Flag "ddump-rtti"              (setDumpFlag Opt_D_dump_rtti)
  , Flag "dcore-lint"              (NoArg (setGeneralFlag Opt_DoCoreLinting))
  , Flag "dstg-lint"               (NoArg (setGeneralFlag Opt_DoStgLinting))
  , Flag "dcmm-lint"               (NoArg (setGeneralFlag Opt_DoCmmLinting))
  , Flag "dasm-lint"               (NoArg (setGeneralFlag Opt_DoAsmLinting))
  , Flag "dshow-passes"            (NoArg (do forceRecompile
                                              setVerbosity $ Just 2))
  , Flag "dfaststring-stats"       (NoArg (setGeneralFlag Opt_D_faststring_stats))
  , Flag "dno-llvm-mangler"        (NoArg (setGeneralFlag Opt_NoLlvmMangler)) -- hidden flag

        ------ Machine dependant (-m<blah>) stuff ---------------------------

  , Flag "monly-2-regs" (NoArg (addWarn "The -monly-2-regs flag does nothing; it will be removed in a future GHC release"))
  , Flag "monly-3-regs" (NoArg (addWarn "The -monly-3-regs flag does nothing; it will be removed in a future GHC release"))
  , Flag "monly-4-regs" (NoArg (addWarn "The -monly-4-regs flag does nothing; it will be removed in a future GHC release"))
  , Flag "msse"         (versionSuffix (\maj min d -> d{ sseVersion = Just (maj, min) }))
  , Flag "mavx"         (noArg (\d -> d{ avx = True }))
  , Flag "mavx2"        (noArg (\d -> d{ avx2 = True }))
  , Flag "mavx512cd"    (noArg (\d -> d{ avx512cd = True }))
  , Flag "mavx512er"    (noArg (\d -> d{ avx512er = True }))
  , Flag "mavx512f"     (noArg (\d -> d{ avx512f = True }))
  , Flag "mavx512pf"    (noArg (\d -> d{ avx512pf = True }))

     ------ Warning opts -------------------------------------------------
  , Flag "W"      (NoArg (mapM_ setWarningFlag minusWOpts))
  , Flag "Werror" (NoArg (setGeneralFlag           Opt_WarnIsError))
  , Flag "Wwarn"  (NoArg (unSetGeneralFlag         Opt_WarnIsError))
  , Flag "Wall"   (NoArg (mapM_ setWarningFlag minusWallOpts))
  , Flag "Wnot"   (NoArg (do upd (\dfs -> dfs {warningFlags = IntSet.empty})
                             deprecate "Use -w instead"))
  , Flag "w"      (NoArg (upd (\dfs -> dfs {warningFlags = IntSet.empty})))

        ------ Plugin flags ------------------------------------------------
  , Flag "fplugin-opt" (hasArg addPluginModuleNameOption)
  , Flag "fplugin"     (hasArg addPluginModuleName)

        ------ Optimisation flags ------------------------------------------
  , Flag "O"      (noArgM (setOptLevel 1))
  , Flag "Onot"   (noArgM (\dflags -> do deprecate "Use -O0 instead"
                                         setOptLevel 0 dflags))
  , Flag "Odph"   (noArgM setDPHOpt)
  , Flag "O"      (optIntSuffixM (\mb_n -> setOptLevel (mb_n `orElse` 1)))
                -- If the number is missing, use 1


  , Flag "fmax-relevant-binds"         (intSuffix (\n d -> d{ maxRelevantBinds = Just n }))
  , Flag "fno-max-relevant-binds"      (noArg (\d -> d{ maxRelevantBinds = Nothing }))
  , Flag "fsimplifier-phases"          (intSuffix (\n d -> d{ simplPhases = n }))
  , Flag "fmax-simplifier-iterations"  (intSuffix (\n d -> d{ maxSimplIterations = n }))
  , Flag "fsimpl-tick-factor"          (intSuffix (\n d -> d{ simplTickFactor = n }))
  , Flag "fspec-constr-threshold"      (intSuffix (\n d -> d{ specConstrThreshold = Just n }))
  , Flag "fno-spec-constr-threshold"   (noArg (\d -> d{ specConstrThreshold = Nothing }))
  , Flag "fspec-constr-count"          (intSuffix (\n d -> d{ specConstrCount = Just n }))
  , Flag "fno-spec-constr-count"       (noArg (\d -> d{ specConstrCount = Nothing }))
  , Flag "fspec-constr-recursive"      (intSuffix (\n d -> d{ specConstrRecursive = n }))
  , Flag "fliberate-case-threshold"    (intSuffix (\n d -> d{ liberateCaseThreshold = Just n }))
  , Flag "fno-liberate-case-threshold" (noArg (\d -> d{ liberateCaseThreshold = Nothing }))
  , Flag "frule-check"                 (sepArg (\s d -> d{ ruleCheck = Just s }))
  , Flag "fcontext-stack"              (intSuffix (\n d -> d{ ctxtStkDepth = n }))
  , Flag "fstrictness-before"          (intSuffix (\n d -> d{ strictnessBefore = n : strictnessBefore d }))
  , Flag "ffloat-lam-args"             (intSuffix (\n d -> d{ floatLamArgs = Just n }))
  , Flag "ffloat-all-lams"             (noArg (\d -> d{ floatLamArgs = Nothing }))

  , Flag "fhistory-size"               (intSuffix (\n d -> d{ historySize = n }))

  , Flag "funfolding-creation-threshold" (intSuffix   (\n d -> d {ufCreationThreshold = n}))
  , Flag "funfolding-use-threshold"      (intSuffix   (\n d -> d {ufUseThreshold = n}))
  , Flag "funfolding-fun-discount"       (intSuffix   (\n d -> d {ufFunAppDiscount = n}))
  , Flag "funfolding-dict-discount"      (intSuffix   (\n d -> d {ufDictDiscount = n}))
  , Flag "funfolding-keeness-factor"     (floatSuffix (\n d -> d {ufKeenessFactor = n}))

  , Flag "fmax-worker-args" (intSuffix (\n d -> d {maxWorkerArgs = n}))

  , Flag "fghci-hist-size" (intSuffix (\n d -> d {ghciHistSize = n}))

        ------ Profiling ----------------------------------------------------

        -- OLD profiling flags
  , Flag "auto-all"              (noArg (\d -> d { profAuto = ProfAutoAll } ))
  , Flag "no-auto-all"           (noArg (\d -> d { profAuto = NoProfAuto } ))
  , Flag "auto"                  (noArg (\d -> d { profAuto = ProfAutoExports } ))
  , Flag "no-auto"               (noArg (\d -> d { profAuto = NoProfAuto } ))
  , Flag "caf-all"               (NoArg (setGeneralFlag Opt_AutoSccsOnIndividualCafs))
  , Flag "no-caf-all"            (NoArg (unSetGeneralFlag Opt_AutoSccsOnIndividualCafs))

        -- NEW profiling flags
  , Flag "fprof-auto"             (noArg (\d -> d { profAuto = ProfAutoAll } ))
  , Flag "fprof-auto-top"         (noArg (\d -> d { profAuto = ProfAutoTop } ))
  , Flag "fprof-auto-exported"    (noArg (\d -> d { profAuto = ProfAutoExports } ))
  , Flag "fprof-auto-calls"       (noArg (\d -> d { profAuto = ProfAutoCalls } ))
  , Flag "fno-prof-auto"          (noArg (\d -> d { profAuto = NoProfAuto } ))

        ------ Compiler flags -----------------------------------------------

  , Flag "fasm"             (NoArg (setObjTarget HscAsm))
  , Flag "fvia-c"           (NoArg
         (addWarn "The -fvia-c flag does nothing; it will be removed in a future GHC release"))
  , Flag "fvia-C"           (NoArg
         (addWarn "The -fvia-C flag does nothing; it will be removed in a future GHC release"))
  , Flag "fllvm"            (NoArg (setObjTarget HscLlvm))

  , Flag "fno-code"         (NoArg (do upd $ \d -> d{ ghcLink=NoLink }
                                       setTarget HscNothing))
  , Flag "fbyte-code"       (NoArg (setTarget HscInterpreted))
  , Flag "fobject-code"     (NoArg (setTargetWithPlatform defaultHscTarget))
  , Flag "fglasgow-exts"    (NoArg (enableGlasgowExts >> deprecate "Use individual extensions instead"))
  , Flag "fno-glasgow-exts" (NoArg (disableGlasgowExts >> deprecate "Use individual extensions instead"))

        ------ Safe Haskell flags -------------------------------------------
  , Flag "fpackage-trust"   (NoArg setPackageTrust)
  , Flag "fno-safe-infer"   (NoArg (setSafeHaskell Sf_None))
  , Flag "fPIC"             (NoArg (setGeneralFlag Opt_PIC))
  , Flag "fno-PIC"          (NoArg (unSetGeneralFlag Opt_PIC))
 ]
 ++ map (mkFlag turnOn  ""     setGeneralFlag  ) negatableFlags
 ++ map (mkFlag turnOff "no-"  unSetGeneralFlag) negatableFlags
 ++ map (mkFlag turnOn  "d"    setGeneralFlag  ) dFlags
 ++ map (mkFlag turnOff "dno-" unSetGeneralFlag) dFlags
 ++ map (mkFlag turnOn  "f"    setGeneralFlag  ) fFlags
 ++ map (mkFlag turnOff "fno-" unSetGeneralFlag) fFlags
 ++ map (mkFlag turnOn  "f"    setWarningFlag  ) fWarningFlags
 ++ map (mkFlag turnOff "fno-" unSetWarningFlag) fWarningFlags
 ++ map (mkFlag turnOn  "f"    setExtensionFlag  ) fLangFlags
 ++ map (mkFlag turnOff "fno-" unSetExtensionFlag) fLangFlags
 ++ map (mkFlag turnOn  "X"    setExtensionFlag  ) xFlags
 ++ map (mkFlag turnOff "XNo"  unSetExtensionFlag) xFlags
 ++ map (mkFlag turnOn  "X"    setLanguage) languageFlags
 ++ map (mkFlag turnOn  "X"    setSafeHaskell) safeHaskellFlags
 ++ [ Flag "XGenerics"       (NoArg (deprecate "it does nothing; look into -XDefaultSignatures and -XDeriveGeneric for generic programming support."))
    , Flag "XNoGenerics"     (NoArg (deprecate "it does nothing; look into -XDefaultSignatures and -XDeriveGeneric for generic programming support.")) ]