Skip to content
This repository was archived by the owner on Jun 26, 2025. It is now read-only.

Commit 817ec45

Browse files
authored
Merge pull request #2 from issuu/dunify
Dunify
2 parents f126e96 + cecd845 commit 817ec45

File tree

19 files changed

+156
-123
lines changed

19 files changed

+156
-123
lines changed

.gitignore

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,7 @@
11
_build
22
__pycache__
3-
gen
4-
*.docdir
5-
6-
*.cmo
7-
*.cma
8-
*.cmi
9-
*.out
10-
*.cmx
11-
*.native
12-
*.byte
133

4+
.merlin
145
*.swp
156
*~
167
\#*\#

.merlin

Lines changed: 0 additions & 10 deletions
This file was deleted.

META

Lines changed: 0 additions & 6 deletions
This file was deleted.

Makefile

Lines changed: 11 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,16 @@
1-
BUILD=_build
1+
build:
2+
dune build
23

3-
# By default (if left blank), the generator script searches for
4-
# the opencv4 headers in /usr/include/ and /usr/local/include/.
5-
# Set this variable if your opencv4 headers are located elsewhere.
6-
SYSTEM_INCLUDE_DIR=
4+
install:
5+
dune install
76

8-
GEN=gen
9-
GENERATOR=generator.py
10-
GENERATOR_SRC=$(GENERATOR) hdr_parser.py type_manager.py incl/*
7+
uninstall:
8+
dune uninstall
119

12-
CPP=$(GEN)/opencv.cpp glue.cpp
13-
HEADERS=$(GEN)/opencv.h glue.h
14-
SHARED_LIB=libocamlopencv.so
15-
SHARED_LIBS_INSTALL_DIR=/usr/lib/
16-
INSTALLED_SHARED_LIB=$(SHARED_LIBS_INSTALL_DIR)/$(SHARED_LIB)
10+
run:
11+
dune build @run
1712

18-
MLS=$(GEN)/opencv
19-
FLAGS=-use-ocamlfind
13+
doc:
14+
dune build @doc
2015

21-
LIB_NAME=opencv
22-
LIB_FILES=META $(BUILD)/$(GEN)/opencv.cmxa $(BUILD)/$(GEN)/*.cmx \
23-
$(BUILD)/$(GEN)/*.cmi $(BUILD)/$(GEN)/*.a $(BUILD)/$(GEN)/*.cma
24-
NATIVE_LIB=$(GEN)/opencv.cmxa
25-
BYTE_LIB=$(GEN)/opencv.cma
26-
BUILT_LIBS=$(BUILD)/$(NATIVE_LIB) $(BUILD)/$(BYTE_LIB)
27-
28-
DEMOS=$(wildcard demos/*)
29-
DEMOS_CLEAN=$(DEMOS:=.clean)
30-
31-
default: install
32-
33-
$(GEN)/%: ${GENERATOR_SRC}
34-
@echo "Running generator script"
35-
mkdir -p $(GEN)
36-
./$(GENERATOR) $(GEN) $(SYSTEM_INCLUDE_DIR)
37-
38-
$(BUILD)/$(SHARED_LIB): $(CPP) $(HEADERS)
39-
@echo "Compiling shared library"
40-
mkdir -p $(BUILD)
41-
g++ --shared -fPIC -g -std=c++11 -pedantic -Werror -Wall $(CPP) \
42-
-I `ocamlc -where` `pkg-config --libs --cflags opencv4` \
43-
-o $(BUILD)/$(SHARED_LIB)
44-
chmod 755 $(BUILD)/$(SHARED_LIB)
45-
46-
$(BUILT_LIBS): $(BUILD)/$(SHARED_LIB) $(MLS:=.ml) $(MLS:=.mli)
47-
@echo "Building opencv OCaml library"
48-
ocamlbuild $(FLAGS) $(NATIVE_LIB) $(BYTE_LIB)
49-
50-
$(INSTALLED_SHARED_LIB): $(BUILD)/$(SHARED_LIB)
51-
@echo "Installing shared library"
52-
# needing sudo is unfortunate but we need to put the shared library
53-
# somewhere that the linker will find it
54-
sudo rm -f $(INSTALLED_SHARED_LIB)
55-
sudo cp $(BUILD)/$(SHARED_LIB) $(INSTALLED_SHARED_LIB)
56-
57-
libinstall: $(BUILT_LIBS)
58-
@echo "Installing ocamlfind library"
59-
ocamlfind remove $(LIB_NAME)
60-
ocamlfind install $(LIB_NAME) $(LIB_FILES)
61-
62-
sharedlib: $(BUILD)/$(SHARED_LIB)
63-
lib: $(BUILT_LIBS)
64-
install: $(INSTALLED_SHARED_LIB) libinstall
65-
66-
docs: $(BUILT_LIBS)
67-
ocamlbuild $(FLAGS) -docflags -stars opencv.docdir/index.html
68-
69-
$(DEMOS): $(INSTALLED_SHARED_LIB) libinstall
70-
@echo "Running demo: $@"
71-
# clean first to guarantee that we pick up changes to the library
72-
$(MAKE) -C $@ clean run
73-
74-
$(DEMOS_CLEAN):
75-
# this is a stupid hack
76-
$(MAKE) -C $(basename $@) clean
77-
78-
clean: $(DEMOS_CLEAN)
79-
ocamlbuild -clean
80-
rm -f $(BUILD)/$(SHARED_LIB)
81-
rm -rf $(GEN)
82-
sudo rm -f $(INSTALLED_SHARED_LIB)
83-
ocamlfind remove $(LIB_NAME)
84-
85-
.PHONY: default sharedlib lib libinstall install docs clean \
86-
$(DEMOS) $(DEMOS_CLEAN)
16+
.PHONY: build install uninstall run doc

README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,23 @@
33

44
## Quick start
55

6-
Run `make` to install the library with ocamlfind. You must have OpenCV
6+
Run `make install` to install the library with dune. You must have OpenCV
77
installed on your system.
88

9-
Run `make demos/basic` to run the demo. This demo requires you to
9+
Run `make run` to run the demo. This demo requires you to
1010
provide a video file `demos/basic/test.mp4` as input. It also requires
1111
you to install the `owl` opam package.
1212

13-
Run `make docs` to generate documentation. Open
14-
`opencv.docdir/index.html` to view. Alternatively, view the
13+
Run `make doc` to generate documentation. Open
14+
`_build/default/_doc/_html/index.html` to view. Alternatively, view the
1515
auto-generated docs online:
1616
[API](https://calsign.github.io/ocaml-opencv/).
1717

18+
## Pinning the dev repo
19+
To build and insstall the package directly from the development
20+
repository, use
21+
`opam pin add opencv https://github.com/Calsign/ocaml-opencv.git`
22+
1823
## Goals
1924

2025
- Provide access to the full OpenCV API through OCaml

_tags

Lines changed: 0 additions & 2 deletions
This file was deleted.

config/discover.ml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
module C = Configurator.V1
2+
3+
let () =
4+
C.main ~name:"opencv" (fun c ->
5+
let default : C.Pkg_config.package_conf =
6+
{ libs = []
7+
; cflags = []
8+
}
9+
in
10+
let conf =
11+
match C.Pkg_config.get c with
12+
| None -> default
13+
| Some pc ->
14+
match (C.Pkg_config.query pc ~package:"opencv4") with
15+
| None -> default
16+
| Some deps -> deps
17+
in
18+
19+
C.Flags.write_sexp "c_flags.sexp" conf.cflags;
20+
C.Flags.write_sexp "c_library_flags.sexp" conf.libs)

config/dune

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(executable
2+
(name discover)
3+
(libraries dune-configurator))

demos/basic/.merlin

Lines changed: 0 additions & 2 deletions
This file was deleted.

demos/basic/dune

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(executable
2+
(name basic)
3+
(libraries owl opencv)
4+
)
5+
6+
(rule
7+
(alias run)
8+
(action (run %{exe:basic.exe})))

0 commit comments

Comments
 (0)