If I'm doing development between ghci and vim, all the different
dependencies I need get linked in when required without me asking.
Similarly if I call "ghc --make" from the command line. But I have to
write them in manually to my *.cabal file otherwise the compilation
process will fail.

Until now I've just loaded the program in to ghci and noted down all
the dependencies it links in. Am I missing a trick? There must be an
easier way, especially for multiple source files.


I once used this perl script to determine the files I was actually used (to have proper LOC stats). It uses ghc -M which usually outputs the dependencies as makefile targets, and then grep over this to get all the .hs files. If you have different file types you might want to modify this:

#!/usr/bin/env perl

# Prints the .hs files that are actually used to STDOUT

$tmpfile = '/tmp/deps';
$mainfile = 'Foo.hs';
$ghc_deps = `ghc -M $mainfile -optdep-f -optdep$tmpfile`; die "ghc -M failed\n" if $? != 0;

open(INF, "< $tmpfile") || die "Could not open $tempfile\n";

@files = ();

while (<INF>) {
  m/(\w+\.hs)/;
  push(@files, $1);
}

close (INF);

undef %saw;
@nodups = grep(!$saw{$_}++, @files);  # remove duplictes

print join(' ',@nodups), "\n";


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to