* Seal the representation of states
[tatoo.git] / Remakefile.in
index cb9fc4a..c1f2b25 100644 (file)
@@ -1,4 +1,5 @@
-OCAMLFINDPACKAGES = "ulex,unix,expat,camlp4.macro"
+.OPTIONS = variable-propagation
+OCAMLFINDPACKAGES = "ulex,unix,expat,camlp4.macro,bigarray"
 OCAMLFINDSYNTAX = camlp4o
 OCAMLFINDPPOPTS = $(addprefix "-ppopt ", @CAMLP4FLAGS@ -I include)
 OCAMLFINDINCLUDES = $(addprefix "-I ", src)
@@ -8,6 +9,7 @@ OCAMLFINDLINKFLAGS = -linkpkg
 PACKAGE = @PACKAGE_TARNAME@
 SRC = src
 BIN = src/@PACKAGE_TARNAME@.native@EXE@
+BYTE = src/@PACKAGE_TARNAME@.byte@EXE@
 EXE = @EXE@
 
 REMAKE = @REMAKE@
@@ -35,7 +37,7 @@ clean:
        for dir in src tools; do
                find $dir -name '*.cm*' -o -name '*.o' -o -name '*.byte' -o \
                          -name '*.native' -o -name '*.mll' -o -name '*.mly' -o \
-                         -name '*.class' -o -name '*.dep' | while read file; do
+                         -name '*.class' -o -name '*.depo' -o -name '*.depx' -o -name '*.ml.str' | while read file; do
                case "$file" in
                        *.mll)
                                rm -f "${file%.mll}.ml"
@@ -43,255 +45,123 @@ clean:
                        *.mly)
                                rm -f "${file%.mly}.ml" "${file%.mly}.mli"
                        ;;
+                       *.ml.str)
+                               rm -f "${file%.ml.str}.ml"
+                       ;;
                        *)
-                       rm -f "$file"
+                               rm -f "$file"
                        ;;
                esac
                done
        done
 
 distclean: clean test_clean
-       rm -rf config.status configure config.log autom4te.cache .remake Remakefile remake
+       rm -rf config.status configure config.log autom4te.cache .remake Remakefile remake Makefile
 
 %.class: %.java
        javac $<
 
-%.native$(EXE): %.cmx %.dep
-       objects=`cat $*.dep | xargs | sed 's/[.]dep/.cmx/g'`
-       $(OCAMLOPT) -o $@  $(OCAMLFLAGS) $(OCAMLOPTFLAGS) $(OCAMLFINDLINKFLAGS) $(OCAMLFINDFLAGS) $objects $<
+%.native$(EXE): %.cmx %.depx
+       if test -f $@".flags"; then
+               FLAGS=`cat $@".flags"`
+       fi
+       objects=`cat $*.depx | xargs | sed 's/[.]depx/.cmx/g'`
+       $(REMAKE) OCAMLNATIVE="-native" $objects #ensure all objects have been built
+       $(OCAMLOPT) -o $@  $(OCAMLFLAGS) $(OCAMLOPTFLAGS) $(OCAMLFINDLINKFLAGS) $(OCAMLFINDFLAGS) $FLAGS $objects $<
 
-%.byte$(EXE): %.cmo %.dep
-       objects=`cat $*.dep | xargs | sed 's/[.]dep/.cmo/g'`
+%.byte$(EXE): %.cmo %.depo
+       objects=`cat $*.depo | xargs | sed 's/[.]depo/.cmo/g'`
+       $(REMAKE) OCAMLNATIVE="" $objects #ensure all objects have been built
        $(OCAMLC) -o $@  $(OCAMLFLAGS) $(OCAMLCFLAGS) $(OCAMLFINDLINKFLAGS) $(OCAMLFINDFLAGS) $objects $<
 
 %.ml:
        if test -f $*.mly; then
+               $(REMAKE) $*.mly
                $(OCAMLYACC) $*.mly
        elif test -f $*.mll; then
+               $(REMAKE) $*.mll
                $(OCAMLLEX) $*.mll
+       elif test -f $*.ml.str; then
+               $(REMAKE) $*.ml.str
+               echo -n 'let content = "' > $*.ml
+               sed -e 's/\(["\\]\)/\\\1/g' $*.ml.str | sed -e 's/^\(.*\)$/\1\\n\\/g' >> $*.ml
+                echo '' >> $*.ml
+                echo '"' >> $*.ml
        fi
 
-%.cmx %.dep:
-       REMAKE="$(REMAKE) -v OCAMLNATIVE=-native"
+%.cmx %.depx:
        base=$*
-       dirname=${base%/*}
-       if test -f "$dirname".pack; then
-               #we are below a pack directory
-               PACKDIR=`basename $dirname`
-               PACKINCLUDE="-I $dirname"
-       elif test -f $*.pack -a -d $*; then
-               $(REMAKE) $*.pack
-               PACKINCLUDE="-I $*"
-               PACKDIR=`basename $*`
-               DOPACK=1
-       fi
-       if test "$PACKDIR"; then
-               PACKNAME=`echo $PACKDIR | cut -b1 | tr a-z A-Z`${PACKDIR#?}
-               FORPACK="-for-pack $PACKNAME"
-       fi
-
-       if test "$DOPACK"; then
-               modules=`cat $*.pack`
-               objects=`echo $modules | xargs tools/ocamlmoduledep.sh -native $PACKINCLUDE -I $(SRC) `
-       else
-               $REMAKE $*.ml
-               modules=`$(OCAMLDEP) $(OCAMLFINDFLAGS) -modules $*.ml | cut -f 2- -d ':'`
-               objects=`tools/ocamlmoduledep.sh -native $PACKINCLUDE -I $(SRC) $modules`
-       fi
-
-       $REMAKE $objects
-
-       deps=`echo $objects | sed 's/[.]cm[ix]/.dep/g'`
-       rm -f $*.dep; touch $*.dep
-       $(REMAKE) $deps
-       for f in $deps; do
-         for g in `cat $f`; do
-             if grep -q $g $*.dep; then continue; fi
-             echo $g >> $*.dep
-          done
-          if grep -q $f $*.dep; then continue; fi
-          echo $f >> $*.dep
-       done
-       if test -f $*.mli; then $REMAKE -v PACKINCLUDE="$PACKINCLUDE" $*.cmi; fi
-       if test "$DOPACK"; then
-               sorted_objects=`cat $*.dep | grep "$PACKDIR" | sed 's/[.]dep/.cmx/' | xargs`
-               cat $*.dep | grep -v "$PACKDIR" > $*.tmp
-               mv $*.tmp $*.dep
-               $(OCAMLOPT) -o $@ -pack $(OCAMLFLAGS) $(OCAMLOPTFLAGS) $(OCAMLFINDFLAGS) $sorted_objects
-       else
-               $(OCAMLOPT) -o $@ $FORPACK -c $PACKINCLUDE $(OCAMLFLAGS) $(OCAMLOPTFLAGS) $(OCAMLFINDFLAGS) $*.ml
+       target=$@
+       DEPEXT=depx
+       NATIVE=-native
+       REMAKE="$(REMAKE) OCAMLNATIVE=$NATIVE"
+       OCAMLDEP="$(OCAMLDEP) $(OCAMLFINDFLAGS)"
+       SRC=$(SRC)
+       if test -f "$base".flags; then
+               FLAGS=`cat "$base".flags`
        fi
+       COMPILE="$(OCAMLOPT) $(OCAMLFLAGS) $(OCAMLOPTFLAGS) $(OCAMLFINDFLAGS) $FLAGS"
+       . tools/ocamldriver.sh
 
-%.cmo %.dep:
-       REMAKE="$(REMAKE)"
+%.cmo %.depo:
        base=$*
-       dirname=${base%/*}
-       if test -f "$dirname".pack; then
-               #we are below a pack directory
-               PACKDIR=`basename $dirname`
-               PACKINCLUDE="-I $dirname"
-       elif test -f $*.pack -a -d $*; then
-               PACKINCLUDE="-I $*"
-               PACKDIR=`basename $*`
-               DOPACK=1
-       fi
+       target=$@
+       DEPEXT=depo
+       NATIVE=""
+       REMAKE="$(REMAKE) OCAMLNATIVE=$NATIVE"
+       OCAMLDEP="$(OCAMLDEP) $(OCAMLFINDFLAGS)"
+       SRC=$(SRC)
+       COMPILE="$(OCAMLC) $(OCAMLFLAGS) $(OCAMLCFLAGS) $(OCAMLFINDFLAGS)"
+       . tools/ocamldriver.sh
 
-       if test "$DOPACK"; then
-               modules=`cat $*.pack`
-               objects=`echo $modules | xargs tools/ocamlmoduledep.sh $PACKINCLUDE -I $(SRC) `
-               $REMAKE $objects
+%.cmi:
+       base=$*
+       target=$@
+       NATIVE=$(OCAMLNATIVE)
+       REMAKE="$(REMAKE) OCAMLNATIVE=$NATIVE"
+       OCAMLDEP="$(OCAMLDEP) $(OCAMLFINDFLAGS)"
+       SRC=$(SRC)
+       if test -z "$NATIVE"; then
+               DEPEXT=.depo
+               COMPILE="$(OCAMLC) $(OCAMLFLAGS) $(OCAMLCFLAGS) $(OCAMLFINDFLAGS)"
        else
-               $REMAKE $*.ml
-               modules=`$(OCAMLDEP) $(OCAMLFINDFLAGS) -modules $*.ml | cut -f 2- -d ':'`
-               objects=`tools/ocamlmoduledep.sh $PACKINCLUDE -I $(SRC) $modules`
-               $REMAKE $objects
+               COMPILE="$(OCAMLOPT) $(OCAMLFLAGS) $(OCAMLOPTFLAGS) $(OCAMLFINDFLAGS)"
+               DEPEXT=.depx
        fi
+       . tools/ocamldriver.sh
 
-       deps=`echo $objects | sed 's/[.]cm[io]/.dep/g'`
-       rm -f $*.dep; touch $*.dep
-       $(REMAKE) $deps
-       for f in $deps; do
-          for g in `cat $f`; do
-             if grep -q $g $*.dep; then continue; fi
-             echo $g >> $*.dep
-          done
-          if grep -q $f $*.dep; then continue; fi
-          echo $f >> $*.dep
-       done
-
-       if test -f $*.mli; then $REMAKE -v PACKINCLUDE="$PACKINCLUDE" $*.cmi; fi
-       if test "$DOPACK"; then
-               sorted_objects=`cat $*.dep | grep "$PACKDIR" | sed 's/[.]dep/.cmo/' | xargs`
-               cat $*.dep | grep -v "$PACKDIR" > $*.tmp
-               mv $*.tmp $*.dep
-               $(OCAMLC) -o $@ -pack $(OCAMLFLAGS) $(OCAMLCFLAGS) $(OCAMLFINDFLAGS) $sorted_objects
-       else
-               $(OCAMLC) -o $@ -c $PACKINCLUDE $(OCAMLFLAGS) $(OCAMLCFLAGS) $(OCAMLFINDFLAGS)  $*.ml
-       fi
+## Tests
 
-%.cmi:
-       $(REMAKE) $*.mli
-       if test -z "$(OCAMLNATIVE)"; then
-               $(OCAMLC) -c $(OCAMLFLAGS) $(OCAMLCFLAGS) $(OCAMLFINDFLAGS) $(PACKINCLUDE) $*.mli
-       else
-               $(OCAMLOPT) -c $(OCAMLFLAGS) $(OCAMLOPTFLAGS) $(OCAMLFINDFLAGS) $(PACKINCLUDE) $*.mli
+test_byte: tools $(BYTE)
+       $(REMAKE) TEST=$(BYTE) real_test
 
-       fi
+test_native: tools $(BIN)
+       $(REMAKE) TEST=$(BIN) real_test
 
-## Tests
+test: test_native
 
-test: tools $(BIN)
+real_test:
        for i in tests/*.xml
        do
          for j in 1 2 3
          do
-               $(REMAKE) "$i".test"$j".summary
+               $(REMAKE) TEST=$(TEST) "$i".test"$j".summary
          done
        done
 
 test_clean:
        rm -rf tests/*.summary tests/*.results/*_"$(PACKAGE)"_*.*
 
-%.test1.summary:
-               base="$@"
-               base=${base%.xml.test1.summary}
-               $(REMAKE) "$base".xml "$base".xml.queries
-               rm -f "$@"
-               MSG="Test 1 (single query: tatoo vs java implementation)"
-               echo "$MSG" >> "$@"
-               echo "$MSG"
-               cat "$base".xml.queries | grep -v '^#' | while read q query; do
-                       echo -n "$base"".xml $q $query ... "
-                       REF="$base".xml.results/"$q"_jaxp.xml
-                       $(REMAKE) "$REF"
-                       OUTPUT="$base".xml.results/"$q"_"$(PACKAGE)"_test1.xml
-                       LOG="$base".xml.results/"$q"_"$(PACKAGE)"_test1.log
-                       cp "$@" /tmp
-                       src/@PACKAGE_TARNAME@.native@EXE@ -s -d "$base".xml \
-                               "$query" -o "$OUTPUT" > "$LOG" 2>&1
-                       cp "$@" /tmp
-                       echo "Query: $q : $query" >> "$@"
-                       cat  "$LOG" | grep '^STATS' >> "$@"
-                       echo -n "Diff: " >> "$@"
-                       if tools/xml_diff.native "$REF" "$OUTPUT" >/dev/null 2>&1; then
-                               echo ok
-                               echo ok >> "$@"
-                       else
-                               echo failed
-                               echo failed >> "$@"
-                               exit 1
-                       fi
-                       echo '-------------------------------------------' >> "$@"
-               done
-
-%.test2.summary:
-               base="$@"
-               base=${base%.xml.test2.summary}
-               $(REMAKE) "$base".xml "$base".xml.queries
-               rm -f "$@"
-               MSG="Test 2 (all queries sequentially vs all queries in parallel)"
-               echo "$MSG" >> "$@"
-               echo "$MSG"
-               allqueries=`cat "$base".xml.queries | grep -v '^#' | while read q query; do echo "'$query'"; done`
-               echo -n "Running all queries ... "
-               OUTPUTA="$base".xml.results/test2a_"$(PACKAGE)".xml
-               LOG="$base".xml.results/test2a_"$(PACKAGE)".log
-               echo -n "sequential ... "
-               echo "$allqueries" | xargs src/@PACKAGE_TARNAME@.native@EXE@ -s -d "$base".xml \
-                -o "$OUTPUTA" > "$LOG" 2>&1
-               cat  "$LOG" | grep '^STATS' >> "$@"
-
-               OUTPUTB="$base".xml.results/test2b_"$(PACKAGE)".xml
-               LOG="$base".xml.results/test2b_"$(PACKAGE)".log
-               echo -n "parallel ... "
-               echo "$allqueries" | xargs src/@PACKAGE_TARNAME@.native@EXE@ -p -s -d "$base".xml \
-                -o "$OUTPUTB" > "$LOG" 2>&1
-               cat  "$LOG" | grep '^STATS' >> "$@"
-                       echo -n "Diff: " >> "$@"
-               if diff "$OUTPUTA" "$OUTPUTB" >/dev/null 2>&1; then
-                       echo ok
-                       echo ok >> "$@"
-               else
-                       echo failed
-                       echo failed >> "$@"
-                       exit 1
-               fi
-               echo '-------------------------------------------' >> "$@"
-
-%.test3.summary:
-               base="$@"
-               base=${base%.xml.test3.summary}
-               $(REMAKE) "$base".xml "$base".xml.queries
-               rm -f "$@"
-               MSG="Test 3 (multiple queries composition: sequential vs parallel)"
-               echo "$MSG" >> "$@"
-               echo "$MSG"
-               cat "$base".xml.queries | grep -v '^#' | while read q query; do
-                       echo -n "$base"".xml $q $query ... sequential ... "
-                       OUTPUTA="$base".xml.results/"$q"_"$(PACKAGE)"_test3a.xml
-                       LOG="$base".xml.results/"$q"_"$(PACKAGE)"_test3a.log
-                       src/@PACKAGE_TARNAME@.native@EXE@ -s -d -C "$base".xml \
-                                -o "$OUTPUTA" $(tools/split_path.native$(EXE) "$query") > "$LOG" 2>&1
-                       echo "Query: $q : $query" >> "$@"
-                       cat  "$LOG" | grep '^STATS' >> "$@"
-
-                       echo -n "parallel ... "
-                       OUTPUTB="$base".xml.results/"$q"_"$(PACKAGE)"_test3a.xml
-                       LOG="$base".xml.results/"$q"_"$(PACKAGE)"_test3a.log
-                       src/@PACKAGE_TARNAME@.native@EXE@ -s -d -p -C "$base".xml \
-                                -o "$OUTPUTB" $(tools/split_path.native$(EXE) "$query") > "$LOG" 2>&1
-                       echo "Query: $q : $query" >> "$@"
-                       cat  "$LOG" | grep '^STATS' >> "$@"
-
-
-                       echo -n "Diff: " >> "$@"
-                       if diff  "$OUTPUTA" "$OUTPUTB" >/dev/null 2>&1; then
-                               echo ok
-                               echo ok >> "$@"
-                       else
-                               echo failed
-                               echo failed >> "$@"
-                               exit 1
-                       fi
-                       echo '-------------------------------------------' >> "$@"
-               done
+%.summary:
+       target=$@
+       base=$*
+       test=${base#*.xml.}
+       xml=${base%.$test}
+       REMAKE=$(REMAKE)
+       BIN=$(TEST)
+       SPLIT=tools/split_path.native$(EXE)
+       XMLDIFF=tools/xml_diff.native$(EXE)
+       PACKAGE=$(PACKAGE)
+       $REMAKE $xml ${xml}.queries tests/${test}.sh
+       rm -f "$target"
+       . tests/${test}.sh