build with ocamlbuild by default
[deriving.git] / OCamlMakefile
blob731736eaf15f7c3f9666ea97d1a4d7718828c708
1 ###########################################################################
2 #                              OCamlMakefile
3 #                  Copyright (C) 1999-2004  Markus Mottl
5 #                             For updates see:
6 #                http://www.ocaml.info/home/ocaml_sources.html
8 #        $Id: OCamlMakefile,v 1.72 2005/12/09 15:30:50 mottl Exp $
10 ###########################################################################
12 # Modified by damien for .glade.ml compilation
14 # Set these variables to the names of the sources to be processed and
15 # the result variable. Order matters during linkage!
17 ifndef SOURCES
18   SOURCES := foo.ml
19 endif
20 export SOURCES
22 ifndef RES_CLIB_SUF
23   RES_CLIB_SUF := _stubs
24 endif
25 export RES_CLIB_SUF
27 ifndef RESULT
28   RESULT := foo
29 endif
30 export RESULT
32 export LIB_PACK_NAME
34 ifndef DOC_FILES
35   DOC_FILES := $(filter %.mli, $(SOURCES))
36 endif
37 export DOC_FILES
39 export BCSUFFIX
40 export NCSUFFIX
42 ifndef TOPSUFFIX
43   TOPSUFFIX := .top
44 endif
45 export TOPSUFFIX
47 # Eventually set include- and library-paths, libraries to link,
48 # additional compilation-, link- and ocamlyacc-flags
49 # Path- and library information needs not be written with "-I" and such...
50 # Define THREADS if you need it, otherwise leave it unset (same for
51 # USE_CAMLP4)!
53 export THREADS
54 export VMTHREADS
55 export ANNOTATE
56 export USE_CAMLP4
58 export INCDIRS
59 export LIBDIRS
60 export EXTLIBDIRS
61 export RESULTDEPS
62 export OCAML_DEFAULT_DIRS
64 export LIBS
65 export CLIBS
67 export OCAMLFLAGS
68 export OCAMLNCFLAGS
69 export OCAMLBCFLAGS
71 export OCAMLLDFLAGS
72 export OCAMLNLDFLAGS
73 export OCAMLBLDFLAGS
75 ifndef OCAMLCPFLAGS
76   OCAMLCPFLAGS := a
77 endif
79 export OCAMLCPFLAGS
81 export PPFLAGS
83 export YFLAGS
84 export IDLFLAGS
86 export OCAMLDOCFLAGS
88 export OCAMLFIND_INSTFLAGS
90 export DVIPSFLAGS
92 export STATIC
94 # Add a list of optional trash files that should be deleted by "make clean"
95 export TRASH
97 ####################  variables depending on your OCaml-installation
99 ifdef MINGW
100   export MINGW
101   WIN32   := 1
102   CFLAGS_WIN32 := -mno-cygwin
103 endif
104 ifdef MSVC
105   export MSVC
106   WIN32   := 1
107   ifndef STATIC
108     CPPFLAGS_WIN32 := -DCAML_DLL
109   endif
110   CFLAGS_WIN32 += -nologo
111   EXT_OBJ := obj
112   EXT_LIB := lib
113   ifeq ($(CC),gcc)
114     # work around GNU Make default value
115     ifdef THREADS
116       CC := cl -MT
117     else
118       CC := cl
119     endif
120   endif
121   ifeq ($(CXX),g++)
122     # work around GNU Make default value
123     CXX := $(CC)
124   endif
125   CFLAG_O := -Fo
126 endif
127 ifdef WIN32
128   EXT_CXX := cpp
129   EXE     := .exe
130 endif
132 ifndef EXT_OBJ
133   EXT_OBJ := o
134 endif
135 ifndef EXT_LIB
136   EXT_LIB := a
137 endif
138 ifndef EXT_CXX
139   EXT_CXX := cc
140 endif
141 ifndef EXE
142   EXE := # empty
143 endif
144 ifndef CFLAG_O
145   CFLAG_O := -o # do not delete this comment (preserves trailing whitespace)!
146 endif
148 export CC
149 export CXX
150 export CFLAGS
151 export CXXFLAGS
152 export LDFLAGS
153 export CPPFLAGS
155 ifndef RPATH_FLAG
156   ifdef ELF_RPATH_FLAG
157     RPATH_FLAG := $(ELF_RPATH_FLAG)
158   else
159     RPATH_FLAG := -R
160   endif
161 endif
162 export RPATH_FLAG
164 ifndef MSVC
165 ifndef PIC_CFLAGS
166   PIC_CFLAGS := -fPIC
167 endif
168 ifndef PIC_CPPFLAGS
169   PIC_CPPFLAGS := -DPIC
170 endif
171 endif
173 export PIC_CFLAGS
174 export PIC_CPPFLAGS
176 BCRESULT  := $(addsuffix $(BCSUFFIX), $(RESULT))
177 NCRESULT  := $(addsuffix $(NCSUFFIX), $(RESULT))
178 TOPRESULT := $(addsuffix $(TOPSUFFIX), $(RESULT))
180 ifndef OCAMLFIND
181   OCAMLFIND := ocamlfind
182 endif
183 export OCAMLFIND
185 ifndef OCAMLC
186   OCAMLC := ocamlc
187 endif
188 export OCAMLC
190 ifndef OCAMLOPT
191   OCAMLOPT := ocamlopt
192 endif
193 export OCAMLOPT
195 ifndef OCAMLMKTOP
196   OCAMLMKTOP := ocamlmktop
197 endif
198 export OCAMLMKTOP
200 ifndef OCAMLCP
201   OCAMLCP := ocamlcp
202 endif
203 export OCAMLCP
205 ifndef OCAMLDEP
206   OCAMLDEP := ocamldep
207 endif
208 export OCAMLDEP
210 ifndef OCAMLLEX
211   OCAMLLEX := ocamllex
212 endif
213 export OCAMLLEX
215 ifndef OCAMLYACC
216   OCAMLYACC := ocamlyacc
217 endif
218 export OCAMLYACC
220 ifndef OCAMLMKLIB
221   OCAMLMKLIB := ocamlmklib
222 endif
223 export OCAMLMKLIB
225 ifndef OCAML_GLADECC
226   OCAML_GLADECC := lablgladecc2
227 endif
228 export OCAML_GLADECC
230 ifndef OCAML_GLADECC_FLAGS
231   OCAML_GLADECC_FLAGS :=
232 endif
233 export OCAML_GLADECC_FLAGS
235 ifndef CAMELEON_REPORT
236   CAMELEON_REPORT := report
237 endif
238 export CAMELEON_REPORT
240 ifndef CAMELEON_REPORT_FLAGS
241   CAMELEON_REPORT_FLAGS :=
242 endif
243 export CAMELEON_REPORT_FLAGS
245 ifndef CAMELEON_ZOGGY
246   CAMELEON_ZOGGY := camlp4o pa_zog.cma pr_o.cmo
247 endif
248 export CAMELEON_ZOGGY
250 ifndef CAMELEON_ZOGGY_FLAGS
251   CAMELEON_ZOGGY_FLAGS :=
252 endif
253 export CAMELEON_ZOGGY_FLAGS
255 ifndef OXRIDL
256   OXRIDL := oxridl
257 endif
258 export OXRIDL
260 ifndef CAMLIDL
261   CAMLIDL := camlidl
262 endif
263 export CAMLIDL
265 ifndef CAMLIDLDLL
266   CAMLIDLDLL := camlidldll
267 endif
268 export CAMLIDLDLL
270 ifndef NOIDLHEADER
271   MAYBE_IDL_HEADER := -header
272 endif
273 export NOIDLHEADER
275 export NO_CUSTOM
277 ifndef CAMLP4
278   CAMLP4 := camlp4
279 endif
280 export CAMLP4
282 ifndef REAL_OCAMLFIND
283   ifdef PACKS
284     ifndef CREATE_LIB
285       ifdef THREADS
286         PACKS += threads
287       endif
288     endif
289     empty :=
290     space := $(empty) $(empty)
291     comma := ,
292     ifdef PREDS
293       PRE_OCAML_FIND_PREDICATES := $(subst $(space),$(comma),$(PREDS))
294       PRE_OCAML_FIND_PACKAGES := $(subst $(space),$(comma),$(PACKS))
295       OCAML_FIND_PREDICATES := -predicates $(PRE_OCAML_FIND_PREDICATES)
296   #    OCAML_DEP_PREDICATES := -syntax $(PRE_OCAML_FIND_PREDICATES)
297       OCAML_FIND_PACKAGES := $(OCAML_FIND_PREDICATES) -package $(PRE_OCAML_FIND_PACKAGES)
298       OCAML_DEP_PACKAGES := $(OCAML_DEP_PREDICATES) -package $(PRE_OCAML_FIND_PACKAGES)
299     else
300       OCAML_FIND_PACKAGES := -package $(subst $(space),$(comma),$(PACKS))
301       OCAML_DEP_PACKAGES :=
302     endif
303     OCAML_FIND_LINKPKG := -linkpkg
304     REAL_OCAMLFIND := $(OCAMLFIND)
305   endif
306 endif
308 export OCAML_FIND_PACKAGES
309 export OCAML_DEP_PACKAGES
310 export OCAML_FIND_LINKPKG
311 export REAL_OCAMLFIND
313 ifndef OCAMLDOC
314   OCAMLDOC := ocamldoc
315 endif
316 export OCAMLDOC
318 ifndef LATEX
319   LATEX := latex
320 endif
321 export LATEX
323 ifndef DVIPS
324   DVIPS := dvips
325 endif
326 export DVIPS
328 ifndef PS2PDF
329   PS2PDF := ps2pdf
330 endif
331 export PS2PDF
333 ifndef OCAMLMAKEFILE
334   OCAMLMAKEFILE := OCamlMakefile
335 endif
336 export OCAMLMAKEFILE
338 ifndef OCAMLLIBPATH
339   OCAMLLIBPATH := \
340     $(shell $(OCAMLC) 2>/dev/null -where || echo /usr/local/lib/ocaml)
341 endif
342 export OCAMLLIBPATH
344 ifndef OCAML_LIB_INSTALL
345   OCAML_LIB_INSTALL := $(OCAMLLIBPATH)/contrib
346 endif
347 export OCAML_LIB_INSTALL
349 ###########################################################################
351 ####################  change following sections only if
352 ####################    you know what you are doing!
354 # delete target files when a build command fails
355 .PHONY: .DELETE_ON_ERROR
356 .DELETE_ON_ERROR:
358 # for pedants using "--warn-undefined-variables"
359 export MAYBE_IDL
360 export REAL_RESULT
361 export CAMLIDLFLAGS
362 export THREAD_FLAG
363 export RES_CLIB
364 export MAKEDLL
365 export ANNOT_FLAG
366 export C_OXRIDL
367 export SUBPROJS
368 export CFLAGS_WIN32
369 export CPPFLAGS_WIN32
371 INCFLAGS :=
373 SHELL := /bin/sh
375 MLDEPDIR := ._d
376 BCDIDIR  := ._bcdi
377 NCDIDIR  := ._ncdi
379 FILTER_EXTNS := %.mli %.ml %.mll %.mly %.idl %.oxridl %.c %.$(EXT_CXX) %.rep %.zog %.glade
381 FILTERED     := $(filter $(FILTER_EXTNS), $(SOURCES))
382 SOURCE_DIRS  := $(filter-out ./, $(sort $(dir $(FILTERED))))
384 FILTERED_REP := $(filter %.rep, $(FILTERED))
385 DEP_REP      := $(FILTERED_REP:%.rep=$(MLDEPDIR)/%.d)
386 AUTO_REP     := $(FILTERED_REP:.rep=.ml)
388 FILTERED_ZOG := $(filter %.zog, $(FILTERED))
389 DEP_ZOG      := $(FILTERED_ZOG:%.zog=$(MLDEPDIR)/%.d)
390 AUTO_ZOG     := $(FILTERED_ZOG:.zog=.ml)
392 FILTERED_GLADE := $(filter %.glade, $(FILTERED))
393 DEP_GLADE      := $(FILTERED_GLADE:%.glade=$(MLDEPDIR)/%.d)
394 AUTO_GLADE     := $(FILTERED_GLADE:.glade=.ml)
396 FILTERED_ML  := $(filter %.ml, $(FILTERED))
397 DEP_ML       := $(FILTERED_ML:%.ml=$(MLDEPDIR)/%.d)
399 FILTERED_MLI := $(filter %.mli, $(FILTERED))
400 DEP_MLI      := $(FILTERED_MLI:.mli=.di)
402 FILTERED_MLL := $(filter %.mll, $(FILTERED))
403 DEP_MLL      := $(FILTERED_MLL:%.mll=$(MLDEPDIR)/%.d)
404 AUTO_MLL     := $(FILTERED_MLL:.mll=.ml)
406 FILTERED_MLY := $(filter %.mly, $(FILTERED))
407 DEP_MLY      := $(FILTERED_MLY:%.mly=$(MLDEPDIR)/%.d) $(FILTERED_MLY:.mly=.di)
408 AUTO_MLY     := $(FILTERED_MLY:.mly=.mli) $(FILTERED_MLY:.mly=.ml)
410 FILTERED_IDL := $(filter %.idl, $(FILTERED))
411 DEP_IDL      := $(FILTERED_IDL:%.idl=$(MLDEPDIR)/%.d) $(FILTERED_IDL:.idl=.di)
412 C_IDL        := $(FILTERED_IDL:%.idl=%_stubs.c)
413 ifndef NOIDLHEADER
414  C_IDL += $(FILTERED_IDL:.idl=.h)
415 endif
416 OBJ_C_IDL    := $(FILTERED_IDL:%.idl=%_stubs.$(EXT_OBJ))
417 AUTO_IDL     := $(FILTERED_IDL:.idl=.mli) $(FILTERED_IDL:.idl=.ml) $(C_IDL)
419 FILTERED_OXRIDL := $(filter %.oxridl, $(FILTERED))
420 DEP_OXRIDL      := $(FILTERED_OXRIDL:%.oxridl=$(MLDEPDIR)/%.d) $(FILTERED_OXRIDL:.oxridl=.di)
421 AUTO_OXRIDL     := $(FILTERED_OXRIDL:.oxridl=.mli) $(FILTERED_OXRIDL:.oxridl=.ml) $(C_OXRIDL)
423 FILTERED_C_CXX := $(filter %.c %.$(EXT_CXX), $(FILTERED))
424 OBJ_C_CXX      := $(FILTERED_C_CXX:.c=.$(EXT_OBJ))
425 OBJ_C_CXX      := $(OBJ_C_CXX:.$(EXT_CXX)=.$(EXT_OBJ))
427 PRE_TARGETS  += $(AUTO_MLL) $(AUTO_MLY) $(AUTO_IDL) $(AUTO_OXRIDL) $(AUTO_ZOG) $(AUTO_REP) $(AUTO_GLADE)
429 ALL_DEPS     := $(DEP_ML) $(DEP_MLI) $(DEP_MLL) $(DEP_MLY) $(DEP_IDL) $(DEP_OXRIDL) $(DEP_ZOG) $(DEP_REP) $(DEP_GLADE)
431 MLDEPS       := $(filter %.d, $(ALL_DEPS))
432 MLIDEPS      := $(filter %.di, $(ALL_DEPS))
433 BCDEPIS      := $(MLIDEPS:%.di=$(BCDIDIR)/%.di)
434 NCDEPIS      := $(MLIDEPS:%.di=$(NCDIDIR)/%.di)
436 ALLML        := $(filter %.mli %.ml %.mll %.mly %.idl %.oxridl %.rep %.zog %.glade, $(FILTERED))
438 IMPLO_INTF   := $(ALLML:%.mli=%.mli.__)
439 IMPLO_INTF   := $(foreach file, $(IMPLO_INTF), \
440                   $(basename $(file)).cmi $(basename $(file)).cmo)
441 IMPLO_INTF   := $(filter-out %.mli.cmo, $(IMPLO_INTF))
442 IMPLO_INTF   := $(IMPLO_INTF:%.mli.cmi=%.cmi)
444 IMPLX_INTF   := $(IMPLO_INTF:.cmo=.cmx)
446 INTF         := $(filter %.cmi, $(IMPLO_INTF))
447 IMPL_CMO     := $(filter %.cmo, $(IMPLO_INTF))
448 IMPL_CMX     := $(IMPL_CMO:.cmo=.cmx)
449 IMPL_ASM     := $(IMPL_CMO:.cmo=.asm)
450 IMPL_S       := $(IMPL_CMO:.cmo=.s)
452 OBJ_LINK     := $(OBJ_C_IDL) $(OBJ_C_CXX)
453 OBJ_FILES    := $(IMPL_CMO:.cmo=.$(EXT_OBJ)) $(OBJ_LINK)
455 EXECS        := $(addsuffix $(EXE), \
456                             $(sort $(TOPRESULT) $(BCRESULT) $(NCRESULT)))
457 ifdef WIN32
458   EXECS      += $(BCRESULT).dll $(NCRESULT).dll
459 endif
461 CLIB_BASE    := $(RESULT)$(RES_CLIB_SUF)
462 ifneq ($(strip $(OBJ_LINK)),)
463   RES_CLIB     := lib$(CLIB_BASE).$(EXT_LIB)
464 endif
466 ifdef WIN32
467 DLLSONAME := $(CLIB_BASE).dll
468 else
469 DLLSONAME := dll$(CLIB_BASE).so
470 endif
472 NONEXECS     := $(INTF) $(IMPL_CMO) $(IMPL_CMX) $(IMPL_ASM) $(IMPL_S) \
473                 $(OBJ_FILES) $(PRE_TARGETS) $(BCRESULT).cma $(NCRESULT).cmxa \
474                 $(NCRESULT).$(EXT_LIB) $(BCRESULT).cmi $(BCRESULT).cmo \
475                 $(NCRESULT).cmi $(NCRESULT).cmx $(NCRESULT).o \
476                 $(RES_CLIB) $(IMPL_CMO:.cmo=.annot) \
477                 $(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmo $(LIB_PACK_NAME).cmx $(LIB_PACK_NAME).o
479 ifndef STATIC
480   NONEXECS += $(DLLSONAME)
481 endif
483 ifndef LIBINSTALL_FILES
484   LIBINSTALL_FILES := $(RESULT).mli $(RESULT).cmi $(RESULT).cma \
485                       $(RESULT).cmxa $(RESULT).$(EXT_LIB) $(RES_CLIB)
486   ifndef STATIC
487     ifneq ($(strip $(OBJ_LINK)),)
488       LIBINSTALL_FILES += $(DLLSONAME)
489     endif
490   endif
491 endif
493 export LIBINSTALL_FILES
495 ifdef WIN32
496   # some extra stuff is created while linking DLLs
497   NONEXECS   += $(BCRESULT).$(EXT_LIB) $(BCRESULT).exp $(NCRESULT).exp $(CLIB_BASE).exp $(CLIB_BASE).lib
498 endif
500 TARGETS      := $(EXECS) $(NONEXECS)
502 # If there are IDL-files
503 ifneq ($(strip $(FILTERED_IDL)),)
504   MAYBE_IDL := -cclib -lcamlidl
505 endif
507 ifdef USE_CAMLP4
508   CAMLP4PATH := \
509     $(shell $(CAMLP4) -where 2>/dev/null || echo /usr/local/lib/camlp4)
510   INCFLAGS := -I $(CAMLP4PATH)
511   CINCFLAGS := -I$(CAMLP4PATH)
512 endif
514 DINCFLAGS := $(INCFLAGS) $(SOURCE_DIRS:%=-I %) $(OCAML_DEFAULT_DIRS:%=-I %)
515 INCFLAGS := $(DINCFLAGS) $(INCDIRS:%=-I %)
516 CINCFLAGS += $(SOURCE_DIRS:%=-I%) $(INCDIRS:%=-I%) $(OCAML_DEFAULT_DIRS:%=-I%)
518 ifndef MSVC
519   CLIBFLAGS += $(SOURCE_DIRS:%=-L%) $(LIBDIRS:%=-L%) \
520                $(EXTLIBDIRS:%=-L%) $(OCAML_DEFAULT_DIRS:%=-L%)
522   ifeq ($(ELF_RPATH), yes)
523     CLIBFLAGS += $(EXTLIBDIRS:%=-Wl,$(RPATH_FLAG)%)
524   endif
525 endif
527 ifndef PROFILING
528   INTF_OCAMLC := $(OCAMLC)
529 else
530   ifndef THREADS
531     INTF_OCAMLC := $(OCAMLCP) -p $(OCAMLCPFLAGS)
532   else
533     # OCaml does not support profiling byte code
534     # with threads (yet), therefore we force an error.
535     ifndef REAL_OCAMLC
536       $(error Profiling of multithreaded byte code not yet supported by OCaml)
537     endif
538     INTF_OCAMLC := $(OCAMLC)
539   endif
540 endif
542 ifndef MSVC
543   COMMON_LDFLAGS := $(LDFLAGS:%=-ccopt %) $(SOURCE_DIRS:%=-ccopt -L%) \
544                     $(LIBDIRS:%=-ccopt -L%) $(EXTLIBDIRS:%=-ccopt -L%) \
545                     $(EXTLIBDIRS:%=-ccopt -Wl $(OCAML_DEFAULT_DIRS:%=-ccopt -L%))
547   ifeq ($(ELF_RPATH),yes)
548     COMMON_LDFLAGS += $(EXTLIBDIRS:%=-ccopt -Wl,$(RPATH_FLAG)%)
549   endif
550 else
551   COMMON_LDFLAGS := -ccopt "/link -NODEFAULTLIB:LIBC $(LDFLAGS:%=%) $(SOURCE_DIRS:%=-LIBPATH:%) \
552                     $(LIBDIRS:%=-LIBPATH:%) $(EXTLIBDIRS:%=-LIBPATH:%) \
553                     $(OCAML_DEFAULT_DIRS:%=-LIBPATH:%) "
554 endif
556 CLIBS_OPTS := $(CLIBS:%=-cclib -l%)
557 ifdef MSVC
558   ifndef STATIC
559   # MSVC libraries do not have 'lib' prefix
560   CLIBS_OPTS := $(CLIBS:%=-cclib %.lib)
561   endif
562 endif
564 ifneq ($(strip $(OBJ_LINK)),)
565   ifdef CREATE_LIB
566     OBJS_LIBS := -cclib -l$(CLIB_BASE) $(CLIBS_OPTS) $(MAYBE_IDL)
567   else
568     OBJS_LIBS := $(OBJ_LINK) $(CLIBS_OPTS) $(MAYBE_IDL)
569   endif
570 else
571   OBJS_LIBS := $(CLIBS_OPTS) $(MAYBE_IDL)
572 endif
574 # If we have to make byte-code
575 ifndef REAL_OCAMLC
576   BYTE_OCAML := y
578   # EXTRADEPS is added dependencies we have to insert for all
579   # executable files we generate.  Ideally it should be all of the
580   # libraries we use, but it's hard to find the ones that get searched on
581   # the path since I don't know the paths built into the compiler, so
582   # just include the ones with slashes in their names.
583   EXTRADEPS := $(addsuffix .cma,$(foreach i,$(LIBS),$(if $(findstring /,$(i)),$(i))))
584   SPECIAL_OCAMLFLAGS := $(OCAMLBCFLAGS)
586   REAL_OCAMLC := $(INTF_OCAMLC)
588   REAL_IMPL := $(IMPL_CMO)
589   REAL_IMPL_INTF := $(IMPLO_INTF)
590   IMPL_SUF := .cmo
592   DEPFLAGS  :=
593   MAKE_DEPS := $(MLDEPS) $(BCDEPIS)
595   ifdef CREATE_LIB
596     override CFLAGS := $(PIC_CFLAGS) $(CFLAGS)
597     override CPPFLAGS := $(PIC_CPPFLAGS) $(CPPFLAGS)
598     ifndef STATIC
599       ifneq ($(strip $(OBJ_LINK)),)
600         MAKEDLL := $(DLLSONAME)
601         ALL_LDFLAGS := -dllib $(DLLSONAME)
602       endif
603     endif
604   endif
606   ifndef NO_CUSTOM
607     ifneq "$(strip $(OBJ_LINK) $(THREADS) $(MAYBE_IDL) $(CLIBS))" ""
608       ALL_LDFLAGS += -custom
609     endif
610   endif
612   ALL_LDFLAGS += $(INCFLAGS) $(OCAMLLDFLAGS) $(OCAMLBLDFLAGS) \
613                  $(COMMON_LDFLAGS) $(LIBS:%=%.cma)
614   CAMLIDLDLLFLAGS :=
616   ifdef THREADS
617     ifdef VMTHREADS
618       THREAD_FLAG := -vmthread
619     else
620       THREAD_FLAG := -thread
621     endif
622     ALL_LDFLAGS := $(THREAD_FLAG) $(ALL_LDFLAGS)
623     ifndef CREATE_LIB
624       ifndef REAL_OCAMLFIND
625         ALL_LDFLAGS := unix.cma threads.cma $(ALL_LDFLAGS)
626       endif
627     endif
628   endif
630 # we have to make native-code
631 else
632   EXTRADEPS := $(addsuffix .cmxa,$(foreach i,$(LIBS),$(if $(findstring /,$(i)),$(i))))
633   ifndef PROFILING
634     SPECIAL_OCAMLFLAGS := $(OCAMLNCFLAGS)
635     PLDFLAGS :=
636   else
637     SPECIAL_OCAMLFLAGS := -p $(OCAMLNCFLAGS)
638     PLDFLAGS := -p
639   endif
641   REAL_IMPL := $(IMPL_CMX)
642   REAL_IMPL_INTF := $(IMPLX_INTF)
643   IMPL_SUF := .cmx
645   override CPPFLAGS := -DNATIVE_CODE $(CPPFLAGS)
647   DEPFLAGS  := -native
648   MAKE_DEPS := $(MLDEPS) $(NCDEPIS)
650   ALL_LDFLAGS := $(PLDFLAGS) $(INCFLAGS) $(OCAMLLDFLAGS) \
651                  $(OCAMLNLDFLAGS) $(COMMON_LDFLAGS)
652   CAMLIDLDLLFLAGS := -opt
654   ifndef CREATE_LIB
655     ALL_LDFLAGS += $(LIBS:%=%.cmxa)
656   else
657     override CFLAGS := $(PIC_CFLAGS) $(CFLAGS)
658     override CPPFLAGS := $(PIC_CPPFLAGS) $(CPPFLAGS)
659   endif
661   ifdef THREADS
662     THREAD_FLAG := -thread
663     ALL_LDFLAGS := $(THREAD_FLAG) $(ALL_LDFLAGS)
664     ifndef CREATE_LIB
665       ifndef REAL_OCAMLFIND
666         ALL_LDFLAGS := unix.cmxa threads.cmxa $(ALL_LDFLAGS)
667       endif
668     endif
669   endif
670 endif
672 export MAKE_DEPS
674 ifdef ANNOTATE
675   ANNOT_FLAG := -dtypes
676 else
677 endif
679 ALL_OCAMLCFLAGS := $(THREAD_FLAG) $(ANNOT_FLAG) $(OCAMLFLAGS) \
680                    $(INCFLAGS) $(SPECIAL_OCAMLFLAGS)
682 ifdef make_deps
683   -include $(MAKE_DEPS)
684   PRE_TARGETS :=
685 endif
687 ###########################################################################
688 # USER RULES
690 # Call "OCamlMakefile QUIET=" to get rid of all of the @'s.
691 QUIET=@
693 # generates byte-code (default)
694 byte-code:              $(PRE_TARGETS)
695                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \
696                                 REAL_RESULT="$(BCRESULT)" make_deps=yes
697 bc:     byte-code
699 byte-code-nolink:       $(PRE_TARGETS)
700                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \
701                                 REAL_RESULT="$(BCRESULT)" make_deps=yes
702 bcnl:   byte-code-nolink
704 top:                    $(PRE_TARGETS)
705                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(TOPRESULT) \
706                                 REAL_RESULT="$(BCRESULT)" make_deps=yes
708 # generates native-code
710 native-code:            $(PRE_TARGETS)
711                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT) \
712                                 REAL_RESULT="$(NCRESULT)" \
713                                 REAL_OCAMLC="$(OCAMLOPT)" \
714                                 make_deps=yes
715 nc:     native-code
717 native-code-nolink:     $(PRE_TARGETS)
718                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \
719                                 REAL_RESULT="$(NCRESULT)" \
720                                 REAL_OCAMLC="$(OCAMLOPT)" \
721                                 make_deps=yes
722 ncnl:   native-code-nolink
724 # generates byte-code libraries
725 byte-code-library:      $(PRE_TARGETS)
726                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
727                                 $(RES_CLIB) $(BCRESULT).cma \
728                                 REAL_RESULT="$(BCRESULT)" \
729                                 CREATE_LIB=yes \
730                                 make_deps=yes
731 bcl:    byte-code-library
733 # generates native-code libraries
734 native-code-library:    $(PRE_TARGETS)
735                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
736                                 $(RES_CLIB) $(NCRESULT).cmxa \
737                                 REAL_RESULT="$(NCRESULT)" \
738                                 REAL_OCAMLC="$(OCAMLOPT)" \
739                                 CREATE_LIB=yes \
740                                 make_deps=yes
741 ncl:    native-code-library
743 ifdef WIN32
744 # generates byte-code dll
745 byte-code-dll:          $(PRE_TARGETS)
746                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
747                                 $(RES_CLIB) $(BCRESULT).dll \
748                                 REAL_RESULT="$(BCRESULT)" \
749                                 make_deps=yes
750 bcd:    byte-code-dll
752 # generates native-code dll
753 native-code-dll:        $(PRE_TARGETS)
754                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
755                                 $(RES_CLIB) $(NCRESULT).dll \
756                                 REAL_RESULT="$(NCRESULT)" \
757                                 REAL_OCAMLC="$(OCAMLOPT)" \
758                                 make_deps=yes
759 ncd:    native-code-dll
760 endif
762 # generates byte-code with debugging information
763 debug-code:             $(PRE_TARGETS)
764                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \
765                                 REAL_RESULT="$(BCRESULT)" make_deps=yes \
766                                 OCAMLFLAGS="-g $(OCAMLFLAGS)" \
767                                 OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)"
768 dc:     debug-code
770 debug-code-nolink:      $(PRE_TARGETS)
771                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) nolink \
772                                 REAL_RESULT="$(BCRESULT)" make_deps=yes \
773                                 OCAMLFLAGS="-g $(OCAMLFLAGS)" \
774                                 OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)"
775 dcnl:   debug-code-nolink
777 # generates byte-code libraries with debugging information
778 debug-code-library:     $(PRE_TARGETS)
779                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
780                                 $(RES_CLIB) $(BCRESULT).cma \
781                                 REAL_RESULT="$(BCRESULT)" make_deps=yes \
782                                 CREATE_LIB=yes \
783                                 OCAMLFLAGS="-g $(OCAMLFLAGS)" \
784                                 OCAMLLDFLAGS="-g $(OCAMLLDFLAGS)"
785 dcl:    debug-code-library
787 # generates byte-code for profiling
788 profiling-byte-code:            $(PRE_TARGETS)
789                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT) \
790                                 REAL_RESULT="$(BCRESULT)" PROFILING="y" \
791                                 make_deps=yes
792 pbc:    profiling-byte-code
794 # generates native-code
796 profiling-native-code:          $(PRE_TARGETS)
797                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(NCRESULT) \
798                                 REAL_RESULT="$(NCRESULT)" \
799                                 REAL_OCAMLC="$(OCAMLOPT)" \
800                                 PROFILING="y" \
801                                 make_deps=yes
802 pnc:    profiling-native-code
804 # generates byte-code libraries
805 profiling-byte-code-library:    $(PRE_TARGETS)
806                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
807                                 $(RES_CLIB) $(BCRESULT).cma \
808                                 REAL_RESULT="$(BCRESULT)" PROFILING="y" \
809                                 CREATE_LIB=yes \
810                                 make_deps=yes
811 pbcl:   profiling-byte-code-library
813 # generates native-code libraries
814 profiling-native-code-library:  $(PRE_TARGETS)
815                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
816                                 $(RES_CLIB) $(NCRESULT).cmxa \
817                                 REAL_RESULT="$(NCRESULT)" PROFILING="y" \
818                                 REAL_OCAMLC="$(OCAMLOPT)" \
819                                 CREATE_LIB=yes \
820                                 make_deps=yes
821 pncl:   profiling-native-code-library
823 # packs byte-code objects
824 pack-byte-code:                 $(PRE_TARGETS)
825                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) $(BCRESULT).cmo \
826                                 REAL_RESULT="$(BCRESULT)" \
827                                 PACK_LIB=yes make_deps=yes
828 pabc:   pack-byte-code
830 # packs native-code objects
831 pack-native-code:               $(PRE_TARGETS)
832                         $(QUIET)$(MAKE) -r -f $(OCAMLMAKEFILE) \
833                                 $(NCRESULT).cmx $(NCRESULT).o \
834                                 REAL_RESULT="$(NCRESULT)" \
835                                 REAL_OCAMLC="$(OCAMLOPT)" \
836                                 PACK_LIB=yes make_deps=yes
837 panc:   pack-native-code
839 # generates HTML-documentation
840 htdoc:  doc/$(RESULT)/html
842 # generates Latex-documentation
843 ladoc:  doc/$(RESULT)/latex
845 # generates PostScript-documentation
846 psdoc:  doc/$(RESULT)/latex/doc.ps
848 # generates PDF-documentation
849 pdfdoc: doc/$(RESULT)/latex/doc.pdf
851 # generates all supported forms of documentation
852 doc: htdoc ladoc psdoc pdfdoc
854 ###########################################################################
855 # LOW LEVEL RULES
857 $(REAL_RESULT):         $(REAL_IMPL_INTF) $(OBJ_LINK) $(EXTRADEPS) $(RESULTDEPS)
858                         $(REAL_OCAMLFIND) $(REAL_OCAMLC) \
859                                 $(OCAML_FIND_PACKAGES) $(OCAML_FIND_LINKPKG) \
860                                 $(ALL_LDFLAGS) $(OBJS_LIBS) -o $@$(EXE) \
861                                 $(REAL_IMPL)
863 nolink:                 $(REAL_IMPL_INTF) $(OBJ_LINK)
865 ifdef WIN32
866 $(REAL_RESULT).dll:     $(REAL_IMPL_INTF) $(OBJ_LINK)
867                         $(CAMLIDLDLL) $(CAMLIDLDLLFLAGS) $(OBJ_LINK) $(CLIBS) \
868                                 -o $@ $(REAL_IMPL)
869 endif
871 %$(TOPSUFFIX):          $(REAL_IMPL_INTF) $(OBJ_LINK) $(EXTRADEPS)
872                         $(REAL_OCAMLFIND) $(OCAMLMKTOP) \
873                                 $(OCAML_FIND_PACKAGES) $(OCAML_FIND_LINKPKG) \
874                                 $(ALL_LDFLAGS) $(OBJS_LIBS) -o $@$(EXE) \
875                                 $(REAL_IMPL)
877 .SUFFIXES:              .mli .ml .cmi .cmo .cmx .cma .cmxa .$(EXT_OBJ) \
878                         .mly .di .d .$(EXT_LIB) .idl %.oxridl .c .$(EXT_CXX) .h .so \
879                         .rep .zog .glade
881 ifndef STATIC
882 ifdef MINGW
883 $(DLLSONAME):           $(OBJ_LINK)
884                         $(CC) $(CFLAGS) $(CFLAGS_WIN32) $(OBJ_LINK) -shared -o $@ \
885                         -Wl,--whole-archive $(wildcard $(foreach dir,$(LIBDIRS),$(CLIBS:%=$(dir)/lib%.a))) \
886                          $(OCAMLLIBPATH)/ocamlrun.a \
887                         -Wl,--export-all-symbols \
888                         -Wl,--no-whole-archive
889 else
890 ifdef MSVC
891 $(DLLSONAME):           $(OBJ_LINK)
892                         link /NOLOGO /DLL /OUT:$@ $(OBJ_LINK) \
893                          $(wildcard $(foreach dir,$(LIBDIRS),$(CLIBS:%=$(dir)/%.lib))) \
894                          $(OCAMLLIBPATH)/ocamlrun.lib
896 else
897 $(DLLSONAME):           $(OBJ_LINK)
898                         $(OCAMLMKLIB) $(INCFLAGS) $(CLIBFLAGS) \
899                                 -o $(CLIB_BASE) $(OBJ_LINK) $(CLIBS:%=-l%) \
900                                 $(OCAMLMKLIB_FLAGS)
901 endif
902 endif
903 endif
905 ifndef LIB_PACK_NAME
906 $(RESULT).cma:          $(REAL_IMPL_INTF) $(MAKEDLL) $(EXTRADEPS) $(RESULTDEPS)
907                         $(REAL_OCAMLFIND) $(REAL_OCAMLC) -a $(ALL_LDFLAGS) \
908                                 $(OBJS_LIBS) -o $@ $(OCAMLBLDFLAGS) $(REAL_IMPL)
910 $(RESULT).cmxa $(RESULT).$(EXT_LIB):    $(REAL_IMPL_INTF) $(EXTRADEPS) $(RESULTDEPS)
911                         $(REAL_OCAMLFIND) $(OCAMLOPT) -a $(ALL_LDFLAGS) $(OBJS_LIBS) \
912                                 $(OCAMLNLDFLAGS) -o $@ $(REAL_IMPL)
913 else
914 ifdef BYTE_OCAML
915 $(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmo: $(REAL_IMPL_INTF)
916                         $(REAL_OCAMLFIND) $(REAL_OCAMLC) -pack -o $(LIB_PACK_NAME).cmo $(OCAMLLDFLAGS) $(REAL_IMPL)
917 else
918 $(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmx: $(REAL_IMPL_INTF)
919                         $(REAL_OCAMLFIND) $(REAL_OCAMLC) -pack -o $(LIB_PACK_NAME).cmx  $(OCAMLLDFLAGS) $(REAL_IMPL)
920 endif
922 $(RESULT).cma:          $(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmo $(MAKEDLL) $(EXTRADEPS) $(RESULTDEPS)
923                         $(REAL_OCAMLFIND) $(REAL_OCAMLC) -a $(ALL_LDFLAGS) \
924                                 $(OBJS_LIBS) -o $@ $(OCAMLBLDFLAGS) $(LIB_PACK_NAME).cmo
926 $(RESULT).cmxa $(RESULT).$(EXT_LIB):    $(LIB_PACK_NAME).cmi $(LIB_PACK_NAME).cmx $(EXTRADEPS) $(RESULTDEPS)
927                         $(REAL_OCAMLFIND) $(OCAMLOPT) -a $(ALL_LDFLAGS) $(OBJS_LIBS) \
928                                 $(OCAMLNLDFLAGS) -o $@ $(LIB_PACK_NAME).cmx
929 endif
931 $(RES_CLIB):            $(OBJ_LINK)
932 ifndef MSVC
933   ifneq ($(strip $(OBJ_LINK)),)
934                       $(AR) rcs $@ $(OBJ_LINK)
935   endif
936 else
937   ifneq ($(strip $(OBJ_LINK)),)
938                         lib -nologo -debugtype:cv -out:$(RES_CLIB) $(OBJ_LINK)
939   endif
940 endif
942 .mli.cmi: $(EXTRADEPS)
943                         $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
944                         if [ -z "$$pp" ]; then \
945                           echo $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \
946                                 -c $(THREAD_FLAG) $(ANNOT_FLAG) \
947                                 $(OCAMLFLAGS) $(INCFLAGS) $<; \
948                           $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \
949                                 -c $(THREAD_FLAG) $(ANNOT_FLAG) \
950                                 $(OCAMLFLAGS) $(INCFLAGS) $<; \
951                         else \
952                             echo $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \
953                                 -c -pp \"$$pp $(PPFLAGS)\" $(THREAD_FLAG) $(ANNOT_FLAG) \
954                                 $(OCAMLFLAGS) $(INCFLAGS) $<; \
955                             $(REAL_OCAMLFIND) $(INTF_OCAMLC) $(OCAML_FIND_PACKAGES) \
956                                 -c -pp "$$pp $(PPFLAGS)" $(THREAD_FLAG) $(ANNOT_FLAG) \
957                                 $(OCAMLFLAGS) $(INCFLAGS) $<; \
958                         fi
960 .ml.cmi .ml.$(EXT_OBJ) .ml.cmx .ml.cmo: $(EXTRADEPS)
961                         $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
962                         if [ -z "$$pp" ]; then \
963                           echo $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \
964                                 -c $(ALL_OCAMLCFLAGS) $<; \
965                           $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \
966                                 -c $(ALL_OCAMLCFLAGS) $<; \
967                         else \
968                           echo $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \
969                                 -c -pp \"$$pp $(PPFLAGS)\" $(ALL_OCAMLCFLAGS) $<; \
970                           $(REAL_OCAMLFIND) $(REAL_OCAMLC) $(OCAML_FIND_PACKAGES) \
971                                 -c -pp "$$pp $(PPFLAGS)" $(ALL_OCAMLCFLAGS) $<; \
972                         fi
974 ifdef PACK_LIB
975 $(REAL_RESULT).cmo $(REAL_RESULT).cmx $(REAL_RESULT).o: $(REAL_IMPL_INTF) $(OBJ_LINK) $(EXTRADEPS)
976                         $(REAL_OCAMLFIND) $(REAL_OCAMLC) -pack $(ALL_LDFLAGS) \
977                                 $(OBJS_LIBS) -o $@ $(REAL_IMPL)
978 endif
980 .PRECIOUS:              %.ml
981 %.ml:                   %.mll
982                         $(OCAMLLEX) $<
984 .PRECIOUS:              %.ml %.mli
985 %.ml %.mli:             %.mly
986                         $(OCAMLYACC) $(YFLAGS) $<
987                         $(QUIET)pp=`sed -n -e 's/.*(\*pp \([^*]*\) \*).*/\1/p;q' $<`; \
988                         if [ ! -z "$$pp" ]; then \
989                           mv $*.ml $*.ml.temporary; \
990                           echo "(*pp $$pp $(PPFLAGS)*)" > $*.ml; \
991                           cat $*.ml.temporary >> $*.ml; \
992                           rm $*.ml.temporary; \
993                           mv $*.mli $*.mli.temporary; \
994                           echo "(*pp $$pp $(PPFLAGS)*)" > $*.mli; \
995                           cat $*.mli.temporary >> $*.mli; \
996                           rm $*.mli.temporary; \
997                         fi
1000 .PRECIOUS:              %.ml
1001 %.ml:                   %.rep
1002                         $(CAMELEON_REPORT) $(CAMELEON_REPORT_FLAGS) -gen $<
1004 .PRECIOUS:              %.ml
1005 %.ml:                   %.zog
1006                         $(CAMELEON_ZOGGY)  $(CAMELEON_ZOGGY_FLAGS) -impl $< > $@
1008 .PRECIOUS:              %.ml
1009 %.ml:                   %.glade
1010                         $(OCAML_GLADECC)  $(OCAML_GLADECC_FLAGS) $< > $@
1012 .PRECIOUS:              %.ml %.mli
1013 %.ml %.mli:             %.oxridl
1014                         $(OXRIDL) $<
1016 .PRECIOUS:              %.ml %.mli %_stubs.c %.h
1017 %.ml %.mli %_stubs.c %.h:               %.idl
1018                         $(CAMLIDL) $(MAYBE_IDL_HEADER) $(IDLFLAGS) \
1019                                 $(CAMLIDLFLAGS) $<
1020                         $(QUIET)if [ $(NOIDLHEADER) ]; then touch $*.h; fi
1022 .c.$(EXT_OBJ):
1023                         $(OCAMLC) -c -cc "$(CC)" -ccopt "$(CFLAGS) \
1024                                 $(CPPFLAGS) $(CPPFLAGS_WIN32) \
1025                                 $(CFLAGS_WIN32) $(CINCFLAGS) $(CFLAG_O)$@ " $<
1027 .$(EXT_CXX).$(EXT_OBJ):
1028                         $(CXX) -c $(CXXFLAGS) $(CINCFLAGS) $(CPPFLAGS) \
1029                                 -I'$(OCAMLLIBPATH)' \
1030                                 $< $(CFLAG_O)$@
1032 $(MLDEPDIR)/%.d:        %.ml
1033                         $(QUIET)if [ ! -d $(@D) ]; then mkdir -p $(@D); fi
1034                         $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
1035                         if [ -z "$$pp" ]; then \
1036                           echo $(REAL_OCAMLFIND) $(OCAMLDEP) $(OCAML_DEP_PACKAGES) \
1037                                 $(DINCFLAGS) $< \> $@; \
1038                           $(REAL_OCAMLFIND) $(OCAMLDEP) $(OCAML_DEP_PACKAGES) \
1039                                 $(DINCFLAGS) $< > $@; \
1040                         else \
1041                           echo $(REAL_OCAMLFIND) $(OCAMLDEP) $(OCAML_DEP_PACKAGES) \
1042                                 -pp \"$$pp $(PPFLAGS)\" $(DINCFLAGS) $< \> $@; \
1043                           $(REAL_OCAMLFIND) $(OCAMLDEP) $(OCAML_DEP_PACKAGES) \
1044                                 -pp "$$pp $(PPFLAGS)" $(DINCFLAGS) $< > $@; \
1045                         fi
1047 $(BCDIDIR)/%.di $(NCDIDIR)/%.di:        %.mli
1048                         $(QUIET)if [ ! -d $(@D) ]; then mkdir -p $(@D); fi
1049                         $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
1050                         if [ -z "$$pp" ]; then \
1051                           echo $(REAL_OCAMLFIND) $(OCAMLDEP) $(DEPFLAGS) $(DINCFLAGS) $< \> $@; \
1052                           $(REAL_OCAMLFIND) $(OCAMLDEP) $(DEPFLAGS) $(DINCFLAGS) $< > $@; \
1053                         else \
1054                           echo $(REAL_OCAMLFIND) $(OCAMLDEP) $(DEPFLAGS) \
1055                             -pp \"$$pp $(PPFLAGS)\" $(DINCFLAGS) $< \> $@; \
1056                           $(REAL_OCAMLFIND) $(OCAMLDEP) $(DEPFLAGS) \
1057                             -pp "$$pp $(PPFLAGS)" $(DINCFLAGS) $< > $@; \
1058                         fi
1060 doc/$(RESULT)/html: $(DOC_FILES)
1061         rm -rf $@
1062         mkdir -p $@
1063         $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
1064         if [ -z "$$pp" ]; then \
1065           echo $(OCAMLDOC) -html -d $@ $(OCAMLDOCFLAGS) $(INCFLAGS) $(DOC_FILES); \
1066           $(OCAMLDOC) -html -d $@ $(OCAMLDOCFLAGS) $(INCFLAGS) $(DOC_FILES); \
1067         else \
1068           echo $(OCAMLDOC) -pp \"$$pp $(PPFLAGS)\" -html -d $@ $(OCAMLDOCFLAGS) \
1069                 $(INCFLAGS) $(DOC_FILES); \
1070           $(OCAMLDOC) -pp "$$pp $(PPFLAGS)" -html -d $@ $(OCAMLDOCFLAGS) \
1071                 $(INCFLAGS) $(DOC_FILES); \
1072         fi
1074 doc/$(RESULT)/latex: $(DOC_FILES)
1075         rm -rf $@
1076         mkdir -p $@
1077         $(QUIET)pp=`sed -n -e '/^#/d' -e 's/(\*pp \([^*]*\) \*)/\1/p;q' $<`; \
1078         if [ -z "$$pp" ]; then \
1079           echo $(OCAMLDOC) -latex $(OCAMLDOCFLAGS) $(INCFLAGS) \
1080                 $(DOC_FILES) -o $@/doc.tex; \
1081           $(OCAMLDOC) -latex $(OCAMLDOCFLAGS) $(INCFLAGS) $(DOC_FILES) \
1082                 -o $@/doc.tex; \
1083         else \
1084           echo $(OCAMLDOC) -pp \"$$pp $(PPFLAGS)\" -latex $(OCAMLDOCFLAGS) \
1085                 $(INCFLAGS) $(DOC_FILES) -o $@/doc.tex; \
1086           $(OCAMLDOC) -pp "$$pp $(PPFLAGS)" -latex $(OCAMLDOCFLAGS) \
1087                 $(INCFLAGS) $(DOC_FILES) -o $@/doc.tex; \
1088         fi
1090 doc/$(RESULT)/latex/doc.ps: doc/$(RESULT)/latex
1091         cd doc/$(RESULT)/latex && \
1092           $(LATEX) doc.tex && \
1093           $(LATEX) doc.tex && \
1094           $(DVIPS) $(DVIPSFLAGS) doc.dvi -o $(@F)
1096 doc/$(RESULT)/latex/doc.pdf: doc/$(RESULT)/latex/doc.ps
1097         cd doc/$(RESULT)/latex && $(PS2PDF) $(<F)
1099 define make_subproj
1100 .PHONY:
1101 subproj_$(1):
1102         $$(eval $$(call PROJ_$(1)))
1103         $(QUIET)if [ "$(SUBTARGET)" != "all" ]; then \
1104           $(MAKE) -f $(OCAMLMAKEFILE) $(SUBTARGET); \
1105         fi
1106 endef
1108 $(foreach subproj,$(SUBPROJS),$(eval $(call make_subproj,$(subproj))))
1110 .PHONY:
1111 subprojs: $(SUBPROJS:%=subproj_%)
1113 ###########################################################################
1114 # (UN)INSTALL RULES FOR LIBRARIES
1116 .PHONY: libinstall
1117 libinstall:     all
1118         $(QUIET)printf "\nInstalling library with ocamlfind\n"
1119         $(OCAMLFIND) install $(OCAMLFIND_INSTFLAGS) $(RESULT) META $(LIBINSTALL_FILES)
1120         $(QUIET)printf "\nInstallation successful.\n"
1122 .PHONY: libuninstall
1123 libuninstall:
1124         $(QUIET)printf "\nUninstalling library with ocamlfind\n"
1125         $(OCAMLFIND) remove $(OCAMLFIND_INSTFLAGS) $(RESULT)
1126         $(QUIET)printf "\nUninstallation successful.\n"
1128 .PHONY: rawinstall
1129 rawinstall:     all
1130         $(QUIET)printf "\nInstalling library to: $(OCAML_LIB_INSTALL)\n"
1131         -install -d $(OCAML_LIB_INSTALL)
1132         for i in $(LIBINSTALL_FILES); do \
1133           if [ -f $$i ]; then \
1134             install -c -m 0644 $$i $(OCAML_LIB_INSTALL); \
1135           fi; \
1136         done
1137         $(QUIET)printf "\nInstallation successful.\n"
1139 .PHONY: rawuninstall
1140 rawuninstall:
1141         $(QUIET)printf "\nUninstalling library from: $(OCAML_LIB_INSTALL)\n"
1142         cd $(OCAML_LIB_INSTALL) && rm $(notdir $(LIBINSTALL_FILES))
1143         $(QUIET)printf "\nUninstallation successful.\n"
1145 ###########################################################################
1146 # MAINTAINANCE RULES
1148 .PHONY: clean
1149 clean::
1150         rm -f $(TARGETS) $(TRASH)
1151         rm -rf $(BCDIDIR) $(NCDIDIR) $(MLDEPDIR)
1153 .PHONY: cleanup
1154 cleanup::
1155         rm -f $(NONEXECS) $(TRASH)
1156         rm -rf $(BCDIDIR) $(NCDIDIR) $(MLDEPDIR)
1158 .PHONY: clean-doc
1159 clean-doc::
1160         rm -rf doc
1162 .PHONY: nobackup
1163 nobackup:
1164         rm -f *.bak *~ *.dup