# Macros for building Haskell programs with vendored dependencies
# Designed for use in conjunction with the cabal-vendor utility from Sisyphus
# Vendoring still isn’t supported out of the box in cabal-install
# See: https://github.com/haskell/cabal/issues/10934

%_prepare_cabal_repo cabal-vendor convert

%__cabal /usr/bin/cabal
%_local_cabal %__cabal --config local-repo/config

%cabal_static_opts %{shrink: --enable-debug-info=3
                             --enable-split-sections
                             --disable-executable-stripping
                             --disable-benchmark
                             --disable-tests
                             %ghc_smp_mflags
                             -f "-dynamic"
}

%cabal_vendor_build %{expand:
    %_prepare_cabal_repo
    %_local_cabal %{shrink: build
                            %cabal_static_opts
    } \\\
}

%cabal_vendor_install %_local_cabal %{shrink: install
    --installdir     %buildroot%_bindir
    --install-method copy
    %cabal_static_opts
}

%cabal_vendor_run %_local_cabal %{shrink: run
    %cabal_static_opts
}

%cabal_vendor_test %_local_cabal test
