[m-rev.] For review: New option for mmake to capture make process
Eric Taucher
gluon at earthlink.net
Wed Aug 1 11:59:02 AEST 2007
A new option to capture all of the makefiles and output created by mmake.
scripts/mmake.in:
Each make file created by mmake is captured to a separate file and the output
of each make file is capture to a separate file.
The captured files are date time stamped in the name for uniqueness, and have
the make target in the name.
This will also capture the makefiles created in the temporary workspaces
before the workspace is deleted.
By creating unique files for each makefile, the make database and make debug
output can be stored with its corresponding makefile output for easier
debugging.
Listed in each output file, is the name of the primary files used to make the
make file. Currently specific include files are not listed.
While some of the information in the captured files duplicates existing
output messages, no deletion of existing output messages was done.
Example of files created for command scripts/mmake --capture-makeprocess .. .
--debug=basic -p GRADE=asm_fast.gc.tr.debug install
make.2007-07-29-16-37-37.mercury-compiler-rotd-2007-07-24.install.Makefile
make.2007-07-29-16-37-37.mercury-compiler-rotd-2007-07-24.install.txt
make.2007-07-29-16-37-38.mercury-compiler-rotd-2007-07-24-scripts.default_target
.Makefile
make.2007-07-29-16-37-38.mercury-compiler-rotd-2007-07-24-scripts.default_target
.txt
< Items removed from example >
make.2007-07-29-16-47-07.mercury-compiler-rotd-2007-07-24-doc.install.Makefile
make.2007-07-29-16-47-07.mercury-compiler-rotd-2007-07-24-doc.install.txt
make.2007-07-29-16-50-44.mercury-compiler-rotd-2007-07-24-tmp_dir-boehm_gc.insta
ll_lib.Makefile
make.2007-07-29-16-50-44.mercury-compiler-rotd-2007-07-24-tmp_dir-boehm_gc.insta
ll_lib.txt
make.2007-07-29-16-50-45.mercury-compiler-rotd-2007-07-24-tmp_dir-runtime.instal
l_lib.Makefile
make.2007-07-29-16-50-45.mercury-compiler-rotd-2007-07-24-tmp_dir-runtime.instal
l_lib.txt
make.2007-07-29-16-51-04.mercury-compiler-rotd-2007-07-24-tmp_dir-library.depend
.Makefile
make.2007-07-29-16-51-04.mercury-compiler-rotd-2007-07-24-tmp_dir-library.depend
.txt
make.2007-07-29-16-51-15.mercury-compiler-rotd-2007-07-24-tmp_dir-library.instal
l_library.Makefile
make.2007-07-29-16-51-15.mercury-compiler-rotd-2007-07-24-tmp_dir-library.instal
l_library.txt
make.2007-07-29-16-51-19.mercury-compiler-rotd-2007-07-24-tmp_dir-mdbcomp.depend
.Makefile
make.2007-07-29-16-51-19.mercury-compiler-rotd-2007-07-24-tmp_dir-mdbcomp.depend
.txt
make.2007-07-29-16-51-28.mercury-compiler-rotd-2007-07-24-tmp_dir-mdbcomp.instal
l_library.Makefile
make.2007-07-29-16-51-28.mercury-compiler-rotd-2007-07-24-tmp_dir-mdbcomp.instal
l_library.txt
make.2007-07-29-16-51-29.mercury-compiler-rotd-2007-07-24-tmp_dir-browser.depend
.Makefile
make.2007-07-29-16-51-29.mercury-compiler-rotd-2007-07-24-tmp_dir-browser.depend
.txt
make.2007-07-29-16-51-46.mercury-compiler-rotd-2007-07-24-tmp_dir-browser.instal
l_library.Makefile
make.2007-07-29-16-51-46.mercury-compiler-rotd-2007-07-24-tmp_dir-browser.instal
l_library.txt
make.2007-07-29-16-51-48.mercury-compiler-rotd-2007-07-24-tmp_dir-trace.install_
lib.Makefile
make.2007-07-29-16-51-48.mercury-compiler-rotd-2007-07-24-tmp_dir-trace.install_
lib.txt
Example of header for captured output showing files used to make makefile.
--------------------------------------------------------------------------------
-
PWD: /cygdrive/d/Mercury/mercury-compiler-rotd-2007-07-24
Mercury make command that started process: scripts/mmake
--capture-makeprocess '..' '.' --debug=basic -p GRADE=asm_fast.gc.tr.debug
install
Standard make command to be executed: make --warn-undefined-variables
-f /tmp/mmake.bQX880 -r --debug=basic -p GRADE=asm_fast.gc.tr.debug install
Note: Standard makefile /tmp/mmake.bQX880 saved as
'/cygdrive/d/Mercury/mercury-compiler-rotd-2007-07-24/make.2007-07-29-16-37-37.m
ercury-compiler-rotd-2007-07-24.install.Makefile'
Files combined into standard makefile:
Vars:
C:/cygwin/usr/local/mercury-rotd-2007-07-24/lib/mercury/mmake/Mmake.vars
dv:
Mercury makefile:
/cygdrive/d/Mercury/mercury-compiler-rotd-2007-07-24/Mmakefile
d:
Dependencies:
Rules:
C:/cygwin/usr/local/mercury-rotd-2007-07-24/lib/mercury/mmake/Mmake.rules
Include files such as Mmake.common, VERSION, Mmake.workspace,
Merucry.options, Mmake.parms may also be used, but are not list here do to the
complexity.
--------------------------------------------------------------------------------
-
Index: mmake.in
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/scripts/mmake.in,v
retrieving revision 1.49
diff -u -r1.49 mmake.in
--- mmake.in 30 Nov 2005 16:23:51 -0000 1.49
+++ mmake.in 1 Aug 2007 01:37:36 -0000
@@ -47,6 +47,26 @@
Save the generated makefile to \`Mmake.makefile'.
This is useful for tracking down syntax errors in
your Mmake file.
+ --capture-makeprocess <base directory> <output directory>:
+ For each generated/executed makefile capture the makefile
+ to a file and it's console output to a separate file.
+ Notes:
+ 1. Since the make process has multiple makefiles in different
+ directories, the directory name is part of the capture
+ name. To keep the capture name shorter,
+ the base directory name is removed from the directory name.
+ .i.e. If the current directory is
+ \`/cygdrive/d/Mercury/mercury-compiler-0.13.1/runtime' and
+ the base directory is \`/cygdrive/d/Mercury/'
+ then part of the capture name will be
+ \`mercury-compiler-0.13.1-runtime'.
+ 2. In order to save the temp makefiles and put all captured
+ files in one place, an output directory is required.
+ 3. When this option is combined with make options -p
+ and/or --debug=basic, it becomes extremely useful.
+ 4. Typical use --capture-makeprocess .. . --debug=basic -p
+ 5. .. . Only work with cygwin environment,
+ other environments must use full directory name.
-f <filename>, --file <filename>:
Use the specified file as the Mmake file.
-v, --verbose:
@@ -84,9 +104,11 @@
@SET_MACOSX_DEPLOYMENT_TARGET@
MMAKE=$0
+MMAKE_OPTIONS=
include_makefile=
verbose=false
save_makefile=false
+capture_makeprocess=false
if [ -d Mercury ]; then
use_subdirs=${MMAKE_USE_SUBDIRS=yes}
else
@@ -104,18 +126,22 @@
;;
--use-subdirs)
use_subdirs=yes
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1"
shift
;;
--no-use-subdirs)
use_subdirs=no
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1"
shift
;;
--use-mmc-make)
use_mmc_make=yes
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1"
shift
;;
--no-mmc-make)
use_mmc_make=no
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1"
shift
;;
--target)
@@ -131,45 +157,90 @@
"\`--target' option" 1>&2
exit 1 ;;
esac
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1 $2"
shift; shift
;;
-s|--save-makefile)
save_makefile=true
MMAKE="$MMAKE $1"
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1"
shift
;;
-s-|--no-save-makefile)
save_makefile=false
MMAKE="$MMAKE $1"
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1"
+ shift
+ ;;
+ --capture-makeprocess)
+ # Can't use a directory if it doesn't exist
+ if [ ! -d "$2" ]; then
+ echo Directory $2 does not exist.
+ exit 1
+ fi
+ if [ ! -d "$3" ]; then
+ echo Directory $3 does not exist.
+ exit 1
+ fi
+ capture_makeprocess=true
+ # Use cygpath -a to convert . or .. to absolute path
+ CAPTURE_BASE_DIR=$(cygpath -a "$2")
+ if [ "$?" = "0" ]; then
+ CAPTURE_OUTPUT_DIR=$(cygpath -a "$3")
+ else
+ # XXX convert . or .. on non cygwin systems
+ CAPTURE_BASE_DIR=$2
+ CAPTURE_OUTPUT_DIR=$3
+ fi
+
+ # if a trailing / is in directory name then remove it
+ CAPTURE_BASE_DIR=${CAPTURE_BASE_DIR%/}
+ CAPTURE_OUTPUT_DIR=${CAPTURE_OUTPUT_DIR%/}
+
+ INDEX_POS=$(expr index '$PWD' '$CAPTURE_BASE_DIR')
+ if [ "$INDEX_POS" != "1" ]; then
+ echo "base directory: '$CAPTURE_BASE_DIR'" \
+ "is not a parent of present directory: '$PWD'"
+ fi
+
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1 '$2' '$3'"
+ shift
+ shift
shift
;;
-f|--file)
mmake="$2"
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1 '$2'"
shift
shift
;;
-v|--verbose)
verbose=true
MMAKE="$MMAKE $1"
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1"
shift
;;
-v-|--no-verbose)
verbose=false
MMAKE="$MMAKE $1"
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1"
shift
;;
-w|--warn-undefined-vars)
warn_undefined_vars=true
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1"
shift
;;
-w-|--no-warn-undefined-vars)
warn_undefined_vars=false
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1"
shift
;;
--include-makefile)
# XXX check that $2 exists first
MMAKE="$MMAKE $1 $2"
include_makefile="$include_makefile $2"
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1 '$2'"
shift
shift
;;
@@ -177,15 +248,19 @@
--mercury-standard-library-directory|--mercury-stdlib-dir)
MERCURY_STDLIB_DIR="$2"
MERCURY_CONFIG_DIR="$2"
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1"
shift
;;
--no-mercury-standard-library-directory|--no-mercury-stdlib-dir)
unset MERCURY_STDLIB_DIR
unset MERCURY_CONFIG_DIR
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1"
+ shift
;;
--mercury-config-directory-directory|--mercury-config-dir)
MERCURY_CONFIG_DIR="$2"
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1"
shift
;;
# We don't allow `MERCURY_CONFIG_DIR' to be unset
@@ -193,6 +268,7 @@
--)
MMAKE="$MMAKE $1"
+ MMAKE_OPTIONS="$MMAKE_OPTIONS $1"
shift
break
;;
@@ -215,6 +291,12 @@
export MERCURY_STDLIB_DIR
fi
+# pass parameters to recursive mmake processes using exported variables
+if [[ "$CAPTURE_BASE_DIR" != "" && "$CAPTURE_OUTPUT_DIR" != "" ]]; then
+ export CAPTURE_BASE_DIR
+ export CAPTURE_OUTPUT_DIR
+fi
+
case "$MMAKE_DIR" in
"")
echo "mmake: MMAKE_DIR not set"
@@ -341,6 +423,33 @@
deps=
fi
+make_target=default_target
+
+# XXX While not an exact method to detect make targets,
+# it does the job.
+for PARM in "$@"
+do
+ case "$PARM" in
+ # Skip any options starting with -- that are unknown.
+ --*)
+ ;;
+ # Skip any options starting with - that are unknown.
+ -*)
+ ;;
+ # Skip any options with = in them that are unknown.
+ *=*)
+ ;;
+ # If there are any parameters left and they are not an option
+ # then it is hoped that they are make targets.
+ *)
+ # While there may be more than one target,
+ # we only use the first one
+ make_target="$PARM"
+ break
+ ;;
+ esac
+done
+
if $verbose; then
echo MMAKE=$MMAKE
echo export MMAKE
@@ -379,9 +488,81 @@
echo 'endif'
cat $deps ${MMAKE_RULES}
} > $tmp
+
+if [[ "$CAPTURE_BASE_DIR" != "" && "$CAPTURE_OUTPUT_DIR" != "" ]]; then
+
+echo
+echo "PWD="$PWD
+echo "command: " $0 $@
+echo
+
+# create output file with a date/time stamp and subdirectory in name
+current_dir=$PWD
+# remove the base directory from the current directory
+subdirectory=${current_dir#${CAPTURE_BASE_DIR}}
+# if a leading / is in sudirectory then remove it
+subdirectory=${subdirectory#/}
+# Can not have / in a file name so replace all / with - in subdirectory.
+subdirectory=${subdirectory//\//-}
+timestamp=$(date +%Y-%m-%d-%H-%M-%S)
+# append .txt to show that it is a text file
+makecapture=$CAPTURE_OUTPUT_DIR/make.$timestamp.$subdirectory.$make_target.txt
+#append .Makefile because it is a Makefile
+makefilename=\
+$CAPTURE_OUTPUT_DIR/make.$timestamp.$subdirectory.$make_target.Makefile
+
+echo "-----------------------------------------------------------------------"
\
+ > $makecapture
+echo >> $makecapture
+echo "PWD: "$PWD >> $makecapture
+echo "Mercury make command that started process: " \
+ $0 $MMAKE_OPTIONS $@ >> $makecapture
+echo "Standard make command to be executed: " \
+ ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r ${set_target_asm} $@ \
+ >> $makecapture
+echo >> $makecapture
+echo "Note: Standard makefile $tmp saved as '$makefilename'" >> $makecapture
+cp $tmp "$makefilename"
+echo "Files combined into standard makefile:" >> $makecapture
+echo $'\t'"Vars: "$MMAKE_VARS >> $makecapture
+echo $'\t'"dv: "$dvs >> $makecapture
+echo $'\t'"Mercury makefile: "$PWD/$MMAKEFILE >> $makecapture
+echo $'\t'"d: "$ds >> $makecapture
+echo $'\t'"Dependencies: "$deps >> $makecapture
+echo $'\t'"Rules: "$MMAKE_RULES >> $makecapture
+echo >> $makecapture
+echo Include files such as Mmake.common, VERSION, Mmake.workspace, \
+Merucry.options, Mmake.parms may also be used, but are not list here \
+do to the complexity. >> $makecapture
+echo >> $makecapture
+echo "-----------------------------------------------------------------------"
\
+ >> $makecapture
+echo >> $makecapture
+
+case $# in
+ # Note that we can't use `exec' here, because if we did that,
+ # that `trap' code which removes $tmp would never get executed.
+ 0) ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r ${set_target_asm} \
+ >> $makecapture 2>&1 ;;
+ *) ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r ${set_target_asm} "$@" \
+ >> $makecapture 2>&1 ;;
+esac
+
+else
+
case $# in
# Note that we can't use `exec' here, because if we did that,
# that `trap' code which removes $tmp would never get executed.
0) ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r ${set_target_asm} ;;
*) ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r ${set_target_asm} "$@" ;;
esac
+
+fi
+
+if $capture_makeprocess; then
+ # clean up temporary exported values
+ CAPTURE_BASE_DIR=
+ CAPTURE_OUTPUT_DIR=
+ export CAPTURE_BASE_DIR
+ export CAPTURE_OUTPUT_DIR
+fi
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list