mirror of
https://github.com/Mercury-Language/mercury.git
synced 2025-12-12 20:34:19 +00:00
Added built-in mmake support for installing user libraries.
Estimated hours taken: 30 Added built-in mmake support for installing user libraries. Mmake.common.in: Moved the definitions of many of the generic install directories (plus FULLARCH and LIBGRADES) to scripts/Mmake.vars.in, so they can be used for things other than just the Mercury compiler. compiler/modules.m: Added code to generate appropriate lib<module>.install* targets. Improved the dependency list generated for the lib<module> target to include intermodule optimisation files if and only if the appropriate flags have been set (previously it always depended on the `.opt' files, but never on the `.trans_opt' files). scripts/Mmake.rules: Added some rules for use when installing libraries. scripts/Mmake.vars.in: Added the definitions of many of the generic install directories (plus FULLARCH and LIBGRADES) from Mmake.common.in. Added support for overriding and/or adding to the definition of LIBGRADES on a per-library basis. scripts/mercury_cleanup_install: New script, for cleaning up after failed installs. scripts/Mmakefile: Added `mercury_cleanup_install' to the list of scripts to be installed. bindist/Mmakefile: bindist/bindist.Makefile.in: Added `mercury_cleanup_install' and `vpath_find' to the list of utilities included in and installed by a binary distribution. These are used by some of the install targets. doc/user_guide.texi: Documented the new features. extras/references/Mmakefile: extras/references/samples/Mmakefile: Changed to exploit/test new features.
This commit is contained in:
@@ -321,3 +321,78 @@ realclean_local: clean_local
|
||||
clean_local: clean_prof_files
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
#
|
||||
# Targets for building and installing libraries.
|
||||
#
|
||||
|
||||
# Note: the `lib%.install_ints' rule is generated in each module's `.dep'
|
||||
# file so it can be more easily customised based on the desired level of
|
||||
# intermodule optimisation.
|
||||
|
||||
.PHONY: lib%.install
|
||||
lib%.install: lib%.install_ints lib%.install_init lib%.install_library
|
||||
$(MMAKE) lib$*.install_grades || ( mercury_cleanup_install && exit 1 )
|
||||
|
||||
.PHONY: lib%.install_split
|
||||
lib%.install_split: lib%.install_ints lib%.install_init \
|
||||
lib%.install_split_library
|
||||
$(MMAKE) lib$*.install_split_grades || \
|
||||
( mercury_cleanup_install && exit 1 )
|
||||
|
||||
.PHONY: lib%.install_init
|
||||
lib%.install_init: %.init install_lib_dirs
|
||||
cp `vpath_find $*.init` $(INSTALL_MODULE_DIR)
|
||||
|
||||
.PHONY: lib%.install_library
|
||||
lib%.install_library: lib%.a lib%.$(EXT_FOR_SHARED_LIB) install_grade_dirs
|
||||
cp `vpath_find lib$*.a lib$*.$(EXT_FOR_SHARED_LIB)` \
|
||||
$(INSTALL_MERC_LIB_DIR)
|
||||
|
||||
lib%.install_split_library: %.split.a install_grade_dirs
|
||||
cp `vpath_find $*.split.a` $(INSTALL_MERC_LIB_DIR)/lib$*.a
|
||||
|
||||
lib%.install_grades:
|
||||
rm -rf tmp_dir && \
|
||||
mkdir tmp_dir && \
|
||||
{ mv -f $($*.cs) $($*.os) $($*.pic_os) *.a *.so tmp_dir || true; } && \
|
||||
for grade in x $(ALL_LIBGRADES); do \
|
||||
if [ "$$grade" != "x" ]; then \
|
||||
$(MMAKE) GRADE=$$grade lib$*.install_library || \
|
||||
exit 1; \
|
||||
rm -f $($*.cs) $($*.os) $($*.pic_os) *.a *.so; \
|
||||
fi; \
|
||||
done && \
|
||||
{ mv tmp_dir/*.c $(cs_subdir). ; \
|
||||
mv tmp_dir/*.o $(os_subdir). ; \
|
||||
mv tmp_dir/*.pic_o $(os_subdir). ; \
|
||||
mv tmp_dir/* . ; rmdir tmp_dir ; true }
|
||||
|
||||
lib%.install_split_grades:
|
||||
rm -rf tmp_dir && \
|
||||
mkdir tmp_dir && \
|
||||
{ mv -f $($*.dirs) *.a *.so tmp_dir || true; } && \
|
||||
for grade in x $(ALL_LIBGRADES); do \
|
||||
if [ "$$grade" != "x" ]; then \
|
||||
$(MMAKE) GRADE=$$grade lib$*.install_split_library || \
|
||||
exit 1; \
|
||||
rm -rf $($*.dirs) *.a *.so; \
|
||||
fi; \
|
||||
done && \
|
||||
{ mv tmp_dir/*.dir $(dirs_subdir). ; \
|
||||
mv tmp_dir/* . ; rmdir tmp_dir ; true }
|
||||
|
||||
|
||||
.PHONY: install_lib_dirs
|
||||
install_lib_dirs:
|
||||
-[ -d $(INSTALL_INT_DIR) ] || mkdir -p $(INSTALL_INT_DIR)
|
||||
-[ -d $(INSTALL_INC_DIR) ] || mkdir -p $(INSTALL_INC_DIR)
|
||||
-[ -d $(INSTALL_MODULE_DIR) ] || mkdir -p $(INSTALL_MODULE_DIR)
|
||||
# The following is needed to support the `--use-subdirs' option
|
||||
-[ -d $(INSTALL_INT_DIR)/Mercury ] || \
|
||||
mkdir -p $(INSTALL_INT_DIR)/Mercury
|
||||
|
||||
.PHONY: install_grade_dirs
|
||||
install_grade_dirs: #install_lib_dirs
|
||||
-[ -d $(INSTALL_MERC_LIB_DIR) ] || mkdir -p $(INSTALL_MERC_LIB_DIR)
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
@@ -188,6 +188,11 @@ ALL_RANLIBFLAGS = $(RANLIBFLAGS) $(EXTRA_RANLIBFLAGS) $(TARGET_RANLIBFLAGS)
|
||||
RANLIBFLAGS =
|
||||
EXTRA_RANLIBFLAGS =
|
||||
|
||||
# List of grades to install for a library
|
||||
ALL_LIBGRADES = $(TARGET_LIBGRADES) $(EXTRA_TARGET_LIBGRADES)
|
||||
LIBGRADES =
|
||||
EXTRA_LIBGRADES =
|
||||
|
||||
# $(CFLAGS_FOR_PIC) is passed to the C compiler when creating `.pic_o' files
|
||||
# (We use `.pic_o' as the extension for `.o' files that must have
|
||||
# position-independent code.)
|
||||
@@ -305,6 +310,17 @@ TARGET_EXTRA_LIBRARIES = \
|
||||
maybe-target-EXTRA_LIBRARIES- = $(EXTRA_LIBRARIES-$(patsubst %_init.c,%,$@))
|
||||
maybe-target-EXTRA_LIBRARIES-undefined =
|
||||
|
||||
TARGET_LIBGRADES = \
|
||||
$(maybe-base-LIBGRADES-$(findstring undefined,$(origin LIBGRADES-$*)))
|
||||
maybe-base-LIBGRADES- = $(LIBGRADES-$*)
|
||||
maybe-base-LIBGRADES-undefined = $(LIBGRADES) $(EXTRA_LIBGRADES)
|
||||
|
||||
EXTRA_TARGET_LIBGRADES = \
|
||||
$(maybe-base-EXTRA_LIBGRADES-$(findstring undefined,\
|
||||
$(origin EXTRA_LIBGRADES-$*)))
|
||||
maybe-base-EXTRA_LIBGRADES- = $(EXTRA_LIBGRADES-$*)
|
||||
maybe-base-EXTRA_LIBGRADES-undefined =
|
||||
|
||||
# Support for compiling Mercury programs with Prolog will probably be
|
||||
# dropped one of these days, so it's probably not worth bothering with these.
|
||||
TARGET_MNCFLAGS =
|
||||
@@ -323,6 +339,9 @@ TARGET_MSPFLAGS =
|
||||
|
||||
ifeq ($(MMAKE_USE_SUBDIRS),yes)
|
||||
|
||||
# If you change any of these, you may need to update
|
||||
# `mercury_cleanup_install'.
|
||||
|
||||
SUBDIR=Mercury/
|
||||
|
||||
nos_subdir=$(SUBDIR)nos/
|
||||
@@ -384,3 +403,66 @@ MAIN_TARGET =
|
||||
default_target: main_target
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
# Specify the locations for installing things.
|
||||
# These directories can all be modified independantly.
|
||||
# In particular, you might want to find a better place for the DVI and
|
||||
# HTML files.
|
||||
|
||||
# FINAL_INSTALL_PREFIX describes the directory that the installation
|
||||
# will finally end up in. When building the Mercury compiler, it
|
||||
# should only be set by the configure script. Other
|
||||
# FINAL_INSTALL_* variables have a similar meaning.
|
||||
#
|
||||
# If you want to install to a different directory temporarily (e.g.
|
||||
# to build a package, or if you don't have the permissions to install
|
||||
# to a final directory), override INSTALL_PREFIX on the command-line.
|
||||
# If you have previously configured to the directory you want to
|
||||
# finally install to, you will then be able to move the files safely,
|
||||
# since any hard-coded paths will be set to their final destination
|
||||
# already (note that the installation in the temporary directory may
|
||||
# not work until moved into its final destination).
|
||||
# e.g.
|
||||
# configure --prefix /usr
|
||||
# make INSTALL_PREFIX=/some/temporary/directory/usr
|
||||
|
||||
# If you don't intend to install to a temporary directory, rather than
|
||||
# overriding INSTALL_PREFIX you should reconfigure using the configure
|
||||
# script, since there are some hardcoded paths created by the configure
|
||||
# script (e.g. in the shell scripts mmc, ml, mmake, etc) that will not
|
||||
# be updated simply by overriding INSTALL_PREFIX.
|
||||
|
||||
INSTALL_PREFIX = @prefix@
|
||||
FINAL_INSTALL_PREFIX = @prefix@
|
||||
INSTALL_BINDIR = $(INSTALL_PREFIX)/bin
|
||||
INSTALL_LIBDIR = $(INSTALL_PREFIX)/lib/mercury
|
||||
FINAL_INSTALL_LIBDIR = $(FINAL_INSTALL_PREFIX)/lib/mercury
|
||||
INSTALL_INFO_DIR = $(INSTALL_PREFIX)/info
|
||||
INSTALL_DVI_DIR = $(INSTALL_PREFIX)/lib/mercury/doc
|
||||
INSTALL_TEXT_DIR = $(INSTALL_PREFIX)/lib/mercury/doc
|
||||
INSTALL_PS_DIR = $(INSTALL_PREFIX)/lib/mercury/doc
|
||||
INSTALL_MAN_DIR = $(INSTALL_PREFIX)/man
|
||||
INSTALL_HTML_DIR = $(INSTALL_PREFIX)/lib/mercury/html
|
||||
INSTALL_MDB_DOC_DIR = $(INSTALL_PREFIX)/lib/mercury/mdb
|
||||
INSTALL_ELISP_DIR = $(INSTALL_PREFIX)/lib/mercury/elisp
|
||||
|
||||
# You should not need to override anything below here
|
||||
|
||||
INSTALL_MODULE_DIR = $(INSTALL_LIBDIR)/modules
|
||||
INSTALL_INT_DIR = $(INSTALL_LIBDIR)/ints
|
||||
INSTALL_INC_DIR = $(INSTALL_LIBDIR)/inc
|
||||
INSTALL_MMAKE_DIR = $(INSTALL_LIBDIR)/mmake
|
||||
FULLARCH = @FULLARCH@
|
||||
INSTALL_MERC_BIN_DIR = $(INSTALL_LIBDIR)/bin/$(FULLARCH)
|
||||
INSTALL_MERC_GRADELESS_LIB_DIR = $(INSTALL_LIBDIR)/lib/$(FULLARCH)
|
||||
FINAL_INSTALL_MERC_GRADELESS_LIB_DIR = $(FINAL_INSTALL_LIBDIR)/lib/$(FULLARCH)
|
||||
INSTALL_MERC_LIB_DIR = $(INSTALL_LIBDIR)/lib/$(GRADESTRING)/$(FULLARCH)
|
||||
FINAL_INSTALL_MERC_LIB_DIR = \
|
||||
$(FINAL_INSTALL_LIBDIR)/lib/$(GRADESTRING)/$(FULLARCH)
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
# Specify the additional compilation models to install by default
|
||||
LIBGRADES = @LIBGRADES@
|
||||
|
||||
#-----------------------------------------------------------------------------#
|
||||
|
||||
@@ -16,7 +16,7 @@ include $(MERCURY_DIR)/Mmake.common
|
||||
|
||||
SCRIPTS = mmake mmc mdb c2init mgnuc ml mprof mprof_merge_runs \
|
||||
sicstus_conv mtags vpath_find mercury_update_interface \
|
||||
mkfifo_using_mknod
|
||||
mkfifo_using_mknod mercury_cleanup_install
|
||||
DEBUGGER_SCRIPTS = mdbrc
|
||||
EMACS_SCRIPTS = gud.el
|
||||
|
||||
|
||||
98
scripts/mercury_cleanup_install
Executable file
98
scripts/mercury_cleanup_install
Executable file
@@ -0,0 +1,98 @@
|
||||
#! /bin/sh
|
||||
#---------------------------------------------------------------------------#
|
||||
# Copyright (C) 1999 Monash University.
|
||||
# This file may only be copied under the terms of the GNU General
|
||||
# Public License - see the file COPYING in the Mercury distribution.
|
||||
#---------------------------------------------------------------------------#
|
||||
#
|
||||
# mercury_cleanup_install
|
||||
#
|
||||
# Author: Warwick Harvey <wharvey@cs.monash.edu.au>
|
||||
#
|
||||
# Checks for failed/aborted installation attempts, and tries to clean up
|
||||
# after them, since simply re-starting the install may do the wrong thing.
|
||||
#
|
||||
# The main problem with restarting an install is when the install is
|
||||
# interrupted during the building of alternative grades of the library,
|
||||
# runtime, etc. When the alternative grades are being built, the versions
|
||||
# of the compiled files needed for the compiler itself (as opposed to
|
||||
# installed libraries) are moved into a `tmp_dir' subdirectory, with the
|
||||
# alternative versions being built in the old location. This means that if
|
||||
# the process is interrupted and then re-started, the build process will
|
||||
# attempt to re-build the compiler using some files with the wrong grade.
|
||||
#
|
||||
# This script checks for the presence of subdirectories named `tmp_dir',
|
||||
# and if it finds them, assumes that an install process has failed and
|
||||
# needs to be cleaned up. Cleaning up the failed install consists simply
|
||||
# of moving all the files in each `tmp_dir' back to where they came
|
||||
# from, overwriting any alternative grade versions that may be there,
|
||||
# and deleting the temporary directories.
|
||||
#
|
||||
# If there is an error while doing the clean-up, a more aggressive approach
|
||||
# is used. An "mmake clean" is run on the directory in question, and then
|
||||
# the `tmp_dir' is deleted completely. Note that for some directories (e.g.
|
||||
# `library' and `browser'), this deletes some C files, which require a
|
||||
# working version of Mercury to rebuild. However, if the installation got
|
||||
# as far as building the different grades of the library, then the compiler
|
||||
# (plus its default grade) has already been installed. The build scripts
|
||||
# are smart enough to find and use this installed version even if it's not
|
||||
# in the user's path, so the "mmake clean" is safe even if there is no
|
||||
# existing Mercury installation (e.g. if the user is building it from
|
||||
# release sources).
|
||||
|
||||
cleanup_failed_dirs=
|
||||
|
||||
for tmp in `find . -name tmp_dir -print` ; do
|
||||
dir=`dirname $tmp`
|
||||
echo "Cleaning up from apparent failed install in \`$dir'..."
|
||||
if (
|
||||
cd $dir && (
|
||||
if [ -d Mercury/dirs ] ; then
|
||||
dirs_subdir=Mercury/dirs/
|
||||
else
|
||||
dirs_subdir=
|
||||
fi
|
||||
# For every saved `.dir' directory, delete any existing one so
|
||||
# it can be moved back (one can't just clobber directories).
|
||||
(
|
||||
cd tmp_dir &&
|
||||
for dir in *.dir ; do
|
||||
if [ "$dir" != "*.dir" ] ; then
|
||||
rm -rf ../$dirs_subdir$dir
|
||||
fi
|
||||
done
|
||||
)
|
||||
[ -d Mercury/dirs ] && mv tmp_dir/*.dir $dirs_subdir
|
||||
[ -d Mercury/cs ] && mv -f tmp_dir/*.c Mercury/cs
|
||||
[ -d Mercury/os ] && mv -f tmp_dir/*.o tmp_dir/*.pic_o Mercury/os
|
||||
mv -f tmp_dir/* .
|
||||
rmdir tmp_dir
|
||||
)
|
||||
) ; then
|
||||
echo "Done."
|
||||
else
|
||||
echo "Failed. Trying a more aggressive approach..."
|
||||
if ( cd $dir && mmake clean && rm -rf tmp_dir ) ; then
|
||||
echo "Succeeded."
|
||||
else
|
||||
echo "Failed again. :-("
|
||||
cleanup_failed_dirs="$cleanup_failed_dirs $dir"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -n "$cleanup_failed_dirs" ] ; then
|
||||
cat <<END
|
||||
|
||||
Clean-up failed in the following directories:
|
||||
|
||||
$cleanup_failed_dirs
|
||||
|
||||
Either fix these directories by hand, or start over from scratch.
|
||||
|
||||
END
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
||||
Reference in New Issue
Block a user