Commits

camlspotter  committed b383bdc

added RecalcFlags for file wise pp flags

  • Participants
  • Parent commits 8044df8

Comments (0)

Files changed (2)

 # OCaml 
 # ========================================================================
 
+#| OCAMLANY is either byte or native
+OCAMLANY =
+    if $(OCAMLC_EXISTS)
+        value $(OCAMLC)
+    else 
+        value $(OCAMLOPT)
+
 #|Path to the OCaml library directory
-OCAML_WHERE = $(shell ocamlc -where)
+OCAML_WHERE = $(shell $(OCAMLANY) -where)
 
 #|Version without extensions
-OCAML_VERSION = $(shell ocamlc -version | sed -e 's/^\([0-9.]*\).*/\1/')
+OCAML_VERSION = $(shell $(OCAMLANY) -version | sed -e 's/^\([0-9.]*\).*/\1/')
 
 #|OMy requires OCamlFind!
 USE_OCAMLFIND = true
     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 by default
 BYTE_ENABLED = true
 
 #|The default warning and errors. If you want to use different warning and error switches, use redefine the variable.
 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!
+#If you are in developing something, override 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.
+#                                BUT of the OCaml compiler used by the author of OMyMakefile.
 OCAMLWARNING_MAX= 45
 
 #|Function to build warning switches
 #|Additional implicit rules by file extensions
 # annot, cmt, cmti files
 %.annot %.cmt: %.ml %.cmi
-	$(OCamlC) -c -annot $(OCAMLANNOTFLAGS) $<
+	$(OCamlC) -c $<
 
 %.cmti: %.mli 
-	$(OCamlC) -c $(OCAMLANNOTFLAGS) $<
+	$(OCamlC) -c $<
 
-#|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)
+#| We recommend to have OCAMLPARAM=_,g=1,annot=1,bin-annot=1,short-paths=1
 
 #|Enable the backtrace
 setenv(OCAMLRUNPARAM, b)
     .PHONY:test
 
     test: inline_tests.log
+
+
+# File compilation rule redefinition
+# ==================================================
+
+RecalcFlags_(FILE) =
+    # println(awking $(FILE))
+    # .MEMO rule seems not working at all in this context...
+    res=
+    awk($(FILE))
+    case $"OMAKE_SYNTAX[(]\([^)]*\)[)]"
+       println("$(FILE): Use the syntax override: $1")
+       res+=$(split ' ',$1)
+       export res
+    value $(res)        
+
+RecalcFlags(FILE) =
+    res=$(RecalcFlags_ $(FILE))
+    if $(not $(equal $(length $(res)), 0))
+        OCAMLPPFLAGS[]=$(split ' ',$(res))
+        OCAMLDEPFLAGS[]=$(split ' ',$(res))
+        export
+    export
+
+public.OCamlScanner(src_file) =
+    RecalcFlags($(src_file))
+    if $(OCAMLDEP_MODULES_ENABLED)
+        value $(OCAMLFIND) $(OCAMLDEP) $(LAZY_OCAMLFINDFLAGS) $(PREFIXED_OCAMLPACKS) $(OCAMLDEPFLAGS) -modules $(src_file) | ocamldep-postproc
+    else
+        value $(OCAMLFIND) $(OCAMLDEP) $(LAZY_OCAMLFINDFLAGS) $(PREFIXED_OCAMLPACKS) $(OCAMLDEPFLAGS) $(PREFIXED_OCAMLINCLUDES) $(src_file)
+
+%.cmx: %.ml
+    section rule
+        RecalcFlags(%.ml)
+        if $(not $(NATIVE_ENABLED))
+            err. =
+                extends $(UnbuildableException)
+                message = $(string $"You are trying to build OCaml native code file: "%.cmx$"
+However, the NATIVE_ENABLED flag is not set.
+Include the following definition in your OMakefile
+if you really want to build this file.
+       NATIVE_ENABLED = true")
+                target = $(file %.cmx)
+            raise $(err)
+        elseif $(target-exists %.mli)
+            %.cmx %$(EXT_OBJ): %.ml %.cmi :scanner: scan-ocaml-%.ml
+                $(OCamlOpt) -c $<
+        elseif $(BYTE_ENABLED)
+            %.cmx %.cmi %$(EXT_OBJ) %.cmo: %.ml :scanner: scan-ocaml-%.ml
+                $(OCamlC) -c $<
+                $(OCamlOpt) -c $<
+        else
+            %.cmx %.cmi %$(EXT_OBJ): %.ml :scanner: scan-ocaml-%.ml
+                $(OCamlOpt) -c $<
+
+%$(EXT_OBJ): %.ml
+    section rule
+        RecalcFlags(%.ml)
+        if $(not $(NATIVE_ENABLED))
+            err. =
+                extends $(UnbuildableException)
+                message = $(string $"You are trying to build OCaml native code file: "%$(EXT_OBJ)$"
+However, the NATIVE_ENABLED flag is not set.
+Include the following definition in your OMakefile
+if you really want to build this file.
+       NATIVE_ENABLED = true")
+                target = $(file %.cmx)
+            raise $(err)
+        elseif $(target-exists %.mli)
+            %$(EXT_OBJ) %.cmx: %.ml %.cmi :scanner: scan-ocaml-%.ml
+                $(OCamlOpt) -c $<
+        elseif $(BYTE_ENABLED)
+            %$(EXT_OBJ) %.cmi %.cmx %.cmo: %.ml :scanner: scan-ocaml-%.ml
+                $(OCamlC) -c $<
+                $(OCamlOpt) -c $<
+        else
+            %$(EXT_OBJ) %.cmi %.cmx: %.ml :scanner: scan-ocaml-%.ml
+                $(OCamlOpt) -c $<
+
+%.cmo: %.ml
+    section rule
+        RecalcFlags(%.ml)
+        if $(not $(BYTE_ENABLED))
+            err. =
+                extends $(UnbuildableException)
+                message = $(string $"You are trying to build OCaml native code file: "%.cmo$"
+However, the BYTE_ENABLED flag is not set.
+Include the following definition in your OMakefile
+if you really want to build this file.
+       BYTE_ENABLED = true")
+                target = $(file %.cmx)
+            raise $(err)
+        elseif $(target-exists %.mli)
+            %.cmo: %.ml %.cmi :scanner: scan-ocaml-%.ml
+                $(OCamlC) -c $<
+        elseif $(NATIVE_ENABLED)
+            %.cmo %.cmi %.cmx %$(EXT_OBJ): %.ml :scanner: scan-ocaml-%.ml
+                $(OCamlC) -c $<
+                $(OCamlOpt) -c $<
+        else
+            %.cmo %.cmi: %.ml :scanner: scan-ocaml-%.ml
+                $(OCamlC) -c $<
+
+%.cmi: %.ml
+    section rule
+        RecalcFlags(%.ml)
+        if $(BYTE_ENABLED)
+            if $(NATIVE_ENABLED)
+                %.cmi %.cmo %.cmx %$(EXT_OBJ): %.ml :scanner: scan-ocaml-%.ml
+                    $(OCamlC) -c $<
+                    $(OCamlOpt) -c $<
+            else
+                %.cmi %.cmo: %.ml :scanner: scan-ocaml-%.ml
+                    $(OCamlC) -c $<
+        else
+            %.cmi %.cmx %$(EXT_OBJ): %.ml :scanner: scan-ocaml-%.ml
+                $(OCamlOpt) -c $<
+
+%.cmi: %.mli :scanner: scan-ocaml-%.mli
+    RecalcFlags(%.mli)
+    $(OCamlC) -c $<

File copy-OMyMakefile

 do
   dir=`dirname $i`
   echo $dir
-  if [ `hg branch` = "default" ]; then
+  branch=`hg branch`
+  if [ "$branch" = "default" ]; then
     cp OMyMakefile $dir
     cp OMakeroot.in $dir
     (cd $dir; hg add OMyMakefile OMakeroot.in; hg commit -m 'auto update of OMyMakefile' OMyMakefile OMakeroot.in)
   else
-    echo $dir is not in default
+    echo "$dir is not in default: $branch"
   fi
 done