-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathOMakeIncludes
249 lines (223 loc) · 8.2 KB
/
OMakeIncludes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
GetVarEnv(name)=
try
value $(getvar $(name))
default
try
value $(getenv $(name))
default
value $(EMPTY)
String_subst(from, to, s) =
# Create a channel from a string
inx = $(open-in-string $s)
# Perform the substitution collecting results
result[] =
lex-search($(inx))
case $(from)
# Evaluate the replacement in this context
result[] += $"$(to)"
export
default
result[] += $0
export
# Remember to close the input
close($(inx))
# Flatten into a normal string
concat($(EMPTY), $(result))
ConfReplace(file)=
$(file): $(file).in
section:
if $(file-exists $(file))
chmod(0644 $(file))
stdout = $(fopen $(file), w)
fsubst($(file).in)
case $"@\([A-Z0-9_]+\)@" g
getvar($1)
close($(stdout))
if $(not $(equal $(OSTYPE), Win32))
chmod(0444 $(file))
clean::
rm -f $(file)
Repeat_targets(t)=
foreach(f, $(t))
$(f).cmi:
$(f).cmo:
$(f).cmx:
$(f)$(EXT_OBJ):
Repeat_ctargets(t)=
foreach(f, $(t))
$(f)$(EXT_OBJ): $(f).c
Camlp4o(FILES) =
section
OCAMLPACKS+= camlp4
OCAMLFINDFLAGS+= -syntax camlp4o
Repeat_targets($(FILES))
.PHONY:doc
CreateDoc(name,folder,files)=
mlifiles = $(filter-exists $(addsuffix .mli, $(set $(removesuffix $(files)))))
cmifiles = $(addsuffix .cmi, $(removesuffix $(mlifiles)))
if $(USE_OCAMLFIND)
$(name).idoc: $(mlifiles) $(cmifiles) /.PHONY/OCamlGeneratedFilesTarget
$(OCAMLFIND) ocamldoc $(OCAMLFINDFLAGS) -dump $(name).idoc -stars \
$(PREFIXED_OCAMLINCLUDES) -package "$(OCAMLPACKS)" \
$(mlifiles)
else
$(name).idoc: $(mlifiles) $(cmifiles) /.PHONY/OCamlGeneratedFilesTarget
ocamldoc -dump $(name).idoc -stars \
$(PREFIXED_OCAMLINCLUDES) $(mlifiles)
doc:: $(cmifiles) $(name).idoc
mkdir(-m 0755 -p $(folder))
$(OCAMLFIND) ocamldoc $(OCAMLDOCFLAGS) -d html -stars -html $(mapprefix -load, $(name).idoc)
clean::
rm(-r -f $(folder))
rm(-f $(name).idoc)
Regex_ar(regex,ar)=
foreach(f, $(ar))
match $(f)
case $(regex)
return $(f)
return $(string)
static. =
section
if $(not $(CheckProg $(OCAMLFIND)))
$(ConfMsgError $(OCAMLFIND) missing)
config_out=$(shella $(OCAMLFIND) ocamlc -config)
CC_CONFIG=$(Regex_ar $"^bytecomp_c_compiler:",$(config_out))
OCAMLC_CC= $(nth 1, $(CC_CONFIG))
OCAMLC_CC_CFLAGS=$(nth-tl 2, $(CC_CONFIG))
OCAMLC_SYSTEM=$(nth 1, $(Regex_ar $"^system:",$(config_out)))
OCAMLLIB=
if $(defined OCAMLLIB)
value $(OCAMLLIB)
else
value $(nth 1, $(Regex_ar $"^standard_library:", $(config_out)))
OCAMLC_VERSION=$(nth 1, $(Regex_ar $"^version:",$(config_out)))
x=$(split .,$(OCAMLC_VERSION))
OCAMLC_VERSION_MAJOR=$(int $(x.nth 0))
OCAMLC_VERSION_MINOR=$(int $(x.nth 1))
HAVE_NATIVE_DYNLINK=$(and $(NATIVE_ENABLED), $(eq 0,$(shell-code $(OCAMLFIND) query -predicates native dynlink)))
export OCAMLLIB
export OCAMLC_VERSION
export OCAMLC_CC
export OCAMLC_SYSTEM
export OCAMLC_CC_CFLAGS
export HAVE_NATIVE_DYNLINK
export OCAMLC_VERSION_MAJOR OCAMLC_VERSION_MINOR
# returns all generated (or existing) files that should be installed
MixedLibrary(name,mlfiles,cfiles)=
CC= $(OCAMLC_CC)
CFLAGS= $(OCAMLC_CC_CFLAGS) -I$(OCAMLLIB) $(CFLAGS)
BYTELIB = $(file $(name).cma)
NATIVELIB = $(file $(name).cmxa) $(file $(name)$(EXT_LIB))
NATIVEDYNLIB= $(file $(name).cmxs)
CMXFILES = $(addsuffix .cmx, $(mlfiles))
CMIFILES = $(addsuffix .cmi, $(mlfiles))
CMOFILES = $(addsuffix .cmo, $(mlfiles))
MLIFILES = $(filter-exists $(addsuffix .mli, $(mlfiles)))
C_OBJS = $(addsuffix $(EXT_OBJ), $(cfiles))
LDOPT_LDFLAGS=$(mapprefix -ldopt, $(LDFLAGS))
if $(or $(equal $(OCAMLC_SYSTEM),mingw), $(equal $(OCAMLC_SYSTEM),mingw64))
LDOPT_LDFLAGS+=$(mapprefix -ldopt, -link -static-libgcc)
export LDOPT_LDFLAGS
CCLIB_LDFLAGS=$(mapprefix -cclib, $(LDFLAGS))
Repeat_ctargets($(cfiles))
lib$(name)$(EXT_LIB) dll$(name)$(EXT_DLL): $(C_OBJS)
$(OCAMLFIND) ocamlmklib -o $(name) $(C_OBJS) $(LDOPT_LDFLAGS)
$(BYTELIB): dll$(name)$(EXT_DLL) $(CMOFILES)
$(OCAMLFIND) ocamlc -a -dllib -l$(name) -cclib -l$(name) $(OCAML_LINK_FLAGS) $(CCLIB_LDFLAGS) \
$(OCamlLinkSort $(CMOFILES)) -o $(BYTELIB)
$(NATIVELIB): lib$(name)$(EXT_LIB) $(CMXFILES)
$(OCAMLFIND) ocamlopt -a -cclib -l$(name) $(OCAML_LINK_FLAGS) $(CCLIB_LDFLAGS) $(OCamlLinkSort $(CMXFILES)) \
-o $(nth 0, $(NATIVELIB))
$(NATIVEDYNLIB): $(NATIVELIB)
$(OCAMLFIND) ocamlopt -shared -o $@ -I . $(OCAML_LINK_FLAGS) $<
return $(array $(if $(NATIVE_ENABLED), $(NATIVELIB) $(CMXFILES) \
$(if $(HAVE_NATIVE_DYNLINK), $(NATIVEDYNLIB))) \
$(if $(BYTE_ENABLED), $(BYTELIB) $(CMOFILES) dll$(name)$(EXT_DLL)) \
lib$(name)$(EXT_LIB) $(CMIFILES) $(MLIFILES) $(C_OBJS) )
MOCamlLibrary(name,files)=
to_add=$(addsuffix .cmi,$(files)) $(if $(BYTE_ENABLED), $(addsuffix .cmo,$(files))) $(if $(NATIVE_ENABLED),$(addsuffix .cmx,$(files)))
x=$(set $(OCamlLibrary $(name),$(files)) $(to_add))
if $(or $(equal $(HAVE_NATIVE_DYNLINK),false), $(equal $(NATIVE_ENABLED),false))
return $(x)
elseif $(not $(equal $(filter %.cmxs, $(x)), $(EMPTY)))
return $(x)
else
section
$(name).cmxs: $(name).cmxa
$(OCAMLFIND) ocamlopt -shared -linkall -o $@ -I . $(OCAML_LINK_FLAGS) $<
return $(x) $(name).cmxs
clean-helper()=
rm(-f $(glob *$(EXT_OBJ) *$(EXT_DLL) *$(EXT_LIB) *.cmt *.annot *.cma \
*.cmi *.cmti *.cmxa *.cmx *.cmxs *.cmo *.opt *.run *.exe *.log *.cache *.core core))
clean-helper-keep(to_keep)=
rm(-f $(filter-out $(to_keep), $(glob *$(EXT_OBJ) *$(EXT_DLL) *$(EXT_LIB) *.cmt *.annot *.cma \
*.cmi *.cmti *.cmxa *.cmx *.cmxs *.cmo *.opt *.run *.exe *.log *.cache *.core core)))
# useful functions from camlspotter
where1(com) =
WHERE = $(where $(prog))
if $(WHERE)
value $(nth 0, $(WHERE))
else
value
Check_prog_in_path(prog) =
ConfMsgChecking(for $(prog))
WHERE = $(where1 $(prog))
if $(WHERE)
ConfMsgResult(found $(WHERE))
return $(WHERE)
else
ConfMsgResult(FAILED - no $(prog) found)
return false
pkg_config(name, libname) =
ConfMsgChecking(for $(libname) by pkg-config)
if $(and $(defined this.PATH_PKG_CONFIG), $(equal 0, $(shell-code $(PATH_PKG_CONFIG) $(libname))))
# this is required since it is called in .STATIC
setvar(this.LDFLAGS_$(name), $(shell $(PATH_PKG_CONFIG) --libs $(libname)))
setvar(this.CFLAGS_$(name), $(shell $(PATH_PKG_CONFIG) --cflags $(libname)))
setvar(this.SUPPORT_$(uppercase $(name)), true)
setvar(this.HAVE_$(uppercase $(name)), true)
ConfMsgResult(found)
export
value true
else
ConfMsgResult(failed $(PATH_PKG_CONFIG) $(libname))
value false
export
pkg_config_version(libname) =
value $(shell $(PATH_PKG_CONFIG) $(libname) --modversion)
pkg_config_between_vers(name, libname, min_ver, too_high_ver) =
if $(pkg_config $(name), $(libname))
ConfMsgChecking($(libname): $(min_ver) <= version < $(too_high_ver))
ver=$(pkg_config_version $(libname))
if $(and $(le $(cmp-versions $(min_ver), $(ver)), 0), $(lt $(cmp-versions $(ver), $(too_high_ver)), 0))
ConfMsgResult($(ver) ... yes)
value true
export
else
ConfMsgResult($(ver) ... no)
value false # do not export
export
else
value false
export
Install_helper_ext(command_suffix,name, OBJFILES, OPT_OBJFILES)=
MLIS=
t1=$(replacesuffixes .cmo .cma .cmx .cmxa .cmxs .cmti $(EXT_OBJ) $(EXT_LIB), .mli .mli .mli .mli .mli .mli .mli .mli, $(OBJFILES) $(OPT_OBJFILES))
t2=$(set $(filter %.mli, $(t1)))
value $(filter-exists $(t2))
IFILES= $(set $(filter-out %$(EXT_OBJ) %.cmo, $(OBJFILES)) $(MLIS) )
OPT_IFILES=$(set $(filter-out %$(EXT_OBJ) %.cmo, $(OPT_OBJFILES) ))
CMTIFILES=$(set $(replacesuffixes .cmo, .cmti, $(filter %.cmo, $(OBJFILES) $(OPT_OBJFILES))))
CMTFILES=$(set $(replacesuffixes .cmx, .cmt, $(filter %.cmx, $(OBJFILES) $(OPT_OBJFILES))) $(replacesuffixes .cmo, .cmt, $(filter %.cmo, $(OBJFILES) $(OPT_OBJFILES))))
install$(command_suffix):: META $(OBJFILES)
$(OCAMLFIND) remove $(name) || true
$(OCAMLFIND) install -patch-version $(VERSION) $(name) META $(IFILES) -optional $(CMTFILES) $(CMTIFILES) $(OPT_IFILES)
uninstall$(command_suffix)::
$(OCAMLFIND) remove $(name)
Install_helper(name, OBJFILES, OPT_OBJFILES)=
Install_helper_ext($(EMPTY),$(name),$(OBJFILES),$(OPT_OBJFILES))
NULL_DEVICE=
if $(not $(equal $(OSTYPE), Win32))
value /dev/null
else
value NUL