camlspotter avatar camlspotter committed 35b8e6f

fix for opam

Comments (0)

Files changed (1)

 USE_OCAMLFIND = true
 OCAMLFIND_DESTDIR= $(shell ocamlfind printconf destdir)
 
+OCAMLFIND_QUERY(name) = 
+    return $(shell ocamlfind query $(name))
+
 #|Set NATIVE_ENABLED false locally if a project does not requre opt compilation.
 NATIVE_ENABLED = $(OCAMLOPT_EXISTS)
 NATIVE_SHARED_ENABLED = $(OCAMLOPT_EXISTS)
 BYTE_ENABLED = true
 
 #|The default warning and errors. If you want to use different warning and error switches, use redefine the variable.
-OCAMLFLAGS = -w A-4-9 -warn-error A-4-9
+OCAMLFLAGS = -g 
+
+#|Warnings not to be printed separted with space
+OCAMLWARNING_IGNORE[] = 4 9 40 42 44 45
+
+#|Warnings treated as non errors
+OCAMLWARNING_NON_ERROR[] = 4 9 40 42 44 45
+
+#|If it is false, warnings do not stop the compilation even if they are listed in OCAMLWARNING_NON_ERROR
+#If you are in developing something, turn it to true!
+OCAMLWARNING_STOP_AT_ERROR_WARNING=false
+
+#|The maximum warning value.
+# This is the maximum warning ID NOT of the current OCaml compiler,
+#                                BUT of the OCaml compiler used by the author.
+OCAMLWARNING_MAX= 45
+
+#|Function to build warning switches
+OCAMLWARNING_MAKE()=
+    if $(OCAMLWARNING_STOP_AT_ERROR_WARNING)
+        return -w A-$(concat -,$(OCAMLWARNING_IGNORE)) -warn-error +1..$(OCAMLWARNING_MAX)-$(concat -, $(OCAMLWARNING_NON_ERROR))
+    else
+        return -w A-$(concat -,$(OCAMLWARNING_IGNORE)) -warn-error a
+
+#|OMyMakefile assumes installation with .cmt files
+OCAMLANNOTFLAGS = -annot -bin-annot
 
 #|Global variable to be defined as empty
 OCAMLPACKAGEFLAGS=
 #   Subdirs()
 #
 # It includes "findlib" by default. If you want to build findlib in OMy framework, you have to remove it from the list.
-OCAML_PREINSTALLED_PACKS[]= bigarray camlp4 dbm dynlink graphics num num-top stdlib str threads unix findlib compiler-libs compiler-libs.common
+OCAML_PREINSTALLED_PACKS[]= bigarray camlp4 dbm dynlink graphics num num-top stdlib str threads unix findlib compiler-libs compiler-libs.common compiler-libs.bytecomp compiler-libs.optcomp compiler-libs.toplevel
 
 #|Redefinition of compiler commands
 public.OCamlC() =
-    value $(OCAMLFIND) $(OCAMLC) $(OCAMLPACKAGEFLAGS) $(LAZY_OCAMLFINDFLAGS) $(PREFIXED_OCAMLPACKS) $(OCAMLFLAGS)\
-              $(OCAMLCFLAGS) $(OCAMLPPFLAGS) $(PREFIXED_OCAMLINCLUDES)
+    value $(OCAMLFIND) $(OCAMLC) \
+        $(OCAMLANNOTFLAGS) \
+        $(OCAMLPACKAGEFLAGS) \
+        $(LAZY_OCAMLFINDFLAGS) \
+        $(PREFIXED_OCAMLPACKS) \
+        $(OCAMLFLAGS) \
+        $(OCAMLWARNING_MAKE) \
+        $(OCAMLCFLAGS) \
+        $(OCAMLPPFLAGS) \
+        $(PREFIXED_OCAMLINCLUDES)
 # Why we need "public." ?
 
 public.OCamlOpt() =
-    value $(OCAMLFIND) $(OCAMLOPT) $(OCAMLPACKAGEFLAGS) $(LAZY_OCAMLFINDFLAGS) $(PREFIXED_OCAMLPACKS) $(OCAMLFLAGS)\
+    value $(OCAMLFIND) $(OCAMLOPT) $(OCAMLANNOTFLAGS) $(OCAMLPACKAGEFLAGS) $(LAZY_OCAMLFINDFLAGS) $(PREFIXED_OCAMLPACKS) $(OCAMLFLAGS)\
+              $(OCAMLWARNING_MAKE) \
               $(OCAMLOPTFLAGS) $(OCAMLPPFLAGS) $(PREFIXED_OCAMLINCLUDES)
 
 if $(and $(not $(NATIVE_ENABLED)) $(not $(BYTE_ENABLED)))
 #|Additional implicit rules by file extensions
 # annot, cmt, cmti files
 %.annot %.cmt: %.ml %.cmi
-	$(OCamlC) -c -annot -bin-annot $<
+	$(OCamlC) -c -annot $(OCAMLANNOTFLAGS) $<
 
-%.spit %.cmti: %.mli 
-	$(OCamlC) -c -bin-annot $<
+%.cmti: %.mli 
+	$(OCamlC) -c $(OCAMLANNOTFLAGS) $<
 
-#|Define OCAML_ANNOT so that ocamlc/ocamlopt automatically create spot/spit/annot/cmt/cmti files, even without -annot/-bin-annot option. This requires a special compiler patch 
+#|Define OCAML_ANNOT so that ocamlc/ocamlopt automatically create annot/cmt/cmti files, even without -annot/-bin-annot option. This requires a special compiler patch 
 setenv(OCAML_ANNOT, 1)
 
 #|Enable the backtrace
 
 # Common phonies
 # ==================================================================
-.PHONY: all install uninstall clean
+.PHONY: all install uninstall clean veryclean
+
+# Very clean
+# ======================================================================
+
+#| OCaml object files which are not real targets of OMake are not be
+# auto-cleaned away by ``omake clean``. This is not good in some situations
+# at linking.
+WithOCamlVeryClean() =
+    veryclean: 
+        rm -f *.cm* *.annot *.o *.a *.so *.exe *.byt *.opt *.run
 
 # Directories
 # =====================================================================
 
 #|Returns packages managed by OMy framework
 OMyManagedPackages(packages) =
-   return $(set-diff $(packages), $(OCAML_PREINSTALLED_PACKS))
+   # need to rename camlimages.jpeg => camlimages
+   packages_prefix=
+   foreach(x, $(packages))
+       match $(x)
+       case $"^\([^.]+\).*"
+          packages_prefix += $1
+          export
+       default
+          packages_prefix += $(x)
+          export
+       export
+   return $(set-diff $(packages_prefix), $(OCAML_PREINSTALLED_PACKS))
 
 #|Add dependencies of OCaml compiled files (cmx, cmo, etc.) over $(files).
 #
 # .. note:: These functions introduce implicit rules: *you may need to export it, if you use this function in a local context.*
 OCamlRequire(files) =
-    %.cmx %.cmo %.cmi %.cma %.cmxa %.annot %.spot %.spit %.cmt %.cmti: $(files)
+    %.cmx %.cmo %.cmi %.cma %.cmxa %.annot %.cmt %.cmti: $(files)
     export
 
 #|Add dependencies of OCaml compiled files (cmx, cmo, etc.) over $(packages).
 OCamlRequirePackages(packages) =
     required_packs = $(OMyManagedPackages $(packages))
     if $(defined INSTALLED)
-      %.cmx %.cmo %.cmi %.cma %.cmxa %.annot %.spot %.spit %.cmt %.cmti: $(Installed $(required_packs))
+      %.cmx %.cmo %.cmi %.cma %.cmxa %.annot %.cmt %.cmti: $(Installed $(required_packs))
       export
     export
 
     required_packs = $(OMyManagedPackages $(packages))
     if $(defined INSTALLED)
       .SCANNER: scan-ocaml-%: $(Installed $(required_packs))
-      %.cmx %.cmo %.cmi %.cma %.cmxa %.annot %.spot %.spit : $(Installed $(required_packs))
+      %.cmx %.cmo %.cmi %.cma %.cmxa %.annot : $(Installed $(required_packs))
       export 
     export
 
 # Build rules
 # ==========================================================
 
-# Extend the bundled OCamlPackage with .spot creation
 public.OCamlLibrary(name, files) =
    # XXX: JYH: these variables should be marked private in 0.9.9
    protected.name = $(file $(name))
                   $(if $(NATIVE_SHARED_ENABLED), $(NATIVESHAREDLIB)), \
                   $(if $(BYTE_ENABLED), $(BYTELIB)))
 
-# Extend the bundled OCamlPackage with .spot creation
+public.OCAML_BYTE_LINK_FLAGS =
+
 public.OCamlPackage(name, files) =
    # XXX: JYH: these variables should be marked private in 0.9.9
    protected.OFILES   = $(addsuffix $(EXT_OBJ), $(files))
              export
          $(BYTE_TARGETS): $(BYTE_DEPS)
             $(OCAMLFIND) $(OCAMLC) $(LAZY_OCAMLFINDFLAGS) $(PREFIXED_OCAMLPACKS) $(OCAMLFLAGS) \
-                $(OCAMLCFLAGS) $(OCAML_LIB_FLAGS) -pack -bin-annot -o $(CMO) $(OCamlLinkSort $(CMOFILES))
+                $(OCAMLCFLAGS) $(OCAML_LIB_FLAGS) -pack $(OCAMLANNOTFLAGS) -o $(CMO) $(OCamlLinkSort $(CMOFILES))
 
    protected.NATIVE_DEPS = $(CMXFILES) $(OFILES)
    $(NATIVE_TARGETS): $(NATIVE_DEPS)
             export
          $(NATIVE_TARGETS): $(NATIVE_DEPS)
             $(OCAMLFIND) $(OCAMLOPTLINK) $(LAZY_OCAMLFINDFLAGS) $(PREFIXED_OCAMLPACKS) $(OCAMLFLAGS) \
-                $(OCAMLOPTFLAGS) $(OCAML_LIB_FLAGS) -pack -bin-annot -o $(CMX) $(OCamlLinkSort $(CMXFILES))
+                $(OCAMLOPTFLAGS) $(OCAML_LIB_FLAGS) -pack $(OCAMLANNOTFLAGS) -o $(CMX) $(OCamlLinkSort $(CMXFILES))
 
    $(CMI):
       section rule
 #
 #  Todo: external C library
 MyOCamlPackage(library_name, files, cmodules, linkopts) =
+  WithOCamlVeryClean()
   AddLocalOCamlPackageDependencies()
   export # The above thing is local: need to be exported
 
   CSTUBS=$(addsuffix .o,$(cmodules))
-  CMOS=$(addsuffix .cmo,$(library_name))
-  CMXS=$(addsuffix .cmx,$(library_name))
+  CMO_S=$(addsuffix .cmo,$(library_name))
+  CMX_S=$(addsuffix .cmx,$(library_name))
   CMA=$(library_name).cma
   CMXA=$(library_name).cmxa
+  CMXS=$(library_name).cmxs
 
   if $(not $(defined MyOCamlPackageExtras))
       MyOCamlPackageExtras[]=
   .PHONY: install-lib
   install-lib: $(library_name).cmo $(library_name).cmx $(library_name).cma $(library_name).cmxa $(MyOCamlPackageExtras)
 
-  $(CMA) $(CMXA) $(library_name).a $(CSTUBLIBRARIES) : $(CSTUBS) $(CMOS) $(CMXS)
+  $(CMA) $(CMXA) $(CMXS) $(library_name).a $(CSTUBLIBRARIES) : $(CSTUBS) $(CMO_S) $(CMX_S)
       if $(not $(equal $(cmodules), $(EMPTY)))
-          ocamlmklib -verbose -o $(library_name) $(CSTUBS) $(linkopts) $(CMOS) $(CMXS)
+          ocamlmklib -verbose -o $(library_name) $(CSTUBS) $(linkopts) $(CMO_S) $(CMX_S)
+          $(OCamlOpt) -shared -o $(CMXS) $(CMX_S) # CR jfuruse: right?
       else
-          $(OCamlC) -a -o $(CMA) $(CMOS)
-          $(OCamlOpt) -a -o $(CMXA) $(CMXS)
+          $(OCamlC) -a -o $(CMA) $(CMO_S)
+          $(OCamlOpt) -a -o $(CMXA) $(CMX_S)
+          $(OCamlOpt) -shared -o $(CMXS) $(CMX_S)
 
   ## the followings are necessary for packing
 
   ## clean
   AutoClean()
   clean:
-	rm -f $(library_name).spot $(library_name).cmt
+	rm -f $(library_name).cmt
 
   ## install
 
   # CR jfuruse: x.cmi is required if x.mli does not exist!
-  targets[]=META $(glob i, *.mli) $(library_name).cmi $(library_name).cmo $(library_name).cmx $(library_name).cma $(library_name).cmxa $(library_name).o $(library_name).a $(CSTUBLIBRARIES) $(MyOCamlPackageExtras)
+  targets[]=META $(glob i, *.mli) $(library_name).cmi $(library_name).cmo $(library_name).cmx $(library_name).cma $(library_name).cmxa $(library_name).cmxs $(library_name).o $(library_name).a $(CSTUBLIBRARIES) $(MyOCamlPackageExtras)
 
   targets[]+= $(library_name).cmt
 
 #      files
 #          OCaml module names (without .ml)
 MyOCamlTestProgram(name, files) =
+  WithOCamlVeryClean()
   AddLocalOCamlPackageDependencies()
   export # The above thing is local: need to be exported
 
-  $(name).run $(name).opt: $(Installed $(OMyManagedPackages $(OCAMLPACKS)))
+  # We must write these two separately, or something messy happens!
+  $(name).run: $(Installed $(OMyManagedPackages $(OCAMLPACKS)))
+  $(name).opt: $(Installed $(OMyManagedPackages $(OCAMLPACKS)))
 
   # CR jfuruse: forgot to add the deps over the packages!
   .DEFAULT: $(OCamlProgram $(name), $(files))
 #          OCaml module names (without .ml)
 #  In addition to MyOCamlTestProgram, the binary is installed by omake install
 MyOCamlProgram(name, files) =
+  WithOCamlVeryClean()
   MyOCamlTestProgram($(name), $(files))
   export # The above thing is local: need to be exported
 
    return $(array $(PROG), $(BYTEPROG))
 
 MyOCamlTop(name, files) =
+  WithOCamlVeryClean()
   AddLocalOCamlPackageDependencies()
   export # The above thing is local: need to be exported
 
 #
 #   .. note :: Probably you should use MyOCamlPackage
 MyOCamlLibrary(library_name, files) =
+  WithOCamlVeryClean()
   AddLocalOCamlPackageDependencies()
-  targets = $(OCamlLibrary $(library_name), $(files))
+  protected.CMIFILES = $(addsuffix .cmi, $(files))
+  targets = $(OCamlLibrary $(library_name), $(files)) $(CMIFILES) $(glob i, *.mli) 
 
   .DEFAULT: $(targets)
 
 
   if $(not $(defined NO_INSTALL))
     targets[] += META 
+    cmts =  $(addsuffix .cmt,  $(removesuffix $(glob i, *.cmo)))
+    cmts += $(addsuffix .cmti, $(removesuffix $(glob i, *.mli)))
     if $(defined INSTALLED)
       $(Installed $(library_name)): $(targets)
         $(OCAMLFIND) remove $(library_name)
         section:
-              $(OCAMLFIND) install $(library_name) $(targets)
+              $(OCAMLFIND) install $(library_name) $(targets) $(cmts)
               CreateInstalled($(library_name), $(targets))
 
       install: $(Installed $(library_name))
     else
       install: $(targets)
         $(OCAMLFIND) remove $(library_name)
-        $(OCAMLFIND) install $(library_name) $(targets)
+        $(OCAMLFIND) install $(library_name) $(targets) $(cmts)
 
       uninstall:
 	$(OCAMLFIND) remove $(library_name)
 #|ditto.
 mkdir_if_not_exists(dir) =
   if $(not $(test -e $(dir))):
-    mkdir $(dir) 
+    mkdir -p $(dir) 
   return
+
+# Pa_ounit test
+# =======================================================================
+
+#| Test with Pa_ounit. Pretty version dependent.
+# Thinking from the implementation Pa_ounit_lib.Runtime, it should be
+# pretty unstable in future releases of Pa_ounit. Sigh.
+
+MyOCamlOUnitTest(LIB) =
+    name=ounittest_$(LIB)
+    $(name).ml:
+        section:
+            chan=$(fopen $@, w)
+            fprintln($(chan), module M = $(capitalize $(LIB)))
+            fprintln($(chan), let \(\) = Pa_ounit_lib.Runtime.summarize \(\))
+            close($(chan))
+
+    section:
+        OCAML_LIBS=$(LIB)
+        MyOCamlTestProgram($(name), $(name))
+
+    inline_tests.log: $(name)
+        println(Check inline_tests.log for test results)
+        ./$(name) inline-test-runner $(capitalize $(LIB)) -verbose -log -strict
+
+    .PHONY:test
+
+    test: inline_tests.log
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.