use alienfile;

probe [ 'pkg-config --exists flac' ];

share {
    start_url 'https://downloads.xiph.org/releases/flac/';
    plugin 'Download' => (
        filter => qr/^flac-.*\.tar\.xz$/,
        version => qr/([0-9\.]+)/,
    );
    plugin 'Extract' => 'tar.xz';
    plugin 'Build::Autoconf';
    build [
        '%{configure} --enable-shared --enable-static',
        '%{make}',
        '%{make} install',
    ];
    gather [
        [ 'pkg-config --cflags flac', \'%{.runtime.cflags}'  ],
        [ 'pkg-config --libs flac', \'%{.runtime.libs}'    ],
        [ 'pkg-config --cflags --static flac', \'%{.runtime.cflags_static}'  ],
        [ 'pkg-config --libs --static flac', \'%{.runtime.libs_static}'    ],
    ];
    plugin 'Gather::IsolateDynamic';
};

sys {
    # the system static libs often aren't compiled with fPIC, so just link dynamically
    gather [
        [ 'pkg-config --cflags flac', \'%{.runtime.cflags}'  ],
        [ 'pkg-config --libs flac', \'%{.runtime.libs}'    ],
    ];
};