#!/usr/bin/perl -w
# usage: perl $0 > SLES-reproducible-builds.spec
use strict;

#system("cd cache ; wget -N https://rb.zq1.de/compare.factory/differed-builds-nachbau.txt");

my $excludes=`cat excludes`;
my %excludes;
foreach(split(/\n/,$excludes)) {
    $excludes{$_} = 1;
}

my $header =
'#
# spec file for package SLES-reproducible-builds
#
# Copyright (c) 2025 SUSE LLC.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

Name:           SLES-reproducible-builds
Version:        16.0.0
Release:        0
License:        MIT
Summary:        Prevent installation of unreproducible packages
BuildArch:      noarch
Source1:        README
Source2:        generate.pl
Source3:        differed-builds.txt
Source4:        includes
Source5:        excludes
';
my $footer =
'
%description
Prevents installation of unreproducible / unverifiable packages
using rpm Conflicts

See https://reproducible-builds.org/ for the general concept.

%prep
cp -a %{S:1} .

%files
%defattr(-,root,root)
%doc README

%changelog
';

open(my $f, "<", "differed-builds.txt") or die $!;
my @l=<$f>;
open($f, "<", "includes") or die $!;
push(@l, <$f>);

print $header;
foreach(sort(@l)) {
    chomp($_);
    s/#.*//; # ignore comments
    next if $excludes{$_};
    next unless /./;
    print "Conflicts:      $_\n";
}
print $footer;
