Recursively calculate dependencies.