mirror of
https://github.com/Mercury-Language/mercury.git
synced 2026-05-01 17:24:34 +00:00
Estimated hours taken: 8 Branches: main Factor out the common Mmake code to set up the mmc, mgnuc and ml flags when building the Mercury compiler and libraries. Use options, not environment variables. This will make it simpler to use `mmc --make' to compile the compiler. Mmake.workspace: Similar to tools/lmc. Sets up Mmake variables to use the library files in a workspace rather than an installed library. configure.in: Check for the `--no-mercury-stdlib-dir' mmc option. Bootstrap CVS tag: bootstrap_20020429_stdlib_dir Mmake.common.in: */Mmakefile: Move common code into Mmake.workspace. browser/Mmakefile: library/Mmakefile: Avoid invoking the linker explicitly when creating libraries of Mercury code. That won't work well with `mmc --make'. tools/bootcheck: tests/Mmake.common: Use Mmake.workspace instead of setting up environment variables in bootcheck. scripts/Mmake.vars.in: mmc compiles split C files to object code itself, so pass `--cflags "$(ALL_CFLAGS)"' to mmc when compiling with `--split-c-files'. browser/interactive_query.m: Use `mmc --make' when compiling the query. This is needed to make tests/debugger/interactive_query.m work when linking against a workspace using options rather than environment variables. This also fixes a bug -- mmc options were being passed to ml. Clean up after the query. tests/debugger/Mmakefile: tests/debugger/interactive.inp: tests/debugger/interactive.inp.subdirs: tests/debugger/interactive.inp.nosubdirs: tests/debugger/interactive.exp: tests/debugger/interactive.exp2: Generate the input file to this test so that MCFLAGS and MC_MAKE_FLAGS (from Mmake.workspace) are used when compiling queries. tests/debugger/Mmakefile now sets SHELL to /usr/local/bash to allow the use of $(...) style command substitution (`...` style command substitution can't be nested). tests/warnings/Mmakefile: tests/dppd/Mmakefile: Include tests/Mmake.common. tools/*: scripts/c2init.in: scripts/ml.in: Update the lists of files containing the library names.
295 lines
9.4 KiB
Plaintext
295 lines
9.4 KiB
Plaintext
#-----------------------------------------------------------------------------#
|
|
# Copyright (C) 1995-2002 The University of Melbourne.
|
|
# This file may only be copied under the terms of the GNU General
|
|
# Public Licence - see the file COPYING in the Mercury distribution.
|
|
#-----------------------------------------------------------------------------#
|
|
|
|
# Mmake - this is Mmake file for building the Mercury compiler
|
|
|
|
MERCURY_DIR=..
|
|
LINK_STATIC=yes
|
|
include $(MERCURY_DIR)/Mmake.common
|
|
|
|
MAIN_TARGET=mercury
|
|
|
|
VPATH=$(LIBRARY_DIR) $(BROWSER_DIR)
|
|
|
|
#-----------------------------------------------------------------------------#
|
|
|
|
# Specify how to link in the GCC back-end.
|
|
# This uses the file `mercury_gcc_backend_libs', which is generated by
|
|
# the gcc Makefile (from gcc/mercury/Make-lang.in), which contains
|
|
# a list of the object files and libraries that we need to link in.
|
|
GCC_SRC_DIR := $(MERCURY_DIR)/$(GCC_SRC_DIR)
|
|
ifeq ($(ENABLE_GCC_BACK_END),yes)
|
|
GCC_LIBS = $(shell cat $(GCC_SRC_DIR)/gcc/mercury_gcc_backend_libs)
|
|
GCC_EXTRA_LIBS = $(filter -l%,$(GCC_LIBS))
|
|
GCC_MAIN_LIBS = $(patsubst %,$(GCC_SRC_DIR)/gcc/%,$(filter-out -l%,$(GCC_LIBS)))
|
|
GCC_BACKEND_LIBS = $(GCC_MAIN_LIBS) $(GCC_EXTRA_LIBS)
|
|
else
|
|
GCC_MAIN_LIBS =
|
|
GCC_BACKEND_LIBS =
|
|
endif
|
|
|
|
MCFLAGS += -I $(BROWSER_DIR)
|
|
ALL_MLLIBS = ../main.$O $(MLLIBS) $(EXTRA_MLLIBS) \
|
|
$(GCC_BACKEND_LIBS) $(MATH_LIB)
|
|
MLFLAGS += --no-main --shared
|
|
|
|
#
|
|
# Work-around for a fixed limit: on alpha-dec-osf3.2, if we compile with
|
|
# `-O5', then when linking mercury_compile we get an error message of the form
|
|
#
|
|
# /usr/bin/ld:
|
|
# Too many GOT entries in object file '/usr/lib/cmplrs/cc/libexc_init.a';
|
|
# Found 8190 (6660 locals + 1530 globals) but max is 8189
|
|
#
|
|
# unless we link it statically.
|
|
#
|
|
ifeq ($(FULLARCH),alpha-dec-osf3.2)
|
|
MLFLAGS += --static
|
|
endif
|
|
|
|
# Compilation of rl_code.c is really slow (about 26 minutes on traveller with
|
|
# --trace deep) at the default level of -O2, due to the C optimizer's use of
|
|
# quadratic algorithms on a couple of 20,000-line functions (the automatically
|
|
# generated index and compare routines on the bytecode type). The code in this
|
|
# module can't really benefit from those algorithms anyway. With -O1, the 26
|
|
# minutes drops to less than 26 seconds.
|
|
|
|
CFLAGS-aditi_backend.rl_code=-O1
|
|
|
|
# process_util.m uses `kill' and `struct sigaction' from <signal.h>,
|
|
# which are not available with `--ansi'.
|
|
MGNUCFLAGS-libs.process_util = --no-ansi
|
|
|
|
# The c_code in the module gcc.m needs the header files from the GNU C
|
|
# distribution.
|
|
CFLAGS-gcc = -DMERCURY_BOOTSTRAP_H \
|
|
-DIN_GCC -DHAVE_CONFIG_H \
|
|
-I. \
|
|
-I$(GCC_SRC_DIR)/gcc \
|
|
-I$(GCC_SRC_DIR)/gcc/mercury \
|
|
-I$(GCC_SRC_DIR)/gcc/config \
|
|
-I$(GCC_SRC_DIR)/include \
|
|
-I$(GCC_SRC_DIR)
|
|
# Likewise for mlds_to_gcc.m
|
|
CFLAGS-mlds_to_gcc = $(CFLAGS-gcc)
|
|
|
|
#-----------------------------------------------------------------------------#
|
|
|
|
# Rules for preprocessing `.pp' files.
|
|
# `.pp_date' files are used as timestamps as for interface files.
|
|
|
|
#
|
|
# Rule to generate foo.m from foo.pp by applying `sed $(PP_SED_EXPR)'
|
|
#
|
|
# Note that we set hash="#" for use in $(PP_SED_EXPR).
|
|
# This seems to be the easiest way to get a "#" character;
|
|
# we can't just use a Make variable since "#" is a comment character
|
|
# in Make and so its hard to create a variable with that value.
|
|
#
|
|
$(dates_subdir)%.pp_date: %.pp
|
|
-hash="#"; \
|
|
m_file=$(<:.pp=.m); \
|
|
[ ! -f $$m_file ] || chmod +w $$m_file; \
|
|
sed $(PP_SED_EXPR) $< > $$m_file.tmp && \
|
|
mercury_update_interface -v $$m_file && \
|
|
touch $@ && \
|
|
chmod -w $$m_file
|
|
|
|
#
|
|
# Define $(PP_SED_EXPR) appropriately for each preprocessed module.
|
|
#
|
|
PP_SED_EXPR = $(PP_SED_EXPR-$*)
|
|
PP_SED_EXPR-rl_file = $(ADITI_SED_EXPR)
|
|
PP_SED_EXPR-rl_out = $(ADITI_SED_EXPR)
|
|
PP_SED_EXPR-maybe_mlds_to_gcc = $(GCC_SED_EXPR)
|
|
|
|
#
|
|
# For Aditi .pp files, enable/disable code within
|
|
# `#if INCLUDE_ADITI_OUTPUT ... #else .. #endif'
|
|
#
|
|
ifeq ($(INCLUDE_ADITI_OUTPUT),yes)
|
|
# Remove the #if line and everything between the #else and #endif lines.
|
|
ADITI_SED_EXPR = -e "/^$${hash}if *INCLUDE_ADITI_OUTPUT/s/.*//" \
|
|
-e "/^$${hash}else/,/^$${hash}endif/s/.*//"
|
|
else
|
|
# Remove everything between the #if line and the #else line,
|
|
# and the #endif line.
|
|
ADITI_SED_EXPR = -e "/^$${hash}if *INCLUDE_ADITI_OUTPUT/,/^$${hash}else/s/.*//" \
|
|
-e "/^$${hash}endif/s/.*//"
|
|
endif
|
|
|
|
#
|
|
# For GCC .pp files, enable/disable code within
|
|
# `#if ENABLE_GCC_BACK_END ... #else .. #endif'
|
|
#
|
|
ifeq ($(ENABLE_GCC_BACK_END),yes)
|
|
# Remove the #if line and everything between the #else and #endif lines.
|
|
GCC_SED_EXPR = -e "/^$${hash}if *ENABLE_GCC_BACK_END/s/.*//" \
|
|
-e "/^$${hash}else/,/^$${hash}endif/s/.*//"
|
|
else
|
|
# Remove everything between the #if line and the #else line,
|
|
# and the #endif line.
|
|
GCC_SED_EXPR = -e "/^$${hash}if *ENABLE_GCC_BACK_END/,/^$${hash}else/s/.*//" \
|
|
-e "/^$${hash}endif/s/.*//"
|
|
endif
|
|
|
|
PREPROCESSED_MODULES = rl_file rl_out maybe_mlds_to_gcc
|
|
PREPROCESSED_FILES = $(PREPROCESSED_MODULES:%=%.pp)
|
|
PREPROCESSED_M_FILES = $(PREPROCESSED_MODULES:%=%.m)
|
|
PP_DATE_FILES = $(PREPROCESSED_MODULES:%=$(dates_subdir)%.pp_date)
|
|
|
|
# Force regeneration of the preprocessed modules.
|
|
# This is necessary if the setting of `INCLUDE_ADITI_OUTPUT' has changed.
|
|
regenerate_preprocessed_files:
|
|
-[ -d ./$(dates_subdir) ] || mkdir -p ./$(dates_subdir)
|
|
touch $(PREPROCESSED_FILES)
|
|
MMAKE_DIR=$(SCRIPTS_DIR) $(MMAKE) $(PREPROCESSED_M_FILES)
|
|
|
|
# The `.m' files for the preprocessed modules depend on the `.pp_date' files.
|
|
$(PREPROCESSED_M_FILES): %.m: $(dates_subdir)%.pp_date
|
|
@:
|
|
|
|
#-----------------------------------------------------------------------------#
|
|
|
|
# targets
|
|
|
|
# specify the name of the top-level module to build
|
|
MC_PROG = top_level
|
|
|
|
# mercury_compile
|
|
|
|
.PHONY: depend
|
|
depend: $(MC_PROG).depend
|
|
|
|
$(MC_PROG).depend: regenerate_preprocessed_files
|
|
|
|
.PHONY: all
|
|
all: mercury
|
|
|
|
.PHONY: mercury
|
|
mercury: mercury_compile
|
|
|
|
.PHONY: libmmc
|
|
libmmc: libmercury_compile.a mercury_compile_init.$O
|
|
|
|
# The executable was previous known as `mercury_compile',
|
|
# but now we generate it as `mc'. For compatibility with
|
|
# various existing code, we make links to the old names.
|
|
|
|
LN = ln
|
|
|
|
mercury_compile: $(MC_PROG)
|
|
rm -f mercury_compile$(EXT_FOR_EXE)
|
|
$(LN) $(MC_PROG)$(EXT_FOR_EXE) mercury_compile$(EXT_FOR_EXE)
|
|
|
|
libmercury_compile.a: lib$(MC_PROG).a
|
|
rm -f libmercury_compile.a
|
|
$(LN) lib$(MC_PROG).a libmercury_compile.a
|
|
|
|
mercury_compile_init.$O: $(MC_PROG)_init.$O
|
|
rm -f mercury_compile_init.$O
|
|
$(LN) $(MC_PROG)_init.$O mercury_compile_init.$O
|
|
|
|
#-----------------------------------------------------------------------------#
|
|
|
|
# The GCC back-end stuff is conditionally compiled out of maybe_mlds_to_gcc.m.
|
|
# But we want to make sure that the GCC back-end continues to compile,
|
|
# even when the compiler was configured without the GCC back-end.
|
|
# So we include the following rules, which tell Mmake to build the
|
|
# dependencies for mlds_to_gcc and to build mlds_to_gcc.c and gcc.c.
|
|
# (We used to just build mlds_to_gcc.err, but that caused bootstrapping problems
|
|
# with the source distribution; using the .c files is little more robust.)
|
|
|
|
.PHONY: depend
|
|
depend: mlds_to_gcc.depend
|
|
|
|
mlds_to_gcc.depend: regenerate_preprocessed_files
|
|
|
|
.PHONY: mercury
|
|
mercury: $(cs_subdir)mlds_to_gcc.c $(cs_subdir)gcc.c
|
|
|
|
.PHONY: cs
|
|
cs: $(cs_subdir)mlds_to_gcc.c $(cs_subdir)gcc.c
|
|
|
|
#-----------------------------------------------------------------------------#
|
|
|
|
# Add some additional dependencies, so that Mmake knows to remake the
|
|
# compiler if one of the libraries changes.
|
|
|
|
$(MC_PROG): ../main.$O
|
|
$(MC_PROG): $(RUNTIME_DIR)/lib$(RT_LIB_NAME).$A
|
|
$(MC_PROG): $(LIBRARY_DIR)/lib$(STD_LIB_NAME).$A
|
|
$(MC_PROG): $(BROWSER_DIR)/lib$(BROWSER_LIB_NAME).$A
|
|
$(MC_PROG): $(TRACE_DIR)/lib$(TRACE_LIB_NAME).$A
|
|
# Should also depend on $(BOEHM_GC_DIR)/libgc(_prof).$A, but only
|
|
# if in .gc(.prof) grade; GNU make does not support dynamic dependencies,
|
|
# so just leave it out.
|
|
$(MC_PROG): $(GCC_MAIN_LIBS)
|
|
|
|
$(MC_PROG)_init.c: $(UTIL_DIR)/mkinit
|
|
|
|
#-----------------------------------------------------------------------------#
|
|
|
|
.PHONY: check
|
|
check : $(MC_PROG).check
|
|
|
|
.PHONY: ints
|
|
ints : $(MC_PROG).ints
|
|
|
|
#-----------------------------------------------------------------------------#
|
|
|
|
tags : $(PREPROCESSED_M_FILES) *.m $(LIBRARY_DIR)/*.m
|
|
$(MTAGS) $(MTAGSFLAGS) *.m $(LIBRARY_DIR)/*.m
|
|
|
|
$(MC_PROG).stats : source_stats.awk $($(MC_PROG).ms)
|
|
awk -f `vpath_find source_stats.awk` \
|
|
`vpath_find $($(MC_PROG).ms)` > $@
|
|
|
|
#-----------------------------------------------------------------------------#
|
|
|
|
.PHONY: dates
|
|
dates :
|
|
touch $($(MC_PROG).dates)
|
|
|
|
#-----------------------------------------------------------------------------#
|
|
|
|
.PHONY: os cs ss
|
|
os: $($(MC_PROG).os) $(os_subdir)$(MC_PROG)_init.$O
|
|
cs: $($(MC_PROG).cs) $(cs_subdir)$(MC_PROG)_init.c
|
|
ss: $($(MC_PROG).ss)
|
|
|
|
#-----------------------------------------------------------------------------#
|
|
|
|
clean_local:
|
|
rm -f ../main.$O $(PREPROCESSED_M_FILES) $(PP_DATE_FILES)
|
|
|
|
realclean_local:
|
|
rm -f tags $(MC_PROG).stats
|
|
|
|
#-----------------------------------------------------------------------------#
|
|
#-----------------------------------------------------------------------------#
|
|
|
|
# Installation targets
|
|
|
|
.PHONY: install
|
|
install: install_mercury
|
|
|
|
.PHONY: install_all
|
|
install_all: install_mercury
|
|
|
|
.PHONY: install_mercury
|
|
install_mercury: install_compiler
|
|
|
|
.PHONY: install_dirs
|
|
install_dirs:
|
|
-[ -d $(INSTALL_MERC_BIN_DIR) ] || mkdir -p $(INSTALL_MERC_BIN_DIR)
|
|
|
|
.PHONY: install_compiler
|
|
install_compiler: mercury_compile install_dirs
|
|
cp `vpath_find mercury_compile$(EXT_FOR_EXE)` $(INSTALL_MERC_BIN_DIR)
|
|
|
|
#-----------------------------------------------------------------------------#
|