% Copyright 1996-2000 Critical Mass, Inc. All rights reserved.
% See file COPYRIGHT-CMASS for details.
% 
% Standard configuration file for HP-PA
%

%-------------------------------------------------- compilation environment ---

readonly TARGET       = "HPPA"                % code generation target
readonly BUILD_DIR    = TARGET                % directory for results
readonly OS_TYPE      = "POSIX"               % { "WIN32" or "POSIX" }
readonly WORD_SIZE    = "32BITS"              % { "32BITS" or "64BITS" }
readonly GNU_PLATFORM = "hppa1.1-hp-hpux"     % "cpu-vendor-os" string for GNU
readonly INSTALL_KEY  = BEGIN_CONFIG
  "What is your installation key?"
    14 %-- user specified key
END_CONFIG

readonly NAMING_CONVENTIONS = "0"
%                                        object files       libraries
%  0=Unix                          =>  .o   .io    .mo       libXX.a
%  1=Unix with a grumpy C compiler =>  .o   _i.o   _m.o      libXX.a
%  2=Windows NT or Windows 95      =>  .obj .io    .mo       XX.lib
%

%-------------------------------------------------- default compile options ---
% "set_config_options" is called before starting the compilation.  It should
% be used to provide system-wide default options.

proc set_config_options () is
  m3_option ("-why")   %-- produce a listing that explains what's happening and why
  m3_debug (TRUE)      %-- produce object code with debugging symbols
  M3_OPTIONS += "-w1"  %-- produce "level 1" warnings
end

%--------------------------------------------------------- Reactor defaults ---
% The first time a user runs Reactor, it will configure itself to use
% the executables defined below.

INITIAL_REACTOR_BROWSER = BEGIN_CONFIG
  "What should be the default World-Wide Web browser for new Reactor users?"
     0  "netscape"
     6 "/usr/local/bin"           "netscape"
     6 "/usr/local/netscape/bin"  "netscape"
     6 "/usr/local/netscape/bin"  "netscape-3"
     6 "/usr/local/netscape/bin"  "netscape-2"
     6 "/usr/local/netscape"      "netscape"
     6 "/usr/local/mosaic"        "mosaic"
     6 "/usr/local/moasic"        "Xmosaic"
END_CONFIG
% A World-Wide Web browser.  Reactor passes it an initial URL
% its first command-line argument.

INITIAL_REACTOR_EDITOR = BEGIN_CONFIG
  "What should be the default text editor for new Reactor users?"
    10 "EDITOR"
     0 "emacsclient"
     0 "emacs"
     0 "vi"
     0 "textedit"
     0 "xedit"
     6 "/usr/local/emacs/bin" "emacsclient"
     6 "/usr/local/bin"       "emacsclient"
     6 "/usr/local/emacs/bin" "emacs"
     6 "/usr/local/bin"       "emacs"
     6 "/usr/bin"             "vi"
     6 "/usr/local/X11R5/bin" "xedit"
     6 "/usr/openwin/bin"     "textedit"
     6 "/usr/openwin/bin"     "xedit"
     6 "/usr/X11/bin"         "xedit"
     6 "/usr/bin/X11"         "xedit"
END_CONFIG
% A text editor.  Reactor passes it "<file> +<line>" on the
% command-line when it wants to edit <file> initially positioned
% at <line>.

%------------------------------------------------------------- export paths ---
% During the installation, destination directories that do not exists 
% will be created. You need the necessary permissions to do so; otherwise,
% the installation will fail, but can be restarted after you have 
% fixed the permissions.

INSTALL_ROOT = BEGIN_CONFIG
  "Where should Reactor be installed?"
    7 %-- user specified install root
END_CONFIG

BIN_INSTALL   = INSTALL_ROOT & "/bin"        % executables
LIB_INSTALL   = INSTALL_ROOT & "/lib"        % libraries
PKG_INSTALL   = INSTALL_ROOT & "/pkg"        % packages
DOC_INSTALL   = INSTALL_ROOT & "/doc"        % documents
EMACS_INSTALL = INSTALL_ROOT & "/elisp"      % emacs lisp code
MAN_INSTALL   = INSTALL_ROOT & "/man"        % man pages
HTML_INSTALL  = INSTALL_ROOT & "/www"        % public hypertext

% On some systems (e.g. AFS) you must install public files in a different
% place from where you use them.  If that is the case for your system,
% specify the "use" location here, otherwise leave them alone.
%
USE_ROOT  = INSTALL_ROOT
BIN_USE   = BIN_INSTALL       % executables
LIB_USE   = LIB_INSTALL       % libraries
PKG_USE   = PKG_INSTALL       % packages

readonly INSTALL_IMPLS = TRUE
% TRUE
%    => save all source files during the install
%    => makes debugging easier and browsing more fruitful
% FALSE
%    => save only the exported interfaces and templates 
%    => makes the installed system slightly smaller.

%------------------------------------------------ external system libraries ---
% SYSTEM_LIBS provides a mapping from Modula-3 names for the common
% external libraries to site-dependent information about how they
% are accessed.  If SYSTEM_LIBS{x} is defined it should be a list
% of linker arguments that are used when linking against that library.
% If SYSTEM_LIBS{x} is not defined, the Modula-3 system will assume
% that the library is not available.

SYSTEM_LIBS = {
  "LIBC"       : [ "-Wl,-a,default", "-lm", "-lBSD" ],
  "LEX-YACC"   : [ "-Wl,-a,default", BEGIN_CONFIG
                     "Where are the lex/yacc libraries?"
                       11 "libl.a"
                       12 "/usr/lib"
                       12 "/usr/local/lib"
                       12 "/usr/local/gnu/lib"
                       13 "/usr/lib"
                   END_CONFIG, "-ll" ],
  "FLEX-BISON" : [ "-Wl,-a,default", BEGIN_CONFIG
                     "Where are the flex/bison libraries?"
                       11 "libfl.a"
                       12 "/usr/lib"
                       12 "/usr/local/lib"
                       12 "/usr/local/gnu/lib"
                       13 "/usr/lib"
                   END_CONFIG, "-lfl" ],
  "POSTGRES95" : [ "-Wl,-a,default", BEGIN_CONFIG
                     "Where are the Postgres95 libraries?"
                       11 "libpq.a"
                       12 "/usr/local/postgres95/lib"
                       12 "/usr/local/lib"
                       12 "/usr/lib"
                       13 "/usr/lib"
                   END_CONFIG, "-lpq" ],
  "ODBC"       : [ BEGIN_CONFIG
                     "Where are the ODBC libraries?"
                       11 "libodbc.a"
                       12 "/usr/local/lib"
                       12 "/usr/lib"
                       12 "/usr/local/pgsql/lib"
                       12 "/usr/local/postgres95/lib"
                       13 "/usr/local/lib"
                   END_CONFIG, "-lodbc" ],
  "OPENGL"     : [ "-Wl,-a,default", BEGIN_CONFIG
                     "Where are the OpenGL libraries?"
                       11 "libGLU.a"
                       11 "libGL.a"
                       12 "/usr/lib"
                       12 "/usr/lib/X11R4"
                       12 "/usr/local/lib"
                       12 "/usr/local/gnu/lib"
                       13 "/usr/lib"
                   END_CONFIG, "-lGLU", "-lGL",
                                     BEGIN_CONFIG
                     "Where are the X11 extension libraries?"
                       11 "libXext.a"
                       12 "/usr/lib"
                       12 "/usr/lib/X11R4"
                       12 "/usr/local/lib"
                       12 "/usr/local/gnu/lib"
                       13 "/usr/lib/X11R4"
                       13 "/usr/lib"
                   END_CONFIG, "-lXext" ],
  "MOTIF"      : [ "-Wl,-a,default", BEGIN_CONFIG
                     "Where are the Motif libraries?"
                       11 "libXm.a"
                       12 "/usr/lib/Motif1.2"
                       12 "/usr/lib"
                       12 "/usr/lib/X11R4"
                       12 "/usr/local/lib"
                       12 "/usr/local/gnu/lib"
                       13 "/usr/lib/X11R4"
                       13 "/usr/lib"
                   END_CONFIG, "-lXm" ],
  "X11"        : [ "-Wl,-a,default", BEGIN_CONFIG
                     "Where are the X11 libraries?"
                       11 "libXaw.a"
                       11 "libXmu.a"
                       11 "libXext.a"
                       11 "libXt.a"
                       11 "libX11.a"
                       12 "/usr/lib"
                       12 "/usr/lib/X11R4"
                       12 "/usr/local/lib"
                       12 "/usr/local/gnu/lib"
                       13 "/usr/lib/X11R4"
                       13 "/usr/lib"
                   END_CONFIG, "-lXaw",
                                     "-lXmu", "-lXext", "-lXt", "-lX11" ],
  "TCP"        : [ ]
}

% SYSTEM_LIBORDER defines the order in which SYSTEM_LIBS should be
% scanned by the linker.

SYSTEM_LIBORDER = [ "OPENGL", "DECPEX", "MOTIF", "X11", "TCP", "ODBC",
                    "POSTGRES95", "FLEX-BISON", "LEX-YACC", "LIBC" ]

%---------------------------------------------------------- system programs ---

readonly SYSTEM_CC  = BEGIN_CONFIG
  "Where is your C compiler?"
    0 "cc"
    6 "/bin"           "cc"
    6 "/usr/bin"       "cc"
    6 "/usr/local"     "cc"
    6 "/usr/local/bin" "cc"
    6 "/usr/local/gnu" "cc"
END_CONFIG % C compiler
readonly SYSTEM_LD  = BEGIN_CONFIG
  "Where is your linker?"
    0 "ld"
    6 "/bin"           "ld"
    6 "/usr/bin"       "ld"
    6 "/usr/local"     "ld"
    6 "/usr/local/bin" "ld"
    6 "/usr/local/gnu" "ld"
END_CONFIG % Linker
readonly SYSTEM_AR  = BEGIN_CONFIG
  "Where is your library archiver?"
    0 "ar"
    6 "/bin"           "ar"
    6 "/usr/bin"       "ar"
    6 "/usr/local"     "ar"
    6 "/usr/local/bin" "ar"
    6 "/usr/local/gnu" "ar"
END_CONFIG % Archiver
readonly SYSTEM_ASM = BEGIN_CONFIG
  "Where is your assembler?"
    0 "as"
    6 "/bin"           "as"
    6 "/usr/bin"       "as"
    6 "/usr/local"     "as"
    6 "/usr/local/bin" "as"
    6 "/usr/local/gnu" "as"
END_CONFIG % Assembler

%--------------------------------------------------------- Modula-3 backend ---
% For platforms without an integrated backend, "m3_backend" is called to
% translate Modula-3 intermediate code to object code.

readonly m3back = "@" & BIN_USE & "/cm3cg"

proc m3_backend (source, object, optimize, debug) is
  %%PIC local args = [ "-fPIC", "-O", "-quiet", source, "-o", object ]
  local args = [ "-O", "-quiet", source, "-o", object ]
  if debug     args += "-g"  end

  %% if optimize  args += "-O"  end
  %% GCC 2.7.2 generates bad code on HPPA if the optimizer is not
  %% enabled.  See forward_branch_p() in m3cc/gcc/config/pa/pa.c.

  return try_exec (m3back, args)
end

M3_BACKEND_MODE = "3"
% -- defines how the frontend, backend, and assembler interact
%  "0"  -- don't call m3_backend, M3CG produces object code
%  "1"  -- don't call m3_backend, M3CG produces assembly code
%  "2"  -- call m3_backend, it produces object code
%  "3"  -- call m3_backend, it produces assembly code

%--------------------------------------------------------------- C compiler ---
% "compile_c" is called to compile C source files.  Note that this function
% is only called if your program or library explicitly includes C source
% code, the system distributed by Critical Mass does not.

proc compile_c (source, object, options, optimize, debug) is
  %%PIC local args = [ "+Z", options ]  % +Z => -fPIC for cc
  %%PIC local args = [ "+z", options ]  % +Z => -fpic for cc
  local args = [ options, "-Dalloca=malloc" ]
  if optimize  args += "-O"  end
  if debug     args += "-g"  end
  return try_exec ("@" & SYSTEM_CC, args, "-c", source)
end

%% Using gcc
% proc compile_c (source, object, options, optimize, debug) is
%   local args = [ "-fPIC", "-z", options ] % gcc
%   if optimize  args += "-O"  end
%   if debug     args += "-g"  end
%   return try_exec ("@" & SYSTEM_CC, args, "-c", source)
% end

%---------------------------------------------------------------- assembler ---
% "assemble" is called to assemble .s or .asm files.  Note that this function
% is only called if your program or library explicitly includes assembly source
% code, the system distributed by Critical Mass does not.

readonly m3asm = "@" & BIN_USE & "/cm3as"  %== GNU as (v2.7)

proc assemble (source, object) is
  %% return try_exec ("@" & SYSTEM_ASM, "-s", "-K", "PIC", source, "-o", object)
  return try_exec (m3asm, source, "-o", object)
end

%--------------------------------------------------------- library creation ---
% "make_lib" is called to combine a collection of object modules into
% a library.

proc make_lib (lib, options, objects, imported_libs, shared) is
  local ret_code = 0
  local lib_a    = format ("lib%s.a", lib)
  local lib_sl   = format ("lib%s.sl", lib)

  % first, build the non-shared library
  ret_code = try_exec ("@" & SYSTEM_AR, "cru", lib_a, objects)
  if not equal (ret_code, 0) return ret_code end

%%PIC  if shared
%%PIC    % build the shared library
%%PIC    ret_code = try_exec ("@" & SYSTEM_LD, "-b -o", lib_sl, objects)
%%PIC    if not equal (ret_code, 0) return ret_code end
%%PIC
%%PIC    % finally, make sure the shared library stuff gets installed properly
%%PIC    install_derived (lib_sl)
%%PIC    install_link_to_derived (lib_sl, LIB_INSTALL)
%%PIC  else
    delete_file (lib_sl)
%%PIC  end

  return 0
end

%-------------------------------------------------------------------
% "skip_lib" is called when the compiler decides it doesn't need to
% call "make_lib", but it wants to discover the names of the derived
% files that should be deleted or shipped.

proc skip_lib (lib, shared) is
  local lib_sl = format ("lib%s.sl", lib)

%%PIC  if shared
%%PIC    % make sure the shared library stuff gets installed properly
%%PIC    install_derived (lib_sl)
%%PIC    install_link_to_derived (lib_sl, LIB_INSTALL)
%%PIC  else
    delete_file (lib_sl)
%%PIC  end

  return 0
end

%------------------------------------------------------------------- linker ---
% "m3_link" is called to produce a final executable.

proc m3_link (prog, options, objects, imported_libs, shared) is
  %% We'd use gcc as the linker, except it insists on moving
  %% the "-a archive" and "-a shared" linker arguments to the
  %% front of the argument list.  Boo, hiss.
  local linker = [ "@" & SYSTEM_CC,
                   "-Wl,-z",             %=> generate NIL faults
                %% "-Wl,+FP,VZOUI",      %=> generate IEEE FP faults
%%PIC                   "-Wl,+s",             %=> use $SHLIB_PATH
%%PIC                   "-Wl,+b," & LIB_USE   %=> then M3 LIB_INSTALL directory
                 ]
  local args = [ options, objects, imported_libs ]
  if shared
    return try_exec (linker, "-o", prog, args)
  else
    return try_exec (linker, "-o", prog, "-Wl,-a,archive", args)
  end
end

%-------------------------------------------------------------------
% "skip_link" is called when the compiler decides it doesn't need to
% call "m3_link", but it wants to discover the names of the derived
% files that should be deleted or shipped.

proc skip_link (prog, shared) is
  return 0
end

%------------------------------------------------------------ misc. options ---
% Note, most of these options can be set from the command line.  Otherwise,
% they can be set "permanently" here in the config file or in as needed
% in user's m3makefiles.

M3_FRONT_FLAGS = [ ]
% --- internal configuration options passed directly to the Modula-3 front-end

M3_OPTIONS = [ ]
% --- user options passed directly to the Modula-3 front-end

% M3_KEEP_FILES = TRUE
% --- keep intermediate and temporary files

% M3_WINDOWS_GUI = TRUE
% --- generate a Windows GUI subsystem program instead of a console one.

% M3_COVERAGE = TRUE
% --- compile & link with coverage options

M3_COVERAGE_LIB = LIB_USE & "/report_coverage.o"
% --- library linked in programs compiled with "-Z" coverage option

M3_SPLIT_LIBNAMES = TRUE
% --- split library names and pass -L/-l arguments to the linker

% M3_SHARED_LIB_ARG = "-R"
% --- pass "-R" flags to the linker too...

% M3_BOOTSTRAP = TRUE
% --- generate bootstrap code (assembly) instead of finaly object code

% M3_COMPILE_ONCE = TRUE
% --- don't recompile code to improve opaque object references

% SYS_HAS_LOADER = TRUE
% --- generate a loader info file with objects, libraries and timestamps

% M3_SKIP_LINK = TRUE
% --- skip the final link for programs, presumably to use the loader instead

% M3_MAIN_IN_C = TRUE
% --- generate the Modula-3 main program as C code

X11_WITH_SHARED_MEM = TRUE
% --- X11 libraries include the shared memory extensions (XShm...)

% M3_NEED_STANDALONE_LINKS = TRUE
% --- linker is broken and we need to build a directory of symbolic
%     links pointing to the non-shared libraries.

%-------------------------------------------------------------------- emacs ---
% If you have emacs and want to compile ".el" files to ".elc" files,
% fill in the function below.  Otherwise, comment out or delete the
% entire function.  Note, the distributed code assumes gnuemacs version 19
% or later.

readonly proc emacs_compile (el) is
  exec ("emacs -batch -f batch-byte-compile", el)
end

%------------------------------------------------------------- GNU variants ---
% The two large pieces of GNU software used by the Modula-3 system
% gcc(=m3cc) and gdb(=m3gdb) often require slightly different C compilers
% or flags.  They are specified here.  Note that they may be overridden
% from the m3build command line.
%
% To use the GNU defaults for CC and CFLAGS, specify "*".
%

GNU_CC     = "gcc"
GNU_CFLAGS = "-g"
GNU_MAKE   = "/usr/local/gnu/bin/make"

