---
# file: roles/roles/postgres_pg_rrule/tasks/build.yml

- name: "install build dependencies"
  ansible.builtin.apt:
    name:
      - build-essential
      - git
      - libical-dev
      - "postgresql-server-dev-{{ pg_version }}"
      - qtcreator
      - qt5-qmake

- name: "git clone src"
  ansible.builtin.git:
    repo: https://github.com/petropavel13/pg_rrule.git
    dest: /usr/local/src/pg_rrule

- name: "qmake pg_rrule.pro"
  ansible.builtin.command:
    cmd: qmake pg_rrule.pro
    chdir: "/usr/local/src/pg_rrule/src"
  environment:
      QT_SELECT: qt5

- name: "make"
  community.general.make:
    chdir: "/usr/local/src/pg_rrule/src"

- name: "install"
  ansible.builtin.copy:
    remote_src: true
    src: "{{ item.src }}"
    dest: "{{ item.dest }}"
  loop:
    - {src: "/usr/local/src/pg_rrule/src/libpg_rrule.so.1.0.0", dest: "/usr/lib/postgresql/{{ pg_version }}/lib/pg_rrule.so"}
    - {src: "/usr/local/src/pg_rrule/pg_rrule.control", dest: "/usr/share/postgresql/{{ pg_version }}/extension/pg_rrule.control"}
    - {src: "/usr/local/src/pg_rrule/sql/pg_rrule.sql.in", dest: "/usr/share/postgresql/{{ pg_version }}/extension/pg_rrule--0.2.0.sql"}

- name: "make clean"
  community.general.make:
    chdir: "/usr/local/src/pg_rrule/src"
    target: clean
