# relaxed TEXTREL check for all 32-bit architectures for system with installed rpm-build-ocaml
# https://github.com/ocaml/ocaml/issues/9800
%_verify_elf_method %{?_is_ilp32:textrel=relaxed}%{!?_is_ilp32:default}

%ocaml_native_arch x86_64 riscv64 aarch64

%_ocamldir %_libdir/ocaml
%_ocaml_req_skip	""
%add_ocaml_req_skip()	%global _ocaml_req_skip %_ocaml_req_skip [[:space:]]%*$
%__dune %_bindir/dune
%dune_build %__dune build --verbose %_smp_mflags

%ocaml_find_files \
	__ocaml_find_files() \
	{ \
find %buildroot%_ocamldir/ -type f -regextype posix-extended \\\( \\\
                -regex '.*\\\.(cmo|cma|cmi|cmxs|so|js)$' \\\
                \\\) -printf '%_ocamldir/%%P\\\n' >ocaml-files.runtime; \
find %buildroot%_ocamldir/ -type d -printf '%%%%dir %_ocamldir/%%P\\\n' >>ocaml-files.runtime; \
find %buildroot%_ocamldir/ -type f -regextype posix-extended \\\( \\\
                -regex '.*\\\.(a|o|cmt|cmti|cmx|cmxa|ml|mli|exe)$' \\\
                -o -name 'META' \\\
                -o -name 'opam' \\\
                -o -name 'dune-package' \\\
                \\\) -printf '%_ocamldir/%%P\\\n' >ocaml-files.devel; \
	} \
	__ocaml_find_files


%dune_install \
	__dune_install() \
	{ \
		%__dune install --destdir=%buildroot "$@"; \
		%ocaml_find_files \
	} \
	__dune_install

%dune_check %__dune runtest

# Generate per-package file listings for multi-package dune projects
# Usage: %ocaml_find_files_multi [pkg1 pkg2 pkg3 ...]
# Creates: ocaml-files.runtime.pkg1, ocaml-files.devel.pkg1, ...
%ocaml_find_files_multi OCAMLDIR=%_ocamldir BINDIR=%_bindir DATADIR=%_datadir BUILDROOT=%buildroot %_rpmlibdir/ocaml-find-files-multi

# Alternative dune_install for multi-package projects
# Usage: %dune_install_multi [pkg1 pkg2 pkg3 ...]
# Creates per-package file listings instead of single ocaml-files.runtime/devel
%dune_install_multi() %__dune install --destdir=%buildroot %* ; %ocaml_find_files_multi %*

