'Generate a spec file so the linker adds a rpath to the libs
the compiler used to build the executable.'

@run_after('install')
def write_rpath_specs(self):

    if (not self.spec_dir):
        tty.warn('Could    not    install    specs    for    {0}.'.format(self.spec.format('$_$@')))
        return
    gcc = self.spec['gcc'].command
    lines = gcc('-dumpspecs', output=str).strip().split('\n')
    specs_file = join_path(self.spec_dir, 'specs')
    with open(specs_file, 'w') as out:
        for line in lines:
            out.write((line + '\n'))
            if line.startswith('*link:'):
                out.write('-rpath    {0}:{1}    '.format(self.prefix.lib, self.prefix.lib64))
    set_install_permissions(specs_file)
