Fix a bug in the build script that was causing some .cmo files to have a false depend...
authorKim Nguyễn <kn@lri.fr>
Sat, 30 Nov 2013 12:19:03 +0000 (13:19 +0100)
committerKim Nguyễn <kn@lri.fr>
Sat, 30 Nov 2013 12:19:03 +0000 (13:19 +0100)
.gitignore
Remakefile.in
tools/ocamldriver.sh
tools/ocamlmoduledep.sh

index 9a69b9e..2925cef 100644 (file)
@@ -1,5 +1,5 @@
 gmon.out
 gmon.out
-*.dep
+*.dep*
 *.cm*
 *.o
 *.native
 *.cm*
 *.o
 *.native
index 623fb86..b3b1168 100644 (file)
@@ -1,5 +1,5 @@
 .OPTIONS = variable-propagation
 .OPTIONS = variable-propagation
-OCAMLFINDPACKAGES = "ulex,unix,expat,camlp4.macro"
+OCAMLFINDPACKAGES = "ulex,unix,expat,camlp4.macro,bigarray"
 OCAMLFINDSYNTAX = camlp4o
 OCAMLFINDPPOPTS = $(addprefix "-ppopt ", @CAMLP4FLAGS@ -I include)
 OCAMLFINDINCLUDES = $(addprefix "-I ", src)
 OCAMLFINDSYNTAX = camlp4o
 OCAMLFINDPPOPTS = $(addprefix "-ppopt ", @CAMLP4FLAGS@ -I include)
 OCAMLFINDINCLUDES = $(addprefix "-I ", src)
@@ -37,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 \
        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' | while read file; do
                case "$file" in
                        *.mll)
                                rm -f "${file%.mll}.ml"
                case "$file" in
                        *.mll)
                                rm -f "${file%.mll}.ml"
@@ -58,12 +58,14 @@ distclean: clean test_clean
 %.class: %.java
        javac $<
 
 %.class: %.java
        javac $<
 
-%.native$(EXE): %.cmx %.dep
-       objects=`cat $*.dep | xargs | sed 's/[.]dep/.cmx/g'`
+%.native$(EXE): %.cmx %.depx
+       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) $objects $<
 
        $(OCAMLOPT) -o $@  $(OCAMLFLAGS) $(OCAMLOPTFLAGS) $(OCAMLFINDLINKFLAGS) $(OCAMLFINDFLAGS) $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:
        $(OCAMLC) -o $@  $(OCAMLFLAGS) $(OCAMLCFLAGS) $(OCAMLFINDLINKFLAGS) $(OCAMLFINDFLAGS) $objects $<
 
 %.ml:
@@ -75,9 +77,10 @@ distclean: clean test_clean
                $(OCAMLLEX) $*.mll
        fi
 
                $(OCAMLLEX) $*.mll
        fi
 
-%.cmx %.dep:
+%.cmx %.depx:
        base=$*
        target=$@
        base=$*
        target=$@
+       DEPEXT=depx
        NATIVE=-native
        REMAKE="$(REMAKE) OCAMLNATIVE=$NATIVE"
        OCAMLDEP="$(OCAMLDEP) $(OCAMLFINDFLAGS)"
        NATIVE=-native
        REMAKE="$(REMAKE) OCAMLNATIVE=$NATIVE"
        OCAMLDEP="$(OCAMLDEP) $(OCAMLFINDFLAGS)"
@@ -85,10 +88,11 @@ distclean: clean test_clean
        COMPILE="$(OCAMLOPT) $(OCAMLFLAGS) $(OCAMLOPTFLAGS) $(OCAMLFINDFLAGS)"
        . tools/ocamldriver.sh
 
        COMPILE="$(OCAMLOPT) $(OCAMLFLAGS) $(OCAMLOPTFLAGS) $(OCAMLFINDFLAGS)"
        . tools/ocamldriver.sh
 
-%.cmo %.dep:
+%.cmo %.depo:
        base=$*
        target=$@
        base=$*
        target=$@
-       NATIVE=
+       DEPEXT=depo
+       NATIVE=""
        REMAKE="$(REMAKE) OCAMLNATIVE=$NATIVE"
        OCAMLDEP="$(OCAMLDEP) $(OCAMLFINDFLAGS)"
        SRC=$(SRC)
        REMAKE="$(REMAKE) OCAMLNATIVE=$NATIVE"
        OCAMLDEP="$(OCAMLDEP) $(OCAMLFINDFLAGS)"
        SRC=$(SRC)
@@ -103,9 +107,11 @@ distclean: clean test_clean
        OCAMLDEP="$(OCAMLDEP) $(OCAMLFINDFLAGS)"
        SRC=$(SRC)
        if test -z "$NATIVE"; then
        OCAMLDEP="$(OCAMLDEP) $(OCAMLFINDFLAGS)"
        SRC=$(SRC)
        if test -z "$NATIVE"; then
+               DEPEXT=.depo
                COMPILE="$(OCAMLC) $(OCAMLFLAGS) $(OCAMLCFLAGS) $(OCAMLFINDFLAGS)"
        else
                COMPILE="$(OCAMLOPT) $(OCAMLFLAGS) $(OCAMLOPTFLAGS) $(OCAMLFINDFLAGS)"
                COMPILE="$(OCAMLC) $(OCAMLFLAGS) $(OCAMLCFLAGS) $(OCAMLFINDFLAGS)"
        else
                COMPILE="$(OCAMLOPT) $(OCAMLFLAGS) $(OCAMLOPTFLAGS) $(OCAMLFINDFLAGS)"
+               DEPEXT=.depx
        fi
        . tools/ocamldriver.sh
 
        fi
        . tools/ocamldriver.sh
 
index 5d65e04..6d8e39b 100644 (file)
@@ -37,27 +37,30 @@ if test "$DOPACK"; then
 else
     $REMAKE ${base}.ml
     modules=`$OCAMLDEP -modules ${base}.ml | cut -f 2- -d ':'`
 else
     $REMAKE ${base}.ml
     modules=`$OCAMLDEP -modules ${base}.ml | cut -f 2- -d ':'`
-    objects=`tools/ocamlmoduledep.sh $NATIVE $PACKINCLUDE -I $SRC $modules`
+    if test "$EXT" = "o"; then
+       INTER=-inter
+    fi
+    objects=`tools/ocamlmoduledep.sh $INTER $NATIVE $PACKINCLUDE -I $SRC $modules`
 fi
 
 $REMAKE $objects
 
 fi
 
 $REMAKE $objects
 
-deps=`echo $objects | sed "s/[.]cm[i${EXT}]/.dep/g"`
-rm -f ${base}.dep; touch ${base}.dep
+deps=`echo $objects | sed "s/[.]cm[i${EXT}]/.$DEPEXT/g"`
+rm -f ${base}.$DEPEXT; touch ${base}.$DEPEXT
 $REMAKE $deps
 for f in $deps; do
     for g in `cat $f`; do
 $REMAKE $deps
 for f in $deps; do
     for g in `cat $f`; do
-       if grep -q $g ${base}.dep; then continue; fi
-       echo $g >> ${base}.dep
+       if grep -q $g ${base}.$DEPEXT; then continue; fi
+       echo $g >> ${base}.$DEPEXT
     done
     done
-    if grep -q $f ${base}.dep; then continue; fi
-    echo $f >> ${base}.dep
+    if grep -q $f ${base}.$DEPEXT; then continue; fi
+    echo $f >> ${base}.$DEPEXT
 done
 if test -f ${base}.mli; then $REMAKE PACKINCLUDE="$PACKINCLUDE" ${base}.cmi; fi
 if test "$DOPACK"; then
 done
 if test -f ${base}.mli; then $REMAKE PACKINCLUDE="$PACKINCLUDE" ${base}.cmi; fi
 if test "$DOPACK"; then
-    sorted_objects=`cat ${base}.dep | grep "$PACKDIR" | sed "s/[.]dep/.cm${EXT}/" | xargs`
-    cat ${base}.dep | grep -v "$PACKDIR" > ${base}.tmp
-    mv ${base}.tmp ${base}.dep
+    sorted_objects=`cat ${base}.$DEPEXT | grep "$PACKDIR" | sed "s/[.]$DEPEXT/.cm${EXT}/" | xargs`
+    cat ${base}.$DEPEXT | grep -v "$PACKDIR" > ${base}.tmp
+    mv ${base}.tmp ${base}.$DEPEXT
     $COMPILE  -o ${target} -pack $sorted_objects
 else
     $COMPILE  -o ${target} $FORPACK -c $PACKINCLUDE ${base}.ml
     $COMPILE  -o ${target} -pack $sorted_objects
 else
     $COMPILE  -o ${target} $FORPACK -c $PACKINCLUDE ${base}.ml
index befd4cd..a9f2ee9 100755 (executable)
@@ -4,7 +4,7 @@
 PROG="$0"
 CMDLINE="$*"
 usage() {
 PROG="$0"
 CMDLINE="$*"
 usage() {
-    echo "$PROG [-native] [-I dir .. -I dir] Module"
+    echo "$PROG [-inter] [-native] [-I dir .. -I dir] Module"
 }
 
 INCLUDES=""
 }
 
 INCLUDES=""
@@ -16,7 +16,7 @@ while true; do
         -I)
             dir=`echo "$2" | sed "s:^+:$(ocamlc -where)/:"`
             INCLUDES="$INCLUDES
         -I)
             dir=`echo "$2" | sed "s:^+:$(ocamlc -where)/:"`
             INCLUDES="$INCLUDES
-$2"
+$dir"
             shift
             ;;
         -native)
             shift
             ;;
         -native)
@@ -46,14 +46,18 @@ fi
 for MODULE in $MODULES; do
     module="$(echo $MODULE | cut -b1 | tr A-Z a-z)$(echo $MODULE | cut -b2-)"
     echo "$INCLUDES" | while read include; do
 for MODULE in $MODULES; do
     module="$(echo $MODULE | cut -b1 | tr A-Z a-z)$(echo $MODULE | cut -b2-)"
     echo "$INCLUDES" | while read include; do
+       if test -z "$include"; then continue; fi
         base="$include/$module"
         base="$include/$module"
-        if test -z "$include"; then continue; fi
         if test  \( "$INTER" = "1" \) -a \( -f "$base".mli \) ; then
         if test  \( "$INTER" = "1" \) -a \( -f "$base".mli \) ; then
+           ## if we want to depend only on cmi of a module
                 echo -n "$base"."cmi "
         elif test -f "$base".ml -o -f "$base".mly -o -f "$base".mll -o -f "$base".pack; then
                 echo -n "$base"."cmi "
         elif test -f "$base".ml -o -f "$base".mly -o -f "$base".mll -o -f "$base".pack; then
+           ## else we depend on the implementation 
             echo -n "$base"."$ext "
             break
         elif test -f "$base".mli; then
             echo -n "$base"."$ext "
             break
         elif test -f "$base".mli; then
+           ## and fall back on depending on the cmi if the cmx is not available
+           ## (which prevents cross-module inlining in the case of cmx)
             echo -n "$base"."cmi "
             break
         fi
             echo -n "$base"."cmi "
             break
         fi