PageRenderTime 96ms CodeModel.GetById 11ms app.highlight 76ms RepoModel.GetById 1ms app.codeStats 0ms

/froc-sanity2/OCamlMakefile

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