From 0fda5a87da428601e05cb5a0b1f46960e62f2193 Mon Sep 17 00:00:00 2001 From: David Allsopp Date: Fri, 17 Jun 2022 12:03:19 +0100 Subject: [PATCH] Generate .install files for opam installations --- .gitignore | 2 +- Makefile | 5 +++++ num.opam | 8 +------- src/Makefile | 45 +++++++++++++++++++++++++++++++++++++++++++-- 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index 885225b..bca155d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,4 @@ test/test.byt test/test.exe .merlin _build/ -num.install +*.install diff --git a/Makefile b/Makefile index f7bb96d..c69ace6 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ test: clean: $(MAKE) -C src clean $(MAKE) -C test clean + rm -f num.install install: $(MAKE) -C src install @@ -20,4 +21,8 @@ uninstall: findlib-uninstall: $(MAKE) -C src findlib-uninstall +.PHONY: opam-% +opam-%: all + cp src/num-$*.install num.install + .PHONY: all test clean install uninstall findlib-install findlib-uninstall diff --git a/num.opam b/num.opam index c26d87f..cd4479c 100644 --- a/num.opam +++ b/num.opam @@ -11,17 +11,11 @@ homepage: "https://github.com/ocaml/num/" bug-reports: "https://github.com/ocaml/num/issues" dev-repo: "git+https://github.com/ocaml/num.git" build: [ - [make] + [make "opam-legacy" {!ocaml:preinstalled} "opam-modern" {ocaml:preinstalled | ocaml:version >= "5.0.0~~"}] [make "test"] {with-test} ] -install: [ - make - "install" {!ocaml:preinstalled} - "findlib-install" {ocaml:preinstalled} -] depends: [ "ocaml" {>= "4.06.0"} - "ocamlfind" {build & >= "1.7.3"} ] conflicts: [ "base-num" ] synopsis: diff --git a/src/Makefile b/src/Makefile index 1db0ca8..1316b5c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -27,7 +27,8 @@ SOURCES_NUM_TOP=\ $(addsuffix .mli,$(MODULES_NUM_TOP)) $(addsuffix .ml,$(MODULES_NUM_TOP)) CMOS_NUM_TOP=$(addsuffix .cmo,$(MODULES_NUM_TOP)) -all:: libnums.$(A) nums.cma num_top.cma META.legacy META.modern META.top +all:: libnums.$(A) nums.cma num_top.cma META.legacy META.modern META.top \ + num-legacy.install num-modern.install ifeq "$(NATIVE_COMPILER)" "true" all:: nums.cmxa @@ -109,6 +110,45 @@ TOINSTALL_STUBS= endif TOINSTALL_NUM_TOP=num_top.cma $(addsuffix .cmi,$(MODULES_NUM_TOP)) +# Generate opam .install files for both installation modes: +# lib_root section +# - num-top files (legacy and modern) +# - num artefacts to ocaml/ (legacy only) +# - dllnums.so to ocaml/stublibs/ (legacy only) +# lib section: +# - num META file +# - num artefacts (modern only) +# stublibs section: +# - dllnums.so (modern only) +define GENERATE_INSTALL_FILE +num-$1.install: + @echo 'lib_root: [' > $$@ + @echo ' "src/META.top" {"num-top/META"}' >> $$@ +$(foreach file,$(TOINSTALL_NUM_TOP), + @echo ' "src/$(file)" {"num-top/$(file)"}' >> $$@) +ifeq "$(1)" "legacy" +$(foreach file,$(TOINSTALL), + @echo ' "src/$(file)" {"ocaml/$(file)"}' >> $$@) +$(foreach file,$(TOINSTALL_STUBS), + @echo ' "src/$(file)" {"ocaml/stublibs/$(file)"}' >> $$@) +endif + @echo ']' >> $$@ + @echo 'lib: [' >> $$@ + @echo ' "src/META.$(1)" {"META"}' >> $$@ +ifeq "$(1)" "modern" +$(foreach file,$(TOINSTALL), + @echo ' "src/$(file)"' >> $$@) + @echo ']' >> $$@ + @echo 'stublibs: [' >> $$@ +$(foreach file,$(TOINSTALL_STUBS), + @echo ' "src/$(file)"' >> $$@) +endif + @echo ']' >> $$@ +endef + +$(eval $(call GENERATE_INSTALL_FILE,legacy)) +$(eval $(call GENERATE_INSTALL_FILE,modern)) + install: num-top-install $(INSTALL_DIR) $(DESTDIR)$(STDLIBDIR) cp META.legacy META @@ -144,7 +184,8 @@ endif clean: rm -f *.cm[ioxta] *.cmx[as] *.cmti *.$(O) *.$(A) *$(EXT_DLL) \ - META.top META.legacy META.modern $(SOURCES_NUM_TOP) + META.top META.legacy META.modern $(SOURCES_NUM_TOP) \ + num-legacy.install num-modern.install $(SOURCES_NUM_TOP:num_=%): $(addprefix ../toplevel/,$(SOURCES_NUM_TOP)) cp $^ .