3 if $(not $(defined TARGET_OS))
4 if $(equal $(OSTYPE), Win32)
14 imt = imt #$(file build/common/bin/imt)
17 ocamlc-cflags = -warn-error A -g
18 ocamlopt-cflags = -warn-error A
23 ocamlopt = ocamlopt.opt
25 host-win32 = $(equal $(OSTYPE), Win32)
26 target-win32 = $(equal $(TARGET_OS), win)
27 cross-win32 = $(and $(target-win32), $(not $(host-win32)))
28 target-mingw = $(defined mingw)
30 darwin = $(equal $(SYSNAME), Darwin)
33 ls -lR $(top-dir) >/dev/null
37 mingw = $(if $(cross-win32), mingwf, $(EMPTY))
38 wine = $(if $(cross-win32), wine, $(EMPTY))
49 ocamlc = $(wine) ocamlc.opt.exe
50 ocamlopt = $(wine) ocamlopt.opt.exe
51 if $(not $(cross-win32))
52 ocamldep = ocamldep.exe
56 c-cflags = -Wall -Werror -g
57 cxx-cflags = -Wall -Werror -g
61 dxsdk = $(getenv DXSDK_DIR, $(EMPTY))
62 if $(not $(equal $(dxsdk), $(EMPTY)))
63 setenv (INCLUDE, $(getenv INCLUDE)$";$(dxsdk)\include")
64 setenv (LIB, $(getenv LIB)$";$(dxsdk)\lib\x86")
66 wine = $(if $(cross-win32), wine, $(EMPTY))
77 ocamlc = $(wine) ocamlc.opt.exe
78 ocamlopt = $(wine) ocamlopt.opt.exe
79 if $(not $(cross-win32))
80 ocamldep = ocamldep.exe
82 c-cflags = -WX -W4 -Zi -MT
83 cxx-cflags = -WX -W4 -Zi -MT
102 c-cflags = -Wall -Werror -W -fstrict-aliasing -g -Wno-long-long -pipe
103 cxx-cflags = -Wall -Werror -W -fstrict-aliasing -g -Wno-long-long -pipe
104 c-cflags += -pedantic
105 cxx-cflags = -pedantic
110 c-cflags += -DX86_ASSEMBLER
114 c-cflags += -DWORDS_BIGENDIAN
118 c-cflags += -DWORDS_BIGENDIAN
122 eprintln (Machine "$(MACHINE)" is not recognized)
126 emit-stdmake-rule(name) =
127 if $(defined make-file)
128 t = $(target $(name))
129 deps = $(fullname $(filter-targets $(filter-out %.scan, $(t.build-deps))))
130 stdout = $(make-file)
131 echo $(fullname $(t.target))\: $(deps)
132 d = $(fullname $(dirof $(t.target)))
133 # mucho importante - first char after quotation mark is tab
134 echo " mkdir -p $d && cd $d && $(t.build-commands)"
137 caml-emit-stdmake-rule(name) =
138 emit-stdmake-rule($(name))
140 c-emit-stdmake-rule(name) =
141 emit-stdmake-rule($(name))
143 cxx-emit-stdmake-rule(name) =
144 emit-stdmake-rule($(name))
146 emit-stdmake-line(line) =
147 if $(defined make-file)
148 fprintln($(make-file), $(line))
150 emit-stdmake-dep(target, prereq) =
151 emit-stdmake-line($(target)\: $(fullname $(prereq)))
154 .caml-order: %.cmi: %.cmo
155 .caml-order: %.cmx: %.cmo
158 return $(file-sort .caml-order, $(files))
160 collect-includes(flags) =
163 foreach (f, $(flags))
171 if $(and $(gt $l, 1), \
172 $(and $(equal $(f.nth 0), -), \
173 $(equal $(f.nth 1), I)))
175 dirs += $(removeprefix -I, $f)
185 cpp-digest-deps(flags) =
186 includes = $(collect-includes $(flags))
187 return $(digest-in-path-optional $(includes) ., $&)
190 return cpp-digest-deps($(c-cflags) $(target-flags))
193 return cpp-digest-deps($(cxx-cflags) $(target-flags))
201 eprintln($(string $(argv)))
204 emacs-helper = directory $"`"$(absname $(dirof $<))\'
205 depflags = $(mapprefix -I, \
206 $(collect-includes $(target-flags) $(ocamlc-cflags)))
207 eecho make[0]\: Entering $(emacs-helper)
208 depflags += $(if $(equal $(length $(filter-out %.cmx, $@)), 0),-native,$(EMPTY))
210 $(ocamldep) $(depflags) $(basename $<) && \
211 eecho make[0]\: Leaving $(emacs-helper) #|| exit 10
213 .SCANNER: %.o.scan: %.c
214 $(cc) -MT $* -M $(target-flags) $(c-cflags) $<
216 .SCANNER: %.o.scan: %.cpp
217 $(cxx) -MT $* -M $(target-flags) $(cxx-cflags) $<
219 %.o: %.c :scanner: %.o.scan \
220 :value: $(c-digest-deps) :value: $(c-emit-stdmake-rule $@)
221 $(cc) -c $(target-flags) $(c-cflags) $<
223 %.o: %.cpp :scanner: %.o.scan \
224 :value: $(cxx-digest-deps) :value: $(cxx-emit-stdmake-rule $@)
225 $(cxx) -c $(target-flags) $(cxx-cflags) $<
227 .SCANNER: %.obj.scan: %.c
228 imt dep7 $* $(target-flags) $(c-cflags) $<
230 .SCANNER: %.obj.scan: %.cpp
231 imt dep7 $* $(target-flags) $(cxx-cflags) $<
233 %.obj: %.c :scanner: %.obj.scan \
234 :value: $(c-digest-deps) :value: $(c-emit-stdmake-rule $@)
235 imt cl -c $(target-flags) $(c-cflags) $<
237 %.obj: %.cpp :scanner: %.obj.scan \
238 :value: $(cxx-digest-deps) :value: $(cxx-emit-stdmake-rule $@)
239 imt cl -c $(target-flags) $(cxx-cflags) $<
241 .SCANNER: %.cmo.scan: %.ml
244 .SCANNER: %.cmx.scan: %.ml
247 .SCANNER: %.cmi.scan: %.mli
250 %.cmi %.cmi-o: %.mli :scanner: %.cmi.scan
251 $(ocamlc) -o $*.cmi -c $(target-flags) $(ocamlc-cflags) $< && touch $*.cmi-o
253 %.cmi %.cmi-x: %.mli :scanner: %.cmi.scan
254 $(ocamlopt) -o $*.cmi -c $(target-flags) $(ocamlopt-cflags) $< \
259 if $(target-exists %.mli)
260 %.cmo: %.ml %.cmi-o %.cmi :value: $(caml-emit-stdmake-rule $@) \
262 $(ocamlc) -o $@ -c $(target-flags) $(ocamlc-cflags) $<
264 %.cmo: %.ml :scanner: %.cmo.scan :effects: %.cmi \
265 :value: $(caml-emit-stdmake-rule $@)
266 $(ocamlc) -o $@ -c $(target-flags) $(ocamlc-cflags) $<
271 if $(target-exists %.mli)
272 %.obj %.cmx: %.ml %.cmi-x %.cmi \
273 :value: $(caml-emit-stdmake-rule $@)
274 $(ocamlopt) -o $*.cmx -c $(target-flags) \
275 $(ocamlopt-cflags) $<
277 %.obj %.cmx: %.ml :scanner: %.cmx.scan :effects: %.cmi \
278 :value: $(caml-emit-stdmake-rule $@)
279 $(ocamlopt) -o $*.cmx -c $(target-flags) \
280 $(ocamlopt-cflags) $<
285 if $(target-exists %.mli)
286 %.o %.cmx: %.ml %.cmi-x %.cmi \
287 :value: $(caml-emit-stdmake-rule $@)
288 $(ocamlopt) -o $*.cmx -c $(target-flags) \
289 $(ocamlopt-cflags) $<
291 %.o %.cmx: %.ml :scanner: %.cmx.scan :effects: %.cmi \
292 :value: $(caml-emit-stdmake-rule $@)
293 $(ocamlopt) -o $*.cmx -c $(target-flags) \
294 $(ocamlopt-cflags) $<
298 if $(defined profile)
305 profile-c-cflags[] = -O2 -DNDEBUG
306 profile-cxx-cflags[] = -O2 -DNDEBUG
309 profile-c-cflags[] = -DDEBUG
310 profile-cxx-cflags[] = -DDEBUG
313 build-dir = build/$(TARGET_OS)/$(profile)
317 if $(not $(defined top-dir))
322 mkdir -p $(build-dir)/$(subdir)
323 add-project-directories($(subdir))
327 add-project-directories($(top-dir)/$(subdir))
329 create-env(subdirs) =
331 foreach(subdir, $(subdirs))
332 mkdir -p $(build-dir)/$(subdir)
333 add-project-directories($(subdirs))
335 create-env($(subdirs))
337 #make-file = $(fopen $(build-dir)/Makefile, w)
339 vmount($(top-dir), $(build-dir))
340 bin-path = $(dir $(build-dir)/bin)
342 mkdir -p $(build-dir)
347 .SUBDIRS: $(build-dir)