|
1 |
| -.SECONDEXPANSION: |
| 1 | +.PHONY: build clean test |
2 | 2 |
|
3 |
| -BEST:=$(shell if ocamlopt > /dev/null 2>&1; then echo native; else echo byte; fi) |
4 |
| -OPAQUE:=$(shell if ocamlopt -opaque 2>/dev/null; then echo -opaque; fi) |
5 |
| -NO_KEEP_LOCS:=$(shell if ocamlopt -no-keep-locs 2>/dev/null; then echo -no-keep-locs; fi) |
6 |
| -DEBUG=true |
7 |
| -COVERAGE=false |
8 |
| -OCAML=ocaml |
9 |
| -OCAMLFIND=ocamlfind $(OCAMLFINDFLAGS) |
10 |
| -HOSTOCAMLFIND=$(OCAMLFIND) |
11 |
| -OCAMLDEP=$(OCAMLFIND) ocamldep |
12 |
| -OCAMLMKLIB=$(OCAMLFIND) ocamlmklib |
13 |
| -VPATH=src examples |
14 |
| -BUILDDIR=_build |
15 |
| -BASE_PROJECTS=configure libffi-abigen configured ctypes ctypes-top |
16 |
| -FOREIGN_PROJECTS=test-libffi ctypes-foreign |
17 |
| -STUB_PROJECTS=cstubs |
18 |
| -PROJECTS=$(BASE_PROJECTS) $(FOREIGN_PROJECTS) $(STUB_PROJECTS) |
19 |
| -DEP_DIRS=$(foreach project,$(PROJECTS),$($(project).dir)) |
20 |
| -GENERATED=src/ctypes/ctypes_primitives.ml \ |
21 |
| - src/ctypes-foreign/libffi_abi.ml \ |
22 |
| - src/ctypes-foreign/dl.ml \ |
23 |
| - src/ctypes-foreign/dl_stubs.c \ |
24 |
| - libffi.config \ |
25 |
| - asneeded.config \ |
26 |
| - discover \ |
27 |
| - gen_c_primitives \ |
28 |
| - gen_c_primitives.log \ |
29 |
| - gen_libffi_abi \ |
30 |
| - src/configure/extract_from_c.cmi \ |
31 |
| - src/configure/extract_from_c.cmo \ |
32 |
| - src/configure/gen_c_primitives.cmi \ |
33 |
| - src/configure/gen_c_primitives.cmo \ |
34 |
| - src/configure/gen_libffi_abi.cmi \ |
35 |
| - src/configure/gen_libffi_abi.cmo \ |
36 |
| - src/discover/commands.cmi \ |
37 |
| - src/discover/commands.cmo \ |
38 |
| - src/discover/discover.cmi \ |
39 |
| - src/discover/discover.cmo |
| 3 | +build: |
| 4 | + dune build |
40 | 5 |
|
41 |
| -OCAML_FFI_INCOPTS=$(libffi_opt) |
42 |
| -export CFLAGS DEBUG |
| 6 | +test: |
| 7 | + dune runtest |
43 | 8 |
|
44 |
| -EXTDLL:=$(shell $(OCAMLFIND) ocamlc -config | awk '/^ext_dll:/{print $$2}') |
45 |
| -OSYSTEM:=$(shell $(OCAMLFIND) ocamlc -config | awk '/^system:/{print $$2}') |
46 |
| - |
47 |
| -ifneq (,$(filter mingw%,$(OSYSTEM))) |
48 |
| -OS_ALT_SUFFIX=.win |
49 |
| -else |
50 |
| -OS_ALT_SUFFIX=.unix |
51 |
| -endif |
52 |
| - |
53 |
| -# public targets |
54 |
| -all: libffi.config $(PROJECTS) |
55 |
| - |
56 |
| -ctypes-base: $(BASE_PROJECTS) |
57 |
| -ctypes-foreign: ctypes-base test-libffi |
58 |
| -ctypes-stubs: ctypes-base $(STUB_PROJECTS) |
59 |
| - |
60 |
| -clean: clean-examples clean-tests |
61 |
| - rm -fr _build |
62 |
| - rm -f $(GENERATED) |
63 |
| - |
64 |
| -# ctypes subproject |
65 |
| -ctypes.cmi_only = ctypes_static ctypes_primitive_types ctypes_structs cstubs_internals |
66 |
| -ctypes.public = lDouble complexL ctypes posixTypes ctypes_types |
67 |
| -ctypes.dir = src/ctypes |
68 |
| -ctypes.extra_mls = ctypes_primitives.ml |
69 |
| -ctypes.deps = bigarray-compat integers |
70 |
| -ctypes.linkdeps = integers_stubs |
71 |
| -ctypes.install = yes |
72 |
| -ctypes.install_native_objects = yes |
73 |
| -ifeq ($(XEN),enable) |
74 |
| -ctypes.xen = yes |
75 |
| -endif |
76 |
| - |
77 |
| -ctypes: PROJECT=ctypes |
78 |
| -ctypes: $(ctypes.dir)/$(ctypes.extra_mls) $$(LIB_TARGETS) |
79 |
| - |
80 |
| -# cstubs subproject |
81 |
| -cstubs.public = cstubs_structs cstubs cstubs_inverted |
82 |
| -cstubs.dir = src/cstubs |
83 |
| -cstubs.subproject_deps = ctypes |
84 |
| -cstubs.deps = str integers |
85 |
| -cstubs.install = yes |
86 |
| -cstubs.install_native_objects = yes |
87 |
| -cstubs.extra_hs = $(package_integers_path)/ocaml_integers.h |
88 |
| - |
89 |
| -cstubs: PROJECT=cstubs |
90 |
| -cstubs: $(cstubs.dir)/$(cstubs.extra_mls) $$(LIB_TARGETS) |
91 |
| - |
92 |
| -# ctypes-foreign subproject |
93 |
| -ctypes-foreign.public = dl libffi_abi foreign |
94 |
| -ctypes-foreign.dir = src/ctypes-foreign |
95 |
| -ctypes-foreign.subproject_deps = ctypes |
96 |
| -ctypes-foreign.deps = integers |
97 |
| -ctypes-foreign.install = yes |
98 |
| -ctypes-foreign.install_native_objects = yes |
99 |
| -ctypes-foreign.extra_cs = dl_stubs.c |
100 |
| -ctypes-foreign.extra_mls = libffi_abi.ml dl.ml |
101 |
| -ctypes-foreign.cmi_opts = $(OPAQUE) $(NO_KEEP_LOCS) |
102 |
| -ctypes-foreign.cmo_opts = $(OCAML_FFI_INCOPTS:%=-ccopt %) |
103 |
| -ctypes-foreign.cmx_opts = $(OCAML_FFI_INCOPTS:%=-ccopt %) |
104 |
| -ctypes-foreign.link_flags = $(libffi_lib) $(lib_process) |
105 |
| -ctypes-foreign.threads = yes |
106 |
| - |
107 |
| -ctypes-foreign: PROJECT=ctypes-foreign |
108 |
| -ctypes-foreign: $$(LIB_TARGETS) |
109 |
| - |
110 |
| -# ctypes-top subproject |
111 |
| -ctypes-top.public = ctypes_printers |
112 |
| -ctypes-top.dir = src/ctypes-top |
113 |
| -ctypes-top.install = yes |
114 |
| -ctypes-top.deps = compiler-libs integers |
115 |
| -ctypes-top.subproject_deps = ctypes |
116 |
| -ctypes-top.install_native_objects = yes |
117 |
| - |
118 |
| -ctypes-top: PROJECT=ctypes-top |
119 |
| -ctypes-top: $$(LIB_TARGETS) |
120 |
| - |
121 |
| -# configuration |
122 |
| -configured: src/ctypes/ctypes_primitives.ml src/ctypes-foreign/libffi_abi.ml src/ctypes-foreign/dl.ml src/ctypes-foreign/dl_stubs.c |
123 |
| - |
124 |
| -src/ctypes-foreign/dl.ml: src/ctypes-foreign/dl.ml$(OS_ALT_SUFFIX) |
125 |
| - cp $< $@ |
126 |
| -src/ctypes-foreign/dl_stubs.c: src/ctypes-foreign/dl_stubs.c$(OS_ALT_SUFFIX) |
127 |
| - cp $< $@ |
128 |
| - |
129 |
| -src/ctypes/ctypes_primitives.ml: src/configure/extract_from_c.ml src/configure/gen_c_primitives.ml |
130 |
| - $(HOSTOCAMLFIND) ocamlc -o gen_c_primitives -package str -strict-sequence -linkpkg $^ -I src/configure |
131 |
| - ./gen_c_primitives > $@ 2> gen_c_primitives.log || (rm $@ && cat gen_c_primitives.log && false) |
132 |
| - |
133 |
| -src/ctypes-foreign/libffi_abi.ml: src/configure/extract_from_c.ml src/configure/gen_libffi_abi.ml |
134 |
| - $(HOSTOCAMLFIND) ocamlc -o gen_libffi_abi -package str -strict-sequence -linkpkg $^ -I src/configure |
135 |
| - ./gen_libffi_abi > $@ 2> gen_c_primitives.log || (rm $@ && cat gen_c_primitives.log && false) |
136 |
| - |
137 |
| -libffi.config: src/discover/commands.mli src/discover/commands.ml src/discover/discover.ml |
138 |
| - $(HOSTOCAMLFIND) ocamlc -o discover -package str -strict-sequence -linkpkg $^ -I src/discover |
139 |
| - ./discover -ocamlc "$(OCAMLFIND) ocamlc" > $@ || (rm $@ && false) |
140 |
| - |
141 |
| -asneeded.config: |
142 |
| - ./src/discover/determine_as_needed_flags.sh >> $@ |
143 |
| - |
144 |
| -# dependencies |
145 |
| -depend: configure |
146 |
| - $(OCAMLDEP) -one-line $(foreach dir,$(DEP_DIRS),-I $(dir)) \ |
147 |
| - $(shell find src examples -name '*.mli' -o -name '*.ml') \ |
148 |
| - | sed "s!src/!_build/src/!g; s!examples/!_build/examples/!g" | sort > .depend |
149 |
| - |
150 |
| -#installation |
151 |
| -META-install: |
152 |
| - $(OCAMLFIND) install ctypes META CHANGES.md |
153 |
| - |
154 |
| -install-%: PROJECT=$* |
155 |
| -install-%: |
156 |
| - $(if $(filter yes,$($(PROJECT).install)),\ |
157 |
| - $(OCAMLFIND) install -add ctypes -optional $^ \ |
158 |
| - $(LIB_TARGETS) $(LIB_TARGET_EXTRAS) \ |
159 |
| - $(INSTALL_MLIS) $(INSTALL_CMIS) \ |
160 |
| - $(INSTALL_CMTS) $(INSTALL_CMTIS) \ |
161 |
| - $(INSTALL_HEADERS) \ |
162 |
| - $(if $(filter yes,$($(PROJECT).install_native_objects)),$(NATIVE_OBJECTS))) |
163 |
| - |
164 |
| -$(PROJECTS:%=install-%): META-install |
165 |
| - |
166 |
| -install: META-install $(PROJECTS:%=install-%) |
167 |
| - |
168 |
| -uninstall: |
169 |
| - $(OCAMLFIND) remove ctypes |
170 |
| - |
171 |
| -DOCFILES=$(foreach project,$(PROJECTS),\ |
172 |
| - $(foreach mli,$($(project).public),\ |
173 |
| - $($(project).dir)/$(mli).mli)) |
174 |
| -DOCFLAGS=-I $(shell ocamlfind query integers) $(foreach project,$(PROJECTS),-I $(BUILDDIR)/$($(project).dir)) |
175 |
| - |
176 |
| -doc: |
177 |
| - ocamldoc -html $(DOCFLAGS) $(DOCFILES) |
178 |
| - |
179 |
| - |
180 |
| -.PHONY: depend clean configure all install doc $(PROJECTS) |
181 |
| - |
182 |
| -include .depend Makefile.rules Makefile.examples Makefile.tests |
183 |
| --include libffi.config |
184 |
| --include asneeded.config |
185 |
| - |
186 |
| -ifeq ($(libffi_available),false) |
187 |
| -test-libffi: |
188 |
| - @echo "The following required C libraries are missing: libffi." |
189 |
| - @echo "Please install them and retry. If they are installed in a non-standard location" |
190 |
| - @echo "or need special flags, set the environment variables <LIB>_CFLAGS and <LIB>_LIBS" |
191 |
| - @echo "accordingly and retry." |
192 |
| - @echo |
193 |
| - @echo " For example, if libffi is installed in /opt/local, you can type:" |
194 |
| - @echo |
195 |
| - @echo " export LIBFFI_CFLAGS=-I/opt/local/include" |
196 |
| - @echo " export LIBFFI_LIBS=\"-L/opt/local/lib -lffi\"" |
197 |
| - @exit 1 |
198 |
| -else: |
199 |
| -test-libffi: |
200 |
| -endif |
| 9 | +clean: |
| 10 | + dune clean |
0 commit comments