# vim: filetype=yaml sw=2
version: '[% c("var/torbrowser_version") %]'
filename: '[% c("var/project-name") %]-[% c("version") %]-[% c("var/build_id") %]'
timestamp: '[% c("var/browser_release_date_timestamp") %]'
container:
  use_container: 1

var:
  system_pkg:
    install_path: 'usr/lib/[% c("var/system_pkg/pkg_name") %]'
    pkg_name: '[% c("var/project-name") %]-[% c("var/channel") %]'
    pkg_version: '[% c("var/torbrowser_version") %]'
    pkg_revision: '1'
    pkg_description: '[% c("var/display_name") %]'
    deb_release_date: '[% USE date; date.format(c("timestamp"), format = "%a, %d %b %Y 01:02:03 +0000", locale = "en_US") %]'
    # https://spdx.github.io/spdx-spec/v2.3/SPDX-license-expressions/
    spdx_license: 'MPL-2.0 AND GPL-3.0-or-later AND OFL-1.1 AND Apache-2.0[% IF c("var/tor-browser") %] AND BSD-3-Clause AND CC0-1.0 AND MIT[% END %]'
    # Use var_p/system_pkg/deb_archs for the processed list
    deb_archs_list:
      - '[% IF c("var/browser-linux-x86_64") %]amd64[% END %]'
      - '[% IF c("var/browser-linux-i686") %]i386[% END %]'


targets:

  deb:
    var:
      build_deb_pkg: 1
      pre_pkginst: |
        dpkg --add-architecture i386
        # some :i386 packages fail to install when /var/lib/dpkg/available
        # does not exist, so create it as an empty file
        echo > /var/lib/dpkg/available
      arch_deps:
        # Packages needed to build the deb package
        - dpkg-dev
        - debhelper
        - dh-exec
        - dh-apparmor
        # Packages needed to generate dependencies for the deb package
        - linux-libc-dev
        - libasound2-dev
        - libfontconfig1-dev
        - libfreetype6-dev
        - libgconf2-dev
        - libgtk-3-dev
        - libpango1.0-dev
        - libpulse-dev
        - libx11-xcb-dev
        - libxt-dev
        - linux-libc-dev:i386
        - libasound2-dev:i386
        - libfontconfig1-dev:i386
        - libfreetype6-dev:i386
        - libgconf2-dev:i386
        - libgtk-3-dev:i386
        - libpango1.0-dev:i386
        - libpulse-dev:i386
        - libx11-xcb-dev:i386
        - libxt-dev:i386

  rpm:
    var:
      build_rpm_pkg: 1

      arch_deps:
        # Packages needed to build the rpm package
        - rpm

      # Use bookworm since rpm version from stretch does not produce
      # reproducible rpm files
      container:
        suite: bookworm

  browser-all:
    - browser-linux-x86_64
    - browser-linux-i686

  browser-all-desktop: browser-all

  browser-linux-x86_64:
    var:
      browser-linux-x86_64: 1
  browser-linux-i686:
    var:
      browser-linux-i686: '[% c("var/browser_type") != "mullvadbrowser" %]'

  torbrowser:
    var:
      browser_type: torbrowser
      system_pkg:
        pkg_description: 'Tor Browser is a privacy-focused web browser designed to minimize tracking and fingerprinting, using the Tor network to protect your privacy and anonymity.'
        pkg_url: 'https://torproject.org/'
  basebrowser:
    var:
      browser_type: basebrowser
  mullvadbrowser:
    var:
      browser_type: mullvadbrowser
      system_pkg:
        pkg_description: 'Mullvad Browser is a privacy-focused web browser designed to minimize tracking and fingerprinting.'
        pkg_url: 'https://mullvad.net/browser'

  release:
    var:
      build_target: release
      system_pkg:
        pkg_name: '[% c("var/project-name") %]'
  nightly:
    var:
      build_target: nightly
      system_pkg:
        # debian package version needs to start with a number
        pkg_version: '[% pc("firefox", "var/browser_series") %]~[% c("var/torbrowser_version") FILTER remove("tbb-nightly.") %]'
  alpha:
    var:
      build_target: alpha
  testbuild:
    var:
      testbuild: 1
      build_target: '[% c("var/browser_type") %]-testbuild'


input_files:

  - project: container-image

  - name: linux-x86_64
    project: browser
    enable: '[% c("var/browser-linux-x86_64") %]'
    target:
      - '[% c("var/build_target") %]'
      - '[% c("var/browser_type") %]-linux-x86_64'

  - name: linux-i686
    project: browser
    enable: '[% c("var/browser-linux-i686") %]'
    target:
      - '[% c("var/build_target") %]'
      - '[% c("var/browser_type") %]-linux-i686'

  - filename: Makefile
    content: "[% INCLUDE 'Makefile.in' %]"
    refresh_input: 1

  - filename: '[% c("var/system_pkg/pkg_name") %].desktop'
    content: "[% INCLUDE 'browser.desktop.in' %]"
    refresh_input: 1
    enable: '[% c("var/build_deb_pkg") || c("var/build_rpm_pkg") %]'

  # Debian Package
  - filename: debian/apparmor
    content: "[% INCLUDE 'debian/apparmor.in' %]"
    refresh_input: 1
    enable: '[% c("var/build_deb_pkg") %]'
  - filename: debian/changelog
    content: "[% INCLUDE 'debian/changelog.in' %]"
    refresh_input: 1
    enable: '[% c("var/build_deb_pkg") %]'
  - filename: debian/compat
    enable: '[% c("var/build_deb_pkg") %]'
  - filename: debian/control
    content: "[% INCLUDE 'debian/control.in' %]"
    refresh_input: 1
    enable: '[% c("var/build_deb_pkg") %]'
  - filename: debian/copyright
    content: "[% INCLUDE 'debian/copyright.in' %]"
    refresh_input: 1
    enable: '[% c("var/build_deb_pkg") %]'
  - filename: debian/docs
    content: "[% INCLUDE 'debian/docs.in' %]"
    refresh_input: 1
    enable: '[% c("var/build_deb_pkg") %]'
  - filename: debian/postinst
    content: "[% INCLUDE 'debian/postinst.in' %]"
    refresh_input: 1
    enable: '[% c("var/build_deb_pkg") %]'
  - filename: debian/rules
    content: "[% INCLUDE 'debian/rules.in' %]"
    refresh_input: 1
    enable: '[% c("var/build_deb_pkg") %]'

  # rpm package
  - filename: '[% c("var/system_pkg/pkg_name") %].spec'
    content: "[% INCLUDE 'rpm-package.spec' %]"
    refresh_input: 1
    enable: '[% c("var/build_rpm_pkg") %]'

--- |
  # This part of the file contains options written in perl
  (
    var_p => {
      system_pkg => {
        deb_archs => sub {
          my ($project, $options) = @_;
          my $deb_archs = project_config($project,
                                    'var/system_pkg/deb_archs_list', $options);
          return [
            grep { $_ } map { process_template($project, $_, '.') } @$deb_archs
          ];
        },
      },
    },
  )
