#-----------------------------------------------------------------------------# # Copyright (C) 1995-2003 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.common - this is the part of the makefiles # for building the Mercury implementation that is shared # between all the subdirectories. It also contains all # the parameters that might need to be modified when installing # Mercury on a new machine. # These parameters should all be determined automatically by `configure'. # Any definitions in the Mmake.params file take precedence over the # definitions here, so if you want to change one of the values here # it is best to just add a definition to Mmake.params. #-----------------------------------------------------------------------------# include $(MERCURY_DIR)/VERSION # The rpath for the libraries needs to be set to the final installation # directory, not $(MERCURY_DIR)/runtime etc. SET_RPATH=no WORKSPACE=$(MERCURY_DIR) include $(MERCURY_DIR)/Mmake.workspace #-----------------------------------------------------------------------------# # Specify the Mercury compiler to use for bootstrapping. MC = @BOOTSTRAP_MC@ # Specify the compilation model to use for compiling the compiler. GRADE = @GRADE@ # Specify EXT_FOR_EXE is `.exe' on MS-Windows and empty elsewhere. EXT_FOR_EXE = @EXT_FOR_EXE@ # Specify EXT_FOR_SHARED_LIB as `so' if the operating system # supports `.so' shared libraries, # `.dll' if it supports DLLs, # or as `a' if it doesn't. EXT_FOR_SHARED_LIB = @EXT_FOR_SHARED_LIB@ # Specify USE_DLLs as `yes' if the OS supports Windows-style DLLs. USE_DLLS = @USE_DLLS@ # Specify any special flags to pass to the C compiler when creating objects # for a shared library (e.g. -fpic or -fPIC for gcc). # For Irix 5 and Alpha/OSF, position-independent code is the default, # so leave this blank. CFLAGS_FOR_PIC = @CFLAGS_FOR_PIC@ # Specify EXT_FOR_PIC_OBJECTS as `pic_o' if any special $(PIC) flags are # required (see above), and as `o' otherwise. This is used to ensure that # we don't bother to build the .pic_o files if $(PIC) is null, since we can # just reuse the .o files. EXT_FOR_PIC_OBJECTS = @EXT_FOR_PIC_OBJECTS@ # Specify the Mmake command to link a shared library. # This is only used if EXT_FOR_SHARED_LIB was defined as `so' above. # This command may reference $(SO_LOCATIONS_DIR). # # LINK_SHARED_OBJ = ld -shared # for Irix 5 # LINK_SHARED_OBJ = gcc -assert nodefinitions # # for SunOS 4 (completely untested) # LINK_SHARED_OBJ = gcc -shared # for Solaris etc. LINK_SHARED_OBJ = @LINK_SHARED_OBJ@ # This is the same as LINK_SHARED_OBJ except that it # specifies a Bourne shell command rather than an Mmake command, # so if it references the SO_LOCATIONS_DIR variable it must use # ${SO_LOCATIONS_DIR} rather than $(SO_LOCATIONS_DIR). LINK_SHARED_OBJ_SH = @LINK_SHARED_OBJ_SH@ # The following variables specify options to $LINK_SHARED_OBJ to # allow/disallow unresolved symbols when building shared libraries. ALLOW_UNDEFINED = @ALLOW_UNDEFINED@ ERROR_UNDEFINED = @ERROR_UNDEFINED@ # The thread-safe version of the Boehm GC library links in lots # of system-specific libraries that we don't want to have to # explicitly link in when building the Mercury shared libraries, # so override ERROR_UNDEFINED in that case. ifeq "$(findstring .par,$(GRADE))$(findstring .gc,$(GRADE))" ".par.gc" ERROR_UNDEFINED = $(ALLOW_UNDEFINED) endif # The following variables specify how to pass options to the # $(CC) or # $(LINK_SHARED_OBJ) command to specify directories to be searched at # runtime for shared libraries. # Normally RPATH_OPT is either "-R" or "-rpath ", but you may need to # do something special to get the C compiler to pass this option on # to the linker (e.g. with gcc you can use "-Wl,-rpath,"). # RPATH_SEP is a path separator; normally either ":" # or just RPATH_OPT with a space in front of it. # The SHLIB_ versions are used when linking shared libraries # (perhaps invoking ld directly, rather than via the C compiler). # The EXE_ versions are used when linking executables. # The empty single quote pairs below are there to ensure that `make' # does not throw away any important trailing or leading whitespace. SHLIB_RPATH_OPT = @SHLIB_RPATH_OPT@'' SHLIB_RPATH_SEP = ''@SHLIB_RPATH_SEP@'' EXE_RPATH_OPT = @EXE_RPATH_OPT@'' EXE_RPATH_SEP = ''@EXE_RPATH_SEP@'' # Specify any extra libraries that must be linked in when linking shared # objects. SHARED_LIBS = @SHARED_LIBS@ # Set the installation prefix. This is done here as well as # in scripts/Mmake.vars to avoid accidentally overwriting an # existing installation when using an installed mmake. INSTALL_PREFIX = @prefix@ FINAL_INSTALL_PREFIX = @prefix@ #-----------------------------------------------------------------------------# INSTALL_MERC_GC_LIB_DIR = $(INSTALL_MERC_GRADELESS_LIB_DIR) FINAL_INSTALL_MERC_GC_LIB_DIR = $(FINAL_INSTALL_MERC_GRADELESS_LIB_DIR) # By default, GRADESTRING is defined as the result of invoking # `mmc --output-grade-string' with $(GRADE) and $(GRADEFLAGS). # But when installing the standard library, the compiler will not yet # have been installed. So we need to define GRADESTRING here, in a way # that doesn't require invoking mmc. # # Note that the definition below does _not_ include GRADEFLAGS. # So any changes to the grade flags for the standard library or # compiler itself should be done by setting GRADE, not GRADEFLAGS. GRADESTRING = $(shell $(SCRIPTS_DIR)/canonical_grade $(ALL_GRADEFLAGS)) # Options to pass to the Mercury compiler MCFLAGS += --no-infer-all --halt-at-warn --no-warn-inferred-erroneous # Do we want to deal with intermodule information when building the library? # By default yes, since this way we note immediately when intermodule # optimization breaks, and always at installation time, since we must install # the library's .opt and .trans_opt files as well. However, during development # some problems are easier to track down without intermodule optimization # complicating things. LIBRARY_INTERMODULE = yes # Do we want to compile the library with --trace minimum? # By default yes, since the library is pretty well debugged. However, # when it is being modified, it may have bugs we may want to chase down, # so we allow the user to override this by setting LIBRARY_TRACE_MINIMUM to no. # However, the test cases assume that the library is compiled with --trace # minimum, so if you do that, expect test case failures in the debugger # directory. LIBRARY_TRACE_MINIMUM = yes # Do we want to include the support for compiling directly to assembler # using the GCC back-end in the compiler? # This requires that you have the source code for gcc in the # directory specified by GCC_SRC_DIR (below). # This can be set using the `--enable-gcc-back-end' or `--disable-gcc-back-end' # options to configure; by default, configure will try to autoconfigure # it based on whether the gcc source is present. ENABLE_GCC_BACK_END = @ENABLE_GCC_BACK_END@ # Specify the directory containing the GCC sources. # This must be a relative path, not an absolute path. # The directory named should contain subdirectories `gcc', `libiberty', etc., # and the `gcc' subdirectory should contain files `gcc.c', # `tree.c', `tree.h', etc. GCC_SRC_DIR = @GCC_SRC_DIR@ # Do we want to include the support for Aditi compilation in the compiler? # This can be set using the `--enable-aditi-back-end' or # `--disable-aditi-back-end' options to configure. # It is not practical to include the code to output Aditi-RL in the alias # branch compiler - it currently takes more than an hour to compile # compiler/rl_code.m, due to performance problems compiling large disjunctions # with the new mode checker. # To disable the Aditi support, put `INCLUDE_ADITI_OUTPUT = no' # in Mmake.stage.params. Do not put this into Mmake.params - we still # want to check that the Aditi code compiles after any changes. # `mmake depend' must be run in any compiler directories affected by # the changed value (tools/bootcheck will do this automatically for # the stage2 and stage3 directories). INCLUDE_ADITI_OUTPUT = @ENABLE_ADITI_BACK_END@ # Enable building of the deep profiler? # This value of ENABLE_DEEP_PROFILER is either yes or no. ENABLE_DEEP_PROFILER=@ENABLE_DEEP_PROFILER@ #-----------------------------------------------------------------------------# INSTALL_INFO=@INSTALL_INFO@ INFO=@INFO@ TEXI2DVI=@TEXI2DVI@ DVIPS=@DVIPS@ MAKEINFO=@MAKEINFO@ LYNX=@LYNX@ PERL=@PERL@ #-----------------------------------------------------------------------------# # The linker option to use to link in the math library, if any. # Typically `-lm'. MATH_LIB=@MATH_LIB@ # More libraries to link SOCKET_LIBRARY=@SOCKET_LIBRARY@ NSL_LIBRARY=@NSL_LIBRARY@ DL_LIBRARY=@DL_LIBRARY@ READLINE_LIBRARIES=@READLINE_LIBRARIES@ TERMCAP_LIBRARY=@TERMCAP_LIBRARY@ # Extensions to use O=@OBJ_SUFFIX@ A=@LIB_SUFFIX@ # The option needed to name object files. # We need to use $(empty_string) here to prevent Make from truncating # any trailing spaces in -o empty_string= OBJFILE_OPT=@OBJFILE_OPT@$(empty_string) # Are we compiling using the MS C compiler? USING_MICROSOFT_CL_COMPILER=@USING_MICROSOFT_CL_COMPILER@ #-----------------------------------------------------------------------------# # Module-specific options should go in Mercury.options so they # can be found by `mmc --make'. include $(MERCURY_DIR)/Mercury.options $(MERCURY_DIR)/Mercury.options: @if [ ! -f $(MERCURY_DIR)/Mercury.options ]; then \ touch $(MERCURY_DIR)/Mercury.options; \ fi # The Mmake.params file can be used to override definitions in this file -include $(MERCURY_DIR)/Mmake.params # Avoid trying to make this file with `mmc --make' if it doesn't exist. $(MERCURY_DIR)/Mmake.params: ; #-----------------------------------------------------------------------------# # # `mmake check_namespace' performs various checks on the header files # and object files to make sure that they conform with our coding standards. # ifdef CHECK_OBJS HDR_CHECK_CS = $(CHECK_HDRS:.h=.check_hdr.c) HDR_CHECK_OBJS = $(CHECK_HDRS:.h=.check_hdr.$O) HDR_CHECK_MACROS = $(CHECK_HDRS:.h=.check.macros) MHDR_CHECK_CS = $(CHECK_MHDRS:.mh=.check_mhdr.c) MHDR_CHECK_OBJS = $(CHECK_MHDRS:.mh=.check_mhdr.$O) MHDR_CHECK_MACROS = $(CHECK_MHDRS:.mh=.check.mmacros) OBJ_CHECKS = $(CHECK_OBJS:%=%.obj_check) # Macro names must normally start with one of the prefixes associated # with the different components of our system: # `MR_' or `MERCURY_' for stuff in the Mercury runtime implementation # (the `runtime' and `trace' directories) # `ML_' for stuff in the Mercury standard library # (the `library' directory) # `MDB_' and `MDBCOMP_'for stuff in the browser # (the `browser' directory) # `GC_' for stuff in the Boehm et al conservative garbage collector # (the `boehm_gc' directory) # `MPS_' or `mps_' for stuff in the Memory Pool System toolkit # (the `mps_gc' directory, if present -- note that this # is in a separate CVS module and is not included in the # normal Mercury source distributions) # Exceptions to this policy must be listed in the RESERVED_MACRO_NAMES file # in the relevant directory. # # XXX The base_typeclass_info prefix is allowed only temporarily; it should # be fixed by adding a prefix giving the name of the module defining the # typeclass. GEN_MACRO_PREFIX_EXPRS = \ -e '^MR_' -e '^MERCURY_' -e '^GC_' -e '^MPS_' -e '^mps_' GEN_OBJ_PREFIX_EXPRS = \ -e '^MR_' -e '^_entry' -e '^mercury_' -e '^base_typeclass_info_' ifeq ("$(ALLOW_LIB_PREFIX)","yes") LIB_MACRO_PREFIX_EXPRS = \ -e '^ML_' LIB_OBJ_PREFIX_EXPRS = \ -e '^ML_' else LIB_MACRO_PREFIX_EXPRS = LIB_OBJ_PREFIX_EXPRS = endif ifeq ("$(ALLOW_BROWSER_PREFIX)","yes") BROWSER_MACRO_PREFIX_EXPRS = \ -e '^MDB_' -e '^MDBCOMP_' BROWSER_OBJ_PREFIX_EXPRS = \ -e '^MDB_' -e '^MDBCOMP_' -e '^mdb_' -e '^mdbcomp_' else BROWSER_MACRO_PREFIX_EXPRS = BROWSER_OBJ_PREFIX_EXPRS = endif MACRO_PREFIX_EXPRS = \ $(GEN_MACRO_PREFIX_EXPRS) \ $(LIB_MACRO_PREFIX_EXPRS) \ $(BROWSER_MACRO_PREFIX_EXPRS) OBJ_PREFIX_EXPRS = \ $(GEN_OBJ_PREFIX_EXPRS) \ $(LIB_OBJ_PREFIX_EXPRS) \ $(BROWSER_OBJ_PREFIX_EXPRS) HEADER_CLEAN_FILTER = \ grep -v $(MACRO_PREFIX_EXPRS) | fgrep -v -x -f RESERVED_MACRO_NAMES # This rule checks that object files are properly namespace-clean, with # regard to the global symbols that they define. # For an object file foo.o, it produces a file foo.o.obj_check that # contains a list of all the globals defined by that object that # do not start with `MR_', `mercury_', or `entry_'. %.obj_check: % nm -g $< | awk '$$1 != "U" { print $$3; }' | \ grep -v $(OBJ_PREFIX_EXPRS) | sort -u > $@ @if cmp -s /dev/null $@; then \ true; \ else \ echo "** Global symbols in user namespace:"; \ cat $@; \ echo "(You may need to add a distinguishing prefix to these names.)"; \ exit 1; \ fi # These rules help to check that header files is self-contained, i.e. that each # header file foo.h includes any other header files that define types # used by foo.h. It creates a foo.check_hdr.c file that contains only a single # `#include' statement that includes foo.h; compiling foo.check_hdr.c will fail # if foo.h is not self-contained. Similarly for .mh files. %.check_hdr.c : %.h echo "#include \"$*.h\"" > $*.check_hdr.c %.check_mhdr.c : %.mh echo "#include \"$*.mh\"" > $*.check_mhdr.c # These rules check whether a header file defines any macros it shouldn't. # They generates the list of macros defined in the header file, and filter this # list through a command that is intended to filter out all references to macro # names that are all right. Each directory that uses this rule must set arrange # for the precursors of the HEADER_CLEAN_FILTER make variable to contain this # command. # # The two rules should differ only in the filenames they use and in the fact # that the automatically created header file for module x is allowed to have # two macros, X_H and X_DECL_GUARD over and above what HEADER_CLEAN_FILTER # allows. # # XXX We should consider deleting the special handling of these macros, and # requiring instead that the compiler put MERCURY_ prefixes in front of them, # considering them to be honorary submodules of the "mercury" module. AWK = awk %.check.macros: %.h %.check_hdr.c @> $*.empty.c -@CC@ -E $*.empty.c -nostdinc -dN 2> /dev/null | \ $(AWK) '/[ \t]*#define/ { print $$2; }' | sort -u > $*.base -$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) \ -DMERCURY_BOOTSTRAP_H -DMR_NO_CONF_BACKWARDS_COMPAT \ -E $*.check_hdr.c -nostdinc -dN \ 2> /dev/null | $(AWK) '/[ \t]*#define/ { print $$2; }' | \ $(HEADER_CLEAN_FILTER) | sort -u > $*.actual @comm -1 -3 $*.base $*.actual > $@ @rm $*.base $*.actual $*.empty.c @if cmp -s /dev/null $@; then \ true; \ else \ echo "** Macro name(s) in user namespace:"; \ cat $@; \ echo "(You may need to add a distinguishing prefix to these names.)"; \ exit 1; \ fi %.check.mmacros: %.mh %.check_mhdr.c @> $*.mempty.c -@CC@ -E $*.mempty.c -nostdinc -dN 2> /dev/null | \ $(AWK) '/[ \t]*#define/ { print $$2; }' | sort -u > $*.mbase -$(MGNUC) $(ALL_GRADEFLAGS) $(ALL_MGNUCFLAGS) \ -DMERCURY_BOOTSTRAP_H -DMR_NO_CONF_BACKWARDS_COMPAT \ -E $*.check_mhdr.c -nostdinc -dN \ 2> /dev/null | $(AWK) '/[ \t]*#define/ { print $$2; }' | \ grep -v -e `echo $(subst .check.mmacros,,$@) | tr '[a-z]' '[A-Z]'`_H | \ grep -v -e `echo $(subst .check.mmacros,,$@) | tr '[a-z]' '[A-Z]'`_DECL_GUARD | \ $(HEADER_CLEAN_FILTER) | sort -u > $*.mactual @comm -1 -3 $*.mbase $*.mactual > $@ @rm $*.mbase $*.mactual $*.mempty.c @if cmp -s /dev/null $@; then \ true; \ else \ echo "** Macro name(s) in user namespace:"; \ cat $@; \ echo "(You may need to add a distinguishing prefix to these names.)"; \ exit 1; \ fi #-----------------------------------------------------------------------------# .PHONY: check_headers_self_contained check_headers_self_contained: $(HDR_CHECK_OBJS) $(MHDR_CHECK_OBJS) .PHONY: check_headers_macros check_headers_macros: $(HDR_CHECK_MACROS) $(MHDR_CHECK_MACROS) .PHONY: check_headers check_headers: check_headers_self_contained check_headers_macros .PHONY: check_objs check_objs: $(OBJ_CHECKS) .PHONY: check_namespace check_namespace: check_headers check_objs .PHONY: clean_check clean_check: -rm -f $(HDR_CHECK_OBJS) $(HDR_CHECK_CS) $(HDR_CHECK_MACROS) -rm -f $(MHDR_CHECK_OBJS) $(MHDR_CHECK_CS) $(MHDR_CHECK_MACROS) -rm -f $(OBJ_CHECKS) endif # ifdef CHECK_OBJS #-----------------------------------------------------------------------------#