mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-15 13:55:07 +00:00
Estimated hours taken: 15 Split the automatically generated `.dep' file into two files. The new `.dv' file contains all the variable definitions which used to be in the `.dep' file, which now contains just the rules. With mmake including the `.dv' files before the user's Mmakefile and the `.dep' files after, this allows user-defined Mmakefiles to refer to the automatically-generated variables and automatically-generated rules to refer to variables defined in the user's Mmakefile. This was possible before to a limited extent, but in particular dependency lists for automatically-generated rules could not refer to user-defined variables. Also introduced `C2INITARGS' as part of an illustration of how this change is useful (though probably this should be a separate change). `C2INITARGS' should be used to specify extra files to be passed to `c2init', rather than the currently-used `C2INITFLAGS' (which should only be used for option flags). The `_init.c' target should depend on these extra arguments, but it was not possible to do this automatically prior to this change (at least, not if one wanted to support per-program specification of `C2INITARGS'). compiler/modules.m: Generate the new `.dv' files and revised `.dep' files. Update the `change_clean' and `real_clean' targets to delete the `.dv' files. Update the `_init.c' rule to refer to `$(ALL_C2INITARGS)' as well as `$(ALL_C2INITFLAGS)', and add a dependency on `$(ALL_C2INITARGS)'. scripts/Mmake.rules: Add appropriate rules and dependencies for `.dv' files. scripts/Mmake.vars.in: Add definitions for implementing `C2INITARGS'. scripts/mmake.in: Add code for using `.dv' files (while maintaining backward compatibility for when they don't exist). doc/user_guide.texi: Document the new `.dv' files. Document the new `C2INITARGS' variables and the dependencies they imply. ../clpr/Mmakefile: ../clpr/samples/Mmakefile: extras/complex_numbers/samples/Mmakefile: extras/complex_numbers/tests/Mmakefile: extras/graphics/mercury_opengl/Mmakefile: extras/references/samples/Mmakefile: extras/references/tests/Mmakefile: extras/trailed_update/samples/Mmakefile: extras/trailed_update/tests/Mmakefile: Update to use `C2INITARGS' instead of `C2INITFLAGS', where appropriate, and remove any now-obsolete `%_init.c' dependencies (which wouldn't have worked anyway since GNU Make ignores pattern dependencies with no commands).
257 lines
6.2 KiB
Bash
257 lines
6.2 KiB
Bash
#! /bin/sh
|
|
# @configure_input@
|
|
#---------------------------------------------------------------------------#
|
|
# Copyright (C) 1995-1999 The University of Melbourne.
|
|
# This file may only be copied under the terms of the GNU General
|
|
# Public License - see the file COPYING in the Mercury distribution.
|
|
#---------------------------------------------------------------------------#
|
|
#
|
|
# mmake - Mercury Make.
|
|
#
|
|
# Type mmake -h for help.
|
|
#
|
|
#-----------------------------------------------------------------------------#
|
|
|
|
# IMPORTANT: the manpage is produced automatically from this help
|
|
# message, so if you change the help message, don't forget to check
|
|
# that the manpage still looks OK.
|
|
Help="\
|
|
Name: mmake -- Mercury Make
|
|
Usage: mmake [<mmake options>] [-- <make options>] <target>...
|
|
Options:
|
|
--use-subdirs:
|
|
Build intermediate files in a \`Mercury' subdirectory,
|
|
rather than in the current directory.
|
|
(If the current directory already contains a \`Mercury'
|
|
subdirectory, then this option is the default.)
|
|
-s, --save-makefile:
|
|
Save the generated makefile to \`Mmake.makefile'.
|
|
This is useful for tracking down syntax errors in
|
|
your Mmake file.
|
|
-v, --verbose:
|
|
Print verbose progress messages.
|
|
-w-, --no-warn-undefined-vars:
|
|
Normally Mmake will warn about variables which are used
|
|
but not defined. This option disables that warning.
|
|
(The warning is never enabled when doing \`mmake clean'
|
|
or \`mmake depend' or the like, to avoid spurious
|
|
warnings when the dependencies have not yet been made.)
|
|
-h, --help:
|
|
Print this usage message.
|
|
Targets:
|
|
<module>.depend:
|
|
Make the files \`<module>.dep' and \`<module>.dv'. This
|
|
step is required in preparation for the targets below.
|
|
<module>:
|
|
Compile and link a Mercury program with main module
|
|
\`<module>.m' to produce an executable.
|
|
<module>.nu:
|
|
Compile and link a Mercury program with NU-Prolog
|
|
rather than with the Mercury compiler.
|
|
<module>.sicstus:
|
|
Compile and link a Mercury program with SICStus Prolog
|
|
rather than with the Mercury compiler.
|
|
<module>.nu.debug:
|
|
<module>.sicstus.debug:
|
|
Debugging versions of the above.
|
|
clean:
|
|
Remove intermediate files.
|
|
realclean:
|
|
Remove all automatically-generated files: intermediate files,
|
|
dependency files, and executables.
|
|
"
|
|
|
|
MMAKE_MAKE=${MMAKE_MAKE=@GNU_MAKE@}
|
|
MMAKE_DIR=${MMAKE_DIR=@LIBDIR@/mmake}
|
|
MMAKE_VARS=${MMAKE_VARS=$MMAKE_DIR/Mmake.vars}
|
|
MMAKE_RULES=${MMAKE_RULES=$MMAKE_DIR/Mmake.rules}
|
|
MERCURY_INT_DIR=${MERCURY_INT_DIR=@LIBDIR@/ints}
|
|
MERCURY_DEFAULT_GRADE=${MERCURY_DEFAULT_GRADE=@DEFAULT_GRADE@}
|
|
MKTEMP=@MKTEMP@
|
|
|
|
MMAKE=$0
|
|
verbose=false
|
|
save_makefile=false
|
|
if [ -d Mercury ]; then
|
|
use_subdirs=${MMAKE_USE_SUBDIRS=yes}
|
|
else
|
|
use_subdirs=${MMAKE_USE_SUBDIRS=no}
|
|
fi
|
|
warn_undefined_vars=true
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case "$1" in
|
|
-h|--help)
|
|
echo "$Help"
|
|
exit 0
|
|
;;
|
|
--use-subdirs)
|
|
use_subdirs=yes
|
|
shift
|
|
;;
|
|
--no-use-subdirs)
|
|
use_subdirs=no
|
|
shift
|
|
;;
|
|
-s|--save-makefile)
|
|
save_makefile=true
|
|
MMAKE="$MMAKE $1"
|
|
shift
|
|
;;
|
|
-s-|--no-save-makefile)
|
|
save_makefile=false
|
|
MMAKE="$MMAKE $1"
|
|
shift
|
|
;;
|
|
-v|--verbose)
|
|
verbose=true
|
|
MMAKE="$MMAKE $1"
|
|
shift
|
|
;;
|
|
-v-|--no-verbose)
|
|
verbose=false
|
|
MMAKE="$MMAKE $1"
|
|
shift
|
|
;;
|
|
-w|--warn-undefined-vars)
|
|
warn_undefined_vars=true
|
|
shift
|
|
;;
|
|
-w-|--no-warn-undefined-vars)
|
|
warn_undefined_vars=false
|
|
shift
|
|
;;
|
|
--)
|
|
MMAKE="$MMAKE $1"
|
|
shift
|
|
break
|
|
;;
|
|
*)
|
|
break
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ -f Mmakefile ]; then
|
|
mmake="Mmakefile"
|
|
else
|
|
if [ -f Mmake ]; then
|
|
mmake="Mmake"
|
|
else
|
|
mmake=""
|
|
fi
|
|
fi
|
|
|
|
case $use_subdirs in
|
|
no)
|
|
dvs="`echo *.dv`"
|
|
if [ "$dvs" = "*.dv" ]; then
|
|
dvs=""
|
|
fi
|
|
deps="`echo *.dep`"
|
|
if [ "$deps" = "*.dep" ]; then
|
|
deps=""
|
|
fi
|
|
ds="`echo *.d`"
|
|
if [ "$ds" = "*.d" ]; then
|
|
ds=""
|
|
fi
|
|
;;
|
|
yes)
|
|
dvs="`echo Mercury/deps/*.dv`"
|
|
if [ "$dvs" = "Mercury/deps/*.dv" ]; then
|
|
dvs=""
|
|
fi
|
|
deps="`echo Mercury/deps/*.dep`"
|
|
if [ "$deps" = "Mercury/deps/*.dep" ]; then
|
|
deps=""
|
|
fi
|
|
ds="`echo Mercury/ds/*.d`"
|
|
if [ "$ds" = "Mercury/ds/*.d" ]; then
|
|
ds=""
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
MMAKE_USE_SUBDIRS=$use_subdirs
|
|
|
|
if $save_makefile; then
|
|
tmp=Mmake.makefile
|
|
else
|
|
case "$MKTEMP" in
|
|
"") old_umask=`umask`
|
|
umask 022
|
|
mmake_tmpdir=/tmp/mmake$$
|
|
tmp=$mmake_tmpdir/mmake
|
|
trap 'rmdir $mmake_tmpdir >/dev/null 2>&1; exit 1' \
|
|
1 2 3 13 15
|
|
if mkdir $mmake_tmpdir ; then
|
|
true
|
|
else
|
|
echo "Unable to create temporary makefile" 1>&2
|
|
exit 1
|
|
fi
|
|
trap 'status=$?; rm -rf $mmake_tmpdir; exit $status' \
|
|
0 1 2 3 13 15
|
|
umask $old_umask
|
|
;;
|
|
*)
|
|
# mktemp should give its own error message.
|
|
tmp=`$MKTEMP /tmp/mmake.XXXXXX` || exit 1
|
|
trap 'status=$?; rm -f $tmp; exit $status' 0 1 2 3 13 15
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
MMAKE_MAKE_CMD="${MMAKE_MAKE} -f $tmp -r"
|
|
|
|
# Enable checking for undefined variables -- but not when making the
|
|
# dependencies, or when cleaning up, because in either of those two
|
|
# cases the dependencies might not have been made yet, so there may be
|
|
# lots of undefined variables.
|
|
case "$@" in
|
|
dep*|*' dep'*|*.dep*|*clean*)
|
|
MMAKE_MAKE_OPTS=""
|
|
;;
|
|
*)
|
|
case $warn_undefined_vars in
|
|
true) MMAKE_MAKE_OPTS="--warn-undefined-variables" ;;
|
|
false) MMAKE_MAKE_OPTS="" ;;
|
|
esac
|
|
;;
|
|
esac
|
|
|
|
# For backwards compatibility/bootstrapping:
|
|
# If no `.dv' files exist, use the `.dep' files instead.
|
|
if [ "$dvs" = "" ] ; then
|
|
dvs=$deps
|
|
deps=
|
|
fi
|
|
|
|
if $verbose; then
|
|
echo MMAKE=$MMAKE
|
|
echo export MMAKE
|
|
echo MMAKE_MAKE_CMD=$MMAKE_MAKE_CMD
|
|
echo export MMAKE_MAKE_CMD
|
|
echo MMAKE_USE_SUBDIRS=$MMAKE_USE_SUBDIRS
|
|
echo export MMAKE_USE_SUBDIRS
|
|
echo MERCURY_INT_DIR=$MERCURY_INT_DIR
|
|
echo export MERCURY_INT_DIR
|
|
echo MERCURY_DEFAULT_GRADE=$MERCURY_DEFAULT_GRADE
|
|
echo export MERCURY_DEFAULT_GRADE
|
|
echo cat ${MMAKE_VARS} $dvs $ds $mmake $deps ${MMAKE_RULES} ">>" $tmp
|
|
echo ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r "$@"
|
|
fi
|
|
export MMAKE
|
|
export MMAKE_MAKE_CMD
|
|
export MMAKE_USE_SUBDIRS
|
|
export MERCURY_INT_DIR
|
|
export MERCURY_DEFAULT_GRADE
|
|
cat ${MMAKE_VARS} $dvs $ds $mmake $deps ${MMAKE_RULES} > $tmp
|
|
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 ;;
|
|
*) ${MMAKE_MAKE} ${MMAKE_MAKE_OPTS} -f $tmp -r "$@" ;;
|
|
esac
|