def argv_to_module_arg_lists(args):
    """Converts module ldflags from argv format to per-module lists.

    Flags are passed to us in the following format:
        ['global flag', '--module', 'flag1', 'flag2', '--module', 'flag 3']

    These should be returned as a list for the global flags and a list of
    per-module lists, i.e.:
        ['global flag'], [['flag1', 'flag2'], ['flag1', 'flag3']]
    """
    modules = [[]]
    for arg in args:
        if arg == '--module':
            modules.append([])
        else:
            modules[-1].append(arg)
    return modules[0], modules[1:]