From: Kim Nguyễn Date: Sat, 30 Nov 2013 12:19:03 +0000 (+0100) Subject: Fix a bug in the build script that was causing some .cmo files to have a false depend... X-Git-Tag: v0.1~26 X-Git-Url: http://git.nguyen.vg/gitweb/?p=tatoo.git;a=commitdiff_plain;h=45ca692d34ec370b542564a1ca195b205b1a3c6f Fix a bug in the build script that was causing some .cmo files to have a false dependency on .cmx files. --- diff --git a/.gitignore b/.gitignore index 9a69b9e..2925cef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ gmon.out -*.dep +*.dep* *.cm* *.o *.native diff --git a/Remakefile.in b/Remakefile.in index 623fb86..b3b1168 100644 --- a/Remakefile.in +++ b/Remakefile.in @@ -1,5 +1,5 @@ .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) @@ -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 \ - -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" @@ -58,12 +58,14 @@ distclean: clean test_clean %.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 $< -%.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: @@ -75,9 +77,10 @@ distclean: clean test_clean $(OCAMLLEX) $*.mll fi -%.cmx %.dep: +%.cmx %.depx: base=$* target=$@ + DEPEXT=depx 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 -%.cmo %.dep: +%.cmo %.depo: base=$* target=$@ - NATIVE= + DEPEXT=depo + NATIVE="" 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 + DEPEXT=.depo COMPILE="$(OCAMLC) $(OCAMLFLAGS) $(OCAMLCFLAGS) $(OCAMLFINDFLAGS)" else COMPILE="$(OCAMLOPT) $(OCAMLFLAGS) $(OCAMLOPTFLAGS) $(OCAMLFINDFLAGS)" + DEPEXT=.depx fi . tools/ocamldriver.sh diff --git a/tools/ocamldriver.sh b/tools/ocamldriver.sh index 5d65e04..6d8e39b 100644 --- a/tools/ocamldriver.sh +++ b/tools/ocamldriver.sh @@ -37,27 +37,30 @@ if test "$DOPACK"; then 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 -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 - 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 - 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 - 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 diff --git a/tools/ocamlmoduledep.sh b/tools/ocamlmoduledep.sh index befd4cd..a9f2ee9 100755 --- a/tools/ocamlmoduledep.sh +++ b/tools/ocamlmoduledep.sh @@ -4,7 +4,7 @@ PROG="$0" CMDLINE="$*" usage() { - echo "$PROG [-native] [-I dir .. -I dir] Module" + echo "$PROG [-inter] [-native] [-I dir .. -I dir] Module" } INCLUDES="" @@ -16,7 +16,7 @@ while true; do -I) dir=`echo "$2" | sed "s:^+:$(ocamlc -where)/:"` INCLUDES="$INCLUDES -$2" +$dir" 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 + if test -z "$include"; then continue; fi base="$include/$module" - if test -z "$include"; then continue; fi 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 + ## else we depend on the implementation 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