Skip to content

Commit

Permalink
Generate .install files for opam installations
Browse files Browse the repository at this point in the history
  • Loading branch information
dra27 committed Dec 20, 2022
1 parent 294b372 commit 0fda5a8
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ test/test.byt
test/test.exe
.merlin
_build/
num.install
*.install
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ test:
clean:
$(MAKE) -C src clean
$(MAKE) -C test clean
rm -f num.install

install:
$(MAKE) -C src install
Expand All @@ -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
8 changes: 1 addition & 7 deletions num.opam
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
45 changes: 43 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 $^ .
Expand Down

0 comments on commit 0fda5a8

Please sign in to comment.