Commits

camlspotter committed 310e2f9

implicit rule debug

Comments (0)

Files changed (2)

 USE_OCAMLFIND = true
 OCAMLFIND_DESTDIR=$(PREFIX)/lib/ocaml/site-lib
 
-#|Preinstalled libraries which are always available once OCamlFind is installed
-OCAMLFIND_PREINSTALLED_LIBRARIES[]= bigarray camlp4 dbm dynlink findlib graphics num num-top stdlib str threads unix
+#|Preinstalled libraries which are always available for normal ocaml.
+#
+# You may want to add the required packages which are built and installed out of OMy framework:
+#
+#::
+#
+#   include OMyMakefile
+#   
+#   OCAMLFIND_PREINSTALLED_PACKAGES += findlib # findlib has been installed already, independently
+#   
+#   Subdirs()
+OCAMLFIND_PREINSTALLED_PACKAGES[]= bigarray camlp4 dbm dynlink graphics num num-top stdlib str threads unix
 
 # byte/nat
 NATIVE_ENABLED = $(OCAMLOPT_EXISTS)
 # Dependencies
 # =========================================================================
 
-#|Add dependencies of OCaml compiled files (cmx, cmo, etc.) over $(files)
-OCamlDependsOn(files) =
-    %.cmx %.cmo %.cmi %.cma %.cmxa %.annot %.spot %.spit: $(files)
+#|Add dependencies of OCaml compiled files (cmx, cmo, etc.) over $(packages).
+# $(packages) listed in OCAMLFIND_PREINSTALLED_PACKAGES are ignored.
+#
+# This introduces implicit rule: *you may need to export it.*
+OCamlRequire(packages) =
+    packages += findlib # Yes we use findlib
+    required_packs = $(set-diff $(packages), $(OCAMLFIND_PREINSTALLED_PACKAGES))
+    %.cmx %.cmo %.cmi %.cma %.cmxa %.annot %.spot %.spit : $(Installed $(required_packs))
+    export
 
-#|We first build ocamlfind before compiling any ocaml compiled files
-OCamlDependsOn($(Installed findlib))
+#|Add dependencies of OCaml dependency analysis and build over $(packages).
+# Use this for adding dependencies for CamlP4 extensions.
+# $(packages) listed in OCAMLFIND_PREINSTALLED_PACKAGES are ignored.
+#
+# This introduces implicit rules: *you may need to export it.*
+OCamlRequireCamlP4(packages) =
+    packages += findlib # Yes we use findlib
+    required_packs = $(set-diff $(packages), $(OCAMLFIND_PREINSTALLED_PACKAGES))
+    .SCANNER: scan-ocaml-%: $(Installed $(required_packs))
+    %.cmx %.cmo %.cmi %.cma %.cmxa %.annot %.spot %.spit : $(Installed $(required_packs))
+    export
 
 #|``omake xxx.auto.mli`` generates .mli file from xxx.ml 
 %.auto.mli: %.ml
 	$(OCamlC) -i -c $< > $@
 
-# CamlP4 modules
+# Packages
 # =========================================================
 
-#| Add dependencies of OCaml dependency analysis and build over $(packages).
-#  Use this for adding dependencies for CamlP4 extensions.
-UseCamlP4Modules(packages) =
-    .SCANNER: scan-ocaml-%: $(Installed $(packages))
-
-    OCamlDependsOn($(Installed $(packages)))
+#| CamlP4 syntax extension packages required for parsing
+public.CAMLP4PACKS[]=
 
 # Build rules
 # ==========================================================
 
    return $(TARGETS)
 
+# Add implicit dependencies over the packages declared in OCAMLPACKS and CAMLP4PACKS
+# If this function is used in a local scope, you may want to export. 
+AddLocalOCamlPackageDependencies() =
+  # We make sure the required libraries are installed
+  OCamlRequire($(OCAMLPACKS)) # must be exported!
+  OCamlRequireCamlP4($(CAMLP4PACKS))
+  export
+
 #| Add a rule for OCaml package $(library_name).cmo, $(library_name).cmx and etc.
 #     library_name
 #         target package name
 #
 #  Todo: external C library
 MyOCamlPackage(library_name, files, cmodules, linkopts) =
-  # We make sure the required libraries are installed
-  installed_packs_ = $(set-diff $(OCAMLPACKS), $(OCAMLFIND_PREINSTALLED_LIBRARIES))
-  installed_packs=$(addprefix $(INSTALLED)/, $(installed_packs_))
+  AddLocalOCamlPackageDependencies()
+  export # The above thing is local: need to be exported
 
   CSTUBS=$(addsuffix .o,$(cmodules))
   CMOS=$(addsuffix .cmo,$(library_name))
       CSTUBLIBRARIES= dll$(library_name).so lib$(library_name).a 
       export
 
-  OCamlDependsOn($(installed_packs))
   # CR jfuruse: I guess we do not need the following
   # export # export the implicit rule above
 
 #      files
 #          OCaml module names (without .ml)
 MyOCamlProgram(name, files) =
-  # We make sure the required libraries are installed
-  installed_packs_ = $(set-diff $(OCAMLPACKS), $(OCAMLFIND_PREINSTALLED_LIBRARIES))
-  installed_packs=$(addprefix $(INSTALLED)/, $(installed_packs_))
-
-  %.cmo %.cmx %.cmi: $(installed_packs)
-  export # export the implicit rule above
+  AddLocalOCamlPackageDependencies()
+  export # The above thing is local: need to be exported
 
   .DEFAULT: $(OCamlProgram $(name), $(files))
 
 #        files
 #            OCaml module name (without .ml)
 MyOCamlLibrary(name, files) =
-  # We make sure the required libraries are installed
-  installed_packs_ = $(set-diff $(OCAMLPACKS), $(OCAMLFIND_PREINSTALLED_LIBRARIES))
-  installed_packs=$(addprefix $(INSTALLED)/, $(installed_packs_))
-
-  %.cmo %.cmx %.cmi: $(installed_packs)
-  export # export the implicit rule above
+  AddLocalOCamlPackageDependencies()
+  export # The above thing is local: need to be exported
 
   .DEFAULT: $(OCamlProgram $(name), $(files))
 
                 heading = ""
             formatted.append(line)
         else:
-            m = re.match("^\s*([A-Za-z_0-9]+\(.*\))\s*=", line) # a function
+            m = re.match("^\s*([A-Za-z_0-9\.]+\(.*\))\s*=", line) # a function
             if m:
                 heading = ".. function:: " + m.group(1) + "\n\n"
             else:
-                m = re.match("^\s*([A-Za-z_0-9\[\]]+)\s*=(.*)", line) # a variable
+                m = re.match("^\s*([A-Za-z_0-9\[\]\.]+)\s*=(.*)", line) # a variable
                 if m:
-                    heading = ".. function:: " + m.group(1) + "\n\n"
+                    heading = ".. function:: " + m.group(1) + " variable\n\n" # CR variable required since py context add () otherwise
                     if not re.match("^\s*$", m.group(2)):
                         formatted = ["\n", "::", "\n", "\n", "    = " + m.group(2) + "\n\n"] + formatted
                 elif re.match(":", line): # a rule